Skip to content

Commit 8b4cb04

Browse files
committedMay 2, 2016
Allow controlling action visibility on attribute table
1 parent c5d00f0 commit 8b4cb04

9 files changed

+75
-3
lines changed
 

‎python/core/qgsaction.sip‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ class QgsAction
5656
*/
5757
QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, const QString& shortTitle = QString() );
5858

59+
/**
60+
* Create a new QgsAction
61+
*
62+
* @param type The type of this action
63+
* @param description A human readable description string
64+
* @param action The action text. Its interpretation depends on the type
65+
* @param icon Path to an icon for this action
66+
* @param capture If this is set to true, the output will be captured when an action is run
67+
* @param showInAttributeTable If this is false, the action will be hidden on the attribute table action widget
68+
* @param shortTitle A short string used to label user interface elements like buttons
69+
*/
70+
QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, bool showInAttributeTable, const QString& shortTitle = QString() );
5971

6072
//! The name of the action. This may be a longer description.
6173
QString name() const;
@@ -78,6 +90,9 @@ class QgsAction
7890
//! Whether to capture output for display when this action is run
7991
bool capture() const;
8092

93+
//! Wheter this action should be shown on the attribute table
94+
bool showInAttributeTable() const;
95+
8196
//! Whether the action is runable on the current platform
8297
bool runable() const;
8398
};

‎src/app/qgsattributeactiondialog.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action )
112112
item->setCheckState( action.capture() ? Qt::Checked : Qt::Unchecked );
113113
mAttributeActionTable->setItem( row, Capture, item );
114114

115+
// Capture output
116+
item = new QTableWidgetItem();
117+
item->setFlags( item->flags() & ~( Qt::ItemIsEditable ) );
118+
item->setCheckState( action.showInAttributeTable() ? Qt::Checked : Qt::Unchecked );
119+
mAttributeActionTable->setItem( row, ShowInAttributeTable, item );
120+
115121
// Icon
116122
QIcon icon = action.icon();
117123
QTableWidgetItem* headerItem = new QTableWidgetItem( icon, "" );
@@ -190,6 +196,7 @@ QgsAction QgsAttributeActionDialog::rowToAction( int row ) const
190196
mAttributeActionTable->item( row, ActionText )->text(),
191197
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
192198
mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked,
199+
mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked,
193200
mAttributeActionTable->item( row, ShortTitle )->text() );
194201
return action;
195202
}
@@ -290,6 +297,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )
290297
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
291298
mAttributeActionTable->item( row, ActionText )->text(),
292299
mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked,
300+
mAttributeActionTable->item( row, ShowInAttributeTable )->checkState() == Qt::Checked,
293301
mLayer
294302
);
295303

@@ -303,6 +311,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )
303311
mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() );
304312
mAttributeActionTable->item( row, ActionText )->setText( actionProperties.actionText() );
305313
mAttributeActionTable->item( row, Capture )->setCheckState( actionProperties.capture() ? Qt::Checked : Qt::Unchecked );
314+
mAttributeActionTable->item( row, ShowInAttributeTable )->setCheckState( actionProperties.showInAttributeTable() ? Qt::Checked : Qt::Unchecked );
306315
mAttributeActionTable->verticalHeaderItem( row )->setData( Qt::UserRole, actionProperties.iconPath() );
307316
mAttributeActionTable->verticalHeaderItem( row )->setIcon( QIcon( actionProperties.iconPath() ) );
308317
}

‎src/app/qgsattributeactiondialog.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
3838
Description,
3939
ShortTitle,
4040
ActionText,
41-
Capture
41+
Capture,
42+
ShowInAttributeTable
4243
};
4344

4445
public:

‎src/app/qgsattributeactionpropertiesdialog.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <QFileDialog>
2828
#include <QImageWriter>
2929

30-
QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, QgsVectorLayer* layer, QWidget* parent )
30+
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 )
3131
: QDialog( parent )
3232
, mLayer( layer )
3333
{
@@ -40,6 +40,7 @@ QgsAttributeActionPropertiesDialog::QgsAttributeActionPropertiesDialog( QgsActio
4040
mIconPreview->setPixmap( QPixmap( iconPath ) );
4141
mActionText->setText( actionText );
4242
mCaptureOutput->setChecked( capture );
43+
mShowInAttributeTable->setChecked( showInAttributeTable );
4344

4445
// display the expression builder
4546
QgsExpressionContext context;
@@ -117,6 +118,11 @@ QString QgsAttributeActionPropertiesDialog::actionText() const
117118
return mActionText->text();
118119
}
119120

121+
bool QgsAttributeActionPropertiesDialog::showInAttributeTable() const
122+
{
123+
return mShowInAttributeTable->isChecked();
124+
}
125+
120126
bool QgsAttributeActionPropertiesDialog::capture() const
121127
{
122128
return mCaptureOutput->isChecked();

‎src/app/qgsattributeactionpropertiesdialog.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu
2727
Q_OBJECT
2828

2929
public:
30-
QgsAttributeActionPropertiesDialog( QgsAction::ActionType type, const QString& description, const QString& shortTitle, const QString& iconPath, const QString& actionText, bool capture, QgsVectorLayer* layer, QWidget* parent = nullptr );
30+
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 );
3131

3232
QgsAttributeActionPropertiesDialog( QgsVectorLayer* layer, QWidget* parent = nullptr );
3333

@@ -41,6 +41,8 @@ class QgsAttributeActionPropertiesDialog: public QDialog, private Ui::QgsAttribu
4141

4242
QString actionText() const;
4343

44+
bool showInAttributeTable() const;
45+
4446
bool capture() const;
4547

4648
private slots:

‎src/core/qgsaction.h‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CORE_EXPORT QgsAction
4848
, mDescription( description )
4949
, mAction( action )
5050
, mCaptureOutput( capture )
51+
, mShowInAttributeTable( true )
5152
{}
5253

5354

@@ -68,6 +69,28 @@ class CORE_EXPORT QgsAction
6869
, mIcon( icon )
6970
, mAction( action )
7071
, mCaptureOutput( capture )
72+
, mShowInAttributeTable( true )
73+
{}
74+
75+
/**
76+
* Create a new QgsAction
77+
*
78+
* @param type The type of this action
79+
* @param description A human readable description string
80+
* @param action The action text. Its interpretation depends on the type
81+
* @param icon Path to an icon for this action
82+
* @param capture If this is set to true, the output will be captured when an action is run
83+
* @param showInAttributeTable If this is false, the action will be hidden on the attribute table action widget
84+
* @param shortTitle A short string used to label user interface elements like buttons
85+
*/
86+
QgsAction( ActionType type, const QString& description, const QString& action, const QString& icon, bool capture, bool showInAttributeTable, const QString& shortTitle = QString() )
87+
: mType( type )
88+
, mDescription( description )
89+
, mShortTitle( shortTitle )
90+
, mIcon( icon )
91+
, mAction( action )
92+
, mCaptureOutput( capture )
93+
, mShowInAttributeTable( showInAttributeTable )
7194
{}
7295

7396
//! The name of the action. This may be a longer description.
@@ -91,6 +114,9 @@ class CORE_EXPORT QgsAction
91114
//! Whether to capture output for display when this action is run
92115
bool capture() const { return mCaptureOutput; }
93116

117+
//! Wheter this action should be shown on the attribute table
118+
bool showInAttributeTable() const { return mShowInAttributeTable; }
119+
94120
//! Checks if the action is runable on the current platform
95121
bool runable() const;
96122

@@ -101,6 +127,7 @@ class CORE_EXPORT QgsAction
101127
QString mIcon;
102128
QString mAction;
103129
bool mCaptureOutput;
130+
bool mShowInAttributeTable;
104131
};
105132

106133
#endif // QGSACTION_H

‎src/core/qgsactionmanager.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ bool QgsActionManager::writeXML( QDomNode& layer_node, QDomDocument& doc ) const
284284
actionSetting.setAttribute( "icon", action.iconPath() );
285285
actionSetting.setAttribute( "action", action.action() );
286286
actionSetting.setAttribute( "capture", action.capture() );
287+
actionSetting.setAttribute( "showInAttributeTable", action.showInAttributeTable() );
287288
aActions.appendChild( actionSetting );
288289
}
289290
layer_node.appendChild( aActions );
@@ -309,6 +310,7 @@ bool QgsActionManager::readXML( const QDomNode& layer_node )
309310
setting.attributeNode( "action" ).value(),
310311
setting.attributeNode( "icon" ).value(),
311312
setting.attributeNode( "capture" ).value().toInt() != 0,
313+
!setting.attributes().contains( "showInAttributeTable" ) || setting.attributeNode( "showInAttributeTable" ).value().toInt() != 0,
312314
setting.attributeNode( "shortTitle" ).value()
313315
)
314316
);

‎src/gui/attributetable/qgsattributetableview.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
146146
{
147147
const QgsAction& action = actions->at( i );
148148

149+
if ( !action.showInAttributeTable() )
150+
continue;
151+
149152
QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton );
150153
act->setToolTip( action.name() );
151154
act->setData( i );

‎src/ui/qgsattributeactionpropertiesdialogbase.ui‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@
252252
</property>
253253
</widget>
254254
</item>
255+
<item row="0" column="3">
256+
<widget class="QCheckBox" name="mShowInAttributeTable">
257+
<property name="text">
258+
<string>Show in attribute table</string>
259+
</property>
260+
</widget>
261+
</item>
255262
</layout>
256263
</widget>
257264
<customwidgets>

0 commit comments

Comments
 (0)
Failed to load comments.