Ejemplo n.º 1
0
void QgsGPSPlugin::loadGPXFile( const QString& fileName, bool loadWaypoints, bool loadRoutes,
                                bool loadTracks )
{
    //check if input file is readable
    QFileInfo fileInfo( fileName );
    if ( !fileInfo.isReadable() )
    {
        QMessageBox::warning( nullptr, tr( "GPX Loader" ),
                              tr( "Unable to read the selected file.\n"
                                  "Please reselect a valid file." ) );
        return;
    }

    // add the requested layers
    if ( loadTracks )
        emit drawVectorLayer( fileName + "?type=track",
                              fileInfo.baseName() + ", tracks", QStringLiteral( "gpx" ) );
    if ( loadRoutes )
        emit drawVectorLayer( fileName + "?type=route",
                              fileInfo.baseName() + ", routes", QStringLiteral( "gpx" ) );
    if ( loadWaypoints )
        emit drawVectorLayer( fileName + "?type=waypoint",
                              fileInfo.baseName() + ", waypoints", QStringLiteral( "gpx" ) );

    emit closeGui();
}
Ejemplo n.º 2
0
// Slot called when the buffer menu item is activated
void QgsE002shpPlugin::run()
{
  QgsE002shpPluginGui *myPluginGui=new QgsE002shpPluginGui(mQGisApp,"e002shp",true,0);
  //listen for when the layer has been made so we can draw it
  connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
  myPluginGui->show();
}
Ejemplo n.º 3
0
// Slot called when the buffer menu item is activated
void QgsDelimitedTextPlugin::run()
{
  QgsDelimitedTextPluginGui *myQgsDelimitedTextPluginGui =
    new QgsDelimitedTextPluginGui( qGisInterface,
                                   qGisInterface->mainWindow(), QgisGui::ModalDialogFlags );
  myQgsDelimitedTextPluginGui->setAttribute( Qt::WA_DeleteOnClose );
  //listen for when the layer has been made so we can draw it
  connect( myQgsDelimitedTextPluginGui,
           SIGNAL( drawVectorLayer( QString, QString, QString ) ),
           this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
  myQgsDelimitedTextPluginGui->exec();
}
Ejemplo n.º 4
0
// Slot called when the buffer menu item is activated
void IMExportPlugin::run()
{
  if (mQGisIface->activeLayer() == NULL ||
      mQGisIface->activeLayer()->type() != QgsMapLayer::VECTOR) {
    QMessageBox::critical(mQGisApp, "Error", 
			  "You must select a vector layer.");
    return;
  }
  
  IMExportPluginGui *myPluginGui=new IMExportPluginGui(mQGisIface, mQGisApp,"Image Map Exporter",true,0);
  //listen for when the layer has been made so we can draw it
  connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
  myPluginGui->show();
}
Ejemplo n.º 5
0
void eVis::launchDatabaseConnection()
{
  eVisDatabaseConnectionGui *myPluginGui = new eVisDatabaseConnectionGui( &mTemporaryFileList, mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
  myPluginGui->setAttribute( Qt::WA_DeleteOnClose );

  connect( myPluginGui, SIGNAL( drawVectorLayer( QString, QString, QString ) ), this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
  myPluginGui->show();
}
Ejemplo n.º 6
0
// Slot called when the menu item is activated
void QgsGPSPlugin::run()
{
    // find all GPX layers
    std::vector<QgsVectorLayer*> gpxLayers;
    QMap<QString, QgsMapLayer*>::const_iterator iter;
    QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
    QMap<QString, QgsMapLayer*> layers = registry->mapLayers();
    for ( iter = layers.constBegin();
            iter != layers.constEnd(); ++iter )
    {
        if ( iter.value()->type() == QgsMapLayer::VectorLayer )
        {
            QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( iter.value() );
            if ( vLayer->providerType() == QLatin1String( "gpx" ) )
                gpxLayers.push_back( vLayer );
        }
    }

    QgsGPSPluginGui *myPluginGui =
        new QgsGPSPluginGui( mImporters, mDevices, gpxLayers, mQGisInterface->mainWindow(),
                             QgisGui::ModalDialogFlags );
    myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
    //listen for when the layer has been made so we can draw it
    connect( myPluginGui, SIGNAL( drawVectorLayer( QString, QString, QString ) ),
             this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
    connect( myPluginGui, SIGNAL( loadGPXFile( QString, bool, bool, bool ) ),
             this, SLOT( loadGPXFile( QString, bool, bool, bool ) ) );
    connect( myPluginGui, SIGNAL( importGPSFile( QString, QgsBabelFormat*, bool,
                                  bool, bool, QString, QString ) ),
             this, SLOT( importGPSFile( QString, QgsBabelFormat*, bool, bool,
                                        bool, QString, QString ) ) );
    connect( myPluginGui, SIGNAL( convertGPSFile( QString, int,
                                  QString, QString ) ),
             this, SLOT( convertGPSFile( QString, int,
                                         QString, QString ) ) );
    connect( myPluginGui, SIGNAL( downloadFromGPS( QString, QString, bool, bool,
                                  bool, QString, QString ) ),
             this, SLOT( downloadFromGPS( QString, QString, bool, bool, bool,
                                          QString, QString ) ) );
    connect( myPluginGui, SIGNAL( uploadToGPS( QgsVectorLayer*, QString, QString ) ),
             this, SLOT( uploadToGPS( QgsVectorLayer*, QString, QString ) ) );
    connect( this, SIGNAL( closeGui() ), myPluginGui, SLOT( close() ) );

    myPluginGui->show();
}
Ejemplo n.º 7
0
void QgsGPSPlugin::createGPX()
{
    QSettings settings;
    QString dir = settings.value( QStringLiteral( "/Plugin-GPS/gpxdirectory" ), QDir::homePath() ).toString();
    QString fileName =
        QFileDialog::getSaveFileName( mQGisInterface->mainWindow(),
                                      tr( "Save new GPX file as..." ),
                                      dir,
                                      tr( "GPS eXchange file" ) + " (*.gpx)" );
    if ( !fileName.isEmpty() )
    {
        if ( !fileName.endsWith( QLatin1String( ".gpx" ), Qt::CaseInsensitive ) )
        {
            fileName += QLatin1String( ".gpx" );
        }
        QFileInfo fileInfo( fileName );
        std::ofstream ofs( fileName.toUtf8() );
        if ( !ofs )
        {
            QMessageBox::warning( nullptr, tr( "Could not create file" ),
                                  tr( "Unable to create a GPX file with the given name. "
                                      "Try again with another name or in another "
                                      "directory." ) );
            return;
        }
        settings.setValue( QStringLiteral( "/Plugin-GPS/gpxdirectory" ), fileInfo.absolutePath() );

        ofs << "<gpx></gpx>" << std::endl;

        emit drawVectorLayer( fileName + "?type=track",
                              fileInfo.baseName() + ", tracks", QStringLiteral( "gpx" ) );
        emit drawVectorLayer( fileName + "?type=route",
                              fileInfo.baseName() + ", routes", QStringLiteral( "gpx" ) );
        emit drawVectorLayer( fileName + "?type=waypoint",
                              fileInfo.baseName() + ", waypoints", QStringLiteral( "gpx" ) );
    }
}
Ejemplo n.º 8
0
/**
* Slot called after the user selects the x, y fields in the field selection gui component
* @param layerName - Name to display in the legend
* @param xCoordinate - Name of the field containing the x coordinate
* @param yCoordinate - Name of the field containing the y coordinate
*/
void eVisDatabaseConnectionGui::drawNewVectorLayer( const QString &layerName, const QString &xCoordinate, const QString &yCoordinate )
{
  //if coorindate fields are defined, load as a delimited text layer
  if ( !xCoordinate.isEmpty() && !yCoordinate.isEmpty() && !mTempOutputFileList->isEmpty() )
  {
    //fileName is only available if the file is open
    //the last file in the list is always the newest
    mTempOutputFileList->last()->open();
    QUrl url = QUrl::fromLocalFile( mTempOutputFileList->last()->fileName() );
    url.addQueryItem( QStringLiteral( "delimiter" ), QStringLiteral( "\t" ) );
    url.addQueryItem( QStringLiteral( "delimiterType" ), QStringLiteral( "regexp" ) );
    url.addQueryItem( QStringLiteral( "xField" ), xCoordinate );
    url.addQueryItem( QStringLiteral( "yField" ), yCoordinate );
    emit drawVectorLayer( QString::fromLatin1( url.toEncoded() ), layerName, QStringLiteral( "delimitedtext" ) );
    mTempOutputFileList->last()->close();
  }
}
Ejemplo n.º 9
0
void QgsGPSPlugin::downloadFromGPS( const QString& device, const QString& port,
                                    bool downloadWaypoints, bool downloadRoutes,
                                    bool downloadTracks, const QString& outputFileName,
                                    const QString& layerName )
{
    // what does the user want to download?
    QString typeArg, features;
    if ( downloadWaypoints )
    {
        typeArg = QStringLiteral( "-w" );
        features = QStringLiteral( "waypoints" );
    }
    else if ( downloadRoutes )
    {
        typeArg = QStringLiteral( "-r" );
        features = QStringLiteral( "routes" );
    }
    else if ( downloadTracks )
    {
        typeArg = QStringLiteral( "-t" );
        features = QStringLiteral( "tracks" );
    }

    // try to start the gpsbabel process
    QStringList babelArgs =
        mDevices[device]->importCommand( mBabelPath, typeArg,
                                         port, outputFileName );
    if ( babelArgs.isEmpty() )
    {
        QMessageBox::warning( nullptr, tr( "Not supported" ),
                              tr( "This device does not support downloading of %1." )
                              .arg( features ) );
        return;
    }

    QgsDebugMsg( QString( "Download command: " ) + babelArgs.join( "|" ) );

    QProcess babelProcess;
    babelProcess.start( babelArgs.join( QStringLiteral( " " ) ) );
    if ( !babelProcess.waitForStarted() )
    {
        QMessageBox::warning( nullptr, tr( "Could not start process" ),
                              tr( "Could not start GPSBabel!" ) );
        return;
    }

    // wait for gpsbabel to finish (or the user to cancel)
    QProgressDialog progressDialog( tr( "Downloading data..." ), tr( "Cancel" ), 0, 0 );
    progressDialog.setWindowModality( Qt::WindowModal );
    for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
    {
        progressDialog.setValue( i / 64 );
        if ( progressDialog.wasCanceled() )
            return;
    }

    // did we get any data?
    if ( babelProcess.exitStatus() != 0 )
    {
        QString babelError( babelProcess.readAllStandardError() );
        QString errorMsg( tr( "Could not download data from GPS!\n\n" ) );
        errorMsg += babelError;
        QMessageBox::warning( nullptr, tr( "Error downloading data" ), errorMsg );
        return;
    }

    // add the layer
    if ( downloadWaypoints )
        emit drawVectorLayer( outputFileName + "?type=waypoint",
                              layerName, QStringLiteral( "gpx" ) );
    if ( downloadRoutes )
        emit drawVectorLayer( outputFileName + "?type=route",
                              layerName, QStringLiteral( "gpx" ) );
    if ( downloadTracks )
        emit drawVectorLayer( outputFileName + "?type=track",
                              layerName, QStringLiteral( "gpx" ) );

    // everything was OK, remember the device and port for next time
    QSettings settings;
    settings.setValue( QStringLiteral( "/Plugin-GPS/lastdldevice" ), device );
    settings.setValue( QStringLiteral( "/Plugin-GPS/lastdlport" ), port );

    emit closeGui();
}
Ejemplo n.º 10
0
void QgsGPSPlugin::convertGPSFile( const QString& inputFileName,
                                   int convertType,
                                   const QString& outputFileName,
                                   const QString& layerName )
{
    // what features does the user want to import?
    QStringList convertStrings;

    switch ( convertType )
    {
    case 0:
        convertStrings << QStringLiteral( "-x" ) << QStringLiteral( "transform,wpt=rte,del" );
        break;
    case 1:
        convertStrings << QStringLiteral( "-x" ) << QStringLiteral( "transform,rte=wpt,del" );
        break;
    case 2:
        convertStrings << QStringLiteral( "-x" ) << QStringLiteral( "transform,trk=wpt,del" );
        break;
    case 3:
        convertStrings << QStringLiteral( "-x" ) << QStringLiteral( "transform,wpt=trk,del" );
        break;
    default:
        QgsDebugMsg( "Illegal conversion index!" );
        return;
    }

    // try to start the gpsbabel process
    QStringList babelArgs;
    babelArgs << mBabelPath << QStringLiteral( "-i" ) << QStringLiteral( "gpx" ) << QStringLiteral( "-f" ) << QStringLiteral( "\"%1\"" ).arg( inputFileName )
              << convertStrings << QStringLiteral( "-o" ) << QStringLiteral( "gpx" ) << QStringLiteral( "-F" ) << QStringLiteral( "\"%1\"" ).arg( outputFileName );
    QgsDebugMsg( QString( "Conversion command: " ) + babelArgs.join( "|" ) );

    QProcess babelProcess;
    babelProcess.start( babelArgs.join( QStringLiteral( " " ) ) );
    if ( !babelProcess.waitForStarted() )
    {
        QMessageBox::warning( nullptr, tr( "Could not start process" ),
                              tr( "Could not start GPSBabel!" ) );
        return;
    }

    // wait for gpsbabel to finish (or the user to cancel)
    QProgressDialog progressDialog( tr( "Importing data..." ), tr( "Cancel" ), 0, 0 );
    progressDialog.setWindowModality( Qt::WindowModal );
    for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
    {
        progressDialog.setValue( i / 64 );
        if ( progressDialog.wasCanceled() )
            return;
    }

    // did we get any data?
    if ( babelProcess.exitStatus() != 0 )
    {
        QString babelError( babelProcess.readAllStandardError() );
        QString errorMsg( tr( "Could not convert data from %1!\n\n" )
                          .arg( inputFileName ) );
        errorMsg += babelError;
        QMessageBox::warning( nullptr, tr( "Error converting data" ), errorMsg );
        return;
    }

    // add the layer
    switch ( convertType )
    {
    case 0:
    case 3:
        emit drawVectorLayer( outputFileName + "?type=waypoint",
                              layerName, QStringLiteral( "gpx" ) );
        break;
    case 1:
        emit drawVectorLayer( outputFileName + "?type=route",
                              layerName, QStringLiteral( "gpx" ) );
        break;
    case 2:
        emit drawVectorLayer( outputFileName + "?type=track",
                              layerName, QStringLiteral( "gpx" ) );
        break;
    default:
        QgsDebugMsg( "Illegal conversion index!" );
        return;
    }

    emit closeGui();
}
Ejemplo n.º 11
0
void QgsGPSPlugin::importGPSFile( const QString& inputFileName, QgsBabelFormat* importer,
                                  bool importWaypoints, bool importRoutes,
                                  bool importTracks, const QString& outputFileName,
                                  const QString& layerName )
{
    // what features does the user want to import?
    QString typeArg;
    if ( importWaypoints )
        typeArg = QStringLiteral( "-w" );
    else if ( importRoutes )
        typeArg = QStringLiteral( "-r" );
    else if ( importTracks )
        typeArg = QStringLiteral( "-t" );

    // try to start the gpsbabel process
    QStringList babelArgs =
        importer->importCommand( mBabelPath, typeArg,
                                 inputFileName, outputFileName );

    QgsDebugMsg( QString( "Import command: " ) + babelArgs.join( "|" ) );

    QProcess babelProcess;
    babelProcess.start( babelArgs.join( QStringLiteral( " " ) ) );
    if ( !babelProcess.waitForStarted() )
    {
        QMessageBox::warning( nullptr, tr( "Could not start process" ),
                              tr( "Could not start GPSBabel!" ) );
        return;
    }

    // wait for gpsbabel to finish (or the user to cancel)
    QProgressDialog progressDialog( tr( "Importing data..." ), tr( "Cancel" ), 0, 0 );
    progressDialog.setWindowModality( Qt::WindowModal );
    for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
    {
        progressDialog.setValue( i / 64 );
        if ( progressDialog.wasCanceled() )
            return;
    }

    babelProcess.waitForFinished();

    // did we get any data?
    if ( babelProcess.exitCode() != 0 )
    {
        QString babelError( babelProcess.readAllStandardError() );
        QString errorMsg( tr( "Could not import data from %1!\n\n" )
                          .arg( inputFileName ) );
        errorMsg += babelError;
        QMessageBox::warning( nullptr, tr( "Error importing data" ), errorMsg );
        return;
    }

    // add the layer
    if ( importTracks )
        emit drawVectorLayer( outputFileName + "?type=track",
                              layerName, QStringLiteral( "gpx" ) );
    if ( importRoutes )
        emit drawVectorLayer( outputFileName + "?type=route",
                              layerName, QStringLiteral( "gpx" ) );
    if ( importWaypoints )
        emit drawVectorLayer( outputFileName + "?type=waypoint",
                              layerName, QStringLiteral( "gpx" ) );

    emit closeGui();
}