From 683dcea78149200a2d80f65dd2fe646baa648cb6 Mon Sep 17 00:00:00 2001 From: jef Date: Wed, 27 Aug 2008 07:44:03 +0000 Subject: [PATCH] vector layer updates - fix: retrieve only existing attributes from provider when editing and set added attributes to null - introduce slider widget for attribute dialog - include added attributes when editing from identify git-svn-id: http://svn.osgeo.org/qgis/trunk@9182 c8812cc2-4d05-0410-92ff-de0c093fc19c --- python/core/qgsvectorlayer.sip | 3 +- src/app/qgsattributedialog.cpp | 43 +++++++++++++++++++--------- src/app/qgsvectorlayerproperties.cpp | 9 ++++-- src/core/qgsvectorlayer.cpp | 32 +++++++++++++++++---- src/core/qgsvectorlayer.h | 6 ++-- 5 files changed, 69 insertions(+), 24 deletions(-) diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index f7ea750b365..0dd7ed139bd 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -11,7 +11,8 @@ public: UniqueValuesEditable, ValueMap, Classification, - Range, + EditRange, + SliderRange }; struct RangeData { diff --git a/src/app/qgsattributedialog.cpp b/src/app/qgsattributedialog.cpp index c61a369d169..80870d640d1 100644 --- a/src/app/qgsattributedialog.cpp +++ b/src/app/qgsattributedialog.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -45,7 +46,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat if ( mpFeature == NULL || vl->dataProvider() == NULL ) return; - const QgsFieldMap &theFieldMap = vl->dataProvider()->fields(); + const QgsFieldMap &theFieldMap = vl->pendingFields(); if ( theFieldMap.isEmpty() ) return; @@ -161,7 +162,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat } break; - case QgsVectorLayer::Range: + case QgsVectorLayer::SliderRange: + case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { @@ -169,13 +171,26 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat int max = vl->range( it.key() ).mMax.toInt(); int step = vl->range( it.key() ).mStep.toInt(); - QSpinBox *sb = new QSpinBox(); - sb->setMinimum( min ); - sb->setMaximum( max ); - sb->setSingleStep( step ); - sb->setValue( it.value().toInt() ); + if ( editType == QgsVectorLayer::EditRange ) + { + QSpinBox *sb = new QSpinBox(); - myWidget = sb; + sb->setRange( min, max ); + sb->setSingleStep( step ); + sb->setValue( it.value().toInt() ); + + myWidget = sb; + } + else + { + QSlider *sl = new QSlider( Qt::Horizontal ); + + sl->setRange( min, max ); + sl->setSingleStep( step ); + sl->setValue( it.value().toInt() ); + + myWidget = sl; + } break; } else if ( myFieldType == QVariant::Double ) @@ -185,16 +200,13 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat double step = vl->range( it.key() ).mStep.toDouble(); QDoubleSpinBox *dsb = new QDoubleSpinBox(); - dsb->setMinimum( min ); - dsb->setMaximum( max ); + dsb->setRange( min, max ); dsb->setSingleStep( step ); dsb->setValue( it.value().toDouble() ); myWidget = dsb; - break; } - } // fall-through @@ -292,13 +304,18 @@ void QgsAttributeDialog::accept() } } - QSpinBox *sb = dynamic_cast( mpWidgets.value( myIndex ) ); if ( sb ) { myFieldValue = QString::number( sb->value() ); } + QSlider *slider = dynamic_cast( mpWidgets.value( myIndex ) ); + if ( slider ) + { + myFieldValue = QString::number( slider->value() ); + } + QDoubleSpinBox *dsb = dynamic_cast( mpWidgets.value( myIndex ) ); if ( dsb ) { diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index 95e9f937c43..019b0e86fda 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -166,7 +166,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field ) cb->addItem( tr( "unique values (editable)" ), QgsVectorLayer::UniqueValuesEditable ); cb->addItem( tr( "value map" ), QgsVectorLayer::ValueMap ); cb->addItem( tr( "classification" ), QgsVectorLayer::Classification ); - cb->addItem( tr( "range" ), QgsVectorLayer::Range ); + cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange ); + cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange ); cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow ); cb->setCurrentIndex( layer->editType( idx ) ); @@ -188,7 +189,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field ) tblAttributes->setItem( row, 7, new QTableWidgetItem( mapList.join( ";" ) ) ); } - else if ( layer->editType( idx ) == QgsVectorLayer::Range ) + else if ( layer->editType( idx ) == QgsVectorLayer::EditRange || + layer->editType( idx ) == QgsVectorLayer::SliderRange ) { tblAttributes->setItem( row, 7, @@ -538,7 +540,8 @@ void QgsVectorLayerProperties::apply() } } } - else if ( editType == QgsVectorLayer::Range ) + else if ( editType == QgsVectorLayer::EditRange || + editType == QgsVectorLayer::SliderRange ) { QStringList values = tblAttributes->item( i, 7 )->text().split( ";" ); diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index a83aa606b7f..a9cfc6e61b6 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -1134,6 +1134,9 @@ void QgsVectorLayer::updateFeatureAttributes( QgsFeature &f ) for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ ) f.changeAttribute( it.key(), it.value() ); } + + for ( QgsAttributeList::const_iterator it = mFetchNullAttributes.begin(); it != mFetchNullAttributes.end(); it++ ) + f.changeAttribute( *it, QVariant( QString::null ) ); } void QgsVectorLayer::updateFeatureGeometry( QgsFeature &f ) @@ -1165,7 +1168,27 @@ void QgsVectorLayer::select( QgsAttributeList attributes, QgsRect rect, bool fet //look in the normal features of the provider if ( mFetchAttributes.size() > 0 ) { - mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect ); + mFetchNullAttributes.clear(); + + if ( mEditable ) + { + // fetch only available field from provider + QgsAttributeList provAttributes; + for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ ) + { + if ( !mUpdatedFields.contains( *it ) ) + continue; + + if ( !mDeletedAttributeIds.contains( *it ) && !mAddedAttributeIds.contains( *it ) ) + provAttributes << *it; + else + mFetchNullAttributes << *it; + } + + mDataProvider->select( provAttributes, rect, fetchGeometries, useIntersect ); + } + else + mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect ); } else { @@ -1957,6 +1980,7 @@ bool QgsVectorLayer::startEditing() mEditable = true; mUpdatedFields = mDataProvider->fields(); + mMaxUpdatedIndex = -1; for ( QgsFieldMap::const_iterator it = mUpdatedFields.begin(); it != mUpdatedFields.end(); it++ ) @@ -2049,7 +2073,7 @@ bool QgsVectorLayer::readXml( QDomNode & layer_node ) mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) ); } } - else if ( editType == Range ) + else if ( editType == EditRange || editType == SliderRange ) { QVariant min = editTypeElement.attribute( "min" ); QVariant max = editTypeElement.attribute( "max" ); @@ -2295,7 +2319,7 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node, } } } - else if ( it.value() == Range ) + else if ( it.value() == EditRange || it.value() == SliderRange ) { if ( mRanges.contains( it.key() ) ) { @@ -3266,8 +3290,6 @@ void QgsVectorLayer::drawFeature( QPainter* p, if ( wkbType == QGis::WKBMultiPoint25D ) // ignore Z value ptr += sizeof( double ); - QgsDebugMsg( QString( "...WKBMultiPoint (%1, %2)" ).arg( x ).arg( y ) ); - transformPoint( x, y, theMapToPixelTransform, ct ); //QPointF pt(x - (marker->width()/2), y - (marker->height()/2)); //QPointF pt(x/markerScaleFactor - (marker->width()/2), y/markerScaleFactor - (marker->height()/2)); diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index 151c05c66ea..eea390904d6 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -66,7 +66,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer UniqueValuesEditable, ValueMap, Classification, - Range + EditRange, + SliderRange }; struct RangeData @@ -341,7 +342,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer */ void drawLabels( QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale ); - /** returns fields list which are not commited */ + /** returns field list in the to-be-committed state */ const QgsFieldMap &pendingFields(); /** returns list of attributes */ @@ -608,6 +609,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer bool mFetching; QgsRect mFetchRect; QgsAttributeList mFetchAttributes; + QgsAttributeList mFetchNullAttributes; bool mFetchGeometry; QSet mFetchConsidered;