-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
qgsmodeldesignerdialog.h
290 lines (228 loc) · 7.93 KB
/
qgsmodeldesignerdialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/***************************************************************************
qgsmodeldesignerdialog.h
------------------------
Date : March 2020
Copyright : (C) 2020 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. *
* *
***************************************************************************/
#ifndef QGSMODELDESIGNERDIALOG_H
#define QGSMODELDESIGNERDIALOG_H
#include "qgis.h"
#include "qgis_gui.h"
#include "ui_qgsmodeldesignerdialogbase.h"
#include "qgsprocessingtoolboxmodel.h"
#include "qgsprocessingmodelchilddependency.h"
class QgsMessageBar;
class QgsProcessingModelAlgorithm;
class QgsModelUndoCommand;
class QUndoView;
class QgsModelViewToolPan;
class QgsModelViewToolSelect;
class QgsScreenHelper;
class QgsProcessingAlgorithmDialogBase;
///@cond NOT_STABLE
#ifndef SIP_RUN
class GUI_EXPORT QgsModelerToolboxModel : public QgsProcessingToolboxProxyModel
{
Q_OBJECT
public:
explicit QgsModelerToolboxModel( QObject *parent = nullptr );
Qt::ItemFlags flags( const QModelIndex &index ) const override;
Qt::DropActions supportedDragActions() const override;
};
#endif
/**
* \ingroup gui
* \brief Model designer dialog base class
* \warning Not stable API
* \since QGIS 3.14
*/
class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsModelDesignerDialogBase
{
Q_OBJECT
public:
QgsModelDesignerDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
~QgsModelDesignerDialog() override;
void closeEvent( QCloseEvent *event ) override;
/**
* Starts an undo command. This should be called before any changes are made to the model.
*/
void beginUndoCommand( const QString &text, int id = 0 );
/**
* Ends the current undo command. This should be called after changes are made to the model.
*/
void endUndoCommand();
/**
* Returns the model shown in the dialog.
*/
QgsProcessingModelAlgorithm *model();
/**
* Sets the \a model shown in the dialog.
*
* Ownership of \a model is transferred to the dialog.
*/
void setModel( QgsProcessingModelAlgorithm *model SIP_TRANSFER );
/**
* Loads a model into the designer from the specified file \a path.
*/
void loadModel( const QString &path );
/**
* Sets the related \a scene.
*/
void setModelScene( QgsModelGraphicsScene *scene SIP_TRANSFER );
/**
* Save action.
*
* \since QGIS 3.24
*/
enum class SaveAction
{
SaveAsFile, //!< Save model as a file
SaveInProject, //!< Save model into project
};
public slots:
/**
* Raise, unminimize and activate this window.
*
* \since QGIS 3.24
*/
void activate();
protected:
// cppcheck-suppress pureVirtualCall
virtual void repaintModel( bool showControls = true ) = 0;
virtual void addAlgorithm( const QString &algorithmId, const QPointF &pos ) = 0;
// cppcheck-suppress pureVirtualCall
virtual void addInput( const QString &inputId, const QPointF &pos ) = 0;
// cppcheck-suppress pureVirtualCall
virtual void exportAsScriptAlgorithm() = 0;
// cppcheck-suppress pureVirtualCall
virtual bool saveModel( bool saveAs = false ) = 0;
// cppcheck-suppress pureVirtualCall
virtual QgsProcessingAlgorithmDialogBase *createExecutionDialog() = 0 SIP_TRANSFERBACK;
QToolBar *toolbar() { return mToolbar; }
QAction *actionOpen() { return mActionOpen; }
QAction *actionSaveInProject() { return mActionSaveInProject; }
QAction *actionRun() { return mActionRun; }
QgsMessageBar *messageBar() { return mMessageBar; }
QGraphicsView *view() { return mView; }
void setDirty( bool dirty );
/**
* Checks if the model can current be saved, and returns TRUE if it can.
*/
bool validateSave( SaveAction action );
/**
* Checks if there are unsaved changes in the model, and if so, prompts the user to save them.
*
* Returns FALSE if the cancel option was selected
*/
bool checkForUnsavedChanges();
/**
* Sets the results of child algorithms for the last run of the model through the designer window.
*/
void setLastRunChildAlgorithmResults( const QVariantMap &results );
/**
* Sets the inputs for child algorithms for the last run of the model through the designer window.
*/
void setLastRunChildAlgorithmInputs( const QVariantMap &inputs );
/**
* Sets the model \a name.
*
* Updates both the name text edit and the model name itself.
*
* \since QGIS 3.24
*/
void setModelName( const QString &name );
private slots:
void zoomIn();
void zoomOut();
void zoomActual();
void zoomFull();
void newModel();
void exportToImage();
void exportToPdf();
void exportToSvg();
void exportAsPython();
void toggleComments( bool show );
void updateWindowTitle();
void deleteSelected();
void populateZoomToMenu();
void validate();
void reorderInputs();
void reorderOutputs();
void setPanelVisibility( bool hidden );
void editHelp();
void run();
void showPreviousResults( const QString &childId );
private:
enum UndoCommand
{
NameChanged = 1,
GroupChanged
};
std::unique_ptr< QgsProcessingModelAlgorithm > mModel;
QgsScreenHelper *mScreenHelper = nullptr;
QgsMessageBar *mMessageBar = nullptr;
QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
QActionGroup *mToolsActionGroup = nullptr;
QgsModelViewToolPan *mPanTool = nullptr;
QgsModelViewToolSelect *mSelectTool = nullptr;
QgsModelGraphicsScene *mScene = nullptr;
bool mHasChanged = false;
QUndoStack *mUndoStack = nullptr;
std::unique_ptr< QgsModelUndoCommand > mActiveCommand;
QAction *mUndoAction = nullptr;
QAction *mRedoAction = nullptr;
QUndoView *mUndoView = nullptr;
QgsDockWidget *mUndoDock = nullptr;
QMenu *mGroupMenu = nullptr;
QAction *mActionCut = nullptr;
QAction *mActionCopy = nullptr;
QAction *mActionPaste = nullptr;
int mBlockUndoCommands = 0;
int mIgnoreUndoStackChanges = 0;
QString mTitle;
int mBlockRepaints = 0;
QVariantMap mChildResults;
QVariantMap mChildInputs;
bool isDirty() const;
void fillInputsTree();
void updateVariablesGui();
struct PanelStatus
{
PanelStatus( bool visible = true, bool active = false )
: isVisible( visible )
, isActive( active )
{}
bool isVisible;
bool isActive;
};
QMap< QString, PanelStatus > mPanelStatus;
QgsProcessingContext mLayerStore;
};
class GUI_EXPORT QgsModelChildDependenciesWidget : public QWidget
{
Q_OBJECT
public:
QgsModelChildDependenciesWidget( QWidget *parent, QgsProcessingModelAlgorithm *model, const QString &childId );
QList< QgsProcessingModelChildDependency > value() const { return mValue; }
void setValue( const QList< QgsProcessingModelChildDependency > &value );
private slots:
void showDialog();
private:
void updateSummaryText();
QLineEdit *mLineEdit = nullptr;
QToolButton *mToolButton = nullptr;
QgsProcessingModelAlgorithm *mModel = nullptr;
QString mChildId;
QList< QgsProcessingModelChildDependency > mValue;
friend class TestProcessingGui;
};
///@endcond
#endif // QGSMODELDESIGNERDIALOG_H