[QGIS Commit] r9196 - in trunk/qgis: python/core src/app src/core
src/providers/ogr src/providers/postgres
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Aug 27 18:13:27 EDT 2008
Author: jef
Date: 2008-08-27 18:13:27 -0400 (Wed, 27 Aug 2008)
New Revision: 9196
Modified:
trunk/qgis/python/core/qgsvectordataprovider.sip
trunk/qgis/src/app/qgsattributedialog.cpp
trunk/qgis/src/app/qgscontinuouscolordialog.cpp
trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp
trunk/qgis/src/app/qgsuniquevaluedialog.cpp
trunk/qgis/src/core/qgsvectordataprovider.cpp
trunk/qgis/src/core/qgsvectordataprovider.h
trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
trunk/qgis/src/providers/ogr/qgsogrprovider.h
trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
trunk/qgis/src/providers/postgres/qgspostgresprovider.h
Log:
vector provider update:
- rename maxValue to maximumValue
- rename getUniqueValues to uniqueValues and let it return a list
of variants instead of strings.
- add protected convertValue to convert string values to attribute values
- update attribute dialog, continuous color dialog, graduated symbol dialog,
unique value dialog, postgres provider and ogr provider accordingly
- fixes #1250
Modified: trunk/qgis/python/core/qgsvectordataprovider.sip
===================================================================
--- trunk/qgis/python/core/qgsvectordataprovider.sip 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/python/core/qgsvectordataprovider.sip 2008-08-27 22:13:27 UTC (rev 9196)
@@ -132,7 +132,7 @@
* and maximal values. If provider has facilities to retrieve maximal
* value directly, override this function.
*/
- virtual QVariant maxValue(int index);
+ virtual QVariant maximumValue(int index);
/**
* Return unique values of an attribute
@@ -141,7 +141,7 @@
*
* Default implementation simply iterates the features
*/
- virtual void getUniqueValues(int index, QStringList &uniqueValues);
+ virtual void uniqueValues(int index, QList<QVariant> &uniqueValues);
/**
* Adds a list of features
Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/app/qgsattributedialog.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -112,13 +112,15 @@
{
case QgsVectorLayer::UniqueValues:
{
- QStringList values;
- mLayer->dataProvider()->getUniqueValues( it.key(), values );
+ QList<QVariant> values;
+ mLayer->dataProvider()->uniqueValues( it.key(), values );
QComboBox *cb = new QComboBox();
cb->setEditable( true );
- cb->addItems( values );
+ for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
+ cb->addItem( it->toString() );
+
int idx = cb->findText( myFieldValue.toString() );
if ( idx >= 0 )
cb->setCurrentIndex( idx );
@@ -219,10 +221,14 @@
if ( editType == QgsVectorLayer::UniqueValuesEditable )
{
- QStringList values;
- mLayer->dataProvider()->getUniqueValues( it.key(), values );
+ QList<QVariant> values;
+ mLayer->dataProvider()->uniqueValues( it.key(), values );
- QCompleter *c = new QCompleter( values );
+ QStringList svalues;
+ for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
+ svalues << it->toString();
+
+ QCompleter *c = new QCompleter( svalues );
c->setCompletionMode( QCompleter::PopupCompletion );
le->setCompleter( c );
}
Modified: trunk/qgis/src/app/qgscontinuouscolordialog.cpp
===================================================================
--- trunk/qgis/src/app/qgscontinuouscolordialog.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/app/qgscontinuouscolordialog.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -23,6 +23,7 @@
#include "qgssymbol.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
+#include "qgslogger.h"
#include <QColorDialog>
@@ -168,11 +169,11 @@
if ( provider )
{
minimum = provider->minimumValue( classfield ).toDouble();
- maximum = provider->maxValue( classfield ).toDouble();
+ maximum = provider->maximumValue( classfield ).toDouble();
}
else
{
- qWarning( "Warning, provider is null in QgsGraSyExtensionWidget::QgsGraSyExtensionWidget(...)" );
+ QgsDebugMsg( "Warning, provider is null" );
return;
}
Modified: trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/app/qgsgraduatedsymboldialog.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -254,7 +254,7 @@
if ( modeComboBox->currentText() == tr( "Equal Interval" ) )
{
minimum = provider->minimumValue( field ).toDouble();
- maximum = provider->maxValue( field ).toDouble();
+ maximum = provider->maximumValue( field ).toDouble();
}
else //don't waste performance if mMode is QgsGraduatedSymbolDialog::EMPTY
{
@@ -435,7 +435,7 @@
int currentIndex = mClassListWidget->currentRow();
mEntries.erase( classValue );
delete( mClassListWidget->takeItem( currentIndex ) );
- QgsDebugMsg( QString("numRows: %1").arg( mClassListWidget->count() ) );
+ QgsDebugMsg( QString( "numRows: %1" ).arg( mClassListWidget->count() ) );
//
if ( mClassListWidget->count() < ( currentIndex + 1 ) )
{
Modified: trunk/qgis/src/app/qgsuniquevaluedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsuniquevaluedialog.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/app/qgsuniquevaluedialog.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -298,13 +298,13 @@
return;
}
- QStringList values;
- provider->getUniqueValues( nr, values );
+ QList<QVariant> values;
+ provider->uniqueValues( nr, values );
for ( int i = 0; i < values.size(); i++ )
{
- if ( !mValues.contains( values[i] ) )
- addClass( values[i] );
+ if ( !mValues.contains( values[i].toString() ) )
+ addClass( values[i].toString() );
}
}
}
Modified: trunk/qgis/src/core/qgsvectordataprovider.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectordataprovider.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/core/qgsvectordataprovider.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -273,7 +273,7 @@
return mCacheMinValues[index];
}
-QVariant QgsVectorDataProvider::maxValue( int index )
+QVariant QgsVectorDataProvider::maximumValue( int index )
{
if ( !fields().contains( index ) )
{
@@ -292,19 +292,24 @@
return mCacheMaxValues[index];
}
-void QgsVectorDataProvider::getUniqueValues( int index, QStringList &values )
+void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values )
{
QgsFeature f;
QgsAttributeList keys;
keys.append( index );
select( keys, QgsRect(), false );
- QMap<QString, int> map;
+ QSet<QString> set;
+ values.clear();
while ( getNextFeature( f ) )
- map.insert( f.attributeMap()[index].toString(), 1 );
-
- values = map.keys();
+ {
+ if ( set.contains( f.attributeMap()[index].toString() ) )
+ {
+ values.append( f.attributeMap()[index] );
+ set.insert( f.attributeMap()[index].toString() );
+ }
+ }
}
void QgsVectorDataProvider::fillMinMaxCache()
@@ -356,3 +361,13 @@
mCacheMinMaxDirty = FALSE;
}
+
+QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, QString value )
+{
+ QVariant v( value );
+
+ if ( !v.convert( type ) )
+ v = QVariant( QString::null );
+
+ return v;
+}
Modified: trunk/qgis/src/core/qgsvectordataprovider.h
===================================================================
--- trunk/qgis/src/core/qgsvectordataprovider.h 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/core/qgsvectordataprovider.h 2008-08-27 22:13:27 UTC (rev 9196)
@@ -168,7 +168,7 @@
* and maximal values. If provider has facilities to retrieve maximal
* value directly, override this function.
*/
- virtual QVariant maxValue( int index );
+ virtual QVariant maximumValue( int index );
/**
* Return unique values of an attribute
@@ -177,7 +177,7 @@
*
* Default implementation simply iterates the features
*/
- virtual void getUniqueValues( int index, QStringList &uniqueValues );
+ virtual void uniqueValues( int index, QList<QVariant> &uniqueValues );
/**
* Adds a list of features
@@ -274,6 +274,7 @@
void setFetchFeaturesWithoutGeom( bool fetch );
protected:
+ QVariant convertValue( QVariant::Type type, QString value );
void fillMinMaxCache();
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -1256,7 +1256,7 @@
return srs;
}
-void QgsOgrProvider::getUniqueValues( int index, QStringList &uniqueValues )
+void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues )
{
QgsField fld = mAttributeFields[index];
QFileInfo fi( dataSourceUri() );
@@ -1274,7 +1274,7 @@
OGRFeatureH f;
while ( 0 != ( f = OGR_L_GetNextFeature( lyr ) ) )
{
- uniqueValues.append( mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
+ uniqueValues << convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
OGR_F_Destroy( f );
}
@@ -1304,26 +1304,15 @@
return QVariant();
}
- QString str = mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) );
+ QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
OGR_F_Destroy( f );
- QVariant value;
-
- switch ( fld.type() )
- {
- case QVariant::String: value = QVariant( str ); break;
- case QVariant::Int: value = QVariant( str.toInt() ); break;
- case QVariant::Double: value = QVariant( str.toDouble() ); break;
- //case QVariant::DateTime: value = QVariant(QDateTime::fromString(str)); break;
- default: assert( NULL && "unsupported field type" );
- }
-
OGR_DS_ReleaseResultSet( ogrDataSource, l );
return value;
}
-QVariant QgsOgrProvider::maxValue( int index )
+QVariant QgsOgrProvider::maximumValue( int index )
{
QgsField fld = mAttributeFields[index];
QFileInfo fi( dataSourceUri() );
@@ -1343,20 +1332,9 @@
return QVariant();
}
- QString str = mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) );
+ QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
OGR_F_Destroy( f );
- QVariant value;
-
- switch ( fld.type() )
- {
- case QVariant::String: value = QVariant( str ); break;
- case QVariant::Int: value = QVariant( str.toInt() ); break;
- case QVariant::Double: value = QVariant( str.toDouble() ); break;
- //case QVariant::DateTime: value = QVariant(QDateTime::fromString(str)); break;
- default: assert( NULL && "unsupported field type" );
- }
-
OGR_DS_ReleaseResultSet( ogrDataSource, l );
return value;
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.h
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.h 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.h 2008-08-27 22:13:27 UTC (rev 9196)
@@ -175,12 +175,12 @@
/** Returns the maximum value of an attribute
* @param index the index of the attribute */
- QVariant maxValue( int index );
+ QVariant maximumValue( int index );
/** Return the unique values of an attribute
* @param index the index of the attribute
* @param values reference to the list of unique values */
- virtual void getUniqueValues( int index, QStringList &uniqueValues );
+ virtual void uniqueValues( int index, QList<QVariant> &uniqueValues );
protected:
/** loads fields from input file to member attributeFields */
Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2008-08-27 22:13:27 UTC (rev 9196)
@@ -494,30 +494,7 @@
if ( !PQgetisnull( queryResult, row, col ) )
{
- QString val = QString::fromUtf8( PQgetvalue( queryResult, row, col ) );
-
- switch ( fld.type() )
- {
- case QVariant::LongLong:
- feature.addAttribute( *it, val.toLongLong() );
- break;
- case QVariant::Int:
- feature.addAttribute( *it, val.toInt() );
- break;
- case QVariant::Double:
- feature.addAttribute( *it, val.toDouble() );
- break;
- case QVariant::String:
- feature.addAttribute( *it, val );
- break;
- default:
- QgsDebugMsg( QString( "feature %1, field %2, value '%3': unexpected variant type %4 considered as NULL" )
- .arg( oid )
- .arg( fld.name() )
- .arg( val )
- .arg( fld.type() ) );
- feature.addAttribute( *it, QVariant( QString::null ) );
- }
+ feature.addAttribute( *it, convertValue( fld.type(), QString::fromUtf8( PQgetvalue( queryResult, row, col ) ) ) );
}
else
{
@@ -1540,8 +1517,7 @@
.arg( sqlWhereClause );
}
Result rmin = connectionRO->PQexec( sql );
- QString minimumValue = QString::fromUtf8( PQgetvalue( rmin, 0, 0 ) );
- return minimumValue.toDouble();
+ return convertValue( fld.type(), QString::fromUtf8( PQgetvalue( rmin, 0, 0 ) ) );
}
catch ( PGFieldNotFound )
{
@@ -1550,7 +1526,7 @@
}
// Returns the list of unique values of an attribute
-void QgsPostgresProvider::getUniqueValues( int index, QStringList &uniqueValues )
+void QgsPostgresProvider::uniqueValues( int index, QList<QVariant> &uniqueValues )
{
uniqueValues.clear();
@@ -1586,8 +1562,7 @@
}
// Returns the maximum value of an attribute
-
-QVariant QgsPostgresProvider::maxValue( int index )
+QVariant QgsPostgresProvider::maximumValue( int index )
{
try
{
@@ -1608,8 +1583,7 @@
.arg( sqlWhereClause );
}
Result rmax = connectionRO->PQexec( sql );
- QString maxValue = QString::fromUtf8( PQgetvalue( rmax, 0, 0 ) );
- return maxValue.toDouble();
+ return convertValue( fld.type(), QString::fromUtf8( PQgetvalue( rmax, 0, 0 ) ) );
}
catch ( PGFieldNotFound )
{
Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.h
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.h 2008-08-27 21:56:29 UTC (rev 9195)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.h 2008-08-27 22:13:27 UTC (rev 9196)
@@ -184,12 +184,12 @@
/** Returns the maximum value of an attribute
* @param index the index of the attribute */
- QVariant maxValue( int index );
+ QVariant maximumValue( int index );
/** Return the unique values of an attribute
* @param index the index of the attribute
* @param values reference to the list of unique values */
- virtual void getUniqueValues( int index, QStringList &uniqueValues );
+ virtual void uniqueValues( int index, QList<QVariant> &uniqueValues );
/**Returns true if layer is valid
*/
More information about the QGIS-commit
mailing list