QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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
A widget wrapper for Processing parameter value widgets.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
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.
An interface for Processing widget wrapper factories.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
#define SIP_FACTORY
Definition: qgis_sip.h:76
Used to store input layer Id and other associated parameters.