Skip to content
Permalink
Browse files
warn when adding model with the same name as the existing one (fix #4…
…2184)

confirm model overwrite if model file has the same name as the existing
one
  • Loading branch information
alexbruy authored and github-actions committed Jul 21, 2021
1 parent b5d6610 commit 7121f4cfbc58ab2d13cc5ac0f0ddc8e3e634b2da
Showing with 19 additions and 1 deletion.
  1. +19 −1 python/plugins/processing/modeler/AddModelFromFileAction.py
@@ -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.