Skip to content

Commit

Permalink
save size and position of the core plugins dialogs (addresses #206)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 17, 2012
1 parent fdd9894 commit 2e7867a
Show file tree
Hide file tree
Showing 25 changed files with 316 additions and 139 deletions.
4 changes: 1 addition & 3 deletions src/plugins/delimited_text/qgsdelimitedtextplugin.cpp
Expand Up @@ -35,8 +35,6 @@
//the gui subclass
#include "qgsdelimitedtextplugingui.h"

//

static const QString pluginVersion = QObject::tr( "Version 0.2" );
static const QString description_ = QObject::tr( "Loads and displays delimited text files containing x,y coordinates" );
static const QString category_ = QObject::tr( "Layers" );
Expand Down Expand Up @@ -115,7 +113,6 @@ void QgsDelimitedTextPlugin::initGui()
qGisInterface->insertAddLayerAction( myQActionPointer );
// this is called when the icon theme is changed
connect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );

}

// Slot called when the buffer menu item is activated
Expand All @@ -131,6 +128,7 @@ void QgsDelimitedTextPlugin::run()
this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
myQgsDelimitedTextPluginGui->exec();
}

//!draw a vector layer in the qui - intended to respond to signal
//sent by diolog when it as finished creating a layer
////needs to be given vectorLayerPath, baseName,
Expand Down
42 changes: 25 additions & 17 deletions src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
Expand Up @@ -12,35 +12,39 @@
* (at your option) any later version. *
***************************************************************************/
#include "qgsdelimitedtextplugingui.h"
#include "qgscontexthelp.h"

#include "qgisinterface.h"
#include "qgscontexthelp.h"
#include "qgslogger.h"

#include <QFileDialog>
#include <QFile>
#include <QComboBox>
#include <QSettings>
#include <QFileDialog>
#include <QFileInfo>
#include <QRegExp>
#include <QMessageBox>
#include <QRegExp>
#include <QSettings>
#include <QTextStream>
#include <QUrl>
#include "qgslogger.h"

QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidget * parent, Qt::WFlags fl )
: QDialog( parent, fl ), qI( _qI )
{
setupUi( this );

QSettings settings;
restoreGeometry( settings.value( "/Plugin-DelimitedText/geometry" ).toByteArray() );

pbnOK = buttonBox->button( QDialogButtonBox::Ok );

updateFieldsAndEnable();

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

rowCounter->setValue( settings.value( key + "/startFrom", 0 ).toInt() );

// and how to use the delimiter
QString delimiterType = settings.value( key + "/delimiterType", "plain" ).toString();
if ( delimiterType == "selection" )
Expand All @@ -60,7 +64,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidg
cbxDelimSpace->setChecked( delimiterChars.contains( " " ) );
cbxDelimTab->setChecked( delimiterChars.contains( "\\t" ) );
cbxDelimColon->setChecked( delimiterChars.contains( ":" ) );
cbxDelimSemicolon->setChecked( delimiterChars.contains( ":" ) );
cbxDelimSemicolon->setChecked( delimiterChars.contains( ";" ) );
cbxDelimComma->setChecked( delimiterChars.contains( "," ) );

cmbXField->setDisabled( true );
Expand Down Expand Up @@ -88,7 +92,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidg
QgsDelimitedTextPluginGui::~QgsDelimitedTextPluginGui()
{
}
/** Autoconnected slots **/

void QgsDelimitedTextPluginGui::on_btnBrowseForFile_clicked()
{
getOpenFileName();
Expand Down Expand Up @@ -140,11 +144,15 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
emit drawVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text(), "delimitedtext" );

// store the settings
saveState();

QSettings settings;
QString key = "/Plugin-DelimitedText";
settings.setValue( key + "/geometry", saveGeometry() );
settings.setValue( key + "/delimiter", txtDelimiter->text() );
QFileInfo fi( txtFilePath->text() );
settings.setValue( key + "/text_path", fi.path() );
settings.setValue( key + "/startFrom", rowCounter->value() );

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

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

Expand Down Expand Up @@ -292,7 +301,6 @@ void QgsDelimitedTextPluginGui::updateFieldLists()

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

//
// We don't know anything about a text based field other
// than its name. All fields are assumed to be text
bool haveFields = false;
Expand Down Expand Up @@ -443,8 +451,7 @@ void QgsDelimitedTextPluginGui::getOpenFileName()
this,
tr( "Choose a delimited text file to open" ),
settings.value( "/Plugin-DelimitedText/text_path", "./" ).toString(),
"Text files (*.txt *.csv);; Well Known Text files (*.wkt);; All files (* *.*)" );

"Text files (*.txt *.csv);;Well Known Text files (*.wkt);;All files (* *.*)" );
// set path
txtFilePath->setText( s );
}
Expand All @@ -457,14 +464,12 @@ void QgsDelimitedTextPluginGui::updateFieldsAndEnable()

void QgsDelimitedTextPluginGui::enableAccept()
{

// If the geometry type field is enabled then there must be
// a valid file, and it must be
bool enabled = haveValidFileAndDelimiters();

if ( enabled )
{

if ( geomTypeXY->isChecked() )
{
enabled = !( cmbXField->currentText().isEmpty() || cmbYField->currentText().isEmpty() || cmbXField->currentText() == cmbYField->currentText() );
Expand Down Expand Up @@ -493,12 +498,15 @@ QString QgsDelimitedTextPluginGui::readLine( QTextStream &stream )
// skip leading CR / LF
continue;
}

break;
}

buffer.append( c );
}

return buffer;
}

void QgsDelimitedTextPluginGui::saveState()
{
QSettings settings;
settings.setValue( "/Plugin-DelimitedText/geometry", saveGeometry() );
}
1 change: 1 addition & 0 deletions src/plugins/delimited_text/qgsdelimitedtextplugingui.h
Expand Up @@ -38,6 +38,7 @@ class QgsDelimitedTextPluginGui : public QDialog, private Ui::QgsDelimitedTextPl
void updateFieldLists();
void getOpenFileName();
QString selectedChars();
void saveState();

QgisInterface * qI;
QAbstractButton *pbnOK;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/dxf2shp_converter/CMakeLists.txt
Expand Up @@ -33,9 +33,9 @@ ADD_LIBRARY (dxf2shpconverterplugin MODULE ${dxf2shpconverter_SRCS} ${dxf2shpcon

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
../../core
../../core/raster
../../core/renderer
../../core
../../core/raster
../../core/renderer
../../core/symbology
../../gui
..
Expand Down
38 changes: 32 additions & 6 deletions src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
Expand Up @@ -32,6 +32,7 @@ dxf2shpConverterGui::dxf2shpConverterGui( QWidget *parent, Qt::WFlags fl ):
QDialog( parent, fl )
{
setupUi( this );
restoreState();
}

dxf2shpConverterGui::~dxf2shpConverterGui()
Expand All @@ -40,6 +41,8 @@ dxf2shpConverterGui::~dxf2shpConverterGui()

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

QString inf = name->text();
QString outd = dirout->text();

Expand Down Expand Up @@ -117,6 +120,7 @@ void dxf2shpConverterGui::on_buttonBox_accepted()

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

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


void dxf2shpConverterGui::on_btnBrowseForFile_clicked()
{
getInputFileName();
Expand All @@ -148,25 +151,48 @@ void dxf2shpConverterGui::on_btnBrowseOutputDir_clicked()
getOutputDir();
}


void dxf2shpConverterGui::getInputFileName()
{
QSettings settings;

QString s = QFileDialog::getOpenFileName( this,
tr( "Choose a DXF file to open" ),
settings.value( "/Plugin-DXF/text_path", "./" ).toString(),
tr( "DXF files (*.dxf)" ) );

name->setText( s );
if ( !s.isEmpty() )
{
name->setText( s );
settings.setValue( "/Plugin-DXF/text_path", QFileInfo( s ).absolutePath() );
}
}

void dxf2shpConverterGui::getOutputDir()
{
QSettings settings;
QString s = QFileDialog::getSaveFileName( this,
tr( "Choose a file name to save to" ),
"output.shp",
settings.value( "/UI/lastShapefileDir", "./" ).toString(),
tr( "Shapefile (*.shp)" ) );

dirout->setText( s );
if ( !s.isEmpty() )
{
if ( !s.toLower().endsWith( ".shp" ) )
{
s += ".shp";
}
dirout->setText( s );
settings.setValue( "/UI/lastShapefileDir", QFileInfo( s ).absolutePath() );
}
}

void dxf2shpConverterGui::saveState()
{
QSettings settings;
settings.setValue( "/Plugin-DXF/geometry", saveGeometry() );
}

void dxf2shpConverterGui::restoreState()
{
QSettings settings;
restoreGeometry( settings.value( "/Plugin-DXF/geometry" ).toByteArray() );
}
3 changes: 3 additions & 0 deletions src/plugins/dxf2shp_converter/dxf2shpconvertergui.h
Expand Up @@ -34,6 +34,9 @@ class dxf2shpConverterGui: public QDialog, private Ui::dxf2shpConverterGui
void getOutputFileName();
void getOutputDir();

void saveState();
void restoreState();

private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
Expand Down

0 comments on commit 2e7867a

Please sign in to comment.