Skip to content

Commit

Permalink
Remove GPX feature type conversion from GPS tools plugin
Browse files Browse the repository at this point in the history
This functionality is now exposed by the processing algorithm instead
  • Loading branch information
nyalldawson committed Jul 30, 2021
1 parent d187a14 commit 8eff5e7
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 293 deletions.
89 changes: 0 additions & 89 deletions src/plugins/gps_importer/qgsgpsplugin.cpp
Expand Up @@ -130,8 +130,6 @@ void QgsGpsPlugin::run()
this, &QgsGpsPlugin::loadGPXFile );
connect( myPluginGui, &QgsGpsPluginGui::importGPSFile,
this, &QgsGpsPlugin::importGPSFile );
connect( myPluginGui, &QgsGpsPluginGui::convertGPSFile,
this, &QgsGpsPlugin::convertGPSFile );
connect( myPluginGui, &QgsGpsPluginGui::downloadFromGPS,
this, &QgsGpsPlugin::downloadFromGPS );
connect( myPluginGui, &QgsGpsPluginGui::uploadToGPS,
Expand Down Expand Up @@ -253,93 +251,6 @@ void QgsGpsPlugin::importGPSFile( const QString &inputFileName, QgsBabelFormat *
emit closeGui();
}

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( QStringLiteral( "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( QStringLiteral( "Conversion command: " ) + babelArgs.join( "|" ) );

QProcess babelProcess;
babelProcess.start( babelArgs.value( 0 ), babelArgs.mid( 1 ) );
if ( !babelProcess.waitForStarted() )
{
QMessageBox::warning( nullptr, tr( "Convert GPS File" ),
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( "Convert GPS File" ), errorMsg );
return;
}

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

emit closeGui();
}

void QgsGpsPlugin::downloadFromGPS( const QString &device, const QString &port,
bool downloadWaypoints, bool downloadRoutes,
bool downloadTracks, const QString &outputFileName,
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/gps_importer/qgsgpsplugin.h
Expand Up @@ -67,10 +67,6 @@ class QgsGpsPlugin: public QObject, public QgisPlugin
bool importWaypoints, bool importRoutes,
bool importTracks, const QString &outputFileName,
const QString &layerName );
void convertGPSFile( const QString &inputFileName,
int convertType,
const QString &outputFileName,
const QString &layerName );
void downloadFromGPS( const QString &device, const QString &port,
bool downloadWaypoints, bool downloadRoutes,
bool downloadTracks, const QString &outputFileName,
Expand Down
76 changes: 1 addition & 75 deletions src/plugins/gps_importer/qgsgpsplugingui.cpp
Expand Up @@ -39,8 +39,6 @@ QgsGpsPluginGui::QgsGpsPluginGui( const BabelMap &importers,
QgsGui::instance()->enableAutoGeometryRestore( this );
connect( pbnIMPInput, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnIMPInput_clicked );
connect( pbnIMPOutput, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnIMPOutput_clicked );
connect( pbnCONVInput, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnCONVInput_clicked );
connect( pbnCONVOutput, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnCONVOutput_clicked );
connect( pbnDLOutput, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnDLOutput_clicked );
connect( pbnRefresh, &QPushButton::clicked, this, &QgsGpsPluginGui::pbnRefresh_clicked );
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsGpsPluginGui::buttonBox_accepted );
Expand All @@ -53,7 +51,6 @@ QgsGpsPluginGui::QgsGpsPluginGui( const BabelMap &importers,
populatePortComboBoxes();
populateULLayerComboBox();
populateIMPBabelFormats();
populateCONVDialog();

connect( pbULEditDevices, &QAbstractButton::clicked, this, &QgsGpsPluginGui::openDeviceEditor );
connect( pbDLEditDevices, &QAbstractButton::clicked, this, &QgsGpsPluginGui::openDeviceEditor );
Expand All @@ -70,12 +67,6 @@ QgsGpsPluginGui::QgsGpsPluginGui( const BabelMap &importers,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leIMPLayer, &QLineEdit::textChanged,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leCONVInput, &QLineEdit::textChanged,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leCONVOutput, &QLineEdit::textChanged,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leCONVLayer, &QLineEdit::textChanged,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leDLOutput, &QLineEdit::textChanged,
this, &QgsGpsPluginGui::enableRelevantControls );
connect( leDLBasename, &QLineEdit::textChanged,
Expand Down Expand Up @@ -146,18 +137,6 @@ void QgsGpsPluginGui::buttonBox_accepted()
cmbULPort->currentData().toString() );
break;
}

case 4:
{
// or convert between waypoints/tracks=
int convertType = cmbCONVType->currentData().toInt();

emit convertGPSFile( leCONVInput->text(),
convertType,
leCONVOutput->text(),
leCONVLayer->text() );
break;
}
}

// The slots that are called above will emit closeGui() when successful.
Expand Down Expand Up @@ -228,16 +207,6 @@ void QgsGpsPluginGui::enableRelevantControls()
else
pbnOK->setEnabled( true );
}

// convert between waypoint/routes
else if ( tabWidget->currentIndex() == 4 )
{
if ( ( leCONVInput->text().isEmpty() ) || ( leCONVOutput->text().isEmpty() ) ||
( leCONVLayer->text().isEmpty() ) )
pbnOK->setEnabled( false );
else
pbnOK->setEnabled( true );
}
}

