@@ -34,8 +34,29 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayer *theLayer, QObjec
34
34
mLastRow = NULL ;
35
35
mLayer = theLayer;
36
36
mFeatureCount = mLayer ->pendingFeatureCount ();
37
- mFieldCount = mLayer ->pendingFields ().size ();
38
- mAttributes = mLayer ->pendingAllAttributesList ();
37
+
38
+ mFieldCount = 0 ;
39
+ mAttributes .clear ();
40
+ mValueMaps .clear ();
41
+
42
+ for ( QgsFieldMap::const_iterator it = theLayer->pendingFields ().constBegin (); it != theLayer->pendingFields ().end (); it++ )
43
+ {
44
+ switch ( mLayer ->editType ( it.key () ) )
45
+ {
46
+ case QgsVectorLayer::Hidden:
47
+ continue ;
48
+
49
+ case QgsVectorLayer::ValueMap:
50
+ mValueMaps .insert ( it.key (), &mLayer ->valueMap ( it.key () ) );
51
+ break ;
52
+
53
+ default :
54
+ break ;
55
+ }
56
+
57
+ mFieldCount ++;
58
+ mAttributes << it.key ();
59
+ }
39
60
40
61
connect ( mLayer , SIGNAL ( layerModified ( bool ) ), this , SLOT ( layerModified ( bool ) ) );
41
62
// connect(mLayer, SIGNAL(attributeAdded(int)), this, SLOT( attributeAdded(int)));
@@ -173,7 +194,7 @@ void QgsAttributeTableModel::loadLayer()
173
194
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
174
195
}
175
196
176
- mLayer ->select ( QgsAttributeList () , QgsRectangle (), false );
197
+ mLayer ->select ( mAttributes , QgsRectangle (), false );
177
198
178
199
// preallocate data before inserting
179
200
mRowIdMap .reserve ( pendingFeatureCount + 50 );
@@ -187,7 +208,7 @@ void QgsAttributeTableModel::loadLayer()
187
208
188
209
// not needed when we have featureAdded signal
189
210
mFeatureCount = pendingFeatureCount;
190
- mFieldCount = mLayer -> pendingFields () .size ();
211
+ mFieldCount = mAttributes .size ();
191
212
192
213
if ( ins )
193
214
{
@@ -369,7 +390,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
369
390
if ( !mLastRow )
370
391
return QVariant ( " ERROR" );
371
392
372
- QVariant &val = ( *mLastRow )[ mAttributes [index .column ()] ];
393
+ const QVariant &val = ( *mLastRow )[ mAttributes [index .column ()] ];
373
394
374
395
if ( val.isNull () )
375
396
{
@@ -384,6 +405,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
384
405
}
385
406
}
386
407
408
+ if ( role == Qt::DisplayRole && mValueMaps .contains ( index .column () ) )
409
+ {
410
+ return mValueMaps [ index .column ()]->key ( val.toString (), QString ( " (%1)" ).arg ( val.toString () ) );
411
+ }
412
+
387
413
// force also numeric data for EditRole to be strings
388
414
// otherwise it creates spinboxes instead of line edits
389
415
// (probably not what we do want)
0 commit comments