Skip to content

Commit

Permalink
consider attribute changes in identify results
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13212 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 31, 2010
1 parent e19a425 commit 6a7f374
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/app/qgsidentifyresults.cpp
Expand Up @@ -161,12 +161,12 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
layItem->setData( 0, Qt::UserRole, QVariant::fromValue( qobject_cast<QObject *>( layer ) ) );
lstResults->addTopLevelItem( layItem );

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer )
{
connect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
connect( vlayer, SIGNAL( layerCrsChanged() ), this, SLOT( layerDestroyed() ) );
connect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
connect( vlayer, SIGNAL( attributeValueChanged( int, int, const QVariant & ) ), this, SLOT( attributeValueChanged( int, int, const QVariant & ) ) );
connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
}
Expand All @@ -182,7 +182,12 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,

for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
{
featItem->addChild( new QTreeWidgetItem( QStringList() << it.key() << it.value() ) );
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
if ( vlayer )
{
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
}
featItem->addChild( attrItem );
}

if ( derivedAttributes.size() >= 0 )
Expand Down Expand Up @@ -644,6 +649,7 @@ void QgsIdentifyResults::disconnectLayer( QObject *layer )
{
disconnect( vlayer, SIGNAL( layerDeleted() ), this, SLOT( layerDestroyed() ) );
disconnect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
disconnect( vlayer, SIGNAL( attributeValueChanged( int, int, const QVariant & ) ), this, SLOT( attributeValueChanged( int, int, const QVariant & ) ) );
disconnect( vlayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
}
Expand Down Expand Up @@ -683,6 +689,35 @@ void QgsIdentifyResults::featureDeleted( int fid )
}
}

void QgsIdentifyResults::attributeValueChanged( int fid, int idx, const QVariant &val )
{
QTreeWidgetItem *layItem = layerItem( sender() );

if ( !layItem )
return;

for ( int i = 0; i < layItem->childCount(); i++ )
{
QTreeWidgetItem *featItem = layItem->child( i );

if ( featItem && featItem->data( 0, Qt::UserRole ).toInt() == fid )
{
for ( int j = 0; j < featItem->childCount(); j++ )
{
QTreeWidgetItem *item = featItem->child( j );
if ( item->childCount() > 0 )
continue;

if ( item->data( 0, Qt::UserRole ).toInt() == idx )
{
item->setData( 1, Qt::DisplayRole, val );
return;
}
}
}
}
}

void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
{
QgsVectorLayer *layer = vectorLayer( item );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsidentifyresults.h
Expand Up @@ -82,6 +82,7 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
void layerDestroyed();
void editingToggled();
void featureDeleted( int fid );
void attributeValueChanged( int fid, int idx, const QVariant & );

void featureForm();
void zoomToFeature();
Expand Down

0 comments on commit 6a7f374

Please sign in to comment.