Skip to content

Commit

Permalink
[processing] When closing a model with unsaved changes, if the user
Browse files Browse the repository at this point in the history
accepts the prompt to save the changes BUT then cancels the file dialog
asking for the destination file name, don't treat this as though the
user has opted to discard the model

(cherry picked from commit 8f34557)
  • Loading branch information
nyalldawson committed Feb 7, 2022
1 parent fa6bcda commit 48c9e6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Raise, unminimize and activate this window.
virtual void addAlgorithm( const QString &algorithmId, const QPointF &pos ) = 0;
virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
virtual void exportAsScriptAlgorithm() = 0;
virtual void saveModel( bool saveAs = false ) = 0;
virtual bool saveModel( bool saveAs = false ) = 0;

QToolBar *toolbar();
QAction *actionOpen();
Expand Down
9 changes: 6 additions & 3 deletions python/plugins/processing/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def saveInProject(self):
self.setDirty(False)
QgsProject.instance().setDirty(True)

def saveModel(self, saveAs):
def saveModel(self, saveAs) -> bool:
if not self.validateSave():
return
return False
if self.model().sourceFilePath() and not saveAs:
filename = self.model().sourceFilePath()
else:
Expand All @@ -203,7 +203,7 @@ def saveModel(self, saveAs):
"This model can't be saved in its original location (probably you do not "
"have permission to do it). Please, use the 'Save as…' option."))
)
return
return False
self.update_model.emit()
if saveAs:
self.messageBar().pushMessage("", self.tr("Model was correctly saved to <a href=\"{}\">{}</a>").format(
Expand All @@ -213,6 +213,9 @@ def saveModel(self, saveAs):
self.messageBar().pushMessage("", self.tr("Model was correctly saved"), level=Qgis.Success, duration=5)

self.setDirty(False)
return True
else:
return False

def openModel(self):
if not self.checkForUnsavedChanges():
Expand Down
3 changes: 1 addition & 2 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ bool QgsModelDesignerDialog::checkForUnsavedChanges()
switch ( ret )
{
case QMessageBox::Save:
saveModel( false );
return true;
return saveModel( false );

case QMessageBox::Discard:
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/models/qgsmodeldesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
virtual void exportAsScriptAlgorithm() = 0;
// cppcheck-suppress pureVirtualCall
virtual void saveModel( bool saveAs = false ) = 0;
virtual bool saveModel( bool saveAs = false ) = 0;

QToolBar *toolbar() { return mToolbar; }
QAction *actionOpen() { return mActionOpen; }
Expand Down

0 comments on commit 48c9e6a

Please sign in to comment.