Skip to content

Commit 6a7f374

Browse files
author
jef
committedMar 31, 2010
consider attribute changes in identify results
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13212 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
 

‎src/app/qgsidentifyresults.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
161161
layItem->setData( 0, Qt::UserRole, QVariant::fromValue( qobject_cast<QObject *>( layer ) ) );
162162
lstResults->addTopLevelItem( layItem );
163163

164-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
165164
if ( vlayer )
166165
{
167166
connect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
168167
connect( vlayer, SIGNAL( layerCrsChanged() ), this, SLOT( layerDestroyed() ) );
169168
connect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
169+
connect( vlayer, SIGNAL( attributeValueChanged( int, int, const QVariant & ) ), this, SLOT( attributeValueChanged( int, int, const QVariant & ) ) );
170170
connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
171171
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
172172
}
@@ -182,7 +182,12 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
182182

183183
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
184184
{
185-
featItem->addChild( new QTreeWidgetItem( QStringList() << it.key() << it.value() ) );
185+
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
186+
if ( vlayer )
187+
{
188+
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
189+
}
190+
featItem->addChild( attrItem );
186191
}
187192

188193
if ( derivedAttributes.size() >= 0 )
@@ -644,6 +649,7 @@ void QgsIdentifyResults::disconnectLayer( QObject *layer )
644649
{
645650
disconnect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
646651
disconnect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
652+
disconnect( vlayer, SIGNAL( attributeValueChanged( int, int, const QVariant & ) ), this, SLOT( attributeValueChanged( int, int, const QVariant & ) ) );
647653
disconnect( vlayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
648654
disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
649655
}
@@ -683,6 +689,35 @@ void QgsIdentifyResults::featureDeleted( int fid )
683689
}
684690
}
685691

692+
void QgsIdentifyResults::attributeValueChanged( int fid, int idx, const QVariant &val )
693+
{
694+
QTreeWidgetItem *layItem = layerItem( sender() );
695+
696+
if ( !layItem )
697+
return;
698+
699+
for ( int i = 0; i < layItem->childCount(); i++ )
700+
{
701+
QTreeWidgetItem *featItem = layItem->child( i );
702+
703+
if ( featItem && featItem->data( 0, Qt::UserRole ).toInt() == fid )
704+
{
705+
for ( int j = 0; j < featItem->childCount(); j++ )
706+
{
707+
QTreeWidgetItem *item = featItem->child( j );
708+
if ( item->childCount() > 0 )
709+
continue;
710+
711+
if ( item->data( 0, Qt::UserRole ).toInt() == idx )
712+
{
713+
item->setData( 1, Qt::DisplayRole, val );
714+
return;
715+
}
716+
}
717+
}
718+
}
719+
}
720+
686721
void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
687722
{
688723
QgsVectorLayer *layer = vectorLayer( item );

‎src/app/qgsidentifyresults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
8282
void layerDestroyed();
8383
void editingToggled();
8484
void featureDeleted( int fid );
85+
void attributeValueChanged( int fid, int idx, const QVariant & );
8586

8687
void featureForm();
8788
void zoomToFeature();

0 commit comments

Comments
 (0)
Please sign in to comment.