QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
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 
102  enum class SaveAction
103  {
104  SaveAsFile,
105  SaveInProject,
106  };
107 
108  public slots:
109 
115  void activate();
116 
117  protected:
118 
119  // cppcheck-suppress pureVirtualCall
120  virtual void repaintModel( bool showControls = true ) = 0;
121  virtual void addAlgorithm( const QString &algorithmId, const QPointF &pos ) = 0;
122  virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
123  virtual void exportAsScriptAlgorithm() = 0;
124  // cppcheck-suppress pureVirtualCall
125  virtual bool saveModel( bool saveAs = false ) = 0;
126 
127  QToolBar *toolbar() { return mToolbar; }
128  QAction *actionOpen() { return mActionOpen; }
129  QAction *actionSaveInProject() { return mActionSaveInProject; }
130  QAction *actionEditHelp() { return mActionEditHelp; }
131  QAction *actionRun() { return mActionRun; }
132  QgsMessageBar *messageBar() { return mMessageBar; }
133  QGraphicsView *view() { return mView; }
134 
135  void setDirty( bool dirty );
136 
140  bool validateSave( SaveAction action );
141 
147  bool checkForUnsavedChanges();
148 
152  void setLastRunChildAlgorithmResults( const QVariantMap &results );
153 
157  void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
158 
166  void setModelName( const QString &name );
167 
168  private slots:
169  void zoomIn();
170  void zoomOut();
171  void zoomActual();
172  void zoomFull();
173  void newModel();
174  void exportToImage();
175  void exportToPdf();
176  void exportToSvg();
177  void exportAsPython();
178  void toggleComments( bool show );
179  void updateWindowTitle();
180  void deleteSelected();
181  void populateZoomToMenu();
182  void validate();
183  void reorderInputs();
184  void setPanelVisibility( bool hidden );
185 
186  private:
187 
188  enum UndoCommand
189  {
190  NameChanged = 1,
191  GroupChanged
192  };
193 
194  std::unique_ptr< QgsProcessingModelAlgorithm > mModel;
195 
196  QgsMessageBar *mMessageBar = nullptr;
197  QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
198 
199  QActionGroup *mToolsActionGroup = nullptr;
200 
201  QgsModelViewToolPan *mPanTool = nullptr;
202  QgsModelViewToolSelect *mSelectTool = nullptr;
203  QgsModelGraphicsScene *mScene = nullptr;
204 
205  bool mHasChanged = false;
206  QUndoStack *mUndoStack = nullptr;
207  std::unique_ptr< QgsModelUndoCommand > mActiveCommand;
208 
209  QAction *mUndoAction = nullptr;
210  QAction *mRedoAction = nullptr;
211  QUndoView *mUndoView = nullptr;
212  QgsDockWidget *mUndoDock = nullptr;
213 
214  QMenu *mGroupMenu = nullptr;
215 
216  QAction *mActionCut = nullptr;
217  QAction *mActionCopy = nullptr;
218  QAction *mActionPaste = nullptr;
219  int mBlockUndoCommands = 0;
220  int mIgnoreUndoStackChanges = 0;
221 
222  QString mTitle;
223 
224  int mBlockRepaints = 0;
225 
226  QVariantMap mChildResults;
227  QVariantMap mChildInputs;
228 
229  bool isDirty() const;
230 
231  void fillInputsTree();
232  void updateVariablesGui();
233 
234  struct PanelStatus
235  {
236  PanelStatus( bool visible = true, bool active = false )
237  : isVisible( visible )
238  , isActive( active )
239  {}
240  bool isVisible;
241  bool isActive;
242  };
243  QMap< QString, PanelStatus > mPanelStatus;
244 };
245 
246 
247 
248 class GUI_EXPORT QgsModelChildDependenciesWidget : public QWidget
249 {
250  Q_OBJECT
251 
252  public:
253 
254  QgsModelChildDependenciesWidget( QWidget *parent, QgsProcessingModelAlgorithm *model, const QString &childId );
255  QList< QgsProcessingModelChildDependency > value() const { return mValue; }
256  void setValue( const QList< QgsProcessingModelChildDependency > &value );
257  private slots:
258 
259  void showDialog();
260 
261  private:
262 
263  void updateSummaryText();
264 
265  QLineEdit *mLineEdit = nullptr;
266  QToolButton *mToolButton = nullptr;
267 
268  QgsProcessingModelAlgorithm *mModel = nullptr;
269  QString mChildId;
270 
271  QList< QgsProcessingModelChildDependency > mValue;
272 
273  friend class TestProcessingGui;
274 };
276 
277 #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