@@ -35,6 +35,10 @@ QgsGPSPluginGui::QgsGPSPluginGui( const BabelMap& importers,
35
35
mImporters( importers ), mDevices( devices )
36
36
{
37
37
setupUi ( this );
38
+
39
+ // restore size, position and active tab
40
+ restoreState ();
41
+
38
42
populatePortComboBoxes ();
39
43
populateULLayerComboBox ();
40
44
populateIMPBabelFormats ();
@@ -80,17 +84,17 @@ QgsGPSPluginGui::~QgsGPSPluginGui()
80
84
81
85
void QgsGPSPluginGui::on_buttonBox_accepted ()
82
86
{
87
+ saveState ();
83
88
84
89
// what should we do?
85
90
switch ( tabWidget->currentIndex () )
86
91
{
87
- // add a GPX layer?
92
+ // add a GPX layer?
88
93
case 0 :
89
94
emit loadGPXFile ( leGPXFile->text (), cbGPXWaypoints->isChecked (),
90
95
cbGPXRoutes->isChecked (), cbGPXTracks->isChecked () );
91
96
break ;
92
-
93
- // or import other file?
97
+ // or import other file?
94
98
case 1 :
95
99
{
96
100
const QString& typeString ( cmbIMPFeature->currentText () );
@@ -109,7 +113,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
109
113
int featureType = cmbDLFeatureType->currentIndex ();
110
114
111
115
QString fileName = leDLOutput->text ();
112
- if ( fileName.right ( 4 ) != " .gpx" )
116
+ if ( ! fileName.toLower (). endsWith ( " .gpx" ) )
113
117
{
114
118
fileName += " .gpx" ;
115
119
}
@@ -140,24 +144,32 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
140
144
break ;
141
145
}
142
146
}
147
+
143
148
// The slots that are called above will emit closeGui() when successful.
144
149
// If not successful, the user will get another shot without starting from scratch
145
150
// accept();
146
151
}
147
152
148
-
149
153
void QgsGPSPluginGui::on_pbnDLOutput_clicked ()
150
154
{
155
+ QSettings settings;
156
+ QString dir = settings.value ( " /Plugin-GPS/gpxdirectory" , " ." ).toString ();
151
157
QString myFileNameQString =
152
- QFileDialog::getSaveFileName ( this , // parent dialog
158
+ QFileDialog::getSaveFileName ( this ,
153
159
tr ( " Choose a file name to save under" ),
154
- " . " , // initial dir
160
+ dir,
155
161
tr ( " GPS eXchange format (*.gpx)" ) );
156
162
if ( !myFileNameQString.isEmpty () )
163
+ {
164
+ if ( !myFileNameQString.toLower ().endsWith ( " .gpx" ) )
165
+ {
166
+ myFileNameQString += " .gpx" ;
167
+ }
157
168
leDLOutput->setText ( myFileNameQString );
169
+ settings.setValue ( " /Plugin-GPS/gpxdirectory" , QFileInfo ( myFileNameQString ).absolutePath () );
170
+ }
158
171
}
159
172
160
-
161
173
void QgsGPSPluginGui::enableRelevantControls ()
162
174
{
163
175
// load GPX
@@ -188,7 +200,6 @@ void QgsGPSPluginGui::enableRelevantControls()
188
200
// import other file
189
201
else if ( tabWidget->currentIndex () == 1 )
190
202
{
191
-
192
203
if (( leIMPInput->text () == " " ) || ( leIMPOutput->text () == " " ) ||
193
204
( leIMPLayer->text () == " " ) )
194
205
pbnOK->setEnabled ( false );
@@ -218,7 +229,6 @@ void QgsGPSPluginGui::enableRelevantControls()
218
229
// convert between waypoint/routes
219
230
else if ( tabWidget->currentIndex () == 4 )
220
231
{
221
-
222
232
if (( leCONVInput->text () == " " ) || ( leCONVOutput->text () == " " ) ||
223
233
( leCONVLayer->text () == " " ) )
224
234
pbnOK->setEnabled ( false );
@@ -227,45 +237,47 @@ void QgsGPSPluginGui::enableRelevantControls()
227
237
}
228
238
}
229
239
230
-
231
240
void QgsGPSPluginGui::on_buttonBox_rejected ()
232
241
{
242
+ saveState ();
233
243
reject ();
234
244
}
235
245
236
-
237
246
void QgsGPSPluginGui::on_pbnGPXSelectFile_clicked ()
238
247
{
239
248
QgsLogger::debug ( " Gps File Importer::pbnGPXSelectFile_clicked() " );
240
- QString myFileTypeQString;
241
- QString myFilterString = tr ( " GPS eXchange format (*.gpx)" );
242
249
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 ();
246
251
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)" ) );
253
256
if ( !myFileNameQString.isEmpty () )
257
+ {
254
258
leGPXFile->setText ( myFileNameQString );
259
+ settings.setValue ( " /Plugin-GPS/gpxdirectory" , QFileInfo ( myFileNameQString ).absolutePath () );
260
+ }
255
261
}
256
262
257
-
258
263
void QgsGPSPluginGui::on_pbnIMPInput_clicked ()
259
264
{
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 ();
261
269
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,
265
273
mBabelFilter ,
266
- &myFileType ); // the pointer to store selected filter
274
+ &myFileType );
267
275
if ( !myFileName.isEmpty () )
268
276
{
277
+ // save directory and file type
278
+ settings.setValue ( " /Plugin-GPS/importdirectory" , QFileInfo ( myFileName ).absolutePath () );
279
+ settings.setValue ( " /Plugin-GPS/lastImportFilter" , myFileType );
280
+
269
281
mImpFormat = myFileType.left ( myFileType.length () - 6 );
270
282
std::map<QString, QgsBabelFormat*>::const_iterator iter;
271
283
iter = mImporters .find ( mImpFormat );
@@ -289,16 +301,24 @@ void QgsGPSPluginGui::on_pbnIMPInput_clicked()
289
301
}
290
302
}
291
303
292
-
293
304
void QgsGPSPluginGui::on_pbnIMPOutput_clicked ()
294
305
{
306
+ QSettings settings;
307
+ QString dir = settings.value ( " /Plugin-GPS/gpxdirectory" , " ." ).toString ();
295
308
QString myFileNameQString =
296
- QFileDialog::getSaveFileName ( this , // parent dialog
309
+ QFileDialog::getSaveFileName ( this ,
297
310
tr ( " Choose a file name to save under" ),
298
- " . " , // initial dir
311
+ dir,
299
312
tr ( " GPS eXchange format (*.gpx)" ) );
300
313
if ( !myFileNameQString.isEmpty () )
314
+ {
315
+ if ( !myFileNameQString.toLower ().endsWith ( " .gpx" ) )
316
+ {
317
+ myFileNameQString += " .gpx" ;
318
+ }
301
319
leIMPOutput->setText ( myFileNameQString );
320
+ settings.setValue ( " /Plugin-GPS/gpxdirectory" , QFileInfo ( myFileNameQString ).absolutePath () );
321
+ }
302
322
}
303
323
304
324
void QgsGPSPluginGui::on_pbnRefresh_clicked ()
@@ -343,7 +363,6 @@ void QgsGPSPluginGui::populateULLayerComboBox()
343
363
cmbULLayer->addItem ( mGPXLayers [i]->name () );
344
364
}
345
365
346
-
347
366
void QgsGPSPluginGui::populateIMPBabelFormats ()
348
367
{
349
368
mBabelFilter = " " ;
@@ -375,31 +394,38 @@ void QgsGPSPluginGui::populateIMPBabelFormats()
375
394
376
395
void QgsGPSPluginGui::on_pbnCONVInput_clicked ()
377
396
{
378
- QString myFileTypeQString;
379
- QString myFilterString = tr ( " GPS eXchange format (*.gpx)" );
380
397
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 ();
384
399
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)" ) );
390
404
if ( !myFileNameQString.isEmpty () )
405
+ {
391
406
leCONVInput->setText ( myFileNameQString );
407
+ settings.setValue ( " /Plugin-GPS/gpxdirectory" , QFileInfo ( myFileNameQString ).absolutePath () );
408
+ }
392
409
}
393
410
394
411
void QgsGPSPluginGui::on_pbnCONVOutput_clicked ()
395
412
{
413
+ QSettings settings;
414
+ QString dir = settings.value ( " /Plugin-GPS/gpxdirectory" , " ." ).toString ();
396
415
QString myFileNameQString =
397
- QFileDialog::getSaveFileName ( this , // parent dialog
416
+ QFileDialog::getSaveFileName ( this ,
398
417
tr ( " Choose a file name to save under" ),
399
- " . " , // initial dir
418
+ dir,
400
419
tr ( " GPS eXchange format (*.gpx)" ) );
401
420
if ( !myFileNameQString.isEmpty () )
421
+ {
422
+ if ( !myFileNameQString.toLower ().endsWith ( " .gpx" ) )
423
+ {
424
+ myFileNameQString += " .gpx" ;
425
+ }
402
426
leCONVOutput->setText ( myFileNameQString );
427
+ settings.setValue ( " /Plugin-GPS/gpxdirectory" , QFileInfo ( myFileNameQString ).absolutePath () );
428
+ }
403
429
}
404
430
405
431
void QgsGPSPluginGui::openDeviceEditor ()
@@ -413,3 +439,17 @@ void QgsGPSPluginGui::devicesUpdated()
413
439
{
414
440
populateIMPBabelFormats ();
415
441
}
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