Skip to content

Commit

Permalink
[FEATURE][multiedit] Add shortcut to modify attributes of selected
Browse files Browse the repository at this point in the history
features to edit menu

Workflow:
- enter edit mode, select multiple features
- select Edit -> Modify Attributes of Selected Features
- edit attributes using feature form, click OK or Cancel
  • Loading branch information
nyalldawson committed May 3, 2016
1 parent 98e9ae1 commit 4335a77
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
43 changes: 43 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1388,6 +1388,7 @@ void QgisApp::createActions()
connect( mActionDeletePart, SIGNAL( triggered() ), this, SLOT( deletePart() ) ); connect( mActionDeletePart, SIGNAL( triggered() ), this, SLOT( deletePart() ) );
connect( mActionMergeFeatures, SIGNAL( triggered() ), this, SLOT( mergeSelectedFeatures() ) ); connect( mActionMergeFeatures, SIGNAL( triggered() ), this, SLOT( mergeSelectedFeatures() ) );
connect( mActionMergeFeatureAttributes, SIGNAL( triggered() ), this, SLOT( mergeAttributesOfSelectedFeatures() ) ); connect( mActionMergeFeatureAttributes, SIGNAL( triggered() ), this, SLOT( mergeAttributesOfSelectedFeatures() ) );
connect( mActionMultiEditAttributes, SIGNAL( triggered() ), this, SLOT( modifyAttributesOfSelectedFeatures() ) );
connect( mActionNodeTool, SIGNAL( triggered() ), this, SLOT( nodeTool() ) ); connect( mActionNodeTool, SIGNAL( triggered() ), this, SLOT( nodeTool() ) );
connect( mActionRotatePointSymbols, SIGNAL( triggered() ), this, SLOT( rotatePointSymbols() ) ); connect( mActionRotatePointSymbols, SIGNAL( triggered() ), this, SLOT( rotatePointSymbols() ) );
connect( mActionSnappingOptions, SIGNAL( triggered() ), this, SLOT( snappingOptions() ) ); connect( mActionSnappingOptions, SIGNAL( triggered() ), this, SLOT( snappingOptions() ) );
Expand Down Expand Up @@ -6551,6 +6552,45 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
} }
} }


void QgisApp::modifyAttributesOfSelectedFeatures()
{
QgsMapLayer* activeMapLayer = activeLayer();
if ( !activeMapLayer )
{
messageBar()->pushMessage(
tr( "No active layer" ),
tr( "Please select a layer in the layer list" ),
QgsMessageBar::WARNING );
return;
}

QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( activeMapLayer );
if ( !vl )
{
messageBar()->pushMessage(
tr( "Invalid layer" ),
tr( "The merge features tool only works on vector layers." ),
QgsMessageBar::WARNING );
return;
}
if ( !vl->isEditable() )
{
messageBar()->pushMessage(
tr( "Layer not editable" ),
tr( "Modifying features can only be done for layers in editing mode." ),
QgsMessageBar::WARNING );

return;
}

//dummy feature
QgsFeature f;
QgsAttributeDialog* dialog = new QgsAttributeDialog( vl, &f, false, this );
dialog->setMode( QgsAttributeForm::MultiEditMode );
dialog->exec();

}

void QgisApp::mergeSelectedFeatures() void QgisApp::mergeSelectedFeatures()
{ {
//get active layer (hopefully vector) //get active layer (hopefully vector)
Expand Down Expand Up @@ -9998,6 +10038,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSplitParts->setEnabled( false ); mActionSplitParts->setEnabled( false );
mActionMergeFeatures->setEnabled( false ); mActionMergeFeatures->setEnabled( false );
mActionMergeFeatureAttributes->setEnabled( false ); mActionMergeFeatureAttributes->setEnabled( false );
mActionMultiEditAttributes->setEnabled( false );
mActionRotatePointSymbols->setEnabled( false ); mActionRotatePointSymbols->setEnabled( false );
mActionEnableTracing->setEnabled( false ); mActionEnableTracing->setEnabled( false );


Expand Down Expand Up @@ -10109,11 +10150,13 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{ {
mActionMergeFeatures->setEnabled( layerHasSelection && canDeleteFeatures && canAddFeatures ); mActionMergeFeatures->setEnabled( layerHasSelection && canDeleteFeatures && canAddFeatures );
mActionMergeFeatureAttributes->setEnabled( layerHasSelection ); mActionMergeFeatureAttributes->setEnabled( layerHasSelection );
mActionMultiEditAttributes->setEnabled( layerHasSelection );
} }
else else
{ {
mActionMergeFeatures->setEnabled( false ); mActionMergeFeatures->setEnabled( false );
mActionMergeFeatureAttributes->setEnabled( false ); mActionMergeFeatureAttributes->setEnabled( false );
mActionMultiEditAttributes->setEnabled( false );
} }


bool isMultiPart = QGis::isMultiType( vlayer->wkbType() ) || !dprovider->doesStrictFeatureTypeCheck(); bool isMultiPart = QGis::isMultiType( vlayer->wkbType() ) || !dprovider->doesStrictFeatureTypeCheck();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1034,6 +1034,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void mergeSelectedFeatures(); void mergeSelectedFeatures();
//! merges the attributes of selected features //! merges the attributes of selected features
void mergeAttributesOfSelectedFeatures(); void mergeAttributesOfSelectedFeatures();
//! Modifies the attributes of selected features via feature form
void modifyAttributesOfSelectedFeatures();
//! provides operations with nodes //! provides operations with nodes
void nodeTool(); void nodeTool();
//! activates the rotate points tool //! activates the rotate points tool
Expand Down
17 changes: 12 additions & 5 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -186,6 +186,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )


case QgsAttributeForm::MultiEditMode: case QgsAttributeForm::MultiEditMode:
resetMultiEdit( false ); resetMultiEdit( false );
synchronizeEnabledState();
break; break;
} }


Expand Down Expand Up @@ -433,7 +434,8 @@ bool QgsAttributeForm::saveMultiEdits()
mMultiEditMessageBarItem = new QgsMessageBarItem( tr( "Changes could not be applied" ), QgsMessageBar::WARNING, messageTimeout() ); mMultiEditMessageBarItem = new QgsMessageBarItem( tr( "Changes could not be applied" ), QgsMessageBar::WARNING, messageTimeout() );
} }


mMessageBar->pushItem( mMultiEditMessageBarItem ); if ( !mButtonBox->isVisible() )
mMessageBar->pushItem( mMultiEditMessageBarItem );
return success; return success;
} }


Expand Down Expand Up @@ -482,12 +484,14 @@ void QgsAttributeForm::clearMultiEditMessages()
{ {
if ( mMultiEditUnsavedMessageBarItem ) if ( mMultiEditUnsavedMessageBarItem )
{ {
mMessageBar->popWidget( mMultiEditUnsavedMessageBarItem ); if ( !mButtonBox->isVisible() )
mMessageBar->popWidget( mMultiEditUnsavedMessageBarItem );
mMultiEditUnsavedMessageBarItem = nullptr; mMultiEditUnsavedMessageBarItem = nullptr;
} }
if ( mMultiEditMessageBarItem ) if ( mMultiEditMessageBarItem )
{ {
mMessageBar->popWidget( mMultiEditMessageBarItem ); if ( !mButtonBox->isVisible() )
mMessageBar->popWidget( mMultiEditMessageBarItem );
mMultiEditMessageBarItem = nullptr; mMultiEditMessageBarItem = nullptr;
} }
} }
Expand Down Expand Up @@ -523,7 +527,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant& value )
clearMultiEditMessages(); clearMultiEditMessages();


mMultiEditUnsavedMessageBarItem = new QgsMessageBarItem( msgLabel, QgsMessageBar::WARNING ); mMultiEditUnsavedMessageBarItem = new QgsMessageBarItem( msgLabel, QgsMessageBar::WARNING );
mMessageBar->pushItem( mMultiEditUnsavedMessageBarItem ); if ( !mButtonBox->isVisible() )
mMessageBar->pushItem( mMultiEditUnsavedMessageBarItem );
} }
break; break;
} }
Expand Down Expand Up @@ -608,7 +613,9 @@ void QgsAttributeForm::refreshFeature()


void QgsAttributeForm::synchronizeEnabledState() void QgsAttributeForm::synchronizeEnabledState()
{ {
bool isEditable = ( mFeature.isValid() || mMode == AddFeatureMode ) && mLayer->isEditable(); bool isEditable = ( mFeature.isValid()
|| mMode == AddFeatureMode
|| mMode == MultiEditMode ) && mLayer->isEditable();


Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets ) Q_FOREACH ( QgsWidgetWrapper* ww, mWidgets )
{ {
Expand Down
15 changes: 14 additions & 1 deletion src/ui/qgisapp.ui
Expand Up @@ -17,7 +17,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1050</width> <width>1050</width>
<height>19</height> <height>25</height>
</rect> </rect>
</property> </property>
<property name="toolTip"> <property name="toolTip">
Expand Down Expand Up @@ -271,6 +271,7 @@
<addaction name="mActionAddFeature"/> <addaction name="mActionAddFeature"/>
<addaction name="mActionMoveFeature"/> <addaction name="mActionMoveFeature"/>
<addaction name="mActionDeleteSelected"/> <addaction name="mActionDeleteSelected"/>
<addaction name="mActionMultiEditAttributes"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="mActionRotateFeature"/> <addaction name="mActionRotateFeature"/>
<addaction name="mActionSimplifyFeature"/> <addaction name="mActionSimplifyFeature"/>
Expand Down Expand Up @@ -2479,6 +2480,18 @@ Acts on currently active editable layer</string>
<string>New GeoPackage Layer...</string> <string>New GeoPackage Layer...</string>
</property> </property>
</action> </action>
<action name="mActionMultiEditAttributes">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionAllEdits.svg</normaloff>:/images/themes/default/mActionAllEdits.svg</iconset>
</property>
<property name="text">
<string>Modify Attributes of Selected Features</string>
</property>
<property name="toolTip">
<string>Modify the Attributes of all Selected Features Simultaneously</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="../../images/images.qrc"/> <include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 4335a77

Please sign in to comment.