Skip to content

Commit

Permalink
[processing] Add direct action to open an existing model in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 21, 2018
1 parent 277e06e commit 146d408
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Expand Up @@ -46,6 +46,7 @@
from processing.modeler.CreateNewModelAction import CreateNewModelAction
from processing.modeler.DeleteModelAction import DeleteModelAction
from processing.modeler.EditModelAction import EditModelAction
from processing.modeler.OpenModelFromFileAction import OpenModelFromFileAction
from processing.modeler.WrongModelException import WrongModelException
from processing.modeler.ModelerUtils import ModelerUtils

Expand All @@ -56,7 +57,7 @@ class ModelerAlgorithmProvider(QgsProcessingProvider):

def __init__(self):
super().__init__()
self.actions = [CreateNewModelAction(), AddModelFromFileAction()]
self.actions = [CreateNewModelAction(), OpenModelFromFileAction(), AddModelFromFileAction()]
self.contextMenuActions = [EditModelAction(), DeleteModelAction()]
self.algs = []

Expand Down
62 changes: 62 additions & 0 deletions python/plugins/processing/modeler/OpenModelFromFileAction.py
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
OpenModelFromFileAction.py
---------------------
Date : February 2018
Copyright : (C) 2018 by Nyall Dawson
Email : nyall dot dawson 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__ = 'Nyall Dawson'
__date__ = 'February 2018'
__copyright__ = '(C) 2018, Nyall Dawson'

# 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.ModelerDialog import ModelerDialog

pluginPath = os.path.split(os.path.dirname(__file__))[0]


class OpenModelFromFileAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Open Existing Model…')
self.group = self.tr('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())

dlg = ModelerDialog()
dlg.loadModel(filename)
dlg.show()

0 comments on commit 146d408

Please sign in to comment.