QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsprocessingmultipleselectiondialog.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingmultipleselectiondialog.h
3 ----------------------------------
4 Date : February 2019
5 Copyright : (C) 2019 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 QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
17#define QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
18
19#include "qgis.h"
20#include "qgis_gui.h"
21#include "ui_qgsprocessingmultipleselectiondialogbase.h"
23#include <QDialog>
24
25class QStandardItemModel;
26class QToolButton;
27class QStandardItem;
28class QgsProcessingModelChildParameterSource;
29class QgsProcessingModelAlgorithm;
30
32
39class GUI_EXPORT QgsProcessingMultipleSelectionPanelWidget : public QgsPanelWidget, private Ui::QgsProcessingMultipleSelectionDialogBase
40{
41 Q_OBJECT
42
43 public:
44
54 QgsProcessingMultipleSelectionPanelWidget( const QVariantList &availableOptions = QVariantList(),
55 const QVariantList &selectedOptions = QVariantList(),
56 QWidget *parent SIP_TRANSFERTHIS = nullptr );
57
61#ifndef SIP_RUN
62 void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
63#else
64 void setValueFormatter( SIP_PYCALLABLE );
65 % MethodCode
66
67 Py_BEGIN_ALLOW_THREADS
68
69 sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
70 {
71 QString res;
72 SIP_BLOCK_THREADS
73 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
74 int state;
75 int sipIsError = 0;
76 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
77 if ( sipIsError == 0 )
78 {
79 res = QString( *t1 );
80 }
81 sipReleaseType( t1, sipType_QString, state );
82 SIP_UNBLOCK_THREADS
83 return res;
84 } );
85
86 Py_END_ALLOW_THREADS
87 % End
88#endif
89
90
94 QVariantList selectedOptions() const;
95
99 QDialogButtonBox *buttonBox() { return mButtonBox; }
100
101 signals:
102
106 void acceptClicked();
107
111 void selectionChanged();
112
113 protected:
114
118 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false );
119
121 QListView *listView() const { return mSelectionList; }
122
124 QStandardItemModel *mModel = nullptr;
126 std::function< QString( const QVariant & )> mValueFormatter;
127 private slots:
128
129 void selectAll( bool checked );
130 void toggleSelection();
131
132 private:
133
134 QPushButton *mButtonSelectAll = nullptr;
135 QPushButton *mButtonClearSelection = nullptr;
136 QPushButton *mButtonToggleSelection = nullptr;
137
138 QList< QStandardItem * > currentItems();
139
140
141 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
142
143 friend class TestProcessingGui;
144};
145
146
153class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
154{
155 Q_OBJECT
156
157 public:
158
168 QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(),
169 const QVariantList &selectedOptions = QVariantList(),
170 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
171
172
176#ifndef SIP_RUN
177 void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
178#else
179 void setValueFormatter( SIP_PYCALLABLE );
180 % MethodCode
181
182 Py_BEGIN_ALLOW_THREADS
183
184 sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
185 {
186 QString res;
187 SIP_BLOCK_THREADS
188 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
189 int state;
190 int sipIsError = 0;
191 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
192 if ( sipIsError == 0 )
193 {
194 res = QString( *t1 );
195 }
196 sipReleaseType( t1, sipType_QString, state );
197 SIP_UNBLOCK_THREADS
198 return res;
199 } );
200
201 Py_END_ALLOW_THREADS
202 % End
203#endif
204
205
209 QVariantList selectedOptions() const;
210
211 private:
212
213 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
214
215};
216
217
224class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
225{
226 Q_OBJECT
227
228 public:
229
233 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter,
234 const QVariantList &selectedOptions,
235 const QList< QgsProcessingModelChildParameterSource > &modelSources,
236 QgsProcessingModelAlgorithm *model = nullptr,
237 QWidget *parent SIP_TRANSFERTHIS = nullptr );
238
242 void setProject( QgsProject *project );
243
244 private slots:
245
246 void addFiles();
247 void addDirectory();
248
249 private:
250
251 void populateFromProject( QgsProject *project );
252
253 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
254};
255
256
263class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
264{
265 Q_OBJECT
266
267 public:
268
275 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter,
276 const QVariantList &selectedOptions,
277 const QList< QgsProcessingModelChildParameterSource > &modelSources,
278 QgsProcessingModelAlgorithm *model = nullptr,
279 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
280
284 QVariantList selectedOptions() const;
285
289 void setProject( QgsProject *project );
290
291 private:
292
293 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
294
295};
296
297
299
300#endif // QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
Base class for any widget that can be shown as a inline panel.
A parameter for processing algorithms which accepts multiple map layers.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53