mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Contains variables for model parameters, algorithm results for other child algorithms which are not dependent on the algorithm. Allows removal of final pieces of ModelerAlgorithm code
71 lines
3.0 KiB
Python
71 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
***************************************************************************
|
|
EditScriptAction.py
|
|
---------------------
|
|
Date : August 2012
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
Email : volayaf at gmail dot com
|
|
***************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************
|
|
"""
|
|
|
|
__author__ = 'Victor Olaya'
|
|
__date__ = 'April 2014'
|
|
__copyright__ = '(C) 201, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
import os
|
|
import shutil
|
|
from qgis.PyQt.QtWidgets import QFileDialog, QMessageBox
|
|
from qgis.PyQt.QtCore import QFileInfo
|
|
|
|
from qgis.core import QgsApplication, QgsSettings, QgsProcessingModelAlgorithm
|
|
|
|
from processing.gui.ToolboxAction import ToolboxAction
|
|
from processing.modeler.WrongModelException import WrongModelException
|
|
from processing.modeler.ModelerUtils import ModelerUtils
|
|
|
|
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
|
|
|
|
|
class AddModelFromFileAction(ToolboxAction):
|
|
|
|
def __init__(self):
|
|
self.name, self.i18n_name = self.trAction('Add model from file')
|
|
self.group, self.i18n_group = self.trAction('Tools')
|
|
|
|
def getIcon(self):
|
|
return QgsApplication.getThemeIcon("/processingModel.svg")
|
|
|
|
def execute(self):
|
|
settings = QgsSettings()
|
|
lastDir = settings.value('Processing/lastModelsDir', '')
|
|
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
|
|
self.tr('Open model', 'AddModelFromFileAction'), lastDir,
|
|
self.tr('Processing model files (*.model3 *.MODEL3)', 'AddModelFromFileAction'))
|
|
if filename:
|
|
settings.setValue('Processing/lastModelsDir',
|
|
QFileInfo(filename).absoluteDir().absolutePath())
|
|
|
|
alg = QgsProcessingModelAlgorithm()
|
|
if not alg.fromFile(filename):
|
|
QMessageBox.warning(
|
|
self.toolbox,
|
|
self.tr('Error reading model', 'AddModelFromFileAction'),
|
|
self.tr('The selected file does not contain a valid model', 'AddModelFromFileAction'))
|
|
return
|
|
destFilename = os.path.join(ModelerUtils.modelsFolders()[0], os.path.basename(filename))
|
|
shutil.copyfile(filename, destFilename)
|
|
QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()
|