Skip to content

Commit 2e7867a

Browse files
committed
save size and position of the core plugins dialogs (addresses #206)
1 parent fdd9894 commit 2e7867a

25 files changed

+316
-139
lines changed

src/plugins/delimited_text/qgsdelimitedtextplugin.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
//the gui subclass
3636
#include "qgsdelimitedtextplugingui.h"
3737

38-
//
39-
4038
static const QString pluginVersion = QObject::tr( "Version 0.2" );
4139
static const QString description_ = QObject::tr( "Loads and displays delimited text files containing x,y coordinates" );
4240
static const QString category_ = QObject::tr( "Layers" );
@@ -115,7 +113,6 @@ void QgsDelimitedTextPlugin::initGui()
115113
qGisInterface->insertAddLayerAction( myQActionPointer );
116114
// this is called when the icon theme is changed
117115
connect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
118-
119116
}
120117

121118
// Slot called when the buffer menu item is activated
@@ -131,6 +128,7 @@ void QgsDelimitedTextPlugin::run()
131128
this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
132129
myQgsDelimitedTextPluginGui->exec();
133130
}
131+
134132
//!draw a vector layer in the qui - intended to respond to signal
135133
//sent by diolog when it as finished creating a layer
136134
////needs to be given vectorLayerPath, baseName,

src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,39 @@
1212
* (at your option) any later version. *
1313
***************************************************************************/
1414
#include "qgsdelimitedtextplugingui.h"
15-
#include "qgscontexthelp.h"
1615

1716
#include "qgisinterface.h"
17+
#include "qgscontexthelp.h"
18+
#include "qgslogger.h"
1819

19-
#include <QFileDialog>
2020
#include <QFile>
21-
#include <QComboBox>
22-
#include <QSettings>
21+
#include <QFileDialog>
2322
#include <QFileInfo>
24-
#include <QRegExp>
2523
#include <QMessageBox>
24+
#include <QRegExp>
25+
#include <QSettings>
2626
#include <QTextStream>
2727
#include <QUrl>
28-
#include "qgslogger.h"
2928

3029
QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidget * parent, Qt::WFlags fl )
3130
: QDialog( parent, fl ), qI( _qI )
3231
{
3332
setupUi( this );
33+
34+
QSettings settings;
35+
restoreGeometry( settings.value( "/Plugin-DelimitedText/geometry" ).toByteArray() );
36+
3437
pbnOK = buttonBox->button( QDialogButtonBox::Ok );
3538

3639
updateFieldsAndEnable();
3740

3841
// at startup, fetch the last used delimiter and directory from
3942
// settings
40-
QSettings settings;
4143
QString key = "/Plugin-DelimitedText";
4244
txtDelimiter->setText( settings.value( key + "/delimiter" ).toString() );
4345

46+
rowCounter->setValue( settings.value( key + "/startFrom", 0 ).toInt() );
47+
4448
// and how to use the delimiter
4549
QString delimiterType = settings.value( key + "/delimiterType", "plain" ).toString();
4650
if ( delimiterType == "selection" )
@@ -60,7 +64,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidg
6064
cbxDelimSpace->setChecked( delimiterChars.contains( " " ) );
6165
cbxDelimTab->setChecked( delimiterChars.contains( "\\t" ) );
6266
cbxDelimColon->setChecked( delimiterChars.contains( ":" ) );
63-
cbxDelimSemicolon->setChecked( delimiterChars.contains( ":" ) );
67+
cbxDelimSemicolon->setChecked( delimiterChars.contains( ";" ) );
6468
cbxDelimComma->setChecked( delimiterChars.contains( "," ) );
6569

6670
cmbXField->setDisabled( true );
@@ -88,7 +92,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidg
8892
QgsDelimitedTextPluginGui::~QgsDelimitedTextPluginGui()
8993
{
9094
}
91-
/** Autoconnected slots **/
95+
9296
void QgsDelimitedTextPluginGui::on_btnBrowseForFile_clicked()
9397
{
9498
getOpenFileName();
@@ -140,11 +144,15 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
140144
emit drawVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text(), "delimitedtext" );
141145

142146
// store the settings
147+
saveState();
148+
143149
QSettings settings;
144150
QString key = "/Plugin-DelimitedText";
151+
settings.setValue( key + "/geometry", saveGeometry() );
145152
settings.setValue( key + "/delimiter", txtDelimiter->text() );
146153
QFileInfo fi( txtFilePath->text() );
147154
settings.setValue( key + "/text_path", fi.path() );
155+
settings.setValue( key + "/startFrom", rowCounter->value() );
148156

149157
if ( delimiterSelection->isChecked() )
150158
settings.setValue( key + "/delimiterType", "selection" );
@@ -164,6 +172,7 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
164172

165173
void QgsDelimitedTextPluginGui::on_buttonBox_rejected()
166174
{
175+
saveState();
167176
reject();
168177
}
169178

@@ -292,7 +301,6 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
292301

293302
QgsDebugMsg( QString( "Split line into %1 parts" ).arg( fieldList.size() ) );
294303

295-
//
296304
// We don't know anything about a text based field other
297305
// than its name. All fields are assumed to be text
298306
bool haveFields = false;
@@ -443,8 +451,7 @@ void QgsDelimitedTextPluginGui::getOpenFileName()
443451
this,
444452
tr( "Choose a delimited text file to open" ),
445453
settings.value( "/Plugin-DelimitedText/text_path", "./" ).toString(),
446-
"Text files (*.txt *.csv);; Well Known Text files (*.wkt);; All files (* *.*)" );
447-
454+
"Text files (*.txt *.csv);;Well Known Text files (*.wkt);;All files (* *.*)" );
448455
// set path
449456
txtFilePath->setText( s );
450457
}
@@ -457,14 +464,12 @@ void QgsDelimitedTextPluginGui::updateFieldsAndEnable()
457464

