QGIS API Documentation  3.27.0-Master (bef583a8ef)
qgsprocessingmeshdatasetwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingmeshdatasetwidget.h
3  ---------------------
4  Date : October 2020
5  Copyright : (C) 2020 by Vincent Cloarec
6  Email : vcloarec 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 QGSPROCESSINGMESHDATASETWIDGET_H
17 #define QGSPROCESSINGMESHDATASETWIDGET_H
18 
19 #include <QAction>
20 
23 #include "qgsmeshlayer.h"
24 
25 #include "ui_qgsprocessingmeshdatasettimewidget.h"
26 
27 #define SIP_NO_FILE
28 
30 
31 class GUI_EXPORT QgsProcessingMeshDatasetGroupsWidget : public QWidget
32 {
33  Q_OBJECT
34  public:
35  QgsProcessingMeshDatasetGroupsWidget( QWidget *parent = nullptr, const QgsProcessingParameterMeshDatasetGroups *param = nullptr );
36 
42  void setMeshLayer( QgsMeshLayer *layer, bool layerFromProject = false );
43  void setValue( const QVariant &value );
44  QVariant value() const;
45 
46  signals:
47  void changed();
48 
49  private slots:
50  void showDialog();
51  void selectCurrentActiveDatasetGroup();
52 
53  private:
54  const QgsProcessingParameterMeshDatasetGroups *mParam = nullptr;
55  QVariantList mValue;
56 
57  QPointer<QLineEdit> mLineEdit = nullptr;
58  QPointer<QToolButton> mToolButton = nullptr;
59  QPointer<QAction> mActionCurrentActiveDatasetGroups = nullptr;
60  QPointer<QAction> mActionAvailableDatasetGroups = nullptr;
61  QgsMeshLayer *mMeshLayer = nullptr;
62  QMap<int, QString> mDatasetGroupsNames; //used to store the dataet groups name if layer is not referenced
63 
64  QStringList datasetGroupsNames();
65  void updateSummaryText();
66 
67  friend class TestProcessingGui;
68 };
69 
70 
71 class GUI_EXPORT QgsProcessingMeshDatasetGroupsWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
72 {
73  Q_OBJECT
74 
75  public:
76  QgsProcessingMeshDatasetGroupsWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
77  QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );
78 
79  QString parameterType() const override;
81  QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
82  QgsProcessingContext &context,
83  const QgsProcessingParameterWidgetContext &widgetContext,
84  const QgsProcessingParameterDefinition *definition = nullptr,
85  const QgsProcessingAlgorithm *algorithm = nullptr ) override;
86  void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers ) override;
87 
89  void setMeshLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper );
90 
91  protected:
92  QStringList compatibleParameterTypes() const override;
93  QStringList compatibleOutputTypes() const override;
94  QWidget *createWidget() override;
95  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
96  QVariant widgetValue() const override;
97 
98  private:
99  QgsProcessingMeshDatasetGroupsWidget *mWidget = nullptr;
100 
101  friend class TestProcessingGui;
102 };
103 
104 class GUI_EXPORT QgsProcessingMeshDatasetGroupsParameterDefinitionWidget : public QgsProcessingAbstractParameterDefinitionWidget
105 {
106  public:
107  QgsProcessingMeshDatasetGroupsParameterDefinitionWidget( QgsProcessingContext &context,
108  const QgsProcessingParameterWidgetContext &widgetContext,
109  const QgsProcessingParameterDefinition *definition = nullptr,
110  const QgsProcessingAlgorithm *algorithm = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
111 
112  QgsProcessingParameterDefinition *createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const;
113 
114  private:
115  QComboBox *mParentLayerComboBox = nullptr;
116 };
117 
118 class GUI_EXPORT QgsProcessingMeshDatasetTimeWidget : public QWidget, private Ui::QgsProcessingMeshDatasetTimeWidgetBase
119 {
120  Q_OBJECT
121  public:
122  QgsProcessingMeshDatasetTimeWidget( QWidget *parent = nullptr,
123  const QgsProcessingParameterMeshDatasetTime *param = nullptr,
125 
131  void setMeshLayer( QgsMeshLayer *layer, bool layerFromProject = false );
132  void setDatasetGroupIndexes( const QList<int> datasetGroupIndexes );
133 
134  void setValue( const QVariant &value );
135  QVariant value() const;
136 
137  public slots:
138  void updateValue();
139 
140  signals:
141  void changed();
142 
143  private:
144  const QgsProcessingParameterMeshDatasetTime *mParam = nullptr;
145  QVariantMap mValue;
146  QgsMapCanvas *mCanvas;
147 
148  QLineEdit *mLineEdit = nullptr;
149  QToolButton *mToolButton = nullptr;
150  QgsMeshLayer *mMeshLayer = nullptr;
151  QList<int> mDatasetGroupIndexes;
152  QDateTime mReferenceTime;
153 
154  void populateTimeSteps();
155  bool hasTemporalDataset() const;
157  void populateTimeStepsFromLayer();
159  void storeTimeStepsFromLayer( QgsMeshLayer *layer );
160  QMap<int, QList<qint64>> mDatasetTimeSteps; //used if layer does not come from project
161 
162  void updateWidget();
163  void buildValue();
164 
165  friend class TestProcessingGui;
166 };
167 
168 class GUI_EXPORT QgsProcessingMeshDatasetTimeWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
169 {
170  Q_OBJECT
171 
172  public:
173  QgsProcessingMeshDatasetTimeWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
174  QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );
175 
176  QString parameterType() const override;
178  void postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers ) override;
179  QgsProcessingAbstractParameterDefinitionWidget *createParameterDefinitionWidget(
180  QgsProcessingContext &context,
181  const QgsProcessingParameterWidgetContext &widgetContext,
182  const QgsProcessingParameterDefinition *definition = nullptr,
183  const QgsProcessingAlgorithm *algorithm = nullptr ) override;
184 
186  void setMeshLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper );
187 
189  void setDatasetGroupIndexesWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper );
190 
191  protected:
192  QStringList compatibleParameterTypes() const override;
193  QStringList compatibleOutputTypes() const override;
194  QWidget *createWidget() override;
195  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
196  QVariant widgetValue() const override;
197 
198  private:
199  QgsProcessingMeshDatasetTimeWidget *mWidget = nullptr;
200  std::unique_ptr<QgsMeshLayer> mTemporarytMeshLayer;
201  friend class TestProcessingGui;
202 };
203 
204 class GUI_EXPORT QgsProcessingMeshDatasetTimeParameterDefinitionWidget : public QgsProcessingAbstractParameterDefinitionWidget
205 {
206  public:
207  QgsProcessingMeshDatasetTimeParameterDefinitionWidget( QgsProcessingContext &context,
208  const QgsProcessingParameterWidgetContext &widgetContext,
209  const QgsProcessingParameterDefinition *definition = nullptr,
210  const QgsProcessingAlgorithm *algorithm = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
211 
212  QgsProcessingParameterDefinition *createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const;
213 
214  private:
215  QComboBox *mParentDatasetComboBox = nullptr;
216  QString mMeshLayerParameterName;
217 };
218 
219 
221 
222 #endif // QGSPROCESSINGMESHDATASETWIDGET_H
A widget wrapper for Processing parameter value widgets.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:99
Abstract base class for widgets which allow users to specify the properties of a Processing parameter...
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
Base class for the definition of processing parameters.
A parameter for processing algorithms that need a list of mesh dataset groups.
A parameter for processing algorithms that need a list of mesh dataset index from time parameter.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
An interface for Processing widget wrapper factories.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53