QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmodeldesignerdialog.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmodeldesignerdialog.h
3  ------------------------
4  Date : March 2020
5  Copyright : (C) 2020 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMODELDESIGNERDIALOG_H
17 #define QGSMODELDESIGNERDIALOG_H
18 
19 #include "qgis.h"
20 #include "qgis_gui.h"
21 #include "ui_qgsmodeldesignerdialogbase.h"
22 
24 #include "qgsprocessingmodelchilddependency.h"
25 
26 class QgsMessageBar;
27 class QgsProcessingModelAlgorithm;
28 class QgsModelUndoCommand;
29 class QUndoView;
31 
33 
34 #ifndef SIP_RUN
35 
36 class GUI_EXPORT QgsModelerToolboxModel : public QgsProcessingToolboxProxyModel
37 {
38  Q_OBJECT
39  public:
40  explicit QgsModelerToolboxModel( QObject *parent = nullptr );
41  Qt::ItemFlags flags( const QModelIndex &index ) const override;
42  Qt::DropActions supportedDragActions() const override;
43 
44 };
45 
46 #endif
47 
54 class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsModelDesignerDialogBase
55 {
56  Q_OBJECT
57  public:
58 
59  QgsModelDesignerDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
60  ~QgsModelDesignerDialog() override;
61 
62  void closeEvent( QCloseEvent *event ) override;
63 
67  void beginUndoCommand( const QString &text, int id = 0 );
68 
72  void endUndoCommand();
73 
77  QgsProcessingModelAlgorithm *model();
78 
84  void setModel( QgsProcessingModelAlgorithm *model SIP_TRANSFER );
85 
89  void loadModel( const QString &path );
90 
94  void setModelScene( QgsModelGraphicsScene *scene SIP_TRANSFER );
95 
96  protected:
97 
98  // cppcheck-suppress pureVirtualCall
99  virtual void repaintModel( bool showControls = true ) = 0;
100  virtual void addAlgorithm( const QString &algorithmId, const QPointF &pos ) = 0;
101  virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
102  virtual void exportAsScriptAlgorithm() = 0;
103  // cppcheck-suppress pureVirtualCall
104  virtual void saveModel( bool saveAs = false ) = 0;
105 
106  QToolBar *toolbar() { return mToolbar; }
107  QAction *actionOpen() { return mActionOpen; }
108  QAction *actionSaveInProject() { return mActionSaveInProject; }
109  QAction *actionEditHelp() { return mActionEditHelp; }
110  QAction *actionRun() { return mActionRun; }
111  QgsMessageBar *messageBar() { return mMessageBar; }
112  QGraphicsView *view() { return mView; }
113 
114  void setDirty( bool dirty );
115 
119  bool validateSave();
120 
126  bool checkForUnsavedChanges();
127 
131  void setLastRunChildAlgorithmResults( const QVariantMap &results );
132 
136  void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
137 
138  private slots:
139  void zoomIn();
140  void zoomOut();
141  void zoomActual();
142  void zoomFull();
143  void exportToImage();
144  void exportToPdf();
145  void exportToSvg();
146  void exportAsPython();
147  void toggleComments( bool show );
148  void updateWindowTitle();
149  void deleteSelected();
150  void populateZoomToMenu();
151  void validate();
152  void reorderInputs();
153 
154  private:
155 
156  enum UndoCommand
157  {
158  NameChanged = 1,
159  GroupChanged
160  };
161 
162  std::unique_ptr< QgsProcessingModelAlgorithm > mModel;
163 
164  QgsMessageBar *mMessageBar = nullptr;
165  QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
166  QgsModelViewToolSelect *mSelectTool = nullptr;
167  QgsModelGraphicsScene *mScene = nullptr;
168 
169  bool mHasChanged = false;
170  QUndoStack *mUndoStack = nullptr;
171  std::unique_ptr< QgsModelUndoCommand > mActiveCommand;
172 
173  QAction *mUndoAction = nullptr;
174  QAction *mRedoAction = nullptr;
175  QUndoView *mUndoView = nullptr;
176  QgsDockWidget *mUndoDock = nullptr;
177 
178  QMenu *mGroupMenu = nullptr;
179 
180  QAction *mActionCut = nullptr;
181  QAction *mActionCopy = nullptr;
182  QAction *mActionPaste = nullptr;
183  int mBlockUndoCommands = 0;
184  int mIgnoreUndoStackChanges = 0;
185 
186  QString mTitle;
187 
188  int mBlockRepaints = 0;
189 
190  QVariantMap mChildResults;
191  QVariantMap mChildInputs;
192 
193  bool isDirty() const;
194 
195  void fillInputsTree();
196  void updateVariablesGui();
197 };
198 
199 
200 
201 class GUI_EXPORT QgsModelChildDependenciesWidget : public QWidget
202 {
203  Q_OBJECT
204 
205  public:
206 
207  QgsModelChildDependenciesWidget( QWidget *parent, QgsProcessingModelAlgorithm *model, const QString &childId );
208  QList< QgsProcessingModelChildDependency > value() const { return mValue; }
209  void setValue( const QList< QgsProcessingModelChildDependency > &value );
210  private slots:
211 
212  void showDialog();
213 
214  private:
215 
216  void updateSummaryText();
217 
218  QLineEdit *mLineEdit = nullptr;
219  QToolButton *mToolButton = nullptr;
220 
221  QgsProcessingModelAlgorithm *mModel = nullptr;
222  QString mChildId;
223 
224  QList< QgsProcessingModelChildDependency > mValue;
225 
226  friend class TestProcessingGui;
227 };
229 
230 #endif // QGSMODELDESIGNERDIALOG_H
qgsprocessingtoolboxmodel.h
QgsModelViewToolSelect
Model designer view tool for selecting items in the model.
Definition: qgsmodelviewtoolselect.h:37
qgis.h
QgsProcessingToolboxProxyModel
A sort/filter proxy model for providers and algorithms shown within the Processing toolbox,...
Definition: qgsprocessingtoolboxmodel.h:418
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
QgsDockWidget
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
Definition: qgsdockwidget.h:32
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53