QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
116 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false );
117
119 QListView *listView() const { return mSelectionList; }
120
122 QStandardItemModel *mModel = nullptr;
124 std::function<QString( const QVariant & )> mValueFormatter;
125
126 void dragEnterEvent( QDragEnterEvent *event ) override;
127 void dropEvent( QDropEvent *event ) override;
128
129 private slots:
130
131 void selectAll( bool checked );
132 void toggleSelection();
133
134 private:
135 QPushButton *mButtonSelectAll = nullptr;
136 QPushButton *mButtonClearSelection = nullptr;
137 QPushButton *mButtonToggleSelection = nullptr;
138
139 QList<QStandardItem *> currentItems();
140
141 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
142
143 friend class TestProcessingGui;
144
149 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
150};
151
152
159class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
160{
161 Q_OBJECT
162
163 public:
173 QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
174
175
179#ifndef SIP_RUN
180 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
181#else
182 void setValueFormatter( SIP_PYCALLABLE );
183 //%MethodCode
184
185 Py_BEGIN_ALLOW_THREADS
186
187 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
188 QString res;
189 SIP_BLOCK_THREADS
190 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
191 int state;
192 int sipIsError = 0;
193 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
194 if ( sipIsError == 0 )
195 {
196 res = QString( *t1 );
197 }
198 sipReleaseType( t1, sipType_QString, state );
199 SIP_UNBLOCK_THREADS
200 return res;
201 } );
202
203 Py_END_ALLOW_THREADS
204 //%End
205#endif
206
207
211 QVariantList selectedOptions() const;
212
213 private:
214 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
215};
216
217
224class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
225{
226 Q_OBJECT
227
228 public:
232 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
233
237 void setProject( QgsProject *project );
238
244 static QStringList compatibleUrisFromMimeData(
245 const QgsProcessingParameterMultipleLayers *parameter,
246 const QMimeData *data,
247 const QgsMimeDataUtils::UriList &skipUrls
248 ) SIP_SKIP;
249
250 private slots:
251
252 void addFiles();
253 void addDirectory();
254
255 protected:
256 void dragEnterEvent( QDragEnterEvent *event ) override;
257 void dropEvent( QDropEvent *event ) override;
258
259 private:
264 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
265 void populateFromProject( QgsProject *project );
266
267 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
268};
269
270
277class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
278{
279 Q_OBJECT
280
281 public:
288 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
289
293 QVariantList selectedOptions() const;
294
298 void setProject( QgsProject *project );
299
300 private:
301 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
302};
303
304
306
307#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:53
#define SIP_SKIP
Definition qgis_sip.h:134