QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 <QDialog>
24
25class QStandardItemModel;
26class QToolButton;
27class QStandardItem;
28class QgsProcessingModelChildParameterSource;
29class QgsProcessingModelAlgorithm;
30
32
39class GUI_EXPORT QgsProcessingMultipleSelectionPanelWidget : public QgsPanelWidget, private Ui::QgsProcessingMultipleSelectionDialogBase
40{
41 Q_OBJECT
42
43 public:
44
54 QgsProcessingMultipleSelectionPanelWidget( const QVariantList &availableOptions = QVariantList(),
55 const QVariantList &selectedOptions = QVariantList(),
56 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 {
71 QString res;
72 SIP_BLOCK_THREADS
73 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
74 int state;
75 int sipIsError = 0;
76 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
77 if ( sipIsError == 0 )
78 {
79 res = QString( *t1 );
80 }
81 sipReleaseType( t1, sipType_QString, state );
82 SIP_UNBLOCK_THREADS
83 return res;
84 } );
85
86 Py_END_ALLOW_THREADS
87 % End
88#endif
89
90
94 QVariantList selectedOptions() const;
95
99 QDialogButtonBox *buttonBox() { return mButtonBox; }
100
101 signals:
102
106 void acceptClicked();
107
111 void selectionChanged();
112
113 protected:
114
118 void addOption( const QVariant &value, const QString &title, bool selected, bool updateExistingTitle = false );
119
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
138 QPushButton *mButtonSelectAll = nullptr;
139 QPushButton *mButtonClearSelection = nullptr;
140 QPushButton *mButtonToggleSelection = nullptr;
141
142 QList< QStandardItem * > currentItems();
143
144 void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
145
146 friend class TestProcessingGui;
147
152 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
153};
154
155
162class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog
163{
164 Q_OBJECT
165
166 public:
167
177 QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(),
178 const QVariantList &selectedOptions = QVariantList(),
179 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
180
181
185#ifndef SIP_RUN
186 void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
187#else
188 void setValueFormatter( SIP_PYCALLABLE );
189 % MethodCode
190
191 Py_BEGIN_ALLOW_THREADS
192
193 sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
194 {
195 QString res;
196 SIP_BLOCK_THREADS
197 PyObject *s = sipCallMethod( NULL, a0, "D", &v, sipType_QVariant, NULL );
198 int state;
199 int sipIsError = 0;
200 QString *t1 = reinterpret_cast<QString *>( sipConvertToType( s, sipType_QString, 0, SIP_NOT_NONE, &state, &sipIsError ) );
201 if ( sipIsError == 0 )
202 {
203 res = QString( *t1 );
204 }
205 sipReleaseType( t1, sipType_QString, state );
206 SIP_UNBLOCK_THREADS
207 return res;
208 } );
209
210 Py_END_ALLOW_THREADS
211 % End
212#endif
213
214
218 QVariantList selectedOptions() const;
219
220 private:
221
222 QgsProcessingMultipleSelectionPanelWidget *mWidget = nullptr;
223
224};
225
226
233class GUI_EXPORT QgsProcessingMultipleInputPanelWidget : public QgsProcessingMultipleSelectionPanelWidget
234{
235 Q_OBJECT
236
237 public:
238
242 QgsProcessingMultipleInputPanelWidget( const QgsProcessingParameterMultipleLayers *parameter,
243 const QVariantList &selectedOptions,
244 const QList< QgsProcessingModelChildParameterSource > &modelSources,
245 QgsProcessingModelAlgorithm *model = nullptr,
246 QWidget *parent SIP_TRANSFERTHIS = nullptr );
247
251 void setProject( QgsProject *project );
252
253 private slots:
254
255 void addFiles();
256 void addDirectory();
257
258 protected:
259 void dragEnterEvent( QDragEnterEvent *event ) override;
260 void dropEvent( QDropEvent *event ) override;
261
262 private:
263
268 QList<int> existingMapLayerFromMimeData( const QMimeData *data ) const;
269 void populateFromProject( QgsProject *project );
270
271 const QgsProcessingParameterMultipleLayers *mParameter = nullptr;
272};
273
274
281class GUI_EXPORT QgsProcessingMultipleInputDialog : public QDialog
282{
283 Q_OBJECT
284
285 public:
286
293 QgsProcessingMultipleInputDialog( const QgsProcessingParameterMultipleLayers *parameter,
294 const QVariantList &selectedOptions,
295 const QList< QgsProcessingModelChildParameterSource > &modelSources,
296 QgsProcessingModelAlgorithm *model = nullptr,
297 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
298
302 QVariantList selectedOptions() const;
303
307 void setProject( QgsProject *project );
308
309 private:
310
311 QgsProcessingMultipleInputPanelWidget *mWidget = nullptr;
312
313};
314
315
317
318#endif // QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
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