QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsfielddomainwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfielddomainwidget.h
3 ------------------
4 Date : February 2022
5 Copyright : (C) 2022 by Nyall Dawson
6 Email : nyall dot dawson 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#ifndef QGSFIELDDOMAINWIDGET_H
16#define QGSFIELDDOMAINWIDGET_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20#include "ui_qgsfielddomainwidgetbase.h"
21#include "ui_qgsrangedomainwidgetbase.h"
22#include "ui_qgsglobdomainwidgetbase.h"
23#include "ui_qgscodedvaluedomainwidgetbase.h"
24#include "qgis.h"
25#include "qgsfielddomain.h"
26#include <QAbstractTableModel>
27#include <QDialog>
28
29class QDialogButtonBox;
30
31#ifndef SIP_RUN
32
42class GUI_EXPORT QgsAbstractFieldDomainWidget : public QWidget
43{
44 Q_OBJECT
45
46 public:
47
51 QgsAbstractFieldDomainWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
52
54
60 virtual void setFieldDomain( const QgsFieldDomain *domain ) = 0;
61
69 virtual QgsFieldDomain *createFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType ) const = 0 SIP_FACTORY;
70
74 virtual bool isValid() const = 0;
75
76 signals:
77
81 void changed();
82
83};
84
94class GUI_EXPORT QgsRangeDomainWidget : public QgsAbstractFieldDomainWidget, private Ui_QgsRangeDomainWidgetBase
95{
96 Q_OBJECT
97
98 public:
99
103 QgsRangeDomainWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
104
105 void setFieldDomain( const QgsFieldDomain *domain ) override;
106 QgsFieldDomain *createFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType ) const override SIP_FACTORY;
107 bool isValid() const override;
108
109};
110
120class GUI_EXPORT QgsGlobDomainWidget : public QgsAbstractFieldDomainWidget, private Ui_QgsGlobDomainWidgetBase
121{
122 Q_OBJECT
123
124 public:
125
129 QgsGlobDomainWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
130
131 void setFieldDomain( const QgsFieldDomain *domain ) override;
132 QgsFieldDomain *createFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType ) const override SIP_FACTORY;
133 bool isValid() const override;
134};
135
143class GUI_EXPORT QgsCodedValueTableModel : public QAbstractTableModel
144{
145 Q_OBJECT
146
147 public:
148
152 QgsCodedValueTableModel( QObject *parent );
153
154 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
155 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
156 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
157 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
158 Qt::ItemFlags flags( const QModelIndex &index ) const override;
159 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
160 bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
161 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
162
168 void setValues( const QList< QgsCodedValue > &values );
169
175 QList< QgsCodedValue > values() const { return mValues; }
176
177 private:
178
179 QList<QgsCodedValue> mValues;
180};
181
182
192class GUI_EXPORT QgsCodedFieldDomainWidget : public QgsAbstractFieldDomainWidget, private Ui_QgsCodedValueDomainWidgetBase
193{
194 Q_OBJECT
195
196 public:
197
201 QgsCodedFieldDomainWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
202
203 void setFieldDomain( const QgsFieldDomain *domain ) override;
204 QgsFieldDomain *createFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType ) const override SIP_FACTORY;
205 bool isValid() const override;
206
207 private:
208
209 QgsCodedValueTableModel *mModel = nullptr;
210
211};
212#endif
213
220class GUI_EXPORT QgsFieldDomainWidget : public QWidget, private Ui_QgsFieldDomainWidgetBase
221{
222 Q_OBJECT
223
224 public:
225
229 QgsFieldDomainWidget( Qgis::FieldDomainType type, QWidget *parent SIP_TRANSFERTHIS = nullptr );
230
236 void setFieldDomain( const QgsFieldDomain *domain );
237
245 QgsFieldDomain *createFieldDomain() const SIP_FACTORY;
246
252 bool isValid() const;
253
254 signals:
255
261 void validityChanged( bool isValid );
262
263 private:
264
265 QgsAbstractFieldDomainWidget *mDomainWidget = nullptr;
266};
267
268
269
276class GUI_EXPORT QgsFieldDomainDialog: public QDialog
277{
278 Q_OBJECT
279
280 public:
281
285 explicit QgsFieldDomainDialog( Qgis::FieldDomainType type, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
286
292 void setFieldDomain( const QgsFieldDomain *domain );
293
301 QgsFieldDomain *createFieldDomain() const SIP_FACTORY;
302
303 public slots:
304
305 void accept() override;
306
307 private slots:
308
309 void validityChanged( bool isValid );
310
311 private:
312 QgsFieldDomainWidget *mWidget = nullptr;
313 QDialogButtonBox *mButtonBox = nullptr;
314};
315
316
317#endif // QGSFIELDDOMAINWIDGET_H
FieldDomainType
Types of field domain.
Definition: qgis.h:1901
Abstract base class for widgets which configure the extended properties of a QgsFieldDomain subclass.
virtual QgsFieldDomain * createFieldDomain(const QString &name, const QString &description, QVariant::Type fieldType) const =0
Creates a new field domain using the properties from the widget.
void changed()
Emitted whenever the field domain configuration in the widget changes.
virtual bool isValid() const =0
Returns true if the widget currently represents a valid field domain configuration.
virtual void setFieldDomain(const QgsFieldDomain *domain)=0
Sets the current field domain to show properties for in the widget.
A widget for configuration of the extended properties of a QgsCodedFieldDomain.
A table model for representing the values in a QgsCodedValue list.
QList< QgsCodedValue > values() const
Returns the values from the model.
A dialog for configuration of the properties of a QgsFieldDomain.
A widget for configuration of the properties of a QgsFieldDomain.
void validityChanged(bool isValid)
Emitted whenever the validity of the field domain configuration in the widget changes.
Base class for field domains.
A widget for configuration of the extended properties of a QgsGlobFieldDomain.
A widget for configuration of the extended properties of a QgsRangeFieldDomain.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76