QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
24 
25 class QStandardItemModel;
26 class QToolButton;
27 class QStandardItem;
28 
30 
37 class GUI_EXPORT QgsProcessingMultipleSelectionDialog : public QDialog, private Ui::QgsProcessingMultipleSelectionDialogBase
38 {
39  Q_OBJECT
40 
41  public:
42 
52  QgsProcessingMultipleSelectionDialog( const QVariantList &availableOptions = QVariantList(),
53  const QVariantList &selectedOptions = QVariantList(),
54  QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = nullptr );
55 
56 
60 #ifndef SIP_RUN
61  void setValueFormatter( const std::function< QString( const QVariant & )> &formatter );
62 #else
63  void setValueFormatter( SIP_PYCALLABLE );
64  % MethodCode
65 
66  Py_BEGIN_ALLOW_THREADS
67 
68  sipCpp->setValueFormatter( [a0]( const QVariant &v )->QString
69  {
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 
95  private slots:
96 
97  void selectAll( bool checked );
98  void toggleSelection();
99 
100  private:
101  std::function< QString( const QVariant & )> mValueFormatter;
102 
103  QPushButton *mButtonSelectAll = nullptr;
104  QPushButton *mButtonClearSelection = nullptr;
105  QPushButton *mButtonToggleSelection = nullptr;
106  QStandardItemModel *mModel = nullptr;
107 
108  QList< QStandardItem * > currentItems();
109 
110  void populateList( const QVariantList &availableOptions, const QVariantList &selectedOptions );
111 
112  friend class TestProcessingGui;
113 };
114 
116 
117 #endif // QGSPROCESSINGMULTIPLESELECTIONDIALOG_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53