Skip to content

Commit 1c3117e

Browse files
committed
save last used dirs and last used filter in GPSTools plugin (fix #1209).
Also remember dialog size and position and restore them (addresses #206)
1 parent 9b25791 commit 1c3117e

File tree

3 files changed

+93
-65
lines changed

3 files changed

+93
-65
lines changed

src/plugins/gps_importer/qgsgpsplugin.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ QgsGPSPlugin::~QgsGPSPlugin()
7979
delete iter2->second;
8080
}
8181

82-
8382
/*
8483
* Initialize the GUI interface for the plugin
8584
*/
@@ -156,13 +155,14 @@ void QgsGPSPlugin::run()
156155
myPluginGui->show();
157156
}
158157

159-
160158
void QgsGPSPlugin::createGPX()
161159
{
160+
QSettings settings;
161+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
162162
QString fileName =
163163
QFileDialog::getSaveFileName( mQGisInterface->mainWindow(),
164164
tr( "Save new GPX file as..." ),
165-
".",
165+
dir,
166166
tr( "GPS eXchange file (*.gpx)" ) );
167167
if ( !fileName.isEmpty() )
168168
{
@@ -180,6 +180,8 @@ void QgsGPSPlugin::createGPX()
180180
"directory." ) );
181181
return;
182182
}
183+
settings.setValue( "/Plugin-GPS/gpxdirectory", fileInfo.absolutePath() );
184+
183185
ofs << "<gpx></gpx>" << std::endl;
184186

185187
emit drawVectorLayer( fileName + "?type=track",
@@ -191,7 +193,6 @@ void QgsGPSPlugin::createGPX()
191193
}
192194
}
193195

194-
195196
void QgsGPSPlugin::drawVectorLayer( QString thePathNameQString,
196197
QString theBaseNameQString,
197198
QString theProviderQString )
@@ -214,7 +215,6 @@ void QgsGPSPlugin::unload()
214215
void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadRoutes,
215216
bool loadTracks )
216217
{
217-
218218
//check if input file is readable
219219
QFileInfo fileInfo( fileName );
220220
if ( !fileInfo.isReadable() )
@@ -225,10 +225,6 @@ void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadR
225225
return;
226226
}
227227

228-
// remember the directory
229-
QSettings settings;
230-
settings.setValue( "/Plugin-GPS/gpxdirectory", fileInfo.path() );
231-
232228
// add the requested layers
233229
if ( loadTracks )
234230
emit drawVectorLayer( fileName + "?type=track",
@@ -243,13 +239,11 @@ void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadR
243239
emit closeGui();
244240
}
245241

246-
247242
void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importer,
248243
bool importWaypoints, bool importRoutes,
249244
bool importTracks, QString outputFileName,
250245
QString layerName )
251246
{
252-
253247
// what features does the user want to import?
254248
QString typeArg;
255249
if ( importWaypoints )
@@ -312,15 +306,12 @@ void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importe
312306
emit closeGui();
313307
}
314308

315-
316309
void QgsGPSPlugin::convertGPSFile( QString inputFileName,
317310
int convertType,
318311
QString outputFileName,
319312
QString layerName )
320313
{
321-
322314
// what features does the user want to import?
323-
324315
QStringList convertStrings;
325316

326317
switch ( convertType )
@@ -399,7 +390,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
399390
bool downloadTracks, QString outputFileName,
400391
QString layerName )
401392
{
402-
403393
// what does the user want to download?
404394
QString typeArg, features;
405395
if ( downloadWaypoints )
@@ -430,7 +420,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
430420
return;
431421
}
432422

433-
434423
QgsDebugMsg( QString( "Download command: " ) + babelArgs.join( "|" ) );
435424

436425
QProcess babelProcess;
@@ -481,11 +470,9 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
481470
emit closeGui();
482471
}
483472

484-
485473
void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
486474
QString port )
487475
{
488-
489476
const QString& source( gpxLayer->dataProvider()->dataSourceUri() );
490477

491478
// what kind of data does the user want to upload?
@@ -562,10 +549,8 @@ void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
562549
emit closeGui();
563550
}
564551

565-
566552
void QgsGPSPlugin::setupBabel()
567553
{
568-
569554
// where is gpsbabel?
570555
QSettings settings;
571556
mBabelPath = settings.value( "/Plugin-GPS/gpsbabelpath", "" ).toString();

src/plugins/gps_importer/qgsgpsplugingui.cpp

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ QgsGPSPluginGui::QgsGPSPluginGui( const BabelMap& importers,
3535
, mDevices( devices )
3636
{
3737
setupUi( this );
38+
39+
// restore size, position and active tab
40+
restoreState();
41+
3842
populatePortComboBoxes();
3943
populateULLayerComboBox();
4044
populateIMPBabelFormats();
@@ -80,17 +84,17 @@ QgsGPSPluginGui::~QgsGPSPluginGui()
8084

8185
void QgsGPSPluginGui::on_buttonBox_accepted()
8286
{
87+
saveState();
8388

8489
// what should we do?
8590
switch ( tabWidget->currentIndex() )
8691
{
87-
// add a GPX layer?
92+
// add a GPX layer?
8893
case 0:
8994
emit loadGPXFile( leGPXFile->text(), cbGPXWaypoints->isChecked(),
9095
cbGPXRoutes->isChecked(), cbGPXTracks->isChecked() );
9196
break;
92-
93-
// or import other file?
97+
// or import other file?
9498
case 1:
9599
{
96100
const QString& typeString( cmbIMPFeature->currentText() );
@@ -109,7 +113,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
109113
int featureType = cmbDLFeatureType->currentIndex();
110114

111115
QString fileName = leDLOutput->text();
112-
if ( fileName.right( 4 ) != ".gpx" )
116+
if ( !fileName.toLower().endsWith( ".gpx" ) )
113117
{
114118
fileName += ".gpx";
115119
}
@@ -140,24 +144,32 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
140144
break;
141145
}
142146
}
147+
143148
// The slots that are called above will emit closeGui() when successful.
144149
// If not successful, the user will get another shot without starting from scratch
145150
// accept();
146151
}
147152

148-
149153
void QgsGPSPluginGui::on_pbnDLOutput_clicked()
150154
{
155+
QSettings settings;
156+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
151157
QString myFileNameQString =
152-
QFileDialog::getSaveFileName( this, //parent dialog
158+
QFileDialog::getSaveFileName( this,
153159
tr( "Choose a file name to save under" ),
154-
".", //initial dir
160+
dir,
155161
tr( "GPS eXchange format (*.gpx)" ) );
156162
if ( !myFileNameQString.isEmpty() )
163+
{
164+
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
165+
{
166+
myFileNameQString += ".gpx";
167+
}
157168
leDLOutput->setText( myFileNameQString );
169+
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
170+
}
158171
}
159172

160-
161173
void QgsGPSPluginGui::enableRelevantControls()
162174
{
163175
// load GPX
@@ -188,7 +200,6 @@ void QgsGPSPluginGui::enableRelevantControls()
188200
// import other file
189201
else if ( tabWidget->currentIndex() == 1 )
190202
{
191-
192203
if (( leIMPInput->text() == "" ) || ( leIMPOutput->text() == "" ) ||
193204
( leIMPLayer->text() == "" ) )
194205
pbnOK->setEnabled( false );
@@ -218,7 +229,6 @@ void QgsGPSPluginGui::enableRelevantControls()
218229
// convert between waypoint/routes
219230
else if ( tabWidget->currentIndex() == 4 )
220231
{
221-
222232
if (( leCONVInput->text() == "" ) || ( leCONVOutput->text() == "" ) ||
223233
( leCONVLayer->text() == "" ) )
224234
pbnOK->setEnabled( false );
@@ -227,45 +237,47 @@ void QgsGPSPluginGui::enableRelevantControls()
227237
}
228238
}
229239

230-
231240
void QgsGPSPluginGui::on_buttonBox_rejected()
232241
{
242+
saveState();
233243
reject();
234244
}
235245

236-
237246
void QgsGPSPluginGui::on_pbnGPXSelectFile_clicked()
238247
{
239248
QgsLogger::debug( " GPS File Importer::pbnGPXSelectFile_clicked() " );
240-
QString myFileTypeQString;
241-
QString myFilterString = tr( "GPS eXchange format (*.gpx)" );
242249
QSettings settings;
243-
QString dir = settings.value( "/Plugin-GPS/gpxdirectory" ).toString();
244-
if ( dir.isEmpty() )
245-
dir = ".";
250+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
246251
QString myFileNameQString = QFileDialog::getOpenFileName(
247-
this, //parent dialog
248-
tr( "Select GPX file" ), //caption
249-
dir, //initial dir
250-
myFilterString, //filters to select
251-
&myFileTypeQString ); //the pointer to store selected filter
252-
QgsLogger::debug( "Selected filetype filter is : " + myFileTypeQString );
252+
this,
253+
tr( "Select GPX file" ),
254+
dir,
255+
tr( "GPS eXchange format (*.gpx)" ) );
253256
if ( !myFileNameQString.isEmpty() )
257+
{
254258
leGPXFile->setText( myFileNameQString );
259+
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
260+
}
255261
}
256262

257-
258263
void QgsGPSPluginGui::on_pbnIMPInput_clicked()
259264
{
260-
QString myFileType;
265+
QSettings settings;
266+
QString dir = settings.value( "/Plugin-GPS/importdirectory", "." ).toString();
267+
QString tf = mBabelFilter.split( ";;" ).first();
268+
QString myFileType = settings.value( "/Plugin-GPS/lastImportFilter", tf ).toString();
261269
QString myFileName = QFileDialog::getOpenFileName(
262-
this, //parent dialog
263-
tr( "Select file and format to import" ), //caption
264-
".", //initial dir
270+
this,
271+
tr( "Select file and format to import" ),
272+
dir,
265273
mBabelFilter,
266-
&myFileType ); //the pointer to store selected filter
274+
&myFileType );
267275
if ( !myFileName.isEmpty() )
268276
{
277+
// save directory and file type
278+
settings.setValue( "/Plugin-GPS/importdirectory", QFileInfo( myFileName ).absolutePath() );
279+
settings.setValue( "/Plugin-GPS/lastImportFilter", myFileType );
280+
269281
mImpFormat = myFileType.left( myFileType.length() - 6 );
270282
std::map<QString, QgsBabelFormat*>::const_iterator iter;
271283
iter = mImporters.find( mImpFormat );
@@ -289,16 +301,24 @@ void QgsGPSPluginGui::on_pbnIMPInput_clicked()
289301
}
290302
}
291303

292-
293304
void QgsGPSPluginGui::on_pbnIMPOutput_clicked()
294305
{
306+
QSettings settings;
307+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
295308
QString myFileNameQString =
296-
QFileDialog::getSaveFileName( this, //parent dialog
309+
QFileDialog::getSaveFileName( this,
297310
tr( "Choose a file name to save under" ),
298-
".", //initial dir
311+
dir,
299312
tr( "GPS eXchange format (*.gpx)" ) );
300313
if ( !myFileNameQString.isEmpty() )
314+
{
315+
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
316+
{
317+
myFileNameQString += ".gpx";
318+
}
301319
leIMPOutput->setText( myFileNameQString );
320+
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
321+
}
302322
}
303323

304324
void QgsGPSPluginGui::on_pbnRefresh_clicked()
@@ -343,7 +363,6 @@ void QgsGPSPluginGui::populateULLayerComboBox()
343363
cmbULLayer->addItem( mGPXLayers[i]->name() );
344364
}
345365

346-
347366
void QgsGPSPluginGui::populateIMPBabelFormats()
348367
{
349368
mBabelFilter = "";
@@ -375,31 +394,38 @@ void QgsGPSPluginGui::populateIMPBabelFormats()
375394

376395
void QgsGPSPluginGui::on_pbnCONVInput_clicked()
377396
{
378-
QString myFileTypeQString;
379-
QString myFilterString = tr( "GPS eXchange format (*.gpx)" );
380397
QSettings settings;
381-
QString dir = settings.value( "/Plugin-GPS/gpxdirectory" ).toString();
382-
if ( dir.isEmpty() )
383-
dir = ".";
398+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
384399
QString myFileNameQString = QFileDialog::getOpenFileName(
385-
this, //parent dialog
386-
tr( "Select GPX file" ), //caption
387-
dir, //initial dir
388-
myFilterString, //filters to select
389-
&myFileTypeQString ); //the pointer to store selected filter
400+
this,
401+
tr( "Select GPX file" ),
402+
dir,
403+
tr( "GPS eXchange format (*.gpx)" ) );
390404
if ( !myFileNameQString.isEmpty() )
405+
{
391406
leCONVInput->setText( myFileNameQString );
407+
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
408+
}
392409
}
393410

394411
void QgsGPSPluginGui::on_pbnCONVOutput_clicked()
395412
{
413+
QSettings settings;
414+
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
396415
QString myFileNameQString =
397-
QFileDialog::getSaveFileName( this, //parent dialog
416+
QFileDialog::getSaveFileName( this,
398417
tr( "Choose a file name to save under" ),
399-
".", //initial dir
418+
dir,
400419
tr( "GPS eXchange format (*.gpx)" ) );
401420
if ( !myFileNameQString.isEmpty() )
421+
{
422+
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
423+
{
424+
myFileNameQString += ".gpx";
425+
}
402426
leCONVOutput->setText( myFileNameQString );
427+
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
428+
}
403429
}
404430

405431
void QgsGPSPluginGui::openDeviceEditor()
@@ -413,3 +439,17 @@ void QgsGPSPluginGui::devicesUpdated()
413439
{
414440
populateIMPBabelFormats();
415441
}
442+
443+
void QgsGPSPluginGui::saveState()
444+
{
445+
QSettings settings;
446+
settings.setValue( "/Plugin-GPS/geometry", saveGeometry() );
447+
settings.setValue( "/Plugin-GPS/lastTab", tabWidget->currentIndex() );
448+
}
449+
450+
void QgsGPSPluginGui::restoreState()
451+
{
452+
QSettings settings;
453+
restoreGeometry( settings.value( "/Plugin-GPS/geometry" ).toByteArray() );
454+
tabWidget->setCurrentIndex( settings.value( "/Plugin-GPS/lastTab", 4 ).toInt() );
455+
}

0 commit comments

Comments
 (0)