Skip to content

Commit

Permalink
Allow controlling action visibility on attribute table
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 2, 2016
1 parent c5d00f0 commit 8b4cb04
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 3 deletions.
15 changes: 15 additions & 0 deletions python/core/qgsaction.sip
Expand Up @@ -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;
Expand All @@ -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;
};
9 changes: 9 additions & 0 deletions src/app/qgsattributeactiondialog.cpp
Expand Up @@ -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, "" );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
);

Expand All @@ -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() ) );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsattributeactiondialog.h
Expand Up @@ -38,7 +38,8 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
Description,
ShortTitle,
ActionText,
Capture
Capture,
ShowInAttributeTable
};

public:
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsattributeactionpropertiesdialog.cpp
Expand Up @@ -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 )
{
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgsattributeactionpropertiesdialog.h
Expand Up @@ -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 );

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

QString actionText() const;

bool showInAttributeTable() const;

bool capture() const;

private slots:
Expand Down
27 changes: 27 additions & 0 deletions src/core/qgsaction.h
Expand Up @@ -48,6 +48,7 @@ class CORE_EXPORT QgsAction
, mDescription( description )
, mAction( action )
, mCaptureOutput( capture )
, mShowInAttributeTable( true )
{}


Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -101,6 +127,7 @@ class CORE_EXPORT QgsAction
QString mIcon;
QString mAction;
bool mCaptureOutput;
bool mShowInAttributeTable;
};

#endif // QGSACTION_H
2 changes: 2 additions & 0 deletions src/core/qgsactionmanager.cpp
Expand Up @@ -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 );
Expand All @@ -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()
)
);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/attributetable/qgsattributetableview.cpp
Expand Up @@ -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 );
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsattributeactionpropertiesdialogbase.ui
Expand Up @@ -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>
Expand Down

2 comments on commit 8b4cb04

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

@m-kuhn m-kuhn commented on 8b4cb04 May 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.