QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 *actionRun() { return mActionRun; }
131  QgsMessageBar *messageBar() { return mMessageBar; }
132  QGraphicsView *view() { return mView; }
133 
134  void setDirty( bool dirty );
135 
139  bool validateSave( SaveAction action );
140 
146  bool checkForUnsavedChanges();
147 
151  void setLastRunChildAlgorithmResults( const QVariantMap &results );
152 
156  void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
157 
165  void setModelName( const QString &name );
166 
167  private slots:
168  void zoomIn();
169  void zoomOut();
170  void zoomActual();
171  void zoomFull();
172  void newModel();
173  void exportToImage();
174  void exportToPdf();
175  void exportToSvg();
176  void exportAsPython();
177  void toggleComments( bool show );
178  void updateWindowTitle();
179  void deleteSelected();
180  void populateZoomToMenu();
181  void validate();
182  void reorderInputs();
183  void setPanelVisibility( bool hidden );
184  void editHelp();
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
qgsprocessingtoolboxmodel.h
QgsModelViewToolSelect
Model designer view tool for selecting items in the model.
Definition: qgsmodelviewtoolselect.h:36
QgsModelViewToolPan
Model designer view tool for panning a model.
Definition: qgsmodelviewtoolpan.h:30
qgis.h
qgsprocessingmodelchilddependency.h
QgsProcessingToolboxProxyModel
A sort/filter proxy model for providers and algorithms shown within the Processing toolbox,...
Definition: qgsprocessingtoolboxmodel.h:417
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:60
QgsDockWidget
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
Definition: qgsdockwidget.h:31
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53