[QGIS Commit] r11600 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Sep 8 19:31:22 EDT 2009
Author: jef
Date: 2009-09-08 19:31:22 -0400 (Tue, 08 Sep 2009)
New Revision: 11600
Modified:
trunk/qgis/src/app/qgsidentifyresults.cpp
trunk/qgis/src/app/qgsidentifyresults.h
Log:
fix attribute actions
Modified: trunk/qgis/src/app/qgsidentifyresults.cpp
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.cpp 2009-09-08 21:25:46 UTC (rev 11599)
+++ trunk/qgis/src/app/qgsidentifyresults.cpp 2009-09-08 23:31:22 UTC (rev 11600)
@@ -171,60 +171,61 @@
if ( !item )
return;
- if ( mActionPopup == 0 )
- {
- QgsVectorLayer *vlayer = vectorLayer( item );
- if ( vlayer == 0 )
- return;
+ if ( mActionPopup )
+ delete mActionPopup;
- QgsAttributeAction *actions = vlayer->actions();
+ QgsVectorLayer *vlayer = vectorLayer( item );
+ if ( vlayer == 0 )
+ return;
- mActionPopup = new QMenu();
+ mActionPopup = new QMenu();
- QAction *a;
+ QAction *a;
- if ( vlayer->isEditable() )
- {
- a = mActionPopup->addAction( tr( "Edit feature" ) );
- a->setEnabled( true );
- a->setData( QVariant::fromValue( -4 ) );
- }
-
- a = mActionPopup->addAction( tr( "Zoom to feature" ) );
+ if ( vlayer->isEditable() )
+ {
+ a = mActionPopup->addAction( tr( "Edit feature" ) );
a->setEnabled( true );
- a->setData( QVariant::fromValue( -3 ) );
+ a->setData( QVariant::fromValue( -4 ) );
+ }
- a = mActionPopup->addAction( tr( "Copy attribute value" ) );
- a->setEnabled( true );
- a->setData( QVariant::fromValue( -2 ) );
+ a = mActionPopup->addAction( tr( "Zoom to feature" ) );
+ a->setEnabled( true );
+ a->setData( QVariant::fromValue( -3 ) );
- a = mActionPopup->addAction( tr( "Copy feature attributes" ) );
- a->setEnabled( true );
- a->setData( QVariant::fromValue( -1 ) );
+ a = mActionPopup->addAction( tr( "Copy attribute value" ) );
+ a->setEnabled( true );
+ a->setData( QVariant::fromValue( -2 ) );
- if ( actions && actions->size() > 0 )
+ a = mActionPopup->addAction( tr( "Copy feature attributes" ) );
+ a->setEnabled( true );
+ a->setData( QVariant::fromValue( -1 ) );
+
+ QgsAttributeAction *actions = vlayer->actions();
+ if ( actions && actions->size() > 0 )
+ {
+ mActionPopup->addSeparator();
+
+ // The assumption is made that an instance of QgsIdentifyResults is
+ // created for each new Identify Results dialog box, and that the
+ // contents of the popup menu doesn't change during the time that
+ // such a dialog box is around.
+ a = mActionPopup->addAction( tr( "Run action" ) );
+ a->setEnabled( false );
+
+ QgsAttributeAction::aIter iter = actions->begin();
+ for ( int i = 0; iter != actions->end(); ++iter, ++i )
{
- // The assumption is made that an instance of QgsIdentifyResults is
- // created for each new Identify Results dialog box, and that the
- // contents of the popup menu doesn't change during the time that
- // such a dialog box is around.
- a = mActionPopup->addAction( tr( "Run action" ) );
- a->setEnabled( false );
- mActionPopup->addSeparator();
-
- QgsAttributeAction::aIter iter = actions->begin();
- for ( int j = 0; iter != actions->end(); ++iter, ++j )
- {
- QAction* a = mActionPopup->addAction( iter->name() );
- // The menu action stores an integer that is used later on to
- // associate an menu action with an actual qgis action.
- a->setData( QVariant::fromValue( j ) );
- }
+ QAction* a = mActionPopup->addAction( iter->name() );
+ a->setEnabled( true );
+ // The menu action stores an integer that is used later on to
+ // associate an menu action with an actual qgis action.
+ a->setData( QVariant::fromValue( i ) );
}
-
- connect( mActionPopup, SIGNAL( triggered( QAction* ) ), this, SLOT( popupItemSelected( QAction* ) ) );
}
+ connect( mActionPopup, SIGNAL( triggered( QAction* ) ), this, SLOT( popupItemSelected( QAction* ) ) );
+
mActionPopup->popup( event->globalPos() );
}
@@ -256,15 +257,15 @@
if ( item == 0 )
return;
- int id = menuAction->data().toInt();
+ int action = menuAction->data().toInt();
- if ( id < 0 )
+ if ( action < 0 )
{
- if ( id == -4 )
+ if ( action == -4 )
{
editFeature( item );
}
- else if ( id == -3 )
+ else if ( action == -3 )
{
zoomToFeature( item );
}
@@ -273,7 +274,7 @@
QClipboard *clipboard = QApplication::clipboard();
QString text;
- if ( id == -2 )
+ if ( action == -2 )
{
text = item->data( 1, Qt::DisplayRole ).toString();
}
@@ -294,7 +295,7 @@
}
else
{
- doAction( item );
+ doAction( item, action );
}
}
@@ -343,20 +344,34 @@
mRubberBandFid = 0;
}
-void QgsIdentifyResults::doAction( QTreeWidgetItem *item )
+void QgsIdentifyResults::doAction( QTreeWidgetItem *item, int action )
{
std::vector< std::pair<QString, QString> > attributes;
QTreeWidgetItem *featItem = retrieveAttributes( item, attributes );
if ( !featItem )
return;
- int id = featItem->data( 0, Qt::UserRole ).toInt();
-
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer *>( featItem->parent()->data( 0, Qt::UserRole ).value<QObject *>() );
if ( !layer )
return;
- layer->actions()->doAction( id, attributes, id );
+ int idx = -1;
+ if ( item->parent() == featItem )
+ {
+ QString fieldName = item->data( 0, Qt::DisplayRole ).toString();
+
+ int idx = -1;
+ for ( QgsFieldMap::const_iterator it = layer->pendingFields().begin(); it != layer->pendingFields().end(); it++ )
+ {
+ if ( it->name() == fieldName )
+ {
+ idx = it.key();
+ break;
+ }
+ }
+ }
+
+ layer->actions()->doAction( action, attributes, idx );
}
QTreeWidgetItem *QgsIdentifyResults::featureItem( QTreeWidgetItem *item )
Modified: trunk/qgis/src/app/qgsidentifyresults.h
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.h 2009-09-08 21:25:46 UTC (rev 11599)
+++ trunk/qgis/src/app/qgsidentifyresults.h 2009-09-08 23:31:22 UTC (rev 11600)
@@ -116,7 +116,7 @@
void zoomToFeature( QTreeWidgetItem *item );
void editFeature( QTreeWidgetItem *item );
- void doAction( QTreeWidgetItem *item );
+ void doAction( QTreeWidgetItem *item, int action );
};
#endif
More information about the QGIS-commit
mailing list