mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
warn when adding model with the same name as the existing one (fix #42184)
confirm model overwrite if model file has the same name as the existing one
This commit is contained in:
parent
a52b2bf060
commit
9098f2c6f9
@ -60,6 +60,24 @@ class AddModelFromFileAction(ToolboxAction):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user