QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
54 QgsProcessingMultipleSelectionPanelWidget( const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr );
55
59#ifndef SIP_RUN
60 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
61#else
62 void setValueFormatter( SIP_PYCALLABLE );
63 //%MethodCode
64
65 Py_BEGIN_ALLOW_THREADS
66
67 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
68 QString res;
69 SIP_BLOCK_THREADS
70 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
71 int state;
72 int sipIsError = 0;
73 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
74 if ( sipIsError == 0 )
75 {
76 res = QString( *t1 );
77 }
78 sipReleaseType( t1, sipType_QString, state );
79 SIP_UNBLOCK_THREADS
80 return res;
81 } );
82
83 Py_END_ALLOW_THREADS
84 //%End
85#endif
86
87
91 QVariantList selectedOptions() const;
92
96 QDialogButtonBox *buttonBox() { return mButtonBox; }
97
98 signals:
99
103 void acceptClicked();
104
108 void selectionChanged();
109
110 protected:
114 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false );
115
117 QListView *listView() const { return mSelectionList; }
118
120 QStandardItemModel *mModel = nullptr;
122 std::function<QString( const QVariant & )> mValueFormatter;
123
124 void dragEnterEvent( QDragEnterEvent *event ) override;
125 void dropEvent( QDropEvent *event ) override;
126
127 private slots:
128
129 void selectAll( bool checked );
130 void toggleSelection();
131
132 private:
133 QPushButton *mButtonSelectAll = nullptr;
134 QPushButton *mButtonClearSelection = nullptr;
135 QPushButton *mButtonToggleSelection = nullptr;
136
137 QList<QStandardItem *> currentItems();
138
139 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
140
141 friend class TestProcessingGui;
142
147 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
148};
149
150
157class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
158{
159 Q_OBJECT
160
161 public:
171 QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(), const QVariantList &selectedOptions = QVariantList(), QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
172
173
177#ifndef SIP_RUN
178 void setValueFormatter( const std::function<QString( const QVariant & )> &formatter );
179#else
180 void setValueFormatter( SIP_PYCALLABLE );
181 //%MethodCode
182
183 Py_BEGIN_ALLOW_THREADS
184
185 sipCpp->setValueFormatter( [a0]( const QVariant &v ) -> QString {
186 QString res;
187 SIP_BLOCK_THREADS
188 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
189 int state;
190 int sipIsError = 0;
191 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
192 if ( sipIsError == 0 )
193 {
194 res = QString( *t1 );
195 }
196 sipReleaseType( t1, sipType_QString, state );
197 SIP_UNBLOCK_THREADS
198 return res;
199 } );
200
201 Py_END_ALLOW_THREADS
202 //%End
203#endif
204
205
209 QVariantList selectedOptions() const;
210
211 private:
212 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
213};
214
215
222class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
223{
224 Q_OBJECT
225
226 public:
230 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
231
235 void setProject( QgsProject *project );
236
242 static QStringList compatibleUrisFromMimeData(
244 const QMimeData *data,
245 const QgsMimeDataUtils::UriList &skipUrls
246 ) SIP_SKIP;
247
248 private slots:
249
250 void addFiles();
251 void addDirectory();
252
253 protected:
254 void dragEnterEvent( QDragEnterEvent *event ) override;
255 void dropEvent( QDropEvent *event ) override;
256
257 private:
262 QList<int> existingMapLayerFromMimeData( const QMimeData *data, QgsMimeDataUtils::UriList &handledUrls ) const;
263 void populateFromProject( QgsProject *project );
264
265 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
266};
267
268
275class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
276{
277 Q_OBJECT
278
279 public:
286 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter, const QVariantList &selectedOptions, const QList<QgsProcessingModelChildParameterSource> &modelSources, QgsProcessingModelAlgorithm *model = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
287
291 QVariantList selectedOptions() const;
292
296 void setProject( QgsProject *project );
297
298 private:
299 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
300};
301
302
304
305#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