Skip to content

Commit

Permalink
warn when adding model with the same name as the existing one (fix #4…
Browse files Browse the repository at this point in the history
…2184)

confirm model overwrite if model file has the same name as the existing
one
  • Loading branch information
alexbruy authored and github-actions[bot] committed Jul 21, 2021
1 parent b5d6610 commit 7121f4c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion python/plugins/processing/modeler/AddModelFromFileAction.py
Expand Up @@ -60,6 +60,24 @@ def execute(self):
self.tr('Open Model', 'AddModelFromFileAction'),
self.tr('The selected file does not contain a valid model', 'AddModelFromFileAction'))
return

if QgsApplication.instance().processingRegistry().algorithmById('model:{}'.format(alg.id())):
QMessageBox.warning(
self.toolbox,
self.tr('Open Model', 'AddModelFromFileAction'),
self.tr('Model with the same name already exists', 'AddModelFromFileAction'))
return

destFilename = os.path.join(ModelerUtils.modelsFolders()[0], os.path.basename(filename))
shutil.copyfile(filename, destFilename)
if os.path.exists(destFilename):
reply = QMessageBox.question(
self.toolbox,
self.tr('Open Model', 'AddModelFromFileAction'),
self.tr('There is already a model file with the same name. Overwrite?', 'AddModelFromFileAction'),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)

if reply == QMessageBox.Yes:
shutil.copyfile(filename, destFilename)

QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()

0 comments on commit 7121f4c

Please sign in to comment.