QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 "ui_qgsprocessingmultipleselectiondialogbase.h"
20
21#include "qgis.h"
22#include "qgis_gui.h"
23#include "qgsmimedatautils.h"
25
26#include <QDialog>
27
28class QStandardItemModel;
29class QToolButton;
30class QStandardItem;
31class QgsProcessingModelChildParameterSource;
32class QgsProcessingModelAlgorithm;
33
35
42class GUI_EXPORT QgsProcessingMultipleSelectionPanelWidget : public QgsPanelWidget, private Ui::QgsProcessingMultipleSelectionDialogBase
43{
44 Q_OBJECT
45
46 public:
56 QgsProcessingMultipleSelectionPanelWidget( const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), 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 QString res;
71 SIP_BLOCK_THREADS
72 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
73 int state;
74 int sipIsError = 0;
75 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
76 if ( sipIsError == 0 )
77 {
78 res = QString( *t1 );
79 }
80 sipReleaseType( t1, sipType_QString, state );
81 SIP_UNBLOCK_THREADS
82 return res;
83 } );
84
85 Py_END_ALLOW_THREADS
86 //%End
87#endif
88
89
93 QVariantList selectedOptions() const;
94
98 QDialogButtonBox *buttonBox() { return mButtonBox; }
99
100 signals:
101
105 void acceptClicked();
106
110 void selectionChanged();
111
112 protected:
118 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false, QIcon optionalIconDecoration = QIcon() );
120 QListView *listView() const { return mSelectionList; }
121
123 QStandardItemModel *mModel = nullptr;
125 std::function<QString( const QVariant & )> mValueFormatter;
126
127 void dragEnterEvent( QDragEnterEvent *event ) override;
128 void dropEvent( QDropEvent *event ) override;
129
130 private slots:
131
132 void selectAll( bool checked );
133 void toggleSelection();
134
135 private:
136 QPushButton *mButtonSelectAll = nullptr;
137 QPushButton *mButtonClearSelection = nullptr;
138 QPushButton *mButtonToggleSelection = nullptr;
139
140 QList<QStandardItem *> currentItems();
141
142 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
143
144 friend class TestProcessingGui;
145
150 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
151};
152
153
160class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
161{
162 Q_OBJECT
163
164 public:
174 QgsProcessingMultipleSelectionDialog(
175 const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()
176 );
177
178
182#ifndef SIP_RUN
183 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
184#else
185 void setValueFormatter( SIP_PYCALLABLE );
186 //%MethodCode
187
188 Py_BEGIN_ALLOW_THREADS
189
190 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
191 QString res;
192 SIP_BLOCK_THREADS
193 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
194 int state;
195 int sipIsError = 0;
196 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
197 if ( sipIsError == 0 )
198 {
199 res = QString( *t1 );
200 }
201 sipReleaseType( t1, sipType_QString, state );
202 SIP_UNBLOCK_THREADS
203 return res;
204 } );
205
206 Py_END_ALLOW_THREADS
207 //%End
208#endif
209
210
214 QVariantList selectedOptions() const;
215
216 private:
217 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
218};
219
220
227class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
228{
229 Q_OBJECT
230
231 public:
235 QgsProcessingMultipleInputPanelWidget(
236 const QgsProcessingParameterMultipleLayers *parameter,
237 const QVariantList &selectedOptions,
238 const QList<QgsProcessingModelChildParameterSource> &modelSources,
239 QgsProcessingModelAlgorithm *model = nullptr,
240 QWidget *parent SIP_TRANSFERTHIS = nullptr
241 );
242
246 void setProject( QgsProject *project );
247
253 static QStringList compatibleUrisFromMimeData( const QgsProcessingParameterMultipleLayers *parameter, const QMimeData *data, const QgsMimeDataUtils::UriList &skipUrls ) SIP_SKIP;
254
255 private slots:
256
257 void addFiles();
258 void addDirectory();
259
260 protected:
261 void dragEnterEvent( QDragEnterEvent *event ) override;
262 void dropEvent( QDropEvent *event ) override;
263
264 private:
269 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
270 void populateFromProject( QgsProject *project );
271
272 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
273};
274
275
282class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
283{
284 Q_OBJECT
285
286 public:
293 QgsProcessingMultipleInputDialog(
294 const QgsProcessingParameterMultipleLayers *parameter,
295 const QVariantList &selectedOptions,
296 const QList<QgsProcessingModelChildParameterSource> &modelSources,
297 QgsProcessingModelAlgorithm *model = nullptr,
298 QWidget *parent SIP_TRANSFERTHIS = nullptr,
299 Qt::WindowFlags flags = Qt::WindowFlags()
300 );
301
305 QVariantList selectedOptions() const;
306
310 void setProject( QgsProject *project );
311
312 private:
313 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
314};
315
316
318
319#endif // QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
QList< QgsMimeDataUtils::Uri > UriList
Base class for any widget that can be shown as an inline panel.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133