QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgis_gui.h"
21#include "qgstooltipcombobox.h"
23
24#include <QTableWidget>
25
26class QLineEdit;
29
31
33
40class QgsFilteredTableWidget : public QWidget
41{
42 Q_OBJECT
43
44 public:
51 QgsFilteredTableWidget( QWidget *parent, bool showSearch, bool displayGroupName );
52
53 bool eventFilter( QObject *watched, QEvent *event ) override;
54
58 QStringList selection() const;
59
63 void checkItems( const QStringList &checked );
64
69
73 void setIndeterminateState();
74
78 void setEnabledTable( const bool enabled );
79
83 void setColumnCount( const int count );
84
88 int rowCount() const { return mTableWidget->rowCount(); }
89
90 signals:
91
95 void itemChanged( QTableWidgetItem *item );
96
97 private slots:
98 void onTableWidgetCustomContextMenuRequested( const QPoint &pos );
99 void onTableWidgetMenuActionSelectAllTriggered();
100 void onTableWidgetMenuActionDeselectAllTriggered();
101
102 private:
103 void filterStringChanged( const QString &filterString );
104 void itemChanged_p( QTableWidgetItem *item );
105 QTableWidgetItem *item( const int row, const int column ) const { return mTableWidget->item( row, column ); }
106
107 int mColumnCount = 1;
108 QgsFilterLineEdit *mSearchWidget = nullptr;
109 QTableWidget *mTableWidget = nullptr;
110 bool mEnabledTable = true;
111 QVector<QPair<QgsValueRelationFieldFormatter::ValueRelationItem, Qt::CheckState>> mCache;
112 bool mDisplayGroupName = false;
113
114 friend class TestQgsValueRelationWidgetWrapper;
115};
116
118
139
141{
142 Q_OBJECT
143
144 public:
155 explicit QgsValueRelationWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor = nullptr, QWidget *parent = nullptr );
156
157 QVariant value() const override;
158
159 void showIndeterminateState() override;
160
161 void setEnabled( bool enabled ) override;
162
163 public slots:
164
165 void parentFormValueChanged( const QString &attribute, const QVariant &value ) override;
166
167 protected:
168 QWidget *createWidget( QWidget *parent ) override;
169 void initWidget( QWidget *editor ) override;
170 bool valid() const override;
171
184 void widgetValueChanged( const QString &attribute, const QVariant &newValue, bool attributeChanged );
185
194 void setFeature( const QgsFeature &feature ) override;
195
196 private slots:
197 void emitValueChangedInternal( const QString &value );
198
199 private:
200 void updateValues( const QVariant &value, const QVariantList & = QVariantList() ) override;
201
212 void updateValue( const QVariant &value, bool forceComboInsertion );
213
218 int columnCount() const;
219
221 QMetaType::Type fkType() const;
222
224 void populate();
225
226 QComboBox *mComboBox = nullptr;
227 QgsFilteredTableWidget *mTableWidget = nullptr;
228 QLineEdit *mLineEdit = nullptr;
229 int mSubWidgetSignalBlocking = 0;
230
232
233 bool mEnabled = true;
234 QString mExpression;
235
238};
239
240#endif // QGSVALUERELATIONWIDGETWRAPPER_H
virtual QVariant value() const =0
Will be used to access the widget's value.
int fieldIdx() const
Access the field index.
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.
QgsEditorWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
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:58
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QVector< QgsValueRelationFieldFormatter::ValueRelationItem > ValueRelationCache
Editor widget factory for value relation widgets.
QVariant value() const override
Will be used to access the widget's value.
QgsValueRelationWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsValueRelationWidgetWrapper.
void widgetValueChanged(const QString &attribute, const QVariant &newValue, bool attributeChanged)
Will be called when a value in the current edited form or table row changes.
Represents a vector layer which manages a vector based dataset.
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.
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.
#define SIP_NO_FILE