QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsfielddomain.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfielddomain.h
3 ------------------
4 Date : January 2022
5 Copyright : (C) 2022 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
16#ifndef QGSFIELDDOMAIN_H
17#define QGSFIELDDOMAIN_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgis.h"
22
33class CORE_EXPORT QgsFieldDomain
34{
35
36#ifdef SIP_RUN
38 if ( sipCpp->type() == Qgis::FieldDomainType::Coded )
39 {
40 sipType = sipType_QgsCodedFieldDomain;
41 }
42 else if ( sipCpp->type() == Qgis::FieldDomainType::Range )
43 {
44 sipType = sipType_QgsRangeFieldDomain;
45 }
46 else if ( sipCpp->type() == Qgis::FieldDomainType::Glob )
47 {
48 sipType = sipType_QgsGlobFieldDomain;
49 }
50 else
51 {
52 sipType = 0;
53 }
55#endif
56
57 public:
58
62 QgsFieldDomain( const QString &name,
63 const QString &description,
64 QVariant::Type fieldType );
65
66 virtual ~QgsFieldDomain();
67
71 virtual QgsFieldDomain *clone() const = 0 SIP_FACTORY;
72
76 virtual Qgis::FieldDomainType type() const = 0;
77
81 virtual QString typeName() const = 0;
82
88 QString name() const { return mName; }
89
95 void setName( const QString &name ) { mName = name; }
96
102 QString description() const { return mDescription; }
103
109 void setDescription( const QString &description ) { mDescription = description; }
110
116 QVariant::Type fieldType() const { return mFieldType; }
117
123 void setFieldType( QVariant::Type type ) { mFieldType = type; }
124
130 Qgis::FieldDomainSplitPolicy splitPolicy() const { return mSplitPolicy; }
131
137 void setSplitPolicy( Qgis::FieldDomainSplitPolicy policy ) { mSplitPolicy = policy; }
138
144 Qgis::FieldDomainMergePolicy mergePolicy() const { return mMergePolicy; }
145
151 void setMergePolicy( Qgis::FieldDomainMergePolicy policy ) { mMergePolicy = policy; }
152
153 protected:
154
155 QString mName;
157
158 QVariant::Type mFieldType = QVariant::Type::String;
161
162};
163
170class CORE_EXPORT QgsCodedValue
171{
172 public:
173
180 QgsCodedValue( const QVariant &code, const QString &value )
181 : mCode( code )
182 , mValue( value )
183 {}
184
189 QVariant code() const { return mCode; }
190
195 QString value() const { return mValue; }
196
197#ifdef SIP_RUN
198 SIP_PYOBJECT __repr__();
199 % MethodCode
200 QString str = QStringLiteral( "<QgsCodedValue: %1 (%2)>" ).arg( sipCpp->code().toString(), sipCpp->value() );
201 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
202 % End
203#endif
204
205 bool operator==( const QgsCodedValue &other ) const;
206 bool operator!=( const QgsCodedValue &other ) const;
207
208 private:
209
210 QVariant mCode;
211 QString mValue;
212};
213
214
225class CORE_EXPORT QgsCodedFieldDomain : public QgsFieldDomain
226{
227
228 public:
229
236 QgsCodedFieldDomain( const QString &name,
237 const QString &description,
238 QVariant::Type fieldType,
239 const QList<QgsCodedValue> &values );
240
241#ifndef SIP_RUN
245 QgsCodedFieldDomain &operator= ( const QgsCodedFieldDomain & ) = delete;
246#endif
247
248 Qgis::FieldDomainType type() const override;
249 QString typeName() const override;
250 QgsCodedFieldDomain *clone() const override SIP_FACTORY;
251
257 QList< QgsCodedValue> values() const { return mValues; }
258
264 void setValues( const QList< QgsCodedValue> &values ) { mValues = values; }
265
266#ifdef SIP_RUN
267 SIP_PYOBJECT __repr__();
268 % MethodCode
269 QString str = QStringLiteral( "<QgsCodedFieldDomain: %1>" ).arg( sipCpp->name() );
270 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
271 % End
272#endif
273
274 private:
275 QList< QgsCodedValue> mValues;
276
277#ifdef SIP_RUN
279#endif
280};
281
282
289class CORE_EXPORT QgsRangeFieldDomain : public QgsFieldDomain
290{
291
292 public:
293
299 QgsRangeFieldDomain( const QString &name,
300 const QString &description,
301 QVariant::Type fieldType,
302 const QVariant &minimum,
303 bool minimumIsInclusive,
304 const QVariant &maximum,
305 bool maximumIsInclusive );
306
307#ifndef SIP_RUN
311 QgsRangeFieldDomain &operator= ( const QgsRangeFieldDomain & ) = delete;
312#endif
313
314 Qgis::FieldDomainType type() const override;
315 QString typeName() const override;
316 QgsRangeFieldDomain *clone() const override SIP_FACTORY;
317
326 QVariant minimum() const { return mMin; }
327
336 void setMinimum( const QVariant &minimum ) { mMin = minimum; }
337
344 bool minimumIsInclusive() const { return mMinIsInclusive; }
345
352 void setMinimumIsInclusive( bool inclusive ) { mMinIsInclusive = inclusive; }
353
362 QVariant maximum() const { return mMax; }
363
372 void setMaximum( const QVariant &maximum ) { mMax = maximum; }
373
380 bool maximumIsInclusive() const { return mMaxIsInclusive; }
381
388 void setMaximumIsInclusive( bool inclusive ) { mMaxIsInclusive = inclusive; }
389
390#ifdef SIP_RUN
391 SIP_PYOBJECT __repr__();
392 % MethodCode
393 QString str = QStringLiteral( "<QgsRangeFieldDomain: %1 %2%3, %4%5>" ).arg( sipCpp->name(),
394 sipCpp->minimumIsInclusive() ? QStringLiteral( "[" ) : QStringLiteral( "(" ),
395 sipCpp->minimum().toString(),
396 sipCpp->maximum().toString(),
397 sipCpp->maximumIsInclusive() ? QStringLiteral( "]" ) : QStringLiteral( ")" ) );
398 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
399 % End
400#endif
401
402 private:
403 QVariant mMin;
404 QVariant mMax;
405 bool mMinIsInclusive = false;
406 bool mMaxIsInclusive = false;
407
408#ifdef SIP_RUN
410#endif
411};
412
413
422class CORE_EXPORT QgsGlobFieldDomain : public QgsFieldDomain
423{
424
425 public:
426
432 QgsGlobFieldDomain( const QString &name,
433 const QString &description,
434 QVariant::Type fieldType,
435 const QString &glob );
436
437#ifndef SIP_RUN
441 QgsGlobFieldDomain &operator= ( const QgsGlobFieldDomain & ) = delete;
442#endif
443
444 Qgis::FieldDomainType type() const override;
445 QString typeName() const override;
446 QgsGlobFieldDomain *clone() const override SIP_FACTORY;
447
455 QString glob() const { return mGlob; }
456
464 void setGlob( const QString &glob ) { mGlob = glob; }
465
466#ifdef SIP_RUN
467 SIP_PYOBJECT __repr__();
468 % MethodCode
469 QString str = QStringLiteral( "<QgsGlobFieldDomain: %1 '%2'>" ).arg( sipCpp->name(), sipCpp->glob() );
470 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
471 % End
472#endif
473
474 private:
475 QString mGlob;
476
477#ifdef SIP_RUN
479#endif
480
481};
482
483#endif // QGSFIELDDOMAIN_H
FieldDomainMergePolicy
Merge policy for field domains.
Definition: qgis.h:3199
@ DefaultValue
Use default field value.
FieldDomainSplitPolicy
Split policy for field domains.
Definition: qgis.h:3182
@ DefaultValue
Use default field value.
FieldDomainType
Types of field domain.
Definition: qgis.h:3212
@ Coded
Coded field domain.
@ Range
Numeric range field domain (min/max)
@ Glob
Glob string pattern field domain.
Definition of a coded / enumerated field domain.
void setValues(const QList< QgsCodedValue > &values)
Sets the enumeration as QgsCodedValue values.
QgsCodedFieldDomain(const QgsCodedFieldDomain &)=delete
QgsCodedFieldDomain cannot be copied - use clone() instead.
Associates a code and a value.
QVariant code() const
Returns the associated code, which is the underlying value stored in fields.
QgsCodedValue(const QVariant &code, const QString &value)
Constructor for QgsCodedValue, with the associated code and value.
QString value() const
Returns the associated value, which is the user-friendly string representation.
Base class for field domains.
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the merge policy.
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the split policy.
QString mDescription
virtual ~QgsFieldDomain()
void setName(const QString &name)
Sets the name of the field domain.
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
QString name() const
Returns the name of the field domain.
void setDescription(const QString &description)
Sets the description of the field domain.
void setSplitPolicy(Qgis::FieldDomainSplitPolicy policy)
Sets the split policy.
QVariant::Type fieldType() const
Returns the associated field type.
QString description() const
Returns the description of the field domain.
void setMergePolicy(Qgis::FieldDomainMergePolicy policy)
Sets the merge policy.
virtual QgsFieldDomain * clone() const =0
Clones the field domain.
virtual QString typeName() const =0
Returns a translated name of the field domain type.
void setFieldType(QVariant::Type type)
Sets the associated field type.
Definition of a field domain for field content validated by a glob.
QgsGlobFieldDomain(const QgsGlobFieldDomain &)=delete
QgsGlobFieldDomain cannot be copied - use clone() instead.
void setGlob(const QString &glob)
Sets the glob expression.
Definition of a numeric field domain with a range of validity for values.
void setMaximumIsInclusive(bool inclusive)
Sets whether the maximum value is inclusive.
QgsRangeFieldDomain(const QgsRangeFieldDomain &)=delete
QgsRangeFieldDomain cannot be copied - use clone() instead.
void setMaximum(const QVariant &maximum)
Sets the maximum allowed value.
bool maximumIsInclusive() const
Returns true if the maximum value is inclusive.
void setMinimum(const QVariant &minimum)
Sets the minimum allowed value.
bool minimumIsInclusive() const
Returns true if the minimum value is inclusive.
void setMinimumIsInclusive(bool inclusive)
Sets whether the minimum value is inclusive.
QVariant maximum() const
Returns the maximum value.
#define str(x)
Definition: qgis.cpp:38
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:191
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:208
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
const QString & typeName