void QgsGpsPluginGui::buttonBox_rejected()
Expand Down Expand Up @@ -351,14 +320,6 @@ void QgsGpsPluginGui::populatePortComboBoxes()
cmbULPort->setCurrentIndex( idx < 0 ? 0 : idx );
}

void QgsGpsPluginGui::populateCONVDialog()
{
cmbCONVType->addItem( tr( "Waypoints from a Route" ), QVariant( int( 0 ) ) );
cmbCONVType->addItem( tr( "Waypoints from a Track" ), QVariant( int( 3 ) ) );
cmbCONVType->addItem( tr( "Route from Waypoints" ), QVariant( int( 1 ) ) );
cmbCONVType->addItem( tr( "Track from Waypoints" ), QVariant( int( 2 ) ) );
}

void QgsGpsPluginGui::populateULLayerComboBox()
{
for ( std::vector<QgsVectorLayer *>::size_type i = 0; i < mGPXLayers.size(); ++i )
Expand Down Expand Up @@ -394,41 +355,6 @@ void QgsGpsPluginGui::populateIMPBabelFormats()
cmbDLDevice->setCurrentIndex( d );
}

void QgsGpsPluginGui::pbnCONVInput_clicked()
{
QgsSettings settings;
QString dir = settings.value( QStringLiteral( "Plugin-GPS/gpxdirectory" ), QDir::homePath() ).toString();
QString myFileNameQString = QFileDialog::getOpenFileName(
this,
tr( "Select GPX file" ),
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
leCONVInput->setText( myFileNameQString );
settings.setValue( QStringLiteral( "Plugin-GPS/gpxdirectory" ), QFileInfo( myFileNameQString ).absolutePath() );
}
}

void QgsGpsPluginGui::pbnCONVOutput_clicked()
{
QgsSettings settings;
QString dir = settings.value( QStringLiteral( "Plugin-GPS/gpxdirectory" ), QDir::homePath() ).toString();
QString myFileNameQString =
QFileDialog::getSaveFileName( this,
tr( "Choose a file name to save under" ),
dir,
tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.endsWith( QLatin1String( ".gpx" ), Qt::CaseInsensitive ) )
{
myFileNameQString += QLatin1String( ".gpx" );
}
leCONVOutput->setText( myFileNameQString );
settings.setValue( QStringLiteral( "Plugin-GPS/gpxdirectory" ), QFileInfo( myFileNameQString ).absolutePath() );
}
}

void QgsGpsPluginGui::openDeviceEditor()
{
Expand All @@ -445,7 +371,7 @@ void QgsGpsPluginGui::devicesUpdated()
void QgsGpsPluginGui::restoreState()
{
QgsSettings settings;
tabWidget->setCurrentIndex( settings.value( QStringLiteral( "Plugin-GPS/lastTab" ), 4 ).toInt() );
tabWidget->setCurrentIndex( settings.value( QStringLiteral( "Plugin-GPS/lastTab" ), 0 ).toInt() );
}

void QgsGpsPluginGui::showHelp()
Expand Down
8 changes: 0 additions & 8 deletions src/plugins/gps_importer/qgsgpsplugingui.h
Expand Up @@ -53,17 +53,13 @@ class QgsGpsPluginGui : public QDialog, private Ui::QgsGpsPluginGuiBase
void pbnIMPInput_clicked();
void pbnIMPOutput_clicked();

void pbnCONVInput_clicked();
void pbnCONVOutput_clicked();

void pbnDLOutput_clicked();

private:
void populateDeviceComboBox();
void populateULLayerComboBox();
void populateIMPBabelFormats();
void populatePortComboBoxes();
void populateCONVDialog();

void saveState();
void restoreState();
Expand Down Expand Up @@ -91,10 +87,6 @@ class QgsGpsPluginGui : public QDialog, private Ui::QgsGpsPluginGuiBase
bool importWaypoints, bool importRoutes,
bool importTracks, const QString &outputFileName,
const QString &layerName );
void convertGPSFile( const QString &inputFileName,
int convertType,
const QString &outputFileName,
const QString &layerName );
void downloadFromGPS( const QString &device, const QString &port, bool downloadWaypoints,
bool downloadRoutes, bool downloadTracks,
const QString &outputFileName, const QString &layerName );
Expand Down

0 comments on commit 8eff5e7

Please sign in to comment.