Address PR comments

This commit is contained in:
Alessandro Pasotti 2021-08-18 15:45:05 +02:00
parent c27d472e8c
commit cc8178821a
7 changed files with 26 additions and 61 deletions

View File

@ -34,7 +34,7 @@ Utility class that encapsulates an action based on vector attributes.
Default constructor Default constructor
%End %End
QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false ); QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false);
%Docstring %Docstring
Create a new QgsAction Create a new QgsAction
@ -42,10 +42,9 @@ Create a new QgsAction
:param description: A human readable description string :param description: A human readable description string
:param command: The action text. Its interpretation depends on the type :param command: The action text. Its interpretation depends on the type
:param capture: If this is set to ``True``, the output will be captured when an action is run :param capture: If this is set to ``True``, the output will be captured when an action is run
:param enabledOnlyWhenEditable: if ``True`` then action is only enable in editmode. Not available in Python bindings.
%End %End
QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString() ); QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring %Docstring
Create a new QgsAction Create a new QgsAction
@ -57,10 +56,9 @@ Create a new QgsAction
:param shortTitle: A short string used to label user interface elements like buttons :param shortTitle: A short string used to label user interface elements like buttons
:param actionScopes: A set of scopes in which this action will be available :param actionScopes: A set of scopes in which this action will be available
:param notificationMessage: A particular message which reception will trigger the action :param notificationMessage: A particular message which reception will trigger the action
:param enabledOnlyWhenEditable: if ``True`` then action is only enable in editmode. Not available in Python bindings.
%End %End
QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString() ); QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring %Docstring
Create a new QgsAction Create a new QgsAction
@ -73,9 +71,9 @@ Create a new QgsAction
:param shortTitle: A short string used to label user interface elements like buttons :param shortTitle: A short string used to label user interface elements like buttons
:param actionScopes: A set of scopes in which this action will be available :param actionScopes: A set of scopes in which this action will be available
:param notificationMessage: A particular message which reception will trigger the action :param notificationMessage: A particular message which reception will trigger the action
:param enabledOnlyWhenEditable: if ``True`` then action is only enable in editmode. Not available in Python bindings.
%End %End
QString name() const; QString name() const;
%Docstring %Docstring
The name of the action. This may be a longer description. The name of the action. This may be a longer description.

View File

@ -58,8 +58,7 @@ class CORE_EXPORT QgsAction
* \param capture If this is set to TRUE, the output will be captured when an action is run * \param capture If this is set to TRUE, the output will be captured when an action is run
* \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings. * \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings.
*/ */
#ifndef SIP_RUN QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false, bool enabledOnlyWhenEditable = false )
: mType( type ) : mType( type )
, mDescription( description ) , mDescription( description )
, mCommand( command ) , mCommand( command )
@ -67,16 +66,6 @@ class CORE_EXPORT QgsAction
, mId( QUuid::createUuid() ) , mId( QUuid::createUuid() )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable ) , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{} {}
#else
QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false )
: mType( type )
, mDescription( description )
, mCommand( command )
, mCaptureOutput( capture )
, mId( QUuid::createUuid() )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{}
#endif
/** /**
* Create a new QgsAction * Create a new QgsAction
@ -91,8 +80,7 @@ class CORE_EXPORT QgsAction
* \param notificationMessage A particular message which reception will trigger the action * \param notificationMessage A particular message which reception will trigger the action
* \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings. * \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings.
*/ */
#ifndef SIP_RUN QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable = false )
: mType( type ) : mType( type )
, mDescription( description ) , mDescription( description )
, mShortTitle( shortTitle ) , mShortTitle( shortTitle )
@ -104,20 +92,6 @@ class CORE_EXPORT QgsAction
, mId( QUuid::createUuid() ) , mId( QUuid::createUuid() )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable ) , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{} {}
#else
QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString() )
: mType( type )
, mDescription( description )
, mShortTitle( shortTitle )
, mIcon( icon )
, mCommand( action )
, mCaptureOutput( capture )
, mActionScopes( actionScopes )
, mNotificationMessage( notificationMessage )
, mId( QUuid::createUuid() )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{}
#endif
/** /**
* Create a new QgsAction * Create a new QgsAction
@ -133,8 +107,7 @@ class CORE_EXPORT QgsAction
* \param notificationMessage A particular message which reception will trigger the action * \param notificationMessage A particular message which reception will trigger the action
* \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings. * \param enabledOnlyWhenEditable if TRUE then action is only enable in editmode. Not available in Python bindings.
*/ */
#ifndef SIP_RUN QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable SIP_PYARGREMOVE = false )
QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString(), bool enabledOnlyWhenEditable = false )
: mType( type ) : mType( type )
, mDescription( description ) , mDescription( description )
, mShortTitle( shortTitle ) , mShortTitle( shortTitle )
@ -146,20 +119,7 @@ class CORE_EXPORT QgsAction
, mId( id ) , mId( id )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable ) , mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{} {}
#else
QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString() )
: mType( type )
, mDescription( description )
, mShortTitle( shortTitle )
, mIcon( icon )
, mCommand( action )
, mCaptureOutput( capture )
, mActionScopes( actionScopes )
, mNotificationMessage( notificationMessage )
, mId( id )
, mIsEnabledOnlyWhenEditable( enabledOnlyWhenEditable )
{}
#endif
//! 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 { return mDescription; } QString name() const { return mDescription; }

View File

@ -48,7 +48,7 @@ void QgsActionWidgetWrapper::setEnabled( bool enabled )
{ {
if ( valid() && layer() ) if ( valid() && layer() )
{ {
mActionButton->setEnabled( ! mAction.isEnabledOnlyWhenEditable() || enabled ); mActionButton->setEnabled( !mAction.isEnabledOnlyWhenEditable() || enabled );
} }
} }
@ -79,7 +79,7 @@ void QgsActionWidgetWrapper::initWidget( QWidget *editor )
// Configure push button // Configure push button
if ( ! icon.isNull() ) if ( ! icon.isNull() )
{ {
mActionButton->setIcon( mAction.icon() ); mActionButton->setIcon( icon );
mActionButton->setToolTip( description ); mActionButton->setToolTip( description );
} }
else else
@ -91,7 +91,7 @@ void QgsActionWidgetWrapper::initWidget( QWidget *editor )
} }
} }
if ( mAction.isEnabledOnlyWhenEditable() && ! layer()->isEditable() ) if ( mAction.isEnabledOnlyWhenEditable() && !layer()->isEditable() )
{ {
mActionButton->setEnabled( false ); mActionButton->setEnabled( false );
} }

View File

@ -444,7 +444,7 @@ void QgsValueRelationWidgetWrapper::showIndeterminateState()
{ {
for ( int i = 0; i < nofColumns; ++i ) for ( int i = 0; i < nofColumns; ++i )
{ {
whileBlocking( mTableWidget ) ->item( j, i )->setCheckState( Qt::PartiallyChecked ); whileBlocking( mTableWidget )->item( j, i )->setCheckState( Qt::PartiallyChecked );
} }
} }
} }

View File

@ -111,8 +111,8 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction &action )
// Type // Type
item = new QTableWidgetItem( textForType( action.type() ) ); item = new QTableWidgetItem( textForType( action.type() ) );
item->setData( Qt::UserRole, action.type() ); item->setData( Role::ActionType, action.type() );
item->setData( Qt::UserRole + 1, action.id() ); item->setData( Role::ActionId, action.id() );
item->setFlags( item->flags() & ~Qt::ItemIsEditable ); item->setFlags( item->flags() & ~Qt::ItemIsEditable );
mAttributeActionTable->setItem( row, Type, item ); mAttributeActionTable->setItem( row, Type, item );
@ -225,9 +225,9 @@ void QgsAttributeActionDialog::swapRows( int row1, int row2 )
QgsAction QgsAttributeActionDialog::rowToAction( int row ) const QgsAction QgsAttributeActionDialog::rowToAction( int row ) const
{ {
const QUuid id { mAttributeActionTable->item( row, Type )->data( Qt::UserRole + 1 ).toUuid() }; const QUuid id { mAttributeActionTable->item( row, Type )->data( Role::ActionId ).toUuid() };
QgsAction action( id, QgsAction action( id,
static_cast<QgsAction::ActionType>( mAttributeActionTable->item( row, Type )->data( Qt::UserRole ).toInt() ), static_cast<QgsAction::ActionType>( mAttributeActionTable->item( row, Type )->data( Role::ActionType ).toInt() ),
mAttributeActionTable->item( row, Description )->text(), mAttributeActionTable->item( row, Description )->text(),
mAttributeActionTable->item( row, ActionText )->data( Qt::UserRole ).toString(), mAttributeActionTable->item( row, ActionText )->data( Qt::UserRole ).toString(),
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
@ -334,7 +334,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem *item )
const int row = item->row(); const int row = item->row();
QgsAttributeActionPropertiesDialog actionProperties( QgsAttributeActionPropertiesDialog actionProperties(
static_cast<QgsAction::ActionType>( mAttributeActionTable->item( row, Type )->data( Qt::UserRole ).toInt() ), static_cast<QgsAction::ActionType>( mAttributeActionTable->item( row, Type )->data( Role::ActionType ).toInt() ),
mAttributeActionTable->item( row, Description )->text(), mAttributeActionTable->item( row, Description )->text(),
mAttributeActionTable->item( row, ShortTitle )->text(), mAttributeActionTable->item( row, ShortTitle )->text(),
mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(),
@ -350,7 +350,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem *item )
if ( actionProperties.exec() ) if ( actionProperties.exec() )
{ {
mAttributeActionTable->item( row, Type )->setData( Qt::UserRole, actionProperties.type() ); mAttributeActionTable->item( row, Type )->setData( Role::ActionType, actionProperties.type() );
mAttributeActionTable->item( row, Type )->setText( textForType( actionProperties.type() ) ); mAttributeActionTable->item( row, Type )->setText( textForType( actionProperties.type() ) );
mAttributeActionTable->item( row, Description )->setText( actionProperties.description() ); mAttributeActionTable->item( row, Description )->setText( actionProperties.description() );
mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() ); mAttributeActionTable->item( row, ShortTitle )->setText( actionProperties.shortTitle() );

View File

@ -51,6 +51,13 @@ class GUI_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib
EnabledOnlyWhenEditable EnabledOnlyWhenEditable
}; };
//! UserRole for Type data
enum Role
{
ActionType = Qt::UserRole,
ActionId = Qt::UserRole + 1
};
public: public:
QgsAttributeActionDialog( const QgsActionManager &actions, QgsAttributeActionDialog( const QgsActionManager &actions,
QWidget *parent = nullptr ); QWidget *parent = nullptr );

View File

@ -588,7 +588,7 @@ void QgsAttributesFormProperties::loadAttributeSpecificEditor( QgsAttributesDnDT
} }
case DnDTreeItemData::Action: case DnDTreeItemData::Action:
{ {
receiver->clearSelection(); receiver->selectFirstMatchingItem( itemData );
break; break;
} }
case DnDTreeItemData::QmlWidget: case DnDTreeItemData::QmlWidget: