QGIS API Documentation 4.1.0-Master (376402f9aeb)
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:
119 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false, QIcon optionalIconDecoration = QIcon(), const QString &tooltip = QString() );
121 QListView *listView() const { return mSelectionList; }
122
124 QStandardItemModel *mModel = nullptr;
126 std::function<QString( const QVariant & )> mValueFormatter;
127
128 void dragEnterEvent( QDragEnterEvent *event ) override;
129 void dropEvent( QDropEvent *event ) override;
130
131 private slots:
132
133 void selectAll( bool checked );
134 void toggleSelection();
135
136 private:
137 QPushButton *mButtonSelectAll = nullptr;
138 QPushButton *mButtonClearSelection = nullptr;
139 QPushButton *mButtonToggleSelection = nullptr;
140
141 QList<QStandardItem *> currentItems();
142
143 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
144
145 friend class TestProcessingGui;
146
151 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
152};
153
154
161class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
162{
163 Q_OBJECT
164
165 public:
175 QgsProcessingMultipleSelectionDialog(
176 const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()
177 );
178
179
183#ifndef SIP_RUN
184 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
185#else
186 void setValueFormatter( SIP_PYCALLABLE );
187 //%MethodCode
188
189 Py_BEGIN_ALLOW_THREADS
190
191 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
192 QString res;
193 SIP_BLOCK_THREADS
194 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
195 int state;
196 int sipIsError = 0;
197 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
198 if ( sipIsError == 0 )
199 {
200 res = QString( *t1 );
201 }
202 sipReleaseType( t1, sipType_QString, state );
203 SIP_UNBLOCK_THREADS
204 return res;
205 } );
206
207 Py_END_ALLOW_THREADS
208 //%End
209#endif
210
211
215 QVariantList selectedOptions() const;
216
217 private:
218 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
219};
220
221
228class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
229{
230 Q_OBJECT
231
232 public:
236 QgsProcessingMultipleInputPanelWidget(
237 const QgsProcessingParameterMultipleLayers *parameter,
238 const QVariantList &selectedOptions,
239 const QList<QgsProcessingModelChildParameterSource> &modelSources,
240 QgsProcessingModelAlgorithm *model = nullptr,
241 QWidget *parent SIP_TRANSFERTHIS = nullptr
242 );
243
247 void setProject( QgsProject *project );
248
254 static QStringList compatibleUrisFromMimeData( const QgsProcessingParameterMultipleLayers *parameter, const QMimeData *data, const QgsMimeDataUtils::UriList &skipUrls ) SIP_SKIP;
255
256 private slots:
257
258 void addFiles();
259 void addDirectory();
260
261 protected:
262 void dragEnterEvent( QDragEnterEvent *event ) override;
263 void dropEvent( QDropEvent *event ) override;
264
265 private:
270 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
271 void populateFromProject( QgsProject *project );
272
273 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
274};
275
276
283class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
284{
285 Q_OBJECT
286
287 public:
294 QgsProcessingMultipleInputDialog(
295 const QgsProcessingParameterMultipleLayers *parameter,
296 const QVariantList &selectedOptions,
297 const QList<QgsProcessingModelChildParameterSource> &modelSources,
298 QgsProcessingModelAlgorithm *model = nullptr,
299 QWidget *parent SIP_TRANSFERTHIS = nullptr,
300 Qt::WindowFlags flags = Qt::WindowFlags()
301 );
302
306 QVariantList selectedOptions() const;
307
311 void setProject( QgsProject *project );
312
313 private:
314 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
315};
316
317
319
320#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