Skip to content

Commit aab222c

Browse files
author
jef
committed
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/qgis@9182 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5c7dfae commit aab222c

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public:
1111
UniqueValuesEditable,
1212
ValueMap,
1313
Classification,
14-
Range,
14+
EditRange,
15+
SliderRange
1516
};
1617

1718
struct RangeData {

src/app/qgsattributedialog.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <QFrame>
3333
#include <QScrollArea>
3434
#include <QCompleter>
35+
#include <QSlider>
3536
#include <QSpinBox>
3637
#include <QDoubleSpinBox>
3738

@@ -45,7 +46,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
4546
if ( mpFeature == NULL || vl->dataProvider() == NULL )
4647
return;
4748

48-
const QgsFieldMap &theFieldMap = vl->dataProvider()->fields();
49+
const QgsFieldMap &theFieldMap = vl->pendingFields();
4950

5051
if ( theFieldMap.isEmpty() ) return;
5152

@@ -161,21 +162,35 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
161162
}
162163
break;
163164

164-
case QgsVectorLayer::Range:
165+
case QgsVectorLayer::SliderRange:
166+
case QgsVectorLayer::EditRange:
165167
{
166168
if ( myFieldType == QVariant::Int )
167169
{
168170
int min = vl->range( it.key() ).mMin.toInt();
169171
int max = vl->range( it.key() ).mMax.toInt();
170172
int step = vl->range( it.key() ).mStep.toInt();
171173

172-
QSpinBox *sb = new QSpinBox();
173-
sb->setMinimum( min );
174-
sb->setMaximum( max );
175-
sb->setSingleStep( step );
176-
sb->setValue( it.value().toInt() );
174+
if ( editType == QgsVectorLayer::EditRange )
175+
{
176+
QSpinBox *sb = new QSpinBox();
177177

178-
myWidget = sb;
178+
sb->setRange( min, max );
179+
sb->setSingleStep( step );
180+
sb->setValue( it.value().toInt() );
181+
182+
myWidget = sb;
183+
}
184+
else
185+
{
186+
QSlider *sl = new QSlider( Qt::Horizontal );
187+
188+
sl->setRange( min, max );
189+
sl->setSingleStep( step );
190+
sl->setValue( it.value().toInt() );
191+
192+
myWidget = sl;
193+
}
179194
break;
180195
}
181196
else if ( myFieldType == QVariant::Double )
@@ -185,16 +200,13 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
185200
double step = vl->range( it.key() ).mStep.toDouble();
186201
QDoubleSpinBox *dsb = new QDoubleSpinBox();
187202

188-
dsb->setMinimum( min );
189-
dsb->setMaximum( max );
203+
dsb->setRange( min, max );
190204
dsb->setSingleStep( step );
191205
dsb->setValue( it.value().toDouble() );
192206

193207
myWidget = dsb;
194-
195208
break;
196209
}
197-
198210
}
199211

200212
// fall-through
@@ -292,13 +304,18 @@ void QgsAttributeDialog::accept()
292304
}
293305
}
294306

295-
296307
QSpinBox *sb = dynamic_cast<QSpinBox *>( mpWidgets.value( myIndex ) );
297308
if ( sb )
298309
{
299310
myFieldValue = QString::number( sb->value() );
300311
}
301312

313+
QSlider *slider = dynamic_cast<QSlider *>( mpWidgets.value( myIndex ) );
314+
if ( slider )
315+
{
316+
myFieldValue = QString::number( slider->value() );
317+
}
318+
302319
QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>( mpWidgets.value( myIndex ) );
303320
if ( dsb )
304321
{

src/app/qgsvectorlayerproperties.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
166166
cb->addItem( tr( "unique values (editable)" ), QgsVectorLayer::UniqueValuesEditable );
167167
cb->addItem( tr( "value map" ), QgsVectorLayer::ValueMap );
168168
cb->addItem( tr( "classification" ), QgsVectorLayer::Classification );
169-
cb->addItem( tr( "range" ), QgsVectorLayer::Range );
169+
cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange );
170+
cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange );
170171
cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
171172
cb->setCurrentIndex( layer->editType( idx ) );
172173

@@ -188,7 +189,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
188189

189190
tblAttributes->setItem( row, 7, new QTableWidgetItem( mapList.join( ";" ) ) );
190191
}
191-
else if ( layer->editType( idx ) == QgsVectorLayer::Range )
192+
else if ( layer->editType( idx ) == QgsVectorLayer::EditRange ||
193+
layer->editType( idx ) == QgsVectorLayer::SliderRange )
192194
{
193195
tblAttributes->setItem(
194196
row, 7,
@@ -538,7 +540,8 @@ void QgsVectorLayerProperties::apply()
538540
}
539541
}
540542
}
541-
else if ( editType == QgsVectorLayer::Range )
543+
else if ( editType == QgsVectorLayer::EditRange ||
544+
editType == QgsVectorLayer::SliderRange )
542545
{
543546
QStringList values = tblAttributes->item( i, 7 )->text().split( ";" );
544547

src/core/qgsvectorlayer.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,9 @@ void QgsVectorLayer::updateFeatureAttributes( QgsFeature &f )
11341134
for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
11351135
f.changeAttribute( it.key(), it.value() );
11361136
}
1137+
1138+
for ( QgsAttributeList::const_iterator it = mFetchNullAttributes.begin(); it != mFetchNullAttributes.end(); it++ )
1139+
f.changeAttribute( *it, QVariant( QString::null ) );
11371140
}
11381141

11391142
void QgsVectorLayer::updateFeatureGeometry( QgsFeature &f )
@@ -1165,7 +1168,27 @@ void QgsVectorLayer::select( QgsAttributeList attributes, QgsRect rect, bool fet
11651168
//look in the normal features of the provider
11661169
if ( mFetchAttributes.size() > 0 )
11671170
{
1168-
mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
1171+
mFetchNullAttributes.clear();
1172+
1173+
if ( mEditable )
1174+
{
1175+
// fetch only available field from provider
1176+
QgsAttributeList provAttributes;
1177+
for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ )
1178+
{
1179+
if ( !mUpdatedFields.contains( *it ) )
1180+
continue;
1181+
1182+
if ( !mDeletedAttributeIds.contains( *it ) && !mAddedAttributeIds.contains( *it ) )
1183+
provAttributes << *it;
1184+
else
1185+
mFetchNullAttributes << *it;
1186+
}
1187+
1188+
mDataProvider->select( provAttributes, rect, fetchGeometries, useIntersect );
1189+
}
1190+
else
1191+
mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
11691192
}
11701193
else
11711194
{
@@ -1957,6 +1980,7 @@ bool QgsVectorLayer::startEditing()
19571980
mEditable = true;
19581981

19591982
mUpdatedFields = mDataProvider->fields();
1983+
19601984
mMaxUpdatedIndex = -1;
19611985

19621986
for ( QgsFieldMap::const_iterator it = mUpdatedFields.begin(); it != mUpdatedFields.end(); it++ )
@@ -2049,7 +2073,7 @@ bool QgsVectorLayer::readXml( QDomNode & layer_node )
20492073
mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
20502074
}
20512075
}
2052-
else if ( editType == Range )
2076+
else if ( editType == EditRange || editType == SliderRange )
20532077
{
20542078
QVariant min = editTypeElement.attribute( "min" );
20552079
QVariant max = editTypeElement.attribute( "max" );
@@ -2295,7 +2319,7 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
22952319
}
22962320
}
22972321
}
2298-
else if ( it.value() == Range )
2322+
else if ( it.value() == EditRange || it.value() == SliderRange )
22992323
{
23002324
if ( mRanges.contains( it.key() ) )
23012325
{
@@ -3266,8 +3290,6 @@ void QgsVectorLayer::drawFeature( QPainter* p,
32663290
if ( wkbType == QGis::WKBMultiPoint25D ) // ignore Z value
32673291
ptr += sizeof( double );
32683292

3269-
QgsDebugMsg( QString( "...WKBMultiPoint (%1, %2)" ).arg( x ).arg( y ) );
3270-
32713293
transformPoint( x, y, theMapToPixelTransform, ct );
32723294
//QPointF pt(x - (marker->width()/2), y - (marker->height()/2));
32733295
//QPointF pt(x/markerScaleFactor - (marker->width()/2), y/markerScaleFactor - (marker->height()/2));

src/core/qgsvectorlayer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
6666
UniqueValuesEditable,
6767
ValueMap,
6868
Classification,
69-
Range
69+
EditRange,
70+
SliderRange
7071
};
7172

7273
struct RangeData
@@ -341,7 +342,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
341342
*/
342343
void drawLabels( QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale );
343344

344-
/** returns fields list which are not commited */
345+
/** returns field list in the to-be-committed state */
345346
const QgsFieldMap &pendingFields();
346347

347348
/** returns list of attributes */
@@ -608,6 +609,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
608609
bool mFetching;
609610
QgsRect mFetchRect;
610611
QgsAttributeList mFetchAttributes;
612+
QgsAttributeList mFetchNullAttributes;
611613
bool mFetchGeometry;
612614

613615
QSet<int> mFetchConsidered;

0 commit comments

Comments
 (0)