Skip to content

Commit 28ff28a

Browse files
committed
[needs-docs][attribute table] UX improvements to cut/copy/paste actions
1 parent ad5a869 commit 28ff28a

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
8787
{
8888
setObjectName( QStringLiteral( "QgsAttributeTableDialog/" ) + layer->id() );
8989
setupUi( this );
90+
connect( mActionCutSelectedRows, &QAction::triggered, this, &QgsAttributeTableDialog::mActionCutSelectedRows_triggered );
9091
connect( mActionCopySelectedRows, &QAction::triggered, this, &QgsAttributeTableDialog::mActionCopySelectedRows_triggered );
9192
connect( mActionPasteFeatures, &QAction::triggered, this, &QgsAttributeTableDialog::mActionPasteFeatures_triggered );
9293
connect( mActionToggleEditing, &QAction::toggled, this, &QgsAttributeTableDialog::mActionToggleEditing_toggled );
@@ -264,15 +265,18 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
264265
mActionReload->setEnabled( ! mLayer->isEditable() );
265266
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
266267
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer->isEditable() );
267-
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
268268
if ( !canDeleteFeatures )
269+
{
269270
mToolbar->removeAction( mActionDeleteSelected );
271+
mToolbar->removeAction( mActionCutSelectedRows );
272+
}
270273
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
274+
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer->isEditable() );
271275
if ( !canAddFeatures )
276+
{
272277
mToolbar->removeAction( mActionAddFeature );
273-
274-
if ( canDeleteFeatures || canAddFeatures )
275-
mToolbar->insertSeparator( mActionExpressionSelect );
278+
mToolbar->removeAction( mActionPasteFeatures );
279+
}
276280

277281
mMainViewButtonGroup->setId( mTableViewButton, QgsDualView::AttributeTable );
278282
mMainViewButtonGroup->setId( mAttributeViewButton, QgsDualView::AttributeEditor );
@@ -382,8 +386,12 @@ void QgsAttributeTableDialog::updateTitle()
382386
else
383387
mRunFieldCalc->setText( tr( "Update Filtered" ) );
384388

389+
bool canDeleteFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures;
385390
bool enabled = mLayer->selectedFeatureCount() > 0;
386391
mRunFieldCalcSelected->setEnabled( enabled );
392+
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() && enabled );
393+
mActionCutSelectedRows->setEnabled( canDeleteFeatures && mLayer->isEditable() && enabled );
394+
mActionCopySelectedRows->setEnabled( enabled );
387395
}
388396

389397
void QgsAttributeTableDialog::updateButtonStatus( const QString &fieldName, bool isValid )
@@ -739,6 +747,11 @@ void QgsAttributeTableDialog::mActionExpressionSelect_triggered()
739747
dlg->show();
740748
}
741749

750+
void QgsAttributeTableDialog::mActionCutSelectedRows_triggered()
751+
{
752+
QgisApp::instance()->cutSelectionToClipboard( mLayer );
753+
}
754+
742755
void QgsAttributeTableDialog::mActionCopySelectedRows_triggered()
743756
{
744757
QgisApp::instance()->copySelectionToClipboard( mLayer );
@@ -823,8 +836,10 @@ void QgsAttributeTableDialog::editingToggled()
823836
bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures;
824837
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
825838
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer->isEditable() );
826-
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
839+
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() && mLayer->selectedFeatureCount() > 0 );
840+
mActionCutSelectedRows->setEnabled( canDeleteFeatures && mLayer->isEditable() && mLayer->selectedFeatureCount() > 0 );
827841
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
842+
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer->isEditable() );
828843
mActionToggleEditing->setEnabled( ( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() );
829844

830845
mUpdateExpressionBox->setVisible( mLayer->isEditable() );

src/app/qgsattributetabledialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
7474

7575
private slots:
7676

77+
/**
78+
* Cut selected rows to the clipboard
79+
*/
80+
void mActionCutSelectedRows_triggered();
81+
7782
/**
7883
* Copies selected rows to the clipboard
7984
*/

src/ui/qgsattributetabledialog.ui

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@
170170
<addaction name="separator"/>
171171
<addaction name="mActionAddFeature"/>
172172
<addaction name="mActionDeleteSelected"/>
173+
<addaction name="mActionCutSelectedRows"/>
174+
<addaction name="mActionCopySelectedRows"/>
175+
<addaction name="mActionPasteFeatures"/>
176+
<addaction name="separator"/>
173177
<addaction name="mActionExpressionSelect"/>
174178
<addaction name="mActionSelectAll"/>
175179
<addaction name="mActionInvertSelection"/>
@@ -179,9 +183,6 @@
179183
<addaction name="mActionPanMapToSelectedRows"/>
180184
<addaction name="mActionZoomMapToSelectedRows"/>
181185
<addaction name="separator"/>
182-
<addaction name="mActionCopySelectedRows"/>
183-
<addaction name="mActionPasteFeatures"/>
184-
<addaction name="separator"/>
185186
<addaction name="mActionAddAttribute"/>
186187
<addaction name="mActionRemoveAttribute"/>
187188
<addaction name="mActionOpenFieldCalculator"/>
@@ -528,13 +529,28 @@
528529
<string>Ctrl+J</string>
529530
</property>
530531
</action>
532+
<action name="mActionCutSelectedRows">
533+
<property name="icon">
534+
<iconset resource="../../images/images.qrc">
535+
<normaloff>:/images/themes/default/mActionEditCut.svg</normaloff>:/images/themes/default/mActionEditCut.svg</iconset>
536+
</property>
537+
<property name="text">
538+
<string>Cut selected rows to clipboard</string>
539+
</property>
540+
<property name="toolTip">
541+
<string>Cut selected rows to clipboard (Ctrl+X)</string>
542+
</property>
543+
<property name="shortcut">
544+
<string>Ctrl+X</string>
545+
</property>
546+
</action>
531547
<action name="mActionCopySelectedRows">
532548
<property name="icon">
533549
<iconset resource="../../images/images.qrc">
534550
<normaloff>:/images/themes/default/mActionEditCopy.svg</normaloff>:/images/themes/default/mActionEditCopy.svg</iconset>
535551
</property>
536552
<property name="text">
537-
<string>Copy selected rows to clipboard (Ctrl+C)</string>
553+
<string>Copy selected rows to clipboard</string>
538554
</property>
539555
<property name="toolTip">
540556
<string>Copy selected rows to clipboard (Ctrl+C)</string>

0 commit comments

Comments
 (0)