QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsprocessingtininputlayerswidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingtininputlayerswidget.h
3  ---------------------
4  Date : August 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 QGSPROCESSINGTININPUTLAYERSWIDGET_H
17 #define QGSPROCESSINGTININPUTLAYERSWIDGET_H
18 
19 #define SIP_NO_FILE
20 
21 #include <QAbstractTableModel>
22 #include <QStyledItemDelegate>
23 
26 #include "ui_qgsprocessingtinmeshdatawidgetbase.h"
27 
29 
30 class GUI_EXPORT QgsProcessingTinInputLayersWidget: public QWidget, private Ui::QgsProcessingTinInputLayersWidgetBase
31 {
32  Q_OBJECT
33  public:
34  QgsProcessingTinInputLayersWidget( QgsProject *project );
35 
36  QVariant value() const;
37  void setValue( const QVariant &value );
38  void setProject( QgsProject *project );
39 
40  signals:
41  void changed();
42 
43  private slots:
44  void onLayerChanged( QgsMapLayer *layer );
45  void onCurrentLayerAdded();
46  void onLayersRemove();
47 
48  private:
49  class QgsProcessingTinInputLayersModel: public QAbstractTableModel
50  {
51  public:
52  enum Roles
53  {
54  Type = Qt::UserRole
55  };
56 
57  QgsProcessingTinInputLayersModel( QgsProject *project );
58 
59  int rowCount( const QModelIndex &parent ) const override;
60  int columnCount( const QModelIndex &parent ) const override;
61  QVariant data( const QModelIndex &index, int role ) const override;
62  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
63  Qt::ItemFlags flags( const QModelIndex &index ) const override;
64  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
65 
67  void removeLayer( int index );
68  void clear();
69 
70  QList<QgsProcessingParameterTinInputLayers::InputLayer> layers() const;
71 
72  void setProject( QgsProject *project );
73 
74  private:
75  QList<QgsProcessingParameterTinInputLayers::InputLayer> mInputLayers;
76  QgsProject *mProject = nullptr;
77  };
78 
79  class Delegate: public QStyledItemDelegate
80  {
81  public:
82  Delegate( QObject *parent ): QStyledItemDelegate( parent ) {}
83 
84  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
85  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
86  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
87  };
88 
89  QgsProcessingTinInputLayersModel mInputLayersModel;
90 };
91 
92 
93 class GUI_EXPORT QgsProcessingTinInputLayersWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
94 {
95  Q_OBJECT
96 
97  public:
98  QgsProcessingTinInputLayersWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
99  QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );
100 
101  QString parameterType() const override;
103 
104  protected:
105  QStringList compatibleParameterTypes() const override;
106  QStringList compatibleOutputTypes() const override;
107  QWidget *createWidget() override SIP_FACTORY;
108  void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
109  QVariant widgetValue() const override;
110 
111  private:
112  QgsProcessingTinInputLayersWidget *mWidget = nullptr;
113 
114  friend class TestProcessingGui;
115 };
116 
118 
119 #endif // QGSPROCESSINGTININPUTLAYERSWIDGET_H
QgsAbstractProcessingParameterWidgetWrapper::createWidget
virtual QWidget * createWidget()=0
Creates a new widget which allows customization of the parameter's value.
QgsProcessingParameterTinInputLayers::InputLayer
Used to store input layer Id and other associated parameters.
Definition: qgsprocessingparametertininputlayers.h:62
qgsprocessingparametertininputlayers.h
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:334
QgsAbstractProcessingParameterWidgetWrapper
A widget wrapper for Processing parameter value widgets.
Definition: qgsprocessingwidgetwrapper.h:282
QgsProcessingParameterWidgetFactoryInterface::createWidgetWrapper
virtual QgsAbstractProcessingParameterWidgetWrapper * createWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)=0
Creates a new widget wrapper for the specified parameter definition.
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsProcessingGui::Standard
@ Standard
Standard algorithm dialog.
Definition: qgsprocessinggui.h:40
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsProcessingParameterWidgetFactoryInterface::parameterType
virtual QString parameterType() const =0
Returns the type string for the parameter type the factory is associated with.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
qgsprocessingwidgetwrapper.h
QgsProcessingGui::WidgetType
WidgetType
Types of dialogs which Processing widgets can be created for.
Definition: qgsprocessinggui.h:38
QgsProcessingParameterWidgetFactoryInterface
An interface for Processing widget wrapper factories.
Definition: qgsprocessingwidgetwrapper.h:532
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsProcessingParameterWidgetFactoryInterface::compatibleOutputTypes
virtual QStringList compatibleOutputTypes() const =0
Returns a list of compatible Processing output types for inputs for this parameter.
QgsProcessingParameterWidgetFactoryInterface::compatibleParameterTypes
virtual QStringList compatibleParameterTypes() const =0
Returns a list of compatible Processing parameter types for inputs for this parameter.