Skip to content
Permalink
Browse files

Delimited text GUI tidy up. Renamed useWatcher option to watchFile

  • Loading branch information
ccrook committed May 13, 2013
1 parent d8dac0c commit 0f756c9528c1b006c3f91c0e73e83e89636f38da
@@ -103,6 +103,19 @@ It is safer to use an explicit coding if the QGIS project needs to be portable.
"Point" includes POINT and MULTIPOINT WKT types, "Line" includes LINESTRING and
MULTLINESTRING WKT types, and "Polygon" includes POLYGON and MULTIPOLYGON WKT types.
</ul>
<h5>Layer settings</h5>
<p>Layer settings control the way the layer is managed in QGIS. The options available are:</p>
<ul>
<li>Use spatial index. Create a spatial index to improve the performance of displaying and selecting spatial objects.
This option may be useful for files larger than a few megabytes in size.</li>
<li>Use subset index. Create an index if a subset of records is being used (either by explicitly setting a subset string
from the layer properties dialog, or an implicit subset of features for which the geometry is valid in files
for which all not geometries are valid). The index will only be created when a subset is defined.</li>
<li>Watch file. If this options is selected QGIS will watch the file for changes by other applications, and
reload the file when it is changed. The map will not be updated until refreshed by the user, but indexes and
extents will be reloaded. This option should be selected if indexes are used and it is likely that another
application will change the file. </li>
</ul>

<h4><a name="csv">How the delimiter, quote, and escape characters work</a></h4>
<p>Records are split into fields using three character sets:
@@ -275,9 +288,9 @@ The following options can be added
<li><tt>crs=...</tt> specifies the coordinate system to use for the vector layer, in a format accepted by QgsCoordinateReferenceSystem.createFromString (for example &quot;EPSG:4167&quot;). If this is not
specified then a dialog box may request this information from the user
when the layer is loaded (depending on QGIS CRS settings).</li>
<li><tt>subsetIndex=(yes|no)</tt> specifies whether the provider should build an index to define subset during the initial file scan. The index will apply both for explicitly defined subsets, and for the implicit subset of features for which the geometry definition is valid. By default the subset index is built if it is applicable. This option is not available from the GUI.</li>
<li><tt>subsetIndex=(yes|no)</tt> specifies whether the provider should build an index to define subset during the initial file scan. The index will apply both for explicitly defined subsets, and for the implicit subset of features for which the geometry definition is valid. By default the subset index is built if it is applicable.</li>
<li><tt>spatialIndex=(yes|no)</tt> specifies whether the provider should build a spatial index during the initial file scan. By default the spatial index is not built. </li>
<li><tt>useWatcher=(yes|no)</tt> specifies whether the provider should use a file system watcher to monitor for changes to the file. This option is not available from the GUI</li>
<li><tt>watchFile=(yes|no)</tt> specifies whether the provider should use a file system watcher to monitor for changes to the file.</li>
<li><tt>quiet=(yes|no)</tt> specifies whether errors encountered loading the layer are presented in a dialog box (they will be written to the QGIS log in any case). The default is no. This option is not available from the GUI</li>
</ul>

@@ -384,7 +384,7 @@ struct CORE_EXPORT QgsVectorJoinInfo
*
* Determines whether the provider generates a spatial index. The default is no.
*
* -useWatcher=(yes|no)
* -watchFile=(yes|no)
*
* Defines whether the file will be monitored for changes. The default is
* to monitor for changes.
@@ -38,7 +38,7 @@ QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
mEncoding( "UTF-8" ),
mFile( 0 ),
mStream( 0 ),
mUseWatcher( true ),
mUseWatcher( false ),
mWatcher( 0 ),
mDefinitionValid( false ),
mUseHeader( true ),
@@ -153,9 +153,9 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
}

//
if ( url.hasQueryItem( "useWatcher" ) )
if ( url.hasQueryItem( "watchFile" ) )
{
mUseWatcher = ! url.queryItemValue( "useWatcher" ).toUpper().startsWith( 'N' );;
mUseWatcher = ! url.queryItemValue( "watchFile" ).toUpper().startsWith( 'N' );;
}

// The default type is csv, to be consistent with the
@@ -264,7 +264,7 @@ QUrl QgsDelimitedTextFile::url()
url.addQueryItem( "encoding", mEncoding );
}

if( ! mUseWatcher ) url.addQueryItem( "useWatcher", "no");
if( mUseWatcher ) url.addQueryItem( "watchFile", "yes");

url.addQueryItem( "type", type() );
if ( mType == DelimTypeRegexp )
@@ -20,6 +20,7 @@
#include "qgsdelimitedtextprovider.h"
#include "qgsdelimitedtextfile.h"

#include <QButtonGroup>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
@@ -52,11 +53,24 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget * parent, Qt
buttonBox->button( QDialogButtonBox::Ok )->hide();
}

bgFileFormat=new QButtonGroup(this);
bgFileFormat->addButton(delimiterCSV,swFileFormat->indexOf( swpCSVOptions));
bgFileFormat->addButton(delimiterChars,swFileFormat->indexOf( swpDelimOptions));
bgFileFormat->addButton(delimiterRegexp,swFileFormat->indexOf( swpRegexpOptions));

bgGeomType=new QButtonGroup(this);
bgGeomType->addButton(geomTypeXY,swGeomType->indexOf( swpGeomXY));
bgGeomType->addButton(geomTypeWKT,swGeomType->indexOf( swpGeomWKT));
bgGeomType->addButton(geomTypeNone,swGeomType->indexOf( swpGeomNone));

connect( bgFileFormat, SIGNAL(buttonClicked(int)), swFileFormat, SLOT(setCurrentIndex(int)));
connect( bgGeomType, SIGNAL(buttonClicked(int)),swGeomType,SLOT(setCurrentIndex(int)));

cmbEncoding->clear();
cmbEncoding->addItems( QgsVectorDataProvider::availableEncodings() );
cmbEncoding->setCurrentIndex( cmbEncoding->findText( "UTF-8" ) );
loadSettings();

loadSettings();
updateFieldsAndEnable();

connect( txtFilePath, SIGNAL( textChanged( QString ) ), this, SLOT( updateFileName() ) );
@@ -173,6 +187,10 @@ void QgsDelimitedTextSourceSelect::on_buttonBox_accepted()
url.addQueryItem( "geomType", "none" );
}

if( ! geomTypeNone->isChecked()) url.addQueryItem( "spatialIndex", cbxSpatialIndex->isChecked() ? "yes" : "no" );
url.addQueryItem( "subsetIndex", cbxSubsetIndex->isChecked() ? "yes" : "no" );
url.addQueryItem( "watchFile", cbxWatchFile->isChecked() ? "yes" : "no" );

// store the settings
saveSettings();
saveSettingsForFile( txtFilePath->text() );
@@ -242,6 +260,7 @@ void QgsDelimitedTextSourceSelect::loadSettings( QString subkey, bool loadGeomSe
{
delimiterCSV->setChecked( true );
}
swFileFormat->setCurrentIndex( bgFileFormat->checkedId() );

QString encoding = settings.value( key + "/encoding", "" ).toString();
if ( ! encoding.isEmpty() ) cmbEncoding->setCurrentIndex( cmbEncoding->findText( encoding ) );
@@ -259,6 +278,9 @@ void QgsDelimitedTextSourceSelect::loadSettings( QString subkey, bool loadGeomSe
cbxTrimFields->setChecked( settings.value( key + "/trimFields", "false" ) == "true" );
cbxSkipEmptyFields->setChecked( settings.value( key + "/skipEmptyFields", "false" ) == "true" );
cbxPointIsComma->setChecked( settings.value( key + "/decimalPoint", "." ).toString().contains( "," ) );
cbxSubsetIndex->setChecked( settings.value( key + "/subsetIndex", "false" ) == "true" );
cbxSpatialIndex->setChecked( settings.value( key + "/spatialIndex", "false" ) == "true" );
cbxWatchFile->setChecked( settings.value( key + "/watchFile", "false" ) == "true" );

if ( loadGeomSettings )
{
@@ -267,6 +289,7 @@ void QgsDelimitedTextSourceSelect::loadSettings( QString subkey, bool loadGeomSe
else if ( geomColumnType == "wkt" ) geomTypeWKT->setChecked( true );
else geomTypeNone->setChecked( true );
cbxXyDms->setChecked( settings.value( key + "/xyDms", "false" ) == "true" );
swGeomType->setCurrentIndex( bgGeomType->checkedId() );
}

}
@@ -294,6 +317,9 @@ void QgsDelimitedTextSourceSelect::saveSettings( QString subkey, bool saveGeomSe
settings.setValue( key + "/trimFields", cbxTrimFields->isChecked() ? "true" : "false" );
settings.setValue( key + "/skipEmptyFields", cbxSkipEmptyFields->isChecked() ? "true" : "false" );
settings.setValue( key + "/decimalPoint", cbxPointIsComma->isChecked() ? "," : "." );
settings.setValue( key + "/subsetIndex", cbxSubsetIndex->isChecked() ? "true" : "false");
settings.setValue( key + "/spatialIndex", cbxSpatialIndex->isChecked() ? "true" : "false");
settings.setValue( key + "/watchFile", cbxWatchFile->isChecked() ? "true" : "false");
if ( saveGeomSettings )
{
QString geomColumnType = "none";
@@ -368,8 +394,6 @@ void QgsDelimitedTextSourceSelect::updateFieldLists()
cmbYField->clear();
cmbWktField->clear();

frmGeometry->setEnabled( false );

// clear the sample text box
tblSample->clear();
tblSample->setColumnCount( 0 );
@@ -532,7 +556,6 @@ void QgsDelimitedTextSourceSelect::updateFieldLists()

if ( haveFields )
{
frmGeometry->setEnabled( true );
connect( cmbXField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
connect( cmbYField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
connect( cmbWktField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
@@ -19,6 +19,7 @@
#include "qgscontexthelp.h"
#include "qgisgui.h"

class QButtonGroup;
class QgisInterface;
class QgsDelimitedTextFile;

@@ -53,6 +54,8 @@ class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTex
int mBadRowCount;
QString mPluginKey;
QString mLastFileType;
QButtonGroup *bgFileFormat;
QButtonGroup *bgGeomType;

private slots:
void on_buttonBox_accepted();

0 comments on commit 0f756c9

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