QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsvaluerelationwidgetwrapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvaluerelationwidgetwrapper.h
3 --------------------------------------
4 Date : 5.1.2014
5 Copyright : (C) 2014 Matthias Kuhn
6 Email : matthias at opengis dot ch
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 QGSVALUERELATIONWIDGETWRAPPER_H
17#define QGSVALUERELATIONWIDGETWRAPPER_H
18
19#include <QTableWidget>
20
23#include "qgstooltipcombobox.h"
24#include "qgis_gui.h"
25
26class QLineEdit;
29
31
33
40class QgsFilteredTableWidget : public QWidget
41{
42 Q_OBJECT
43
44 public:
45
52 QgsFilteredTableWidget( QWidget *parent, bool showSearch, bool displayGroupName );
53
54 bool eventFilter( QObject *watched, QEvent *event ) override;
55
59 QStringList selection() const;
60
64 void checkItems( const QStringList &checked );
65
70
74 void setIndeterminateState();
75
79 void setEnabledTable( const bool enabled );
80
84 void setColumnCount( const int count );
85
89 int rowCount() const { return mTableWidget->rowCount(); }
90
91 signals:
92
96 void itemChanged( QTableWidgetItem *item );
97
98 private:
99 void filterStringChanged( const QString &filterString );
100 void itemChanged_p( QTableWidgetItem *item );
101 QTableWidgetItem *item( const int row, const int column ) const { return mTableWidget->item( row, column ); }
102
103 int mColumnCount = 1;
104 QgsFilterLineEdit *mSearchWidget = nullptr;
105 QTableWidget *mTableWidget = nullptr;
106 bool mEnabledTable = true;
107 QVector<QPair<QgsValueRelationFieldFormatter::ValueRelationItem, Qt::CheckState>> mCache;
108 bool mDisplayGroupName = false;
109
110 friend class TestQgsValueRelationWidgetWrapper;
111};
112
114
137{
138 Q_OBJECT
139
140 public:
141
152 explicit QgsValueRelationWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor = nullptr, QWidget *parent = nullptr );
153
154 QVariant value() const override;
155
156 void showIndeterminateState() override;
157
158 void setEnabled( bool enabled ) override;
159
160 public slots:
161
162 void parentFormValueChanged( const QString &attribute, const QVariant &value ) override;
163
164 protected:
165 QWidget *createWidget( QWidget *parent ) override;
166 void initWidget( QWidget *editor ) override;
167 bool valid() const override;
168
181 void widgetValueChanged( const QString &attribute, const QVariant &newValue, bool attributeChanged );
182
191 void setFeature( const QgsFeature &feature ) override;
192
193 private slots:
194 void emitValueChangedInternal( const QString &value );
195
196 private:
197 void updateValues( const QVariant &value, const QVariantList & = QVariantList() ) override;
198
199
204 int columnCount() const;
205
207 QVariant::Type fkType() const;
208
210 void populate( );
211
212 QComboBox *mComboBox = nullptr;
213 QgsFilteredTableWidget *mTableWidget = nullptr;
214 QLineEdit *mLineEdit = nullptr;
215 int mSubWidgetSignalBlocking = 0;
216
218 QgsVectorLayer *mLayer = nullptr;
219
220 bool mEnabled = true;
221 QString mExpression;
222
224 friend class TestQgsValueRelationWidgetWrapper;
225
226};
227
228#endif // QGSVALUERELATIONWIDGETWRAPPER_H
Manages an editor widget Widget and wrapper share the same parent.
virtual QVariant value() const =0
Will be used to access the widget's value.
virtual void parentFormValueChanged(const QString &attribute, const QVariant &value)
Is called in embedded form widgets when an attribute value in the parent form has changed.
virtual void showIndeterminateState()
Sets the widget to display in an indeterminate "mixed value" state.
void setFeature(const QgsFeature &feature) override
Will be called when the feature changes.
void setEnabled(bool enabled) override
Is used to enable or disable the edit functionality of the managed widget.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QVector< QgsValueRelationFieldFormatter::ValueRelationItem > ValueRelationCache
Represents a vector layer which manages a vector based data sets.
virtual bool valid() const =0
Returns true if the widget has been properly initialized.
virtual void initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.
#define SIP_NO_FILE