/
qgsprocessingalgorithmdialogbase.h
345 lines (271 loc) · 8.81 KB
/
qgsprocessingalgorithmdialogbase.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/***************************************************************************
qgsprocessingalgorithmdialogbase.h
----------------------------------
Date : November 2017
Copyright : (C) 2017 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 QGSPROCESSINGALGORITHMDIALOGBASE_H
#define QGSPROCESSINGALGORITHMDIALOGBASE_H
#include "qgis.h"
#include "qgis_gui.h"
#include "ui_qgsprocessingalgorithmdialogbase.h"
#include "ui_qgsprocessingalgorithmprogressdialogbase.h"
#include "processing/qgsprocessingcontext.h"
#include "processing/qgsprocessingfeedback.h"
///@cond NOT_STABLE
class QgsProcessingAlgorithm;
class QToolButton;
class QgsProcessingAlgorithmDialogBase;
class QgsMessageBar;
class QgsProcessingAlgRunnerTask;
class QgsTask;
#ifndef SIP_RUN
/**
* \ingroup gui
* \brief QgsProcessingFeedback subclass linked to a QgsProcessingAlgorithmDialogBase
* \note Not stable API
* \since QGIS 3.0
*/
class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
{
Q_OBJECT
public:
/**
* Constructor for QgsProcessingAlgorithmDialogFeedback.
*/
QgsProcessingAlgorithmDialogFeedback();
signals:
void progressTextChanged( const QString &text );
void errorReported( const QString &text );
void infoPushed( const QString &text );
void commandInfoPushed( const QString &text );
void debugInfoPushed( const QString &text );
void consoleInfoPushed( const QString &text );
public slots:
void setProgressText( const QString &text ) override;
void reportError( const QString &error ) override;
void pushInfo( const QString &info ) override;
void pushCommandInfo( const QString &info ) override;
void pushDebugInfo( const QString &info ) override;
void pushConsoleInfo( const QString &info ) override;
};
#endif
/**
* \ingroup gui
* \brief Base class for processing algorithm dialogs.
* \note This is not considered stable API and may change in future QGIS versions.
* \since QGIS 3.0
*/
class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::QgsProcessingDialogBase
{
Q_OBJECT
public:
/**
* Constructor for QgsProcessingAlgorithmDialogBase.
*/
QgsProcessingAlgorithmDialogBase( QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr );
/**
* Sets the \a algorithm to run in the dialog.
* \see algorithm()
*/
void setAlgorithm( QgsProcessingAlgorithm *algorithm );
/**
* Returns the algorithm running in the dialog.
* \see setAlgorithm()
*/
QgsProcessingAlgorithm *algorithm();
/**
* Sets the main \a widget for the dialog, usually a panel for configuring algorithm parameters.
* \see mainWidget()
*/
void setMainWidget( QWidget *widget SIP_TRANSFER );
/**
* Returns the main widget for the dialog, usually a panel for configuring algorithm parameters.
* \see setMainWidget()
*/
QWidget *mainWidget();
/**
* Switches the dialog to the log page.
*/
void showLog();
/**
* Returns true if an algorithm was executed in the dialog.
* \see results()
* \see setExecuted()
*/
bool wasExecuted() const { return mExecuted; }
/**
* Returns the results returned by the algorithm executed.
* \see wasExecuted()
* \see setResults()
*/
QVariantMap results() const { return mResults; }
/**
* Creates a new processing feedback object, automatically connected to the appropriate
* slots in this dialog.
*/
QgsProcessingFeedback *createFeedback() SIP_FACTORY;
/**
* Returns the parameter values for the algorithm to run in the dialog.
*/
virtual QVariantMap getParameterValues() const;
public slots:
void accept() override;
/**
* Reports an \a error string to the dialog's log.
*/
void reportError( const QString &error );
/**
* Pushes an information string to the dialog's log.
*/
void pushInfo( const QString &info );
/**
* Pushes a debug info string to the dialog's log.
*/
void pushDebugInfo( const QString &message );
/**
* Pushes command info to the dialog's log.
*/
void pushCommandInfo( const QString &info );
/**
* Sets the percentage progress for the dialog, between 0 and 100.
*/
void setPercentage( double percent );
/**
* Sets a progress text message.
*/
void setProgressText( const QString &text );
/**
* Pushes a console info string to the dialog's log.
*/
void pushConsoleInfo( const QString &info );
/**
* Creates a modal progress dialog showing progress and log messages
* from this dialog.
*/
QDialog *createProgressDialog();
protected:
void closeEvent( QCloseEvent *e ) override;
/**
* Returns the dialog's run button.
*/
QPushButton *runButton();
/**
* Returns the dialog's cancel button.
*/
QPushButton *cancelButton();
/**
* Returns the dialog's button box.
*/
QDialogButtonBox *buttonBox();
/**
* Returns the dialog's tab widget.
*/
QTabWidget *tabWidget();
/**
* Clears any current progress from the dialog.
*/
void clearProgress();
/**
* Sets whether the algorithm was executed through the dialog.
* \see wasExecuted()
* \see setResults()
*/
void setExecuted( bool executed );
/**
* Sets the algorithm results.
* \see results()
* \see setExecuted()
*/
void setResults( const QVariantMap &results );
/**
* Displays an info \a message in the dialog's log.
*/
void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );
/**
* Resets the dialog's gui, ready for another algorithm execution.
*/
void resetGui();
/**
* Returns the dialog's message bar.
*/
QgsMessageBar *messageBar();
/**
* Hides the short help panel.
*/
void hideShortHelp();
/**
* Sets the current \a task running in the dialog. The task will automatically be started
* by the dialog. Ownership of \a task is transferred to the dialog.
*/
void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
protected slots:
/**
* Called when the algorithm has finished executing.
*/
virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
private slots:
void openHelp();
void toggleCollapsed();
void splitterChanged( int pos, int index );
void linkClicked( const QUrl &url );
void algExecuted( bool successful, const QVariantMap &results );
void taskTriggered( QgsTask *task );
void closeClicked();
private:
QPushButton *mButtonRun = nullptr;
QPushButton *mButtonClose = nullptr;
QByteArray mSplitterState;
QToolButton *mButtonCollapse = nullptr;
QgsMessageBar *mMessageBar = nullptr;
bool mExecuted = false;
QVariantMap mResults;
QWidget *mMainWidget = nullptr;
QgsProcessingAlgorithm *mAlgorithm = nullptr;
QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
bool mHelpCollapsed = false;
QString formatHelp( QgsProcessingAlgorithm *algorithm );
void scrollToBottomOfLog();
void processEvents();
};
#ifndef SIP_RUN
/**
* \ingroup gui
* \brief A modal dialog for showing algorithm progress and log messages.
* \note This is not considered stable API and may change in future QGIS versions.
* \since QGIS 3.0
*/
class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
{
Q_OBJECT
public:
/**
* Constructor for QgsProcessingAlgorithmProgressDialog.
*/
QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
/**
* Returns the dialog's progress bar.
*/
QProgressBar *progressBar();
/**
* Returns the dialog's cancel button.
*/
QPushButton *cancelButton();
/**
* Returns the dialog's text log.
*/
QTextEdit *logTextEdit();
public slots:
void reject() override;
};
#endif
///@endcond
#endif // QGSPROCESSINGALGORITHMDIALOGBASE_H