458465
void QgsDelimitedTextPluginGui::enableAccept()
459466
{
460-
461467
// If the geometry type field is enabled then there must be
462468
// a valid file, and it must be
463469
bool enabled = haveValidFileAndDelimiters();
464470

465471
if ( enabled )
466472
{
467-
468473
if ( geomTypeXY->isChecked() )
469474
{
470475
enabled = !( cmbXField->currentText().isEmpty() || cmbYField->currentText().isEmpty() || cmbXField->currentText() == cmbYField->currentText() );
@@ -493,12 +498,15 @@ QString QgsDelimitedTextPluginGui::readLine( QTextStream &stream )
493498
// skip leading CR / LF
494499
continue;
495500
}
496-
497501
break;
498502
}
499-
500503
buffer.append( c );
501504
}
502-
503505
return buffer;
504506
}
507+
508+
void QgsDelimitedTextPluginGui::saveState()
509+
{
510+
QSettings settings;
511+
settings.setValue( "/Plugin-DelimitedText/geometry", saveGeometry() );
512+
}

src/plugins/delimited_text/qgsdelimitedtextplugingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsDelimitedTextPluginGui : public QDialog, private Ui::QgsDelimitedTextPl
3838
void updateFieldLists();
3939
void getOpenFileName();
4040
QString selectedChars();
41+
void saveState();
4142

4243
QgisInterface * qI;
4344
QAbstractButton *pbnOK;

src/plugins/dxf2shp_converter/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ADD_LIBRARY (dxf2shpconverterplugin MODULE ${dxf2shpconverter_SRCS} ${dxf2shpcon
3333

3434
INCLUDE_DIRECTORIES(
3535
${CMAKE_CURRENT_BINARY_DIR}
36-
../../core
37-
../../core/raster
38-
../../core/renderer
36+
../../core
37+
../../core/raster
38+
../../core/renderer
3939
../../core/symbology
4040
../../gui
4141
..

src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dxf2shpConverterGui::dxf2shpConverterGui( QWidget *parent, Qt::WFlags fl ):
3232
QDialog( parent, fl )
3333
{
3434
setupUi( this );
35+
restoreState();
3536
}
3637

3738
dxf2shpConverterGui::~dxf2shpConverterGui()
@@ -40,6 +41,8 @@ dxf2shpConverterGui::~dxf2shpConverterGui()
4041

4142
void dxf2shpConverterGui::on_buttonBox_accepted()
4243
{
44+
saveState();
45+
4346
QString inf = name->text();
4447
QString outd = dirout->text();
4548

@@ -117,6 +120,7 @@ void dxf2shpConverterGui::on_buttonBox_accepted()
117120

118121
void dxf2shpConverterGui::on_buttonBox_rejected()
119122
{
123+
saveState();
120124
reject();
121125
}
122126

@@ -137,7 +141,6 @@ void dxf2shpConverterGui::on_buttonBox_helpRequested()
137141
QMessageBox::information( this, "Help", s );
138142
}
139143

140-
141144
void dxf2shpConverterGui::on_btnBrowseForFile_clicked()
142145
{
143146
getInputFileName();
@@ -148,25 +151,48 @@ void dxf2shpConverterGui::on_btnBrowseOutputDir_clicked()
148151
getOutputDir();
149152
}
150153

151-
152154
void dxf2shpConverterGui::getInputFileName()
153155
{
154156
QSettings settings;
155-
156157
QString s = QFileDialog::getOpenFileName( this,
157158
tr( "Choose a DXF file to open" ),
158159
settings.value( "/Plugin-DXF/text_path", "./" ).toString(),
159160
tr( "DXF files (*.dxf)" ) );
160161

161-
name->setText( s );
162+
if ( !s.isEmpty() )
163+
{
164+
name->setText( s );
165+
settings.setValue( "/Plugin-DXF/text_path", QFileInfo( s ).absolutePath() );
166+
}
162167
}
163168

164169
void dxf2shpConverterGui::getOutputDir()
165170
{
171+
QSettings settings;
166172
QString s = QFileDialog::getSaveFileName( this,
167173
tr( "Choose a file name to save to" ),
168-
"output.shp",
174+
settings.value( "/UI/lastShapefileDir", "./" ).toString(),
169175
tr( "Shapefile (*.shp)" ) );
170176

171-
dirout->setText( s );
177+
if ( !s.isEmpty() )
178+
{
179+
if ( !s.toLower().endsWith( ".shp" ) )
180+
{
181+
s += ".shp";
182+
}
183+
dirout->setText( s );
184+
settings.setValue( "/UI/lastShapefileDir", QFileInfo( s ).absolutePath() );
185+
}
186+
}
187+
188+
void dxf2shpConverterGui::saveState()
189+
{
190+
QSettings settings;
191+
settings.setValue( "/Plugin-DXF/geometry", saveGeometry() );
192+
}
193+
194+
void dxf2shpConverterGui::restoreState()
195+
{
196+
QSettings settings;
197+
restoreGeometry( settings.value( "/Plugin-DXF/geometry" ).toByteArray() );
172198
}

src/plugins/dxf2shp_converter/dxf2shpconvertergui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class dxf2shpConverterGui: public QDialog, private Ui::dxf2shpConverterGui
3434
void getOutputFileName();
3535
void getOutputDir();
3636

37+
void saveState();
38+
void restoreState();
39+
3740
private slots:
3841
void on_buttonBox_accepted();
3942
void on_buttonBox_rejected();

0 commit comments

Comments
 (0)