Skip to content

Commit e531a53

Browse files
committedJan 12, 2012
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 8d65c97 commit e531a53

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
@@ -80,7 +80,6 @@ QgsGPSPlugin::~QgsGPSPlugin()
8080
delete iter2->second;
8181
}
8282

83-
8483
/*
8584
* Initialize the GUI interface for the plugin
8685
*/
@@ -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 )
@@ -213,7 +214,6 @@ void QgsGPSPlugin::unload()
213214
void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadRoutes,
214215
bool loadTracks )
215216
{
216-
217217
//check if input file is readable
218218
QFileInfo fileInfo( fileName );
219219
if ( !fileInfo.isReadable() )
@@ -224,10 +224,6 @@ void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadR
224224
return;
225225
}
226226

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

245-
246241
void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importer,
247242
bool importWaypoints, bool importRoutes,
248243
bool importTracks, QString outputFileName,
249244
QString layerName )
250245
{
251-
252246
// what features does the user want to import?
253247
QString typeArg;
254248
if ( importWaypoints )
@@ -311,15 +305,12 @@ void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importe
311305
emit closeGui();
312306
}
313307

314-
315308
void QgsGPSPlugin::convertGPSFile( QString inputFileName,
316309
int convertType,
317310
QString outputFileName,
318311
QString layerName )
319312
{
320-
321313
// what features does the user want to import?
322-
323314
QStringList convertStrings;
324315

325316
switch ( convertType )
@@ -402,7 +393,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
402393
bool downloadTracks, QString outputFileName,
403394
QString layerName )
404395
{
405-
406396
// what does the user want to download?
407397
QString typeArg, features;
408398
if ( downloadWaypoints )
@@ -433,7 +423,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
433423
return;
434424
}
435425

436-
437426
QgsDebugMsg( QString( "Download command: " ) + babelArgs.join( "|" ) );
438427

439428
QProcess babelProcess;
@@ -484,11 +473,9 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
484473
emit closeGui();
485474
}
486475

487-
488476
void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
489477
QString port )
490478
{
491-
492479
const QString& source( gpxLayer->dataProvider()->dataSourceUri() );
493480

494481
// what kind of data does the user want to upload?
@@ -565,10 +552,8 @@ void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
565552
emit closeGui();
566553
}
567554

568-
569555
void QgsGPSPlugin::setupBabel()
570556
{
571-
572557
// where is gpsbabel?
573558
QSettings settings;
574559
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
mImporters( importers ), 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+
}

‎src/plugins/gps_importer/qgsgpsplugingui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class QgsGPSPluginGui : public QDialog, private Ui::QgsGPSPluginGuiBase
6666
void populatePortComboBoxes();
6767
void populateCONVDialog();
6868

69+
void saveState();
70+
void restoreState();
71+
6972
#if 0
7073
void populateLoadDialog();
7174
void populateDLDialog();

0 commit comments

Comments
 (0)
Please sign in to comment.