Skip to content

Commit 164f89c

Browse files
author
jef
committed
vector editing update:
- show mapped value instead of attribute value for value maps in attribute table and identify results. - alternating background color in identify results - allow hiding of attributes - add actions (including edit action) into identify results git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11681 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d2c0eab commit 164f89c

15 files changed

+394
-98
lines changed

src/app/attributetable/qgsattributetablemodel.cpp

+31-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,29 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayer *theLayer, QObjec
3434
mLastRow = NULL;
3535
mLayer = theLayer;
3636
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+
}
3960

4061
connect( mLayer, SIGNAL( layerModified( bool ) ), this, SLOT( layerModified( bool ) ) );
4162
//connect(mLayer, SIGNAL(attributeAdded(int)), this, SLOT( attributeAdded(int)));
@@ -173,7 +194,7 @@ void QgsAttributeTableModel::loadLayer()
173194
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
174195
}
175196

176-
mLayer->select( QgsAttributeList(), QgsRectangle(), false );
197+
mLayer->select( mAttributes, QgsRectangle(), false );
177198

178199
// preallocate data before inserting
179200
mRowIdMap.reserve( pendingFeatureCount + 50 );
@@ -187,7 +208,7 @@ void QgsAttributeTableModel::loadLayer()
187208

188209
// not needed when we have featureAdded signal
189210
mFeatureCount = pendingFeatureCount;
190-
mFieldCount = mLayer->pendingFields().size();
211+
mFieldCount = mAttributes.size();
191212

192213
if ( ins )
193214
{
@@ -369,7 +390,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
369390
if ( !mLastRow )
370391
return QVariant( "ERROR" );
371392

372-
QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
393+
const QVariant &val = ( *mLastRow )[ mAttributes[index.column()] ];
373394

374395
if ( val.isNull() )
375396
{
@@ -384,6 +405,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
384405
}
385406
}
386407

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+
387413
// force also numeric data for EditRole to be strings
388414
// otherwise it creates spinboxes instead of line edits
389415
// (probably not what we do want)

src/app/attributetable/qgsattributetablemodel.h

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class QgsAttributeTableModel: public QAbstractTableModel
188188

189189
mutable QgsAttributeMap *mLastRow;
190190
QgsAttributeList mAttributes;
191+
QMap< int, const QMap<QString, QVariant> * > mValueMaps;
191192

192193
QList<QgsAttributeTableIdColumnPair> mSortList;
193194
QHash<int, int> mIdRowMap;

src/app/qgisapp.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -3667,9 +3667,6 @@ void QgisApp::openProject( const QString & fileName )
36673667
{
36683668
QgsDebugMsg( "unable to load project " + fileName );
36693669
}
3670-
else
3671-
{
3672-
}
36733670
}
36743671
catch ( QgsIOException & io_exception )
36753672
{

src/app/qgsattributedialog.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
4343

4444
const QgsFieldMap &theFieldMap = vl->pendingFields();
4545

46-
if ( theFieldMap.isEmpty() ) return;
46+
if ( theFieldMap.isEmpty() )
47+
return;
4748

4849
QgsAttributeMap myAttributes = mpFeature->attributeMap();
4950
//
@@ -64,8 +65,6 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
6465
mypScrollArea->setWidgetResizable( true );
6566
QGridLayout * mypInnerLayout = new QGridLayout( mypInnerFrame );
6667

67-
68-
6968
int index = 0;
7069
for ( QgsAttributeMap::const_iterator it = myAttributes.begin();
7170
it != myAttributes.end();
@@ -77,6 +76,10 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
7776
QString myFieldName = vl->attributeDisplayName( it.key() );
7877
int myFieldType = field.type();
7978

79+
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
80+
if ( !myWidget )
81+
continue;
82+
8083
QLabel * mypLabel = new QLabel();
8184
mypInnerLayout->addWidget( mypLabel, index, 0 );
8285
if ( myFieldType == QVariant::Int )
@@ -93,9 +96,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
9396
mypLabel->setText( myFieldName + tr( " (txt)" ) );
9497
}
9598

96-
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
97-
9899
mypInnerLayout->addWidget( myWidget, index, 1 );
100+
mpIndizes << it.key();
99101
mpWidgets << myWidget;
100102
++index;
101103
}
@@ -124,8 +126,9 @@ void QgsAttributeDialog::accept()
124126
{
125127
QVariant value;
126128

127-
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, it.key(), value ) )
128-
mpFeature->changeAttribute( it.key(), value );
129+
int idx = mpIndizes.value( myIndex );
130+
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
131+
mpFeature->changeAttribute( idx, value );
129132

130133
++myIndex;
131134
}

src/app/qgsattributedialog.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
5555
private:
5656
QString mSettingsPath;
5757
QList<QWidget *> mpWidgets;
58+
QList<int> mpIndizes;
5859
QgsVectorLayer *mLayer;
5960
QgsFeature * mpFeature;
6061

src/app/qgsattributeeditor.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QgsVectorLa
228228
}
229229
break;
230230

231+
case QgsVectorLayer::Hidden:
232+
myWidget = NULL;
233+
break;
234+
231235
case QgsVectorLayer::FileName:
232236
{
233237
QLineEdit *le = new QLineEdit();
@@ -252,6 +256,9 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QgsVectorLa
252256

253257
bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
254258
{
259+
if ( !widget )
260+
return false;
261+
255262
const QgsField &theField = vl->pendingFields()[idx];
256263
QgsVectorLayer::EditType editType = vl->editType( idx );
257264
bool modified = false;
@@ -349,6 +356,9 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
349356

350357
bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
351358
{
359+
if ( !editor )
360+
return false;
361+
352362
QgsVectorLayer::EditType editType = vl->editType( idx );
353363
const QgsField &field = vl->pendingFields()[idx];
354364
QVariant::Type myFieldType = field.type();
@@ -362,7 +372,8 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
362372
QComboBox *cb = dynamic_cast<QComboBox *>( editor );
363373
if ( cb == NULL )
364374
return false;
365-
int idx = cb->findText( value.toString() );
375+
376+
int idx = cb->findData( value );
366377
if ( idx < 0 )
367378
return false;
368379

src/app/qgsattributetypedialog.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
226226
setPage( 7 );
227227
break;
228228

229+
case QgsVectorLayer::Hidden:
230+
setPage( 8 );
231+
break;
232+
229233
case QgsVectorLayer::LineEdit:
230234
setPage( 0 );
231235
break;
@@ -501,6 +505,9 @@ void QgsAttributeTypeDialog::accept()
501505
case 7:
502506
mEditType = QgsVectorLayer::Immutable;
503507
break;
508+
case 8:
509+
mEditType = QgsVectorLayer::Hidden;
510+
break;
504511
default:
505512
mEditType = QgsVectorLayer::LineEdit;
506513
}

0 commit comments

Comments
 (0)