From bd5a8875b964f5fbb3a5eadffe9524f6212c519c Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Mon, 3 Jun 2024 16:14:41 -0700 Subject: [PATCH] Added duplicate button to actions dialogue --- src/gui/vector/qgsattributeactiondialog.cpp | 31 +++++++++ src/gui/vector/qgsattributeactiondialog.h | 1 + src/ui/qgsattributeactiondialogbase.ui | 73 +++++++++++++-------- 3 files changed, 76 insertions(+), 29 deletions(-) diff --git a/src/gui/vector/qgsattributeactiondialog.cpp b/src/gui/vector/qgsattributeactiondialog.cpp index aabc5b30cc41..450be0491d8f 100644 --- a/src/gui/vector/qgsattributeactiondialog.cpp +++ b/src/gui/vector/qgsattributeactiondialog.cpp @@ -52,6 +52,7 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( const QgsActionManager &acti connect( mMoveDownButton, &QAbstractButton::clicked, this, &QgsAttributeActionDialog::moveDown ); connect( mRemoveButton, &QAbstractButton::clicked, this, &QgsAttributeActionDialog::remove ); connect( mAddButton, &QAbstractButton::clicked, this, &QgsAttributeActionDialog::insert ); + connect( mDuplicateButton, &QAbstractButton::clicked, this, &QgsAttributeActionDialog::duplicate ); connect( mAddDefaultActionsButton, &QAbstractButton::clicked, this, &QgsAttributeActionDialog::addDefaultActions ); init( actions, mLayer->attributeTableConfig() ); @@ -296,6 +297,35 @@ void QgsAttributeActionDialog::insert() } } +void QgsAttributeActionDialog::duplicate() +{ + // Add the action details as a new row in the table. + const int pos = mAttributeActionTable->rowCount(); + const int row = mAttributeActionTable->currentRow(); + + QgsAttributeActionPropertiesDialog dlg( + static_cast( mAttributeActionTable->item( row, Type )->data( Role::ActionType ).toInt() ), + mAttributeActionTable->item( row, Description )->text(), + mAttributeActionTable->item( row, ShortTitle )->text(), + mAttributeActionTable->verticalHeaderItem( row )->data( Qt::UserRole ).toString(), + mAttributeActionTable->item( row, ActionText )->data( Qt::UserRole ).toString(), + mAttributeActionTable->item( row, Capture )->checkState() == Qt::Checked, + mAttributeActionTable->item( row, ActionScopes )->data( Qt::UserRole ).value>(), + mAttributeActionTable->item( row, NotificationMessage )->text(), + mAttributeActionTable->item( row, EnabledOnlyWhenEditable )->checkState() == Qt::Checked, + mLayer + ); + + dlg.setWindowTitle( tr( "Duplicate Action" ) ); + + if ( dlg.exec() ) + { + const QString name = uniqueName( dlg.description() ); + + insertRow( pos, dlg.type(), name, dlg.actionText(), dlg.iconPath(), dlg.capture(), dlg.shortTitle(), dlg.actionScopes(), dlg.notificationMessage(), dlg.isEnabledOnlyWhenEditable() ); + } +} + void QgsAttributeActionDialog::updateButtons() { QList selection = mAttributeActionTable->selectedItems(); @@ -314,6 +344,7 @@ void QgsAttributeActionDialog::updateButtons() } mRemoveButton->setEnabled( hasSelection ); + mDuplicateButton->setEnabled( hasSelection ); } void QgsAttributeActionDialog::addDefaultActions() diff --git a/src/gui/vector/qgsattributeactiondialog.h b/src/gui/vector/qgsattributeactiondialog.h index 87a7b5478aaf..24cc48797af3 100644 --- a/src/gui/vector/qgsattributeactiondialog.h +++ b/src/gui/vector/qgsattributeactiondialog.h @@ -81,6 +81,7 @@ class GUI_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib void moveDown(); void remove(); void insert(); + void duplicate(); void addDefaultActions(); void itemDoubleClicked( QTableWidgetItem *item ); void updateButtons(); diff --git a/src/ui/qgsattributeactiondialogbase.ui b/src/ui/qgsattributeactiondialogbase.ui index f01ec84972fe..0e618877069c 100644 --- a/src/ui/qgsattributeactiondialogbase.ui +++ b/src/ui/qgsattributeactiondialogbase.ui @@ -68,6 +68,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -88,7 +101,35 @@ + + + + Add a new action + + + + + + + :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg + + + + + + Duplicate an action + + + + + + + :/images/themes/default/mActionDuplicateLayout.svg:/images/themes/default/mActionDuplicateLayout.svg + + + + Qt::Horizontal @@ -101,7 +142,7 @@ - + Create Default Actions @@ -128,7 +169,7 @@ - + @@ -193,33 +234,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add a new action - - - - - - - :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg - - - @@ -273,6 +287,7 @@ mMoveDownButton mRemoveButton mAddButton + mDuplicateButton mAddDefaultActionsButton mShowInAttributeTable mAttributeTableWidgetType