QGIS API Documentation 3.99.0-Master (d270888f95f)
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( const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
175
176
180#ifndef SIP_RUN
181 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
182#else
183 void setValueFormatter( SIP_PYCALLABLE );
184 //%MethodCode
185
186 Py_BEGIN_ALLOW_THREADS
187
188 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
189 QString res;
190 SIP_BLOCK_THREADS
191 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
192 int state;
193 int sipIsError = 0;
194 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
195 if ( sipIsError == 0 )
196 {
197 res = QString( *t1 );
198 }
199 sipReleaseType( t1, sipType_QString, state );
200 SIP_UNBLOCK_THREADS
201 return res;
202 } );
203
204 Py_END_ALLOW_THREADS
205 //%End
206#endif
207
208
212 QVariantList selectedOptions() const;
213
214 private:
215 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
216};
217
218
225class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
226{
227 Q_OBJECT
228
229 public:
233 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
234
238 void setProject( QgsProject *project );
239
245 static QStringList compatibleUrisFromMimeData(
246 const QgsProcessingParameterMultipleLayers *parameter,
247 const QMimeData *data,
248 const QgsMimeDataUtils::UriList &skipUrls
249 ) SIP_SKIP;
250
251 private slots:
252
253 void addFiles();
254 void addDirectory();
255
256 protected:
257 void dragEnterEvent( QDragEnterEvent *event ) override;
258 void dropEvent( QDropEvent *event ) override;
259
260 private:
265 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
266 void populateFromProject( QgsProject *project );
267
268 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
269};
270
271
278class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
279{
280 Q_OBJECT
281
282 public:
289 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
290
294 QVariantList selectedOptions() const;
295
299 void setProject( QgsProject *project );
300
301 private:
302 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
303};
304
305
307
308#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