mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[FEATURE] add configurable decimal "point" to delimited text plugin
This commit is contained in:
parent
b81c63ccd2
commit
bd09bc5cbe
2
src/core/qgsproviderregistry.cpp
Normal file → Executable file
2
src/core/qgsproviderregistry.cpp
Normal file → Executable file
@ -406,6 +406,8 @@ QgsDataProvider *QgsProviderRegistry::provider( QString const & providerKey, QSt
|
||||
{
|
||||
QgsLogger::warning( "Unable to instantiate the data provider plugin" );
|
||||
|
||||
delete dataProvider;
|
||||
|
||||
myLib->unload();
|
||||
delete myLib;
|
||||
return 0;
|
||||
|
@ -2800,7 +2800,6 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
|
||||
else
|
||||
{
|
||||
QgsDebugMsg( " unable to get data provider" );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
29
src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
Normal file → Executable file
29
src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
Normal file → Executable file
@ -68,6 +68,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui( QgisInterface * _qI, QWidg
|
||||
cmbWktField->setDisabled( true );
|
||||
|
||||
connect( txtFilePath, SIGNAL( textChanged( QString ) ), this, SLOT( updateFieldsAndEnable() ) );
|
||||
connect( decimalPoint, SIGNAL( textChanged( QString ) ), this, SLOT( updateFieldsAndEnable() ) );
|
||||
|
||||
connect( delimiterSelection, SIGNAL( toggled( bool ) ), this, SLOT( updateFieldsAndEnable() ) );
|
||||
connect( delimiterPlain, SIGNAL( toggled( bool ) ), this, SLOT( updateFieldsAndEnable() ) );
|
||||
@ -110,6 +111,11 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
|
||||
url.addQueryItem( "delimiter", txtDelimiter->text() );
|
||||
url.addQueryItem( "delimiterType", delimiterType );
|
||||
|
||||
if ( !decimalPoint->text().isEmpty() )
|
||||
{
|
||||
url.addQueryItem( "decimalPoint", decimalPoint->text() );
|
||||
}
|
||||
|
||||
if ( geomTypeXY->isChecked() )
|
||||
{
|
||||
if ( !cmbXField->currentText().isEmpty() && !cmbYField->currentText().isEmpty() )
|
||||
@ -258,6 +264,9 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
|
||||
cmbYField->setEnabled( false );
|
||||
cmbWktField->setEnabled( false );
|
||||
|
||||
// clear the sample text box
|
||||
tblSample->clear();
|
||||
|
||||
if ( ! haveValidFileAndDelimiters() )
|
||||
return;
|
||||
|
||||
@ -374,7 +383,6 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
|
||||
cmbYField->setEnabled( isXY );
|
||||
cmbWktField->setEnabled( ! isXY );
|
||||
|
||||
|
||||
connect( cmbXField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
|
||||
connect( cmbYField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
|
||||
connect( cmbWktField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( enableAccept() ) );
|
||||
@ -383,9 +391,6 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
|
||||
connect( geomTypeXY, SIGNAL( toggled( bool ) ), cmbWktField, SLOT( setDisabled( bool ) ) );
|
||||
}
|
||||
|
||||
// clear the sample text box
|
||||
tblSample->clear();
|
||||
|
||||
tblSample->setColumnCount( fieldList.size() );
|
||||
tblSample->setHorizontalHeaderLabels( fieldList );
|
||||
|
||||
@ -400,7 +405,21 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
|
||||
|
||||
for ( int i = 0; i < tblSample->columnCount(); i++ )
|
||||
{
|
||||
tblSample->setItem( counter, i, new QTableWidgetItem( i < values.size() ? values[i] : "" ) );
|
||||
QString value = i < values.size() ? values[i] : "";
|
||||
bool ok = true;
|
||||
if ( i == indexX || i == indexY )
|
||||
{
|
||||
if ( !decimalPoint->text().isEmpty() )
|
||||
{
|
||||
value.replace( decimalPoint->text(), "." );
|
||||
}
|
||||
|
||||
value.toDouble( &ok );
|
||||
}
|
||||
QTableWidgetItem *item = new QTableWidgetItem( value );
|
||||
if ( !ok )
|
||||
item->setTextColor( Qt::red );
|
||||
tblSample->setItem( counter, i, item );
|
||||
}
|
||||
|
||||
counter++;
|
||||
|
@ -426,6 +426,16 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="decimalPoint"/>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Decimal point</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
22
src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Normal file → Executable file
22
src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Normal file → Executable file
@ -168,6 +168,8 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
|
||||
mSkipLines = url.queryItemValue( "skipLines" ).toInt();
|
||||
if ( url.hasQueryItem( "crs" ) )
|
||||
mCrs.createFromString( url.queryItemValue( "crs" ) );
|
||||
if ( url.hasQueryItem( "decimalPoint" ) )
|
||||
mDecimalPoint = url.queryItemValue( "decimalPoint" );
|
||||
|
||||
QgsDebugMsg( "Data source uri is " + uri );
|
||||
QgsDebugMsg( "Delimited text file is: " + mFileName );
|
||||
@ -367,6 +369,13 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
|
||||
QString sX = parts[mXFieldIndex];
|
||||
QString sY = parts[mYFieldIndex];
|
||||
|
||||
|
||||
if ( !mDecimalPoint.isEmpty() )
|
||||
{
|
||||
sX.replace( mDecimalPoint, "." );
|
||||
sY.replace( mDecimalPoint, "." );
|
||||
}
|
||||
|
||||
bool xOk = false;
|
||||
bool yOk = false;
|
||||
double x = sX.toDouble( &xOk );
|
||||
@ -502,9 +511,18 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature )
|
||||
}
|
||||
else if ( mXFieldIndex >= 0 && mYFieldIndex >= 0 )
|
||||
{
|
||||
QString sX = tokens[mXFieldIndex];
|
||||
QString sY = tokens[mYFieldIndex];
|
||||
|
||||
if ( !mDecimalPoint.isEmpty() )
|
||||
{
|
||||
sX.replace( mDecimalPoint, "." );
|
||||
sY.replace( mDecimalPoint, "." );
|
||||
}
|
||||
|
||||
bool xOk, yOk;
|
||||
double x = tokens[mXFieldIndex].toDouble( &xOk );
|
||||
double y = tokens[mYFieldIndex].toDouble( &yOk );
|
||||
double x = sX.toDouble( &xOk );
|
||||
double y = sY.toDouble( &yOk );
|
||||
if ( xOk && yOk )
|
||||
{
|
||||
mFid++;
|
||||
|
1
src/providers/delimitedtext/qgsdelimitedtextprovider.h
Normal file → Executable file
1
src/providers/delimitedtext/qgsdelimitedtextprovider.h
Normal file → Executable file
@ -222,6 +222,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
|
||||
long mNumberFeatures;
|
||||
int mSkipLines;
|
||||
int mFirstDataLine; // Actual first line of data (accounting for blank lines)
|
||||
QString mDecimalPoint;
|
||||
|
||||
//! Storage for any lines in the file that couldn't be loaded
|
||||
QStringList mInvalidLines;
|
||||
|
Loading…
x
Reference in New Issue
Block a user