Allow controlling action visibility on attribute table

This commit is contained in:
Matthias Kuhn 2016-05-02 12:21:08 +02:00
parent c5d00f09d0
commit 8b4cb049ae
9 changed files with 75 additions and 3 deletions

View File

@ -56,6 +56,18 @@ class QgsAction
*/ */
QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, const QString& shortTitle = QString() ); 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. //! The name of the action. This may be a longer description.
QString name() const; QString name() const;
@ -78,6 +90,9 @@ class QgsAction
//! Whether to capture output for display when this action is run //! Whether to capture output for display when this action is run
bool capture() const; 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 //! Whether the action is runable on the current platform
bool runable() const; bool runable() const;
}; };

View File

@ -112,6 +112,12 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action )
item->setCheckState( action.capture() ? Qt::Checked : Qt::Unchecked ); item->setCheckState( action.capture() ? Qt::Checked : Qt::Unchecked );
mAttributeActionTable->setItem( row, Capture, item ); 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 // Icon
QIcon icon = action.icon(); QIcon icon = action.icon();
QTableWidgetItem* headerItem = new QTableWidgetItem( icon, "" ); QTableWidgetItem* headerItem = new QTableWidgetItem( icon, "" );
@ -190,6 +196,7 @@ QgsAction QgsAttributeActionDialog::rowToAction( int row ) const
mAttributeActionTable->item( row, ActionText )->text(), mAttributeActionTable->item( row, ActionText )->text(),
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked, mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked,
mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked,
mAttributeActionTable->item( row, ShortTitle )->text() ); mAttributeActionTable->item( row, ShortTitle )->text() );
return action; return action;
} }
@ -290,6 +297,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
mAttributeActionTable->item( row, ActionText )->text(), mAttributeActionTable->item( row, ActionText )->text(),
mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked, mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked,
mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked,
mLayer mLayer
); );
@ -303,6 +311,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )
mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() ); mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() );
mAttributeActionTable->item( row, ActionText )->setText( actionProperties.actionText() ); mAttributeActionTable->item( row, ActionText )->setText( actionProperties.actionText() );
mAttributeActionTable->item( row, Capture )->setCheckState( actionProperties.capture() ? Qt::Checked : Qt::Unchecked ); 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 )->setData( Qt::UserRole, actionProperties.iconPath() );
mAttributeActionTable->verticalHeaderItem( row )->setIcon( QIcon( actionProperties.iconPath() ) ); mAttributeActionTable->verticalHeaderItem( row )->setIcon( QIcon( actionProperties.iconPath() ) );
} }

View File

@ -38,7 +38,8 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
Description, Description,
ShortTitle, ShortTitle,
ActionText, ActionText,
Capture Capture,
ShowInAttributeTable
}; };
public: public:

View File

@ -27,7 +27,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QImageWriter> #include <QImageWriter>
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 ) : QDialog( parent )
, mLayer( layer ) , mLayer( layer )
{ {
@ -40,6 +40,7 @@ QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsActio
mIconPreview->setPixmap( QPixmap( iconPath ) ); mIconPreview->setPixmap( QPixmap( iconPath ) );
mActionText->setText( actionText ); mActionText->setText( actionText );
mCaptureOutput->setChecked( capture ); mCaptureOutput->setChecked( capture );
mShowInAttributeTable->setChecked( showInAttributeTable );
// display the expression builder // display the expression builder
QgsExpressionContext context; QgsExpressionContext context;
@ -117,6 +118,11 @@ QString QgsAttributeActionPropertiesDialog::actionText() const
return mActionText->text(); return mActionText->text();
} }
bool QgsAttributeActionPropertiesDialog::showInAttributeTable() const
{
return mShowInAttributeTable->isChecked();
}
bool QgsAttributeActionPropertiesDialog::capture() const bool QgsAttributeActionPropertiesDialog::capture() const
{ {
return mCaptureOutput->isChecked(); return mCaptureOutput->isChecked();

View File

@ -27,7 +27,7 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu
Q_OBJECT Q_OBJECT
public: 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 ); QgsAttributeActionPropertiesDialog( QgsVectorLayer* layer, QWidget* parent = nullptr );
@ -41,6 +41,8 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu
QString actionText() const; QString actionText() const;
bool showInAttributeTable() const;
bool capture() const; bool capture() const;
private slots: private slots:

View File

@ -48,6 +48,7 @@ class CORE_EXPORT QgsAction
, mDescription( description ) , mDescription( description )
, mAction( action ) , mAction( action )
, mCaptureOutput( capture ) , mCaptureOutput( capture )
, mShowInAttributeTable( true )
{} {}
@ -68,6 +69,28 @@ class CORE_EXPORT QgsAction
, mIcon( icon ) , mIcon( icon )
, mAction( action ) , mAction( action )
, mCaptureOutput( capture ) , 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. //! 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 //! Whether to capture output for display when this action is run
bool capture() const { return mCaptureOutput; } 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 //! Checks if the action is runable on the current platform
bool runable() const; bool runable() const;
@ -101,6 +127,7 @@ class CORE_EXPORT QgsAction
QString mIcon; QString mIcon;
QString mAction; QString mAction;
bool mCaptureOutput; bool mCaptureOutput;
bool mShowInAttributeTable;
}; };
#endif // QGSACTION_H #endif // QGSACTION_H

View File

@ -284,6 +284,7 @@ bool QgsActionManager::writeXML( QDomNode& layer_node, QDomDocument& doc ) const
actionSetting.setAttribute( "icon", action.iconPath() ); actionSetting.setAttribute( "icon", action.iconPath() );
actionSetting.setAttribute( "action", action.action() ); actionSetting.setAttribute( "action", action.action() );
actionSetting.setAttribute( "capture", action.capture() ); actionSetting.setAttribute( "capture", action.capture() );
actionSetting.setAttribute( "showInAttributeTable", action.showInAttributeTable() );
aActions.appendChild( actionSetting ); aActions.appendChild( actionSetting );
} }
layer_node.appendChild( aActions ); layer_node.appendChild( aActions );
@ -309,6 +310,7 @@ bool QgsActionManager::readXML( const QDomNode& layer_node )
setting.attributeNode( "action" ).value(), setting.attributeNode( "action" ).value(),
setting.attributeNode( "icon" ).value(), setting.attributeNode( "icon" ).value(),
setting.attributeNode( "capture" ).value().toInt() != 0, setting.attributeNode( "capture" ).value().toInt() != 0,
!setting.attributes().contains( "showInAttributeTable" ) || setting.attributeNode( "showInAttributeTable" ).value().toInt() != 0,
setting.attributeNode( "shortTitle" ).value() setting.attributeNode( "shortTitle" ).value()
) )
); );

View File

@ -146,6 +146,9 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
{ {
const QgsAction& action = actions->at( i ); const QgsAction& action = actions->at( i );
if ( !action.showInAttributeTable() )
continue;
QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton ); QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton );
act->setToolTip( action.name() ); act->setToolTip( action.name() );
act->setData( i ); act->setData( i );

View File

@ -252,6 +252,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3">
<widget class="QCheckBox" name="mShowInAttributeTable">
<property name="text">
<string>Show in attribute table</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>