Skip to content

Commit

Permalink
[multiedit] Prompt to apply changes when switching out of multiedit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 29, 2016
1 parent 25c0624 commit d870b73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &featur
, mPreventFeatureRefresh( false )
, mIsSettingFeature( false )
, mIsSettingMultiEditFeatures( false )
, mUnsavedMultiEditChanges( false )
, mEditCommandMessage( tr( "Attributes changed" ) )
, mMode( SingleEditMode )
{
Expand Down Expand Up @@ -123,8 +124,19 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
if ( mMode == MultiEditMode )
{
//switching out of multi edit mode triggers a save
save();
if ( mUnsavedMultiEditChanges )
{
// prompt for save
int res = QMessageBox::information( this, tr( "Multiedit attributes" ),
tr( "Apply changes to edited features?" ), QMessageBox::Yes | QMessageBox::No );
if ( res == QMessageBox::Yes )
{
save();
}
}
clearMultiEditMessages();
}
mUnsavedMultiEditChanges = false;

mMode = mode;

Expand Down Expand Up @@ -345,6 +357,7 @@ void QgsAttributeForm::resetMultiEdit( bool promptToSave )
if ( promptToSave )
save();

mUnsavedMultiEditChanges = false;
setMultiEditFeatureIds( mLayer->selectedFeaturesIds() );
}

Expand Down Expand Up @@ -452,6 +465,7 @@ bool QgsAttributeForm::save()
}

mIsSaving = false;
mUnsavedMultiEditChanges = false;

return success;
}
Expand Down Expand Up @@ -500,6 +514,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant& value )
{
if ( !mIsSettingMultiEditFeatures )
{
mUnsavedMultiEditChanges = true;

QLabel *msgLabel = new QLabel( tr( "Unsaved multiedit changes: <a href=\"#apply\">apply changes</a> or <a href=\"#reset\">reset changes</a>." ), mMessageBar );
msgLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
msgLabel->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeform.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
bool mIsSettingMultiEditFeatures;

QgsFeatureIds mMultiEditFeatureIds;
bool mUnsavedMultiEditChanges;

QString mEditCommandMessage;

Expand Down

0 comments on commit d870b73

Please sign in to comment.