Skip to content
Permalink
Browse files

save last used dirs and last used filter in GPSTools plugin (fix #1209).

Also remember dialog size and position and restore them (addresses #206)
  • Loading branch information
alexbruy committed Jan 12, 2012
1 parent 8d65c97 commit e531a53e0e643856a7a4976582eae636b2a920ac
@@ -80,7 +80,6 @@ QgsGPSPlugin::~QgsGPSPlugin()
delete iter2->second;
}


/*
* Initialize the GUI interface for the plugin
*/
@@ -156,13 +155,14 @@ void QgsGPSPlugin::run()
myPluginGui->show();
}


void QgsGPSPlugin::createGPX()
{
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString fileName =
QFileDialog::getSaveFileName( mQGisInterface->mainWindow(),
tr( "Save new GPX file as..." ),
".",
dir,
tr( "GPS eXchange file (*.gpx)" ) );
if ( !fileName.isEmpty() )
{
@@ -180,6 +180,8 @@ void QgsGPSPlugin::createGPX()
"directory." ) );
return;
}
settings.setValue( "/Plugin-GPS/gpxdirectory", fileInfo.absolutePath() );

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

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


void QgsGPSPlugin::drawVectorLayer( QString thePathNameQString,
QString theBaseNameQString,
QString theProviderQString )
@@ -213,7 +214,6 @@ void QgsGPSPlugin::unload()
void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadRoutes,
bool loadTracks )
{

//check if input file is readable
QFileInfo fileInfo( fileName );
if ( !fileInfo.isReadable() )
@@ -224,10 +224,6 @@ void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadR
return;
}

// remember the directory
QSettings settings;
settings.setValue( "/Plugin-GPS/gpxdirectory", fileInfo.path() );

// add the requested layers
if ( loadTracks )
emit drawVectorLayer( fileName + "?type=track",
@@ -242,13 +238,11 @@ void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadR
emit closeGui();
}


void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importer,
bool importWaypoints, bool importRoutes,
bool importTracks, QString outputFileName,
QString layerName )
{

// what features does the user want to import?
QString typeArg;
if ( importWaypoints )
@@ -311,15 +305,12 @@ void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importe
emit closeGui();
}


void QgsGPSPlugin::convertGPSFile( QString inputFileName,
int convertType,
QString outputFileName,
QString layerName )
{

// what features does the user want to import?

QStringList convertStrings;

switch ( convertType )
@@ -402,7 +393,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
bool downloadTracks, QString outputFileName,
QString layerName )
{

// what does the user want to download?
QString typeArg, features;
if ( downloadWaypoints )
@@ -433,7 +423,6 @@ void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
return;
}


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

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


void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
QString port )
{

const QString& source( gpxLayer->dataProvider()->dataSourceUri() );

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


void QgsGPSPlugin::setupBabel()
{

// where is gpsbabel?
QSettings settings;
mBabelPath = settings.value( "/Plugin-GPS/gpsbabelpath", "" ).toString();
@@ -35,6 +35,10 @@ QgsGPSPluginGui::QgsGPSPluginGui( const BabelMap& importers,
mImporters( importers ), mDevices( devices )
{
setupUi( this );

// restore size, position and active tab
restoreState();

populatePortComboBoxes();
populateULLayerComboBox();
populateIMPBabelFormats();
@@ -80,17 +84,17 @@ QgsGPSPluginGui::~QgsGPSPluginGui()

void QgsGPSPluginGui::on_buttonBox_accepted()
{
saveState();

// what should we do?
switch ( tabWidget->currentIndex() )
{
// add a GPX layer?
// add a GPX layer?
case 0:
emit loadGPXFile( leGPXFile->text(), cbGPXWaypoints->isChecked(),
cbGPXRoutes->isChecked(), cbGPXTracks->isChecked() );
break;

// or import other file?
// or import other file?
case 1:
{
const QString& typeString( cmbIMPFeature->currentText() );
@@ -109,7 +113,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
int featureType = cmbDLFeatureType->currentIndex();

QString fileName = leDLOutput->text();
if ( fileName.right( 4 ) != ".gpx" )
if ( !fileName.toLower().endsWith( ".gpx" ) )
{
fileName += ".gpx";
}
@@ -140,24 +144,32 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
break;
}
}

// The slots that are called above will emit closeGui() when successful.
// If not successful, the user will get another shot without starting from scratch
// accept();
}


void QgsGPSPluginGui::on_pbnDLOutput_clicked()
{
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString myFileNameQString =
QFileDialog::getSaveFileName( this, //parent dialog
QFileDialog::getSaveFileName( this,
tr( "Choose a file name to save under" ),
".", //initial dir
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
{
myFileNameQString += ".gpx";
}
leDLOutput->setText( myFileNameQString );
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
}
}


void QgsGPSPluginGui::enableRelevantControls()
{
// load GPX
@@ -188,7 +200,6 @@ void QgsGPSPluginGui::enableRelevantControls()
// import other file
else if ( tabWidget->currentIndex() == 1 )
{

if (( leIMPInput->text() == "" ) || ( leIMPOutput->text() == "" ) ||
( leIMPLayer->text() == "" ) )
pbnOK->setEnabled( false );
@@ -218,7 +229,6 @@ void QgsGPSPluginGui::enableRelevantControls()
// convert between waypoint/routes
else if ( tabWidget->currentIndex() == 4 )
{

if (( leCONVInput->text() == "" ) || ( leCONVOutput->text() == "" ) ||
( leCONVLayer->text() == "" ) )
pbnOK->setEnabled( false );
@@ -227,45 +237,47 @@ void QgsGPSPluginGui::enableRelevantControls()
}
}


void QgsGPSPluginGui::on_buttonBox_rejected()
{
saveState();
reject();
}


void QgsGPSPluginGui::on_pbnGPXSelectFile_clicked()
{
QgsLogger::debug( " Gps File Importer::pbnGPXSelectFile_clicked() " );
QString myFileTypeQString;
QString myFilterString = tr( "GPS eXchange format (*.gpx)" );
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory" ).toString();
if ( dir.isEmpty() )
dir = ".";
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString myFileNameQString = QFileDialog::getOpenFileName(
this, //parent dialog
tr( "Select GPX file" ), //caption
dir, //initial dir
myFilterString, //filters to select
&myFileTypeQString ); //the pointer to store selected filter
QgsLogger::debug( "Selected filetype filter is : " + myFileTypeQString );
this,
tr( "Select GPX file" ),
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
leGPXFile->setText( myFileNameQString );
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
}
}


void QgsGPSPluginGui::on_pbnIMPInput_clicked()
{
QString myFileType;
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/importdirectory", "." ).toString();
QString tf = mBabelFilter.split( ";;" ).first();
QString myFileType = settings.value( "/Plugin-GPS/lastImportFilter", tf ).toString();
QString myFileName = QFileDialog::getOpenFileName(
this, //parent dialog
tr( "Select file and format to import" ), //caption
".", //initial dir
this,
tr( "Select file and format to import" ),
dir,
mBabelFilter,
&myFileType ); //the pointer to store selected filter
&myFileType );
if ( !myFileName.isEmpty() )
{
// save directory and file type
settings.setValue( "/Plugin-GPS/importdirectory", QFileInfo( myFileName ).absolutePath() );
settings.setValue( "/Plugin-GPS/lastImportFilter", myFileType );

mImpFormat = myFileType.left( myFileType.length() - 6 );
std::map<QString, QgsBabelFormat*>::const_iterator iter;
iter = mImporters.find( mImpFormat );
@@ -289,16 +301,24 @@ void QgsGPSPluginGui::on_pbnIMPInput_clicked()
}
}


void QgsGPSPluginGui::on_pbnIMPOutput_clicked()
{
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString myFileNameQString =
QFileDialog::getSaveFileName( this, //parent dialog
QFileDialog::getSaveFileName( this,
tr( "Choose a file name to save under" ),
".", //initial dir
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
{
myFileNameQString += ".gpx";
}
leIMPOutput->setText( myFileNameQString );
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
}
}

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


void QgsGPSPluginGui::populateIMPBabelFormats()
{
mBabelFilter = "";
@@ -375,31 +394,38 @@ void QgsGPSPluginGui::populateIMPBabelFormats()

void QgsGPSPluginGui::on_pbnCONVInput_clicked()
{
QString myFileTypeQString;
QString myFilterString = tr( "GPS eXchange format (*.gpx)" );
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory" ).toString();
if ( dir.isEmpty() )
dir = ".";
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString myFileNameQString = QFileDialog::getOpenFileName(
this, //parent dialog
tr( "Select GPX file" ), //caption
dir, //initial dir
myFilterString, //filters to select
&myFileTypeQString ); //the pointer to store selected filter
this,
tr( "Select GPX file" ),
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
leCONVInput->setText( myFileNameQString );
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
}
}

void QgsGPSPluginGui::on_pbnCONVOutput_clicked()
{
QSettings settings;
QString dir = settings.value( "/Plugin-GPS/gpxdirectory", "." ).toString();
QString myFileNameQString =
QFileDialog::getSaveFileName( this, //parent dialog
QFileDialog::getSaveFileName( this,
tr( "Choose a file name to save under" ),
".", //initial dir
dir,
tr( "GPS eXchange format (*.gpx)" ) );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
{
myFileNameQString += ".gpx";
}
leCONVOutput->setText( myFileNameQString );
settings.setValue( "/Plugin-GPS/gpxdirectory", QFileInfo( myFileNameQString ).absolutePath() );
}
}

void QgsGPSPluginGui::openDeviceEditor()
@@ -413,3 +439,17 @@ void QgsGPSPluginGui::devicesUpdated()
{
populateIMPBabelFormats();
}

void QgsGPSPluginGui::saveState()
{
QSettings settings;
settings.setValue( "/Plugin-GPS/geometry", saveGeometry() );
settings.setValue( "/Plugin-GPS/lastTab", tabWidget->currentIndex() );
}

void QgsGPSPluginGui::restoreState()
{
QSettings settings;
restoreGeometry( settings.value( "/Plugin-GPS/geometry" ).toByteArray() );
tabWidget->setCurrentIndex( settings.value( "/Plugin-GPS/lastTab", 4 ).toInt() );
}

0 comments on commit e531a53

Please sign in to comment.
You can’t perform that action at this time.