QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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;
32 
34 
35 #ifndef SIP_RUN
36 
37 class GUI_EXPORT QgsModelerToolboxModel : public QgsProcessingToolboxProxyModel
38 {
39  Q_OBJECT
40  public:
41  explicit QgsModelerToolboxModel( QObject *parent = nullptr );
42  Qt::ItemFlags flags( const QModelIndex &index ) const override;
43  Qt::DropActions supportedDragActions() const override;
44 
45 };
46 
47 #endif
48 
55 class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsModelDesignerDialogBase
56 {
57  Q_OBJECT
58  public:
59 
60  QgsModelDesignerDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
61  ~QgsModelDesignerDialog() override;
62 
63  void closeEvent( QCloseEvent *event ) override;
64 
68  void beginUndoCommand( const QString &text, int id = 0 );
69 
73  void endUndoCommand();
74 
78  QgsProcessingModelAlgorithm *model();
79 
85  void setModel( QgsProcessingModelAlgorithm *model SIP_TRANSFER );
86 
90  void loadModel( const QString &path );
91 
95  void setModelScene( QgsModelGraphicsScene *scene SIP_TRANSFER );
96 
97  protected:
98 
99  // cppcheck-suppress pureVirtualCall
100  virtual void repaintModel( bool showControls = true ) = 0;
101  virtual void addAlgorithm( const QString &algorithmId, const QPointF &pos ) = 0;
102  virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
103  virtual void exportAsScriptAlgorithm() = 0;
104  // cppcheck-suppress pureVirtualCall
105  virtual void saveModel( bool saveAs = false ) = 0;
106 
107  QToolBar *toolbar() { return mToolbar; }
108  QAction *actionOpen() { return mActionOpen; }
109  QAction *actionSaveInProject() { return mActionSaveInProject; }
110  QAction *actionEditHelp() { return mActionEditHelp; }
111  QAction *actionRun() { return mActionRun; }
112  QgsMessageBar *messageBar() { return mMessageBar; }
113  QGraphicsView *view() { return mView; }
114 
115  void setDirty( bool dirty );
116 
120  bool validateSave();
121 
127  bool checkForUnsavedChanges();
128 
132  void setLastRunChildAlgorithmResults( const QVariantMap &results );
133 
137  void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
138 
139  private slots:
140  void zoomIn();
141  void zoomOut();
142  void zoomActual();
143  void zoomFull();
144  void exportToImage();
145  void exportToPdf();
146  void exportToSvg();
147  void exportAsPython();
148  void toggleComments( bool show );
149  void updateWindowTitle();
150  void deleteSelected();
151  void populateZoomToMenu();
152  void validate();
153  void reorderInputs();
154  void setPanelVisibility( bool hidden );
155 
156  private:
157 
158  enum UndoCommand
159  {
160  NameChanged = 1,
161  GroupChanged
162  };
163 
164  std::unique_ptr< QgsProcessingModelAlgorithm > mModel;
165 
166  QgsMessageBar *mMessageBar = nullptr;
167  QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
168 
169  QActionGroup *mToolsActionGroup = nullptr;
170 
171  QgsModelViewToolPan *mPanTool = nullptr;
172  QgsModelViewToolSelect *mSelectTool = nullptr;
173  QgsModelGraphicsScene *mScene = nullptr;
174 
175  bool mHasChanged = false;
176  QUndoStack *mUndoStack = nullptr;
177  std::unique_ptr< QgsModelUndoCommand > mActiveCommand;
178 
179  QAction *mUndoAction = nullptr;
180  QAction *mRedoAction = nullptr;
181  QUndoView *mUndoView = nullptr;
182  QgsDockWidget *mUndoDock = nullptr;
183 
184  QMenu *mGroupMenu = nullptr;
185 
186  QAction *mActionCut = nullptr;
187  QAction *mActionCopy = nullptr;
188  QAction *mActionPaste = nullptr;
189  int mBlockUndoCommands = 0;
190  int mIgnoreUndoStackChanges = 0;
191 
192  QString mTitle;
193 
194  int mBlockRepaints = 0;
195 
196  QVariantMap mChildResults;
197  QVariantMap mChildInputs;
198 
199  bool isDirty() const;
200 
201  void fillInputsTree();
202  void updateVariablesGui();
203 
204  struct PanelStatus
205  {
206  PanelStatus( bool visible = true, bool active = false )
207  : isVisible( visible )
208  , isActive( active )
209  {}
210  bool isVisible;
211  bool isActive;
212  };
213  QMap< QString, PanelStatus > mPanelStatus;
214 };
215 
216 
217 
218 class GUI_EXPORT QgsModelChildDependenciesWidget : public QWidget
219 {
220  Q_OBJECT
221 
222  public:
223 
224  QgsModelChildDependenciesWidget( QWidget *parent, QgsProcessingModelAlgorithm *model, const QString &childId );
225  QList< QgsProcessingModelChildDependency > value() const { return mValue; }
226  void setValue( const QList< QgsProcessingModelChildDependency > &value );
227  private slots:
228 
229  void showDialog();
230 
231  private:
232 
233  void updateSummaryText();
234 
235  QLineEdit *mLineEdit = nullptr;
236  QToolButton *mToolButton = nullptr;
237 
238  QgsProcessingModelAlgorithm *mModel = nullptr;
239  QString mChildId;
240 
241  QList< QgsProcessingModelChildDependency > mValue;
242 
243  friend class TestProcessingGui;
244 };
246 
247 #endif // QGSMODELDESIGNERDIALOG_H
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
Definition: qgsdockwidget.h:32
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Model designer view tool for panning a model.
Model designer view tool for selecting items in the model.
A sort/filter proxy model for providers and algorithms shown within the Processing toolbox,...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36