QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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 "qgsmimedatautils.h"
24#include <QDialog>
25
26class QStandardItemModel;
27class QToolButton;
28class QStandardItem;
29class QgsProcessingModelChildParameterSource;
30class QgsProcessingModelAlgorithm;
31
33
40class GUI_EXPORT QgsProcessingMultipleSelectionPanelWidget : public QgsPanelWidget, private Ui::QgsProcessingMultipleSelectionDialogBase
41{
42 Q_OBJECT
43
44 public:
45
55 QgsProcessingMultipleSelectionPanelWidget( const QVariantList &availableOptions = QVariantList(),
56 const QVariantList &selectedOptions = QVariantList(),
57 QWidget *parent SIP_TRANSFERTHIS = nullptr );
58
62#ifndef SIP_RUN
63 void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
64#else
65 void setValueFormatter( SIP_PYCALLABLE );
66 % MethodCode
67
68 Py_BEGIN_ALLOW_THREADS
69
70 sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
71 {
72 QString res;
73 SIP_BLOCK_THREADS
74 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
75 int state;
76 int sipIsError = 0;
77 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
78 if ( sipIsError == 0 )
79 {
80 res = QString( *t1 );
81 }
82 sipReleaseType( t1, sipType_QString, state );
83 SIP_UNBLOCK_THREADS
84 return res;
85 } );
86
87 Py_END_ALLOW_THREADS
88 % End
89#endif
90
91
95 QVariantList selectedOptions() const;
96
100 QDialogButtonBox *buttonBox() { return mButtonBox; }
101
102 signals:
103
107 void acceptClicked();
108
112 void selectionChanged();
113
114 protected:
115
119 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false );
120
122 QListView *listView() const { return mSelectionList; }
123
125 QStandardItemModel *mModel = nullptr;
127 std::function< QString( const QVariant & )> mValueFormatter;
128
129 void dragEnterEvent( QDragEnterEvent *event ) override;
130 void dropEvent( QDropEvent *event ) override;
131
132 private slots:
133
134 void selectAll( bool checked );
135 void toggleSelection();
136
137 private:
138
139 QPushButton *mButtonSelectAll = nullptr;
140 QPushButton *mButtonClearSelection = nullptr;
141 QPushButton *mButtonToggleSelection = nullptr;
142
143 QList< QStandardItem * > currentItems();
144
145 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
146
147 friend class TestProcessingGui;
148
153 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
154};
155
156
163class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
164{
165 Q_OBJECT
166
167 public:
168
178 QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(),
179 const QVariantList &selectedOptions = QVariantList(),
180 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
181
182
186#ifndef SIP_RUN
187 void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
188#else
189 void setValueFormatter( SIP_PYCALLABLE );
190 % MethodCode
191
192 Py_BEGIN_ALLOW_THREADS
193
194 sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
195 {
196 QString res;
197 SIP_BLOCK_THREADS
198 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
199 int state;
200 int sipIsError = 0;
201 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
202 if ( sipIsError == 0 )
203 {
204 res = QString( *t1 );
205 }
206 sipReleaseType( t1, sipType_QString, state );
207 SIP_UNBLOCK_THREADS
208 return res;
209 } );
210
211 Py_END_ALLOW_THREADS
212 % End
213#endif
214
215
219 QVariantList selectedOptions() const;
220
221 private:
222
223 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
224
225};
226
227
234class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
235{
236 Q_OBJECT
237
238 public:
239
243 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter,
244 const QVariantList &selectedOptions,
245 const QList< QgsProcessingModelChildParameterSource > &modelSources,
246 QgsProcessingModelAlgorithm *model = nullptr,
247 QWidget *parent SIP_TRANSFERTHIS = nullptr );
248
252 void setProject( QgsProject *project );
253
259 static QStringList compatibleUrisFromMimeData(
261 const QMimeData *data,
262 const QgsMimeDataUtils::UriList &skipUrls ) SIP_SKIP;
263
264 private slots:
265
266 void addFiles();
267 void addDirectory();
268
269 protected:
270 void dragEnterEvent( QDragEnterEvent *event ) override;
271 void dropEvent( QDropEvent *event ) override;
272
273 private:
274
279 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
280 void populateFromProject( QgsProject *project );
281
282 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
283};
284
285
292class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
293{
294 Q_OBJECT
295
296 public:
297
304 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter,
305 const QVariantList &selectedOptions,
306 const QList< QgsProcessingModelChildParameterSource > &modelSources,
307 QgsProcessingModelAlgorithm *model = nullptr,
308 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
309
313 QVariantList selectedOptions() const;
314
318 void setProject( QgsProject *project );
319
320 private:
321
322 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
323
324};
325
326
328
329#endif // QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
QList< QgsMimeDataUtils::Uri > UriList
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:107
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126