|
31 | 31 | #include "qgslogger.h"
|
32 | 32 | #include "qgsnetworkaccessmanager.h"
|
33 | 33 | #include "qgsproject.h"
|
| 34 | +#include "qgsmaplayeractionregistry.h" |
34 | 35 |
|
35 | 36 | #include <QCloseEvent>
|
36 | 37 | #include <QLabel>
|
@@ -242,6 +243,7 @@ void QgsIdentifyResultsWebViewItem::loadFinished( bool ok )
|
242 | 243 | // actions (if any) [userrole: "actions"]
|
243 | 244 | // edit [userrole: "edit"]
|
244 | 245 | // action [userrole: "action", idx]
|
| 246 | +// action [userrole: "map_layer_action", QgsMapLayerAction] |
245 | 247 | // displayname [userroles: fieldIdx, original name] displayvalue [userrole: original value]
|
246 | 248 | // displayname [userroles: fieldIdx, original name] displayvalue [userrole: original value]
|
247 | 249 | // displayname [userroles: fieldIdx, original name] displayvalue [userrole: original value]
|
@@ -421,9 +423,9 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
|
421 | 423 | }
|
422 | 424 |
|
423 | 425 | //get valid QgsMapLayerActions for this layer
|
424 |
| - mMapLayerActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ); |
| 426 | + QList< QgsMapLayerAction* > registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ); |
425 | 427 |
|
426 |
| - if ( vlayer->pendingFields().size() > 0 || vlayer->actions()->size() || mMapLayerActions.size() ) |
| 428 | + if ( vlayer->pendingFields().size() > 0 || vlayer->actions()->size() || registeredActions.size() ) |
427 | 429 | {
|
428 | 430 | QTreeWidgetItem *actionItem = new QTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
|
429 | 431 | actionItem->setData( 0, Qt::UserRole, "actions" );
|
@@ -452,20 +454,35 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
|
452 | 454 | }
|
453 | 455 |
|
454 | 456 | //add actions from QgsMapLayerActionRegistry
|
455 |
| - for ( int i = 0; i < mMapLayerActions.size(); i++ ) |
| 457 | + for ( int i = 0; i < registeredActions.size(); i++ ) |
456 | 458 | {
|
457 |
| - QgsMapLayerAction* action = mMapLayerActions.at( i ); |
| 459 | + QgsMapLayerAction* action = registeredActions.at( i ); |
458 | 460 | QTreeWidgetItem *twi = new QTreeWidgetItem( QStringList() << "" << action->text() );
|
459 | 461 | twi->setIcon( 0, QgsApplication::getThemeIcon( "/mAction.svg" ) );
|
460 | 462 | twi->setData( 0, Qt::UserRole, "map_layer_action" );
|
461 |
| - twi->setData( 0, Qt::UserRole + 1, QVariant::fromValue( i ) ); |
| 463 | + twi->setData( 0, Qt::UserRole + 1, qVariantFromValue( qobject_cast<QObject *>( action ) ) ); |
462 | 464 | actionItem->addChild( twi );
|
| 465 | + |
| 466 | + connect( action, SIGNAL( destroyed() ), this, SLOT( mapLayerActionDestroyed() ) ); |
463 | 467 | }
|
464 | 468 | }
|
465 | 469 |
|
466 | 470 | highlightFeature( featItem );
|
467 | 471 | }
|
468 | 472 |
|
| 473 | +void QgsIdentifyResultsDialog::mapLayerActionDestroyed() |
| 474 | +{ |
| 475 | + QTreeWidgetItemIterator it( lstResults ); |
| 476 | + while( *it ) |
| 477 | + { |
| 478 | + if( (*it)->data( 0, Qt::UserRole ) == "map_layer_action" && |
| 479 | + (*it)->data( 0, Qt::UserRole + 1 ).value< QObject *>() == sender() ) |
| 480 | + delete *it; |
| 481 | + else |
| 482 | + ++it; |
| 483 | + } |
| 484 | +} |
| 485 | + |
469 | 486 | void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
|
470 | 487 | QString label,
|
471 | 488 | const QMap<QString, QString> &attributes,
|
@@ -692,11 +709,8 @@ void QgsIdentifyResultsDialog::itemClicked( QTreeWidgetItem *item, int column )
|
692 | 709 | }
|
693 | 710 | else if ( item->data( 0, Qt::UserRole ).toString() == "map_layer_action" )
|
694 | 711 | {
|
695 |
| - QgsMapLayerAction* action = mMapLayerActions.at( item->data( 0, Qt::UserRole + 1 ).toInt() ); |
696 |
| - if ( action ) |
697 |
| - { |
698 |
| - doMapLayerAction( item, action ); |
699 |
| - } |
| 712 | + QObject *action = item->data( 0, Qt::UserRole + 1 ).value<QObject *>(); |
| 713 | + doMapLayerAction( item, qobject_cast<QgsMapLayerAction *>( action ) ); |
700 | 714 | }
|
701 | 715 | }
|
702 | 716 |
|
@@ -939,6 +953,9 @@ void QgsIdentifyResultsDialog::doMapLayerAction( QTreeWidgetItem *item, QgsMapLa
|
939 | 953 | if ( !layer )
|
940 | 954 | return;
|
941 | 955 |
|
| 956 | + if ( !action ) |
| 957 | + return; |
| 958 | + |
942 | 959 | int featIdx = featItem->data( 0, Qt::UserRole + 1 ).toInt();
|
943 | 960 | action->triggerForFeature( layer, &mFeatures[ featIdx ] );
|
944 | 961 | }
|
|
0 commit comments