Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[needs-docs][attribute table] UX improvements to cut/copy/paste actions
  • Loading branch information
nirvn committed Jan 31, 2018
1 parent ad5a869 commit 28ff28a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
25 changes: 20 additions & 5 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -87,6 +87,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
{
setObjectName( QStringLiteral( "QgsAttributeTableDialog/" ) + layer->id() );
setupUi( this );
connect( mActionCutSelectedRows, &QAction::triggered, this, &QgsAttributeTableDialog::mActionCutSelectedRows_triggered );
connect( mActionCopySelectedRows, &QAction::triggered, this, &QgsAttributeTableDialog::mActionCopySelectedRows_triggered );
connect( mActionPasteFeatures, &QAction::triggered, this, &QgsAttributeTableDialog::mActionPasteFeatures_triggered );
connect( mActionToggleEditing, &QAction::toggled, this, &QgsAttributeTableDialog::mActionToggleEditing_toggled );
Expand Down Expand Up @@ -264,15 +265,18 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
mActionReload->setEnabled( ! mLayer->isEditable() );
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer->isEditable() );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
if ( !canDeleteFeatures )
{
mToolbar->removeAction( mActionDeleteSelected );
mToolbar->removeAction( mActionCutSelectedRows );
}
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer->isEditable() );
if ( !canAddFeatures )
{
mToolbar->removeAction( mActionAddFeature );

if ( canDeleteFeatures || canAddFeatures )
mToolbar->insertSeparator( mActionExpressionSelect );
mToolbar->removeAction( mActionPasteFeatures );
}

mMainViewButtonGroup->setId( mTableViewButton, QgsDualView::AttributeTable );
mMainViewButtonGroup->setId( mAttributeViewButton, QgsDualView::AttributeEditor );
Expand Down Expand Up @@ -382,8 +386,12 @@ void QgsAttributeTableDialog::updateTitle()
else
mRunFieldCalc->setText( tr( "Update Filtered" ) );

bool canDeleteFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool enabled = mLayer->selectedFeatureCount() > 0;
mRunFieldCalcSelected->setEnabled( enabled );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() && enabled );
mActionCutSelectedRows->setEnabled( canDeleteFeatures && mLayer->isEditable() && enabled );
mActionCopySelectedRows->setEnabled( enabled );
}

void QgsAttributeTableDialog::updateButtonStatus( const QString &fieldName, bool isValid )
Expand Down Expand Up @@ -739,6 +747,11 @@ void QgsAttributeTableDialog::mActionExpressionSelect_triggered()
dlg->show();
}

void QgsAttributeTableDialog::mActionCutSelectedRows_triggered()
{
QgisApp::instance()->cutSelectionToClipboard( mLayer );
}

void QgsAttributeTableDialog::mActionCopySelectedRows_triggered()
{
QgisApp::instance()->copySelectionToClipboard( mLayer );
Expand Down Expand Up @@ -823,8 +836,10 @@ void QgsAttributeTableDialog::editingToggled()
bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures;
mActionAddAttribute->setEnabled( ( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mActionRemoveAttribute->setEnabled( canDeleteAttributes && mLayer->isEditable() );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() && mLayer->selectedFeatureCount() > 0 );
mActionCutSelectedRows->setEnabled( canDeleteFeatures && mLayer->isEditable() && mLayer->selectedFeatureCount() > 0 );
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionPasteFeatures->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionToggleEditing->setEnabled( ( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() );

mUpdateExpressionBox->setVisible( mLayer->isEditable() );
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsattributetabledialog.h
Expand Up @@ -74,6 +74,11 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib

private slots:

/**
* Cut selected rows to the clipboard
*/
void mActionCutSelectedRows_triggered();

/**
* Copies selected rows to the clipboard
*/
Expand Down
24 changes: 20 additions & 4 deletions src/ui/qgsattributetabledialog.ui
Expand Up @@ -170,6 +170,10 @@
<addaction name="separator"/>
<addaction name="mActionAddFeature"/>
<addaction name="mActionDeleteSelected"/>
<addaction name="mActionCutSelectedRows"/>
<addaction name="mActionCopySelectedRows"/>
<addaction name="mActionPasteFeatures"/>
<addaction name="separator"/>
<addaction name="mActionExpressionSelect"/>
<addaction name="mActionSelectAll"/>
<addaction name="mActionInvertSelection"/>
Expand All @@ -179,9 +183,6 @@
<addaction name="mActionPanMapToSelectedRows"/>
<addaction name="mActionZoomMapToSelectedRows"/>
<addaction name="separator"/>
<addaction name="mActionCopySelectedRows"/>
<addaction name="mActionPasteFeatures"/>
<addaction name="separator"/>
<addaction name="mActionAddAttribute"/>
<addaction name="mActionRemoveAttribute"/>
<addaction name="mActionOpenFieldCalculator"/>
Expand Down Expand Up @@ -528,13 +529,28 @@
<string>Ctrl+J</string>
</property>
</action>
<action name="mActionCutSelectedRows">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionEditCut.svg</normaloff>:/images/themes/default/mActionEditCut.svg</iconset>
</property>
<property name="text">
<string>Cut selected rows to clipboard</string>
</property>
<property name="toolTip">
<string>Cut selected rows to clipboard (Ctrl+X)</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</action>
<action name="mActionCopySelectedRows">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionEditCopy.svg</normaloff>:/images/themes/default/mActionEditCopy.svg</iconset>
</property>
<property name="text">
<string>Copy selected rows to clipboard (Ctrl+C)</string>
<string>Copy selected rows to clipboard</string>
</property>
<property name="toolTip">
<string>Copy selected rows to clipboard (Ctrl+C)</string>
Expand Down

0 comments on commit 28ff28a

Please sign in to comment.