Skip to content
Permalink
Browse files
Allow controlling action visibility on attribute table
  • Loading branch information
m-kuhn committed May 2, 2016
1 parent c5d00f0 commit 8b4cb049aefb7a2c58ca5847c31cc636a3908f45
@@ -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;
};
@@ -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() ) );
}
@@ -38,7 +38,8 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
Description,
ShortTitle,
ActionText,
Capture
Capture,
ShowInAttributeTable
};

public:
@@ -27,7 +27,7 @@
#include <QFileDialog>
#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 )
, 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();
@@ -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:
@@ -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
@@ -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()
)
);
@@ -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 );
@@ -252,6 +252,13 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="mShowInAttributeTable">
<property name="text">
<string>Show in attribute table</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>

2 comments on commit 8b4cb04

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied May 2, 2016

@m-kuhn I can't seem to get this to stick. If I enable it on the attribute screen, then apply and open the table I see nothing new, and reopening layer properties shows the checkbox as cleared again.

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied May 3, 2016

Seems the columns need to be reordered first to initialize the datastructure. Fixing it now.

Please sign in to comment.