From 8b4cb049aefb7a2c58ca5847c31cc636a3908f45 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Mon, 2 May 2016 12:21:08 +0200 Subject: [PATCH] Allow controlling action visibility on attribute table --- python/core/qgsaction.sip | 15 +++++++++++ src/app/qgsattributeactiondialog.cpp | 9 +++++++ src/app/qgsattributeactiondialog.h | 3 ++- .../qgsattributeactionpropertiesdialog.cpp | 8 +++++- src/app/qgsattributeactionpropertiesdialog.h | 4 ++- src/core/qgsaction.h | 27 +++++++++++++++++++ src/core/qgsactionmanager.cpp | 2 ++ .../attributetable/qgsattributetableview.cpp | 3 +++ .../qgsattributeactionpropertiesdialogbase.ui | 7 +++++ 9 files changed, 75 insertions(+), 3 deletions(-) diff --git a/python/core/qgsaction.sip b/python/core/qgsaction.sip index d1564830ca9..8bf94e4debd 100644 --- a/python/core/qgsaction.sip +++ b/python/core/qgsaction.sip @@ -56,6 +56,18 @@ class QgsAction */ QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, const QString& shortTitle = QString() ); + /** + * Create a new QgsAction + * + * @param type The type of this action + * @param description A human readable description string + * @param action The action text. Its interpretation depends on the type + * @param icon Path to an icon for this action + * @param capture If this is set to true, the output will be captured when an action is run + * @param showInAttributeTable If this is false, the action will be hidden on the attribute table action widget + * @param shortTitle A short string used to label user interface elements like buttons + */ + QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, bool showInAttributeTable, const QString& shortTitle = QString() ); //! The name of the action. This may be a longer description. QString name() const; @@ -78,6 +90,9 @@ class QgsAction //! Whether to capture output for display when this action is run bool capture() const; + //! Wheter this action should be shown on the attribute table + bool showInAttributeTable() const; + //! Whether the action is runable on the current platform bool runable() const; }; diff --git a/src/app/qgsattributeactiondialog.cpp b/src/app/qgsattributeactiondialog.cpp index cea5da7be28..f7d9d328156 100644 --- a/src/app/qgsattributeactiondialog.cpp +++ b/src/app/qgsattributeactiondialog.cpp @@ -112,6 +112,12 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action ) item->setCheckState( action.capture() ? Qt::Checked : Qt::Unchecked ); mAttributeActionTable->setItem( row, Capture, item ); + // Capture output + item = new QTableWidgetItem(); + item->setFlags( item->flags() & ~( Qt::ItemIsEditable ) ); + item->setCheckState( action.showInAttributeTable() ? Qt::Checked : Qt::Unchecked ); + mAttributeActionTable->setItem( row, ShowInAttributeTable, item ); + // Icon QIcon icon = action.icon(); QTableWidgetItem* headerItem = new QTableWidgetItem( icon, "" ); @@ -190,6 +196,7 @@ QgsAction QgsAttributeActionDialog::rowToAction( int row ) const mAttributeActionTable->item( row, ActionText )->text(), mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked, + mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked, mAttributeActionTable->item( row, ShortTitle )->text() ); return action; } @@ -290,6 +297,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item ) mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->item( row, ActionText )->text(), mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked, + mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked, mLayer ); @@ -303,6 +311,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item ) mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() ); mAttributeActionTable->item( row, ActionText )->setText( actionProperties.actionText() ); mAttributeActionTable->item( row, Capture )->setCheckState( actionProperties.capture() ? Qt::Checked : Qt::Unchecked ); + mAttributeActionTable->item( row, ShowInAttributeTable )->setCheckState( actionProperties.showInAttributeTable() ? Qt::Checked : Qt::Unchecked ); mAttributeActionTable->verticalHeaderItem( row )->setData( Qt::UserRole, actionProperties.iconPath() ); mAttributeActionTable->verticalHeaderItem( row )->setIcon( QIcon( actionProperties.iconPath() ) ); } diff --git a/src/app/qgsattributeactiondialog.h b/src/app/qgsattributeactiondialog.h index 8120007ff75..0f9cb26452b 100644 --- a/src/app/qgsattributeactiondialog.h +++ b/src/app/qgsattributeactiondialog.h @@ -38,7 +38,8 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib Description, ShortTitle, ActionText, - Capture + Capture, + ShowInAttributeTable }; public: diff --git a/src/app/qgsattributeactionpropertiesdialog.cpp b/src/app/qgsattributeactionpropertiesdialog.cpp index 9151641205d..b1b9e37c9c5 100644 --- a/src/app/qgsattributeactionpropertiesdialog.cpp +++ b/src/app/qgsattributeactionpropertiesdialog.cpp @@ -27,7 +27,7 @@ #include #include -QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, QgsVectorLayer* layer, QWidget* parent ) +QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, bool showInAttributeTable, QgsVectorLayer* layer, QWidget* parent ) : QDialog( parent ) , mLayer( layer ) { @@ -40,6 +40,7 @@ QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsActio mIconPreview->setPixmap( QPixmap( iconPath ) ); mActionText->setText( actionText ); mCaptureOutput->setChecked( capture ); + mShowInAttributeTable->setChecked( showInAttributeTable ); // display the expression builder QgsExpressionContext context; @@ -117,6 +118,11 @@ QString QgsAttributeActionPropertiesDialog::actionText() const return mActionText->text(); } +bool QgsAttributeActionPropertiesDialog::showInAttributeTable() const +{ + return mShowInAttributeTable->isChecked(); +} + bool QgsAttributeActionPropertiesDialog::capture() const { return mCaptureOutput->isChecked(); diff --git a/src/app/qgsattributeactionpropertiesdialog.h b/src/app/qgsattributeactionpropertiesdialog.h index 665cc7e36fa..f2f3669413b 100644 --- a/src/app/qgsattributeactionpropertiesdialog.h +++ b/src/app/qgsattributeactionpropertiesdialog.h @@ -27,7 +27,7 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu Q_OBJECT public: - QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, QgsVectorLayer* layer, QWidget* parent = nullptr ); + QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, bool showInAttributeTable, QgsVectorLayer* layer, QWidget* parent = nullptr ); QgsAttributeActionPropertiesDialog( QgsVectorLayer* layer, QWidget* parent = nullptr ); @@ -41,6 +41,8 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu QString actionText() const; + bool showInAttributeTable() const; + bool capture() const; private slots: diff --git a/src/core/qgsaction.h b/src/core/qgsaction.h index 76c75f19486..d5800880e0e 100644 --- a/src/core/qgsaction.h +++ b/src/core/qgsaction.h @@ -48,6 +48,7 @@ class CORE_EXPORT QgsAction , mDescription( description ) , mAction( action ) , mCaptureOutput( capture ) + , mShowInAttributeTable( true ) {} @@ -68,6 +69,28 @@ class CORE_EXPORT QgsAction , mIcon( icon ) , mAction( action ) , mCaptureOutput( capture ) + , mShowInAttributeTable( true ) + {} + + /** + * Create a new QgsAction + * + * @param type The type of this action + * @param description A human readable description string + * @param action The action text. Its interpretation depends on the type + * @param icon Path to an icon for this action + * @param capture If this is set to true, the output will be captured when an action is run + * @param showInAttributeTable If this is false, the action will be hidden on the attribute table action widget + * @param shortTitle A short string used to label user interface elements like buttons + */ + QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, bool showInAttributeTable, const QString& shortTitle = QString() ) + : mType( type ) + , mDescription( description ) + , mShortTitle( shortTitle ) + , mIcon( icon ) + , mAction( action ) + , mCaptureOutput( capture ) + , mShowInAttributeTable( showInAttributeTable ) {} //! The name of the action. This may be a longer description. @@ -91,6 +114,9 @@ class CORE_EXPORT QgsAction //! Whether to capture output for display when this action is run bool capture() const { return mCaptureOutput; } + //! Wheter this action should be shown on the attribute table + bool showInAttributeTable() const { return mShowInAttributeTable; } + //! Checks if the action is runable on the current platform bool runable() const; @@ -101,6 +127,7 @@ class CORE_EXPORT QgsAction QString mIcon; QString mAction; bool mCaptureOutput; + bool mShowInAttributeTable; }; #endif // QGSACTION_H diff --git a/src/core/qgsactionmanager.cpp b/src/core/qgsactionmanager.cpp index 56d40965a9e..9789a94d242 100644 --- a/src/core/qgsactionmanager.cpp +++ b/src/core/qgsactionmanager.cpp @@ -284,6 +284,7 @@ bool QgsActionManager::writeXML( QDomNode& layer_node, QDomDocument& doc ) const actionSetting.setAttribute( "icon", action.iconPath() ); actionSetting.setAttribute( "action", action.action() ); actionSetting.setAttribute( "capture", action.capture() ); + actionSetting.setAttribute( "showInAttributeTable", action.showInAttributeTable() ); aActions.appendChild( actionSetting ); } layer_node.appendChild( aActions ); @@ -309,6 +310,7 @@ bool QgsActionManager::readXML( const QDomNode& layer_node ) setting.attributeNode( "action" ).value(), setting.attributeNode( "icon" ).value(), setting.attributeNode( "capture" ).value().toInt() != 0, + !setting.attributes().contains( "showInAttributeTable" ) || setting.attributeNode( "showInAttributeTable" ).value().toInt() != 0, setting.attributeNode( "shortTitle" ).value() ) ); diff --git a/src/gui/attributetable/qgsattributetableview.cpp b/src/gui/attributetable/qgsattributetableview.cpp index b0033e710b4..6350abe158a 100644 --- a/src/gui/attributetable/qgsattributetableview.cpp +++ b/src/gui/attributetable/qgsattributetableview.cpp @@ -146,6 +146,9 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid ) { const QgsAction& action = actions->at( i ); + if ( !action.showInAttributeTable() ) + continue; + QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton ); act->setToolTip( action.name() ); act->setData( i ); diff --git a/src/ui/qgsattributeactionpropertiesdialogbase.ui b/src/ui/qgsattributeactionpropertiesdialogbase.ui index 7bf0feec35b..49e3549b59a 100644 --- a/src/ui/qgsattributeactionpropertiesdialogbase.ui +++ b/src/ui/qgsattributeactionpropertiesdialogbase.ui @@ -252,6 +252,13 @@ + + + + Show in attribute table + + +