QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
37class CORE_EXPORT QgsFieldDomain
38{
39#ifdef SIP_RUN
41 if ( sipCpp->type() == Qgis::FieldDomainType::Coded )
42 {
43 sipType = sipType_QgsCodedFieldDomain;
44 }
45 else if ( sipCpp->type() == Qgis::FieldDomainType::Range )
46 {
47 sipType = sipType_QgsRangeFieldDomain;
48 }
49 else if ( sipCpp->type() == Qgis::FieldDomainType::Glob )
50 {
51 sipType = sipType_QgsGlobFieldDomain;
52 }
53 else
54 {
55 sipType = 0;
56 }
58#endif
59
60 public:
61
65 QgsFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType );
66
71 Q_DECL_DEPRECATED QgsFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType ) SIP_DEPRECATED;
72
73 virtual ~QgsFieldDomain();
74
78 virtual QgsFieldDomain *clone() const = 0 SIP_FACTORY;
79
83 virtual Qgis::FieldDomainType type() const = 0;
84
88 virtual QString typeName() const = 0;
89
95 QString name() const { return mName; }
96
102 void setName( const QString &name ) { mName = name; }
103
109 QString description() const { return mDescription; }
110
117
123 QMetaType::Type fieldType() const { return mFieldType; }
124
130 void setFieldType( QMetaType::Type type ) { mFieldType = type; }
131
138 Q_DECL_DEPRECATED void setFieldType( QVariant::Type type ) SIP_DEPRECATED;
139
146
153
160
167
168 protected:
169 QString mName;
171
172 QMetaType::Type mFieldType = QMetaType::Type::QString;
175};
176
183class CORE_EXPORT QgsCodedValue
184{
185 public:
192 QgsCodedValue( const QVariant &code, const QString &value )
193 : mCode( code )
194 , mValue( value )
195 {}
196
201 QVariant code() const { return mCode; }
202
207 QString value() const { return mValue; }
208
209#ifdef SIP_RUN
210 // clang-format off
211 SIP_PYOBJECT __repr__();
212 % MethodCode
213 QString str = u"<QgsCodedValue: %1 (%2)>"_s.arg( sipCpp->code().toString(), sipCpp->value() );
214 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
215 % End
216// clang-format on
217#endif
218
219 bool operator==( const QgsCodedValue &other ) const;
220 bool operator!=( const QgsCodedValue &other ) const;
221
222 private:
223 QVariant mCode;
224 QString mValue;
225};
226
227
238class CORE_EXPORT QgsCodedFieldDomain : public QgsFieldDomain
239{
240 public:
247 QgsCodedFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QList<QgsCodedValue> &values );
248
256 Q_DECL_DEPRECATED QgsCodedFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType, const QList<QgsCodedValue> &values ) SIP_DEPRECATED;
257
258#ifndef SIP_RUN
263#endif
264
265 Qgis::FieldDomainType type() const override;
266 QString typeName() const override;
267 QgsCodedFieldDomain *clone() const override SIP_FACTORY;
268
274 QList< QgsCodedValue> values() const { return mValues; }
275
281 void setValues( const QList< QgsCodedValue> &values ) { mValues = values; }
282
283#ifdef SIP_RUN
284 // clang-format off
285 SIP_PYOBJECT __repr__();
286 % MethodCode
287 QString str = u"<QgsCodedFieldDomain: %1>"_s.arg( sipCpp->name() );
288 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
289 % End
290// clang-format on
291#endif
292
293 // clang-format off
294 private:
295 // clang-format on
296 QList< QgsCodedValue>
297 mValues;
298
299#ifdef SIP_RUN
301#endif
302};
303
304
311class CORE_EXPORT QgsRangeFieldDomain : public QgsFieldDomain
312{
313 public:
319 QgsRangeFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive );
320
327 Q_DECL_DEPRECATED QgsRangeFieldDomain(
328 const QString &name, const QString &description, QVariant::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive
330
331
332#ifndef SIP_RUN
337#endif
338
339 Qgis::FieldDomainType type() const override;
340 QString typeName() const override;
341 QgsRangeFieldDomain *clone() const override SIP_FACTORY;
342
351 QVariant minimum() const { return mMin; }
352
361 void setMinimum( const QVariant &minimum ) { mMin = minimum; }
362
369 bool minimumIsInclusive() const { return mMinIsInclusive; }
370
377 void setMinimumIsInclusive( bool inclusive ) { mMinIsInclusive = inclusive; }
378
387 QVariant maximum() const { return mMax; }
388
397 void setMaximum( const QVariant &maximum ) { mMax = maximum; }
398
405 bool maximumIsInclusive() const { return mMaxIsInclusive; }
406
413 void setMaximumIsInclusive( bool inclusive ) { mMaxIsInclusive = inclusive; }
414
415#ifdef SIP_RUN
416 // clang-format off
417 SIP_PYOBJECT __repr__();
418 % MethodCode
419 QString str = u"<QgsRangeFieldDomain: %1 %2%3, %4%5>"_s.arg( sipCpp->name(),
420 sipCpp->minimumIsInclusive() ? u"["_s : u"("_s,
421 sipCpp->minimum().toString(),
422 sipCpp->maximum().toString(),
423 sipCpp->maximumIsInclusive() ? u"]"_s : u")"_s );
424 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
425 % End
426// clang-format on
427#endif
428
429 // clang-format off
430 private:
431 // clang-format on
432 QVariant mMin;
433 QVariant mMax;
434 bool mMinIsInclusive = false;
435 bool mMaxIsInclusive = false;
436
437#ifdef SIP_RUN
439#endif
440};
441
442
451class CORE_EXPORT QgsGlobFieldDomain : public QgsFieldDomain
452{
453 public:
459 QgsGlobFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QString &glob );
460
467 Q_DECL_DEPRECATED QgsGlobFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType, const QString &glob ) SIP_DEPRECATED;
468
469
470#ifndef SIP_RUN
475#endif
476
477 Qgis::FieldDomainType type() const override;
478 QString typeName() const override;
479 QgsGlobFieldDomain *clone() const override SIP_FACTORY;
480
488 QString glob() const { return mGlob; }
489
497 void setGlob( const QString &glob ) { mGlob = glob; }
498
499#ifdef SIP_RUN
500 // clang-format off
501 SIP_PYOBJECT __repr__();
502 % MethodCode
503 QString str = u"<QgsGlobFieldDomain: %1 '%2'>"_s.arg( sipCpp->name(), sipCpp->glob() );
504 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
505 % End
506// clang-format on
507#endif
508
509 // clang-format off
510 private:
511 // clang-format on
512 QString mGlob;
513
514#ifdef SIP_RUN
516#endif
517};
518
519#endif // QGSFIELDDOMAIN_H
FieldDomainMergePolicy
Merge policy for field domains.
Definition qgis.h:4040
@ DefaultValue
Use default field value.
Definition qgis.h:4041
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:4023
@ DefaultValue
Use default field value.
Definition qgis.h:4024
FieldDomainType
Types of field domain.
Definition qgis.h:4073
@ Coded
Coded field domain.
Definition qgis.h:4074
@ Range
Numeric range field domain (min/max).
Definition qgis.h:4075
@ Glob
Glob string pattern field domain.
Definition qgis.h:4076
Definition of a coded / enumerated field domain.
QgsCodedFieldDomain * clone() const override
Clones the field domain.
void setValues(const QList< QgsCodedValue > &values)
Sets the enumeration as QgsCodedValue values.
QList< QgsCodedValue > values() const
Returns the enumeration as QgsCodedValue values.
QgsCodedFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QList< QgsCodedValue > &values)
Constructor for QgsCodedFieldDomain, with the associated name, description and fieldType.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
QgsCodedFieldDomain(const QgsCodedFieldDomain &)=delete
QgsCodedFieldDomain cannot be copied - use clone() instead.
QgsCodedFieldDomain & operator=(const QgsCodedFieldDomain &)=delete
QgsCodedFieldDomain cannot be copied - use clone() instead.
QString typeName() const override
Returns a translated name of the field domain type.
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.
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the merge policy.
Qgis::FieldDomainSplitPolicy mSplitPolicy
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the split policy.
void setFieldType(QMetaType::Type type)
Sets the associated field type.
virtual ~QgsFieldDomain()
void setName(const QString &name)
Sets the name of the field domain.
QMetaType::Type fieldType() const
Returns the associated field type.
Qgis::FieldDomainMergePolicy mMergePolicy
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
QMetaType::Type mFieldType
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.
QgsFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType)
Constructor for QgsFieldDomain, with the specified name, description and fieldType.
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.
Definition of a field domain for field content validated by a glob.
QgsGlobFieldDomain(const QgsGlobFieldDomain &)=delete
QgsGlobFieldDomain cannot be copied - use clone() instead.
QgsGlobFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QString &glob)
Constructor for QgsGlobFieldDomain, with the specified name, description and fieldType.
QString typeName() const override
Returns a translated name of the field domain type.
QgsGlobFieldDomain & operator=(const QgsGlobFieldDomain &)=delete
QgsGlobFieldDomain cannot be copied - use clone() instead.
QString glob() const
Returns the glob expression.
QgsGlobFieldDomain * clone() const override
Clones the field domain.
void setGlob(const QString &glob)
Sets the glob expression.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
Definition of a numeric field domain with a range of validity for values.
void setMaximumIsInclusive(bool inclusive)
Sets whether the maximum value is inclusive.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
QVariant minimum() const
Returns the minimum value.
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.
QgsRangeFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive)
Constructor for QgsRangeFieldDomain, with the specified name, description and fieldType.
void setMinimum(const QVariant &minimum)
Sets the minimum allowed value.
QgsRangeFieldDomain * clone() const override
Clones the field domain.
bool minimumIsInclusive() const
Returns true if the minimum value is inclusive.
void setMinimumIsInclusive(bool inclusive)
Sets whether the minimum value is inclusive.
QgsRangeFieldDomain & operator=(const QgsRangeFieldDomain &)=delete
QgsRangeFieldDomain cannot be copied - use clone() instead.
QVariant maximum() const
Returns the maximum value.
QString typeName() const override
Returns a translated name of the field domain type.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)