QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgsfielddomain.cpp
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#include "qgsfielddomain.h"
17#include "qgsvariantutils.h"
18#include <memory>
19
20//
21// QgsFieldDomain
22//
23
24QgsFieldDomain::QgsFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType )
25 : mName( name )
26 , mDescription( description )
27 , mFieldType( fieldType )
28{
29
30}
31
32QgsFieldDomain::QgsFieldDomain( const QString &name,
33 const QString &description,
34 QVariant::Type fieldType )
35 : QgsFieldDomain( name, description, QgsVariantUtils::variantTypeToMetaType( fieldType ) )
36{
37}
38
40
45
46//
47// QgsCodedValue
48//
49bool QgsCodedValue::operator==( const QgsCodedValue &other ) const
50{
51 return other.mCode == mCode && other.mValue == mValue;
52}
53
54bool QgsCodedValue::operator!=( const QgsCodedValue &other ) const
55{
56 return !( *this == other );
57}
58
59//
60// QgsCodedFieldDomain
61//
62
63QgsCodedFieldDomain::QgsCodedFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QList<QgsCodedValue> &values )
64 : QgsFieldDomain( name, description, fieldType )
65 , mValues( values )
66{
67
68}
69
70QgsCodedFieldDomain::QgsCodedFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType, const QList<QgsCodedValue> &values )
71 : QgsCodedFieldDomain( name, description, QgsVariantUtils::variantTypeToMetaType( fieldType ), values )
72{
73
74}
75
80
82{
83 return QObject::tr( "Coded Values" );
84}
85
87{
88 std::unique_ptr< QgsCodedFieldDomain > res = std::make_unique< QgsCodedFieldDomain >( mName, mDescription, mFieldType, mValues );
89 res->mSplitPolicy = mSplitPolicy;
90 res->mMergePolicy = mMergePolicy;
91 return res.release();
92}
93
94//
95// QgsRangeFieldDomain
96//
97
98QgsRangeFieldDomain::QgsRangeFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive )
99 : QgsFieldDomain( name, description, fieldType )
100 , mMin( minimum )
101 , mMax( maximum )
102 , mMinIsInclusive( minimumIsInclusive )
103 , mMaxIsInclusive( maximumIsInclusive )
104{
105
106}
107
108QgsRangeFieldDomain::QgsRangeFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive )
109 : QgsRangeFieldDomain( name, description, QgsVariantUtils::variantTypeToMetaType( fieldType ), minimum, minimumIsInclusive, maximum, maximumIsInclusive )
110{
111}
112
117
119{
120 return QObject::tr( "Range" );
121}
122
124{
125 std::unique_ptr< QgsRangeFieldDomain > res = std::make_unique< QgsRangeFieldDomain >( mName, mDescription, mFieldType, mMin, mMinIsInclusive, mMax, mMaxIsInclusive );
126 res->mSplitPolicy = mSplitPolicy;
127 res->mMergePolicy = mMergePolicy;
128 return res.release();
129}
130
131
132//
133// QgsGlobFieldDomain
134//
135
136QgsGlobFieldDomain::QgsGlobFieldDomain( const QString &name, const QString &description, QMetaType::Type fieldType, const QString &glob )
137 : QgsFieldDomain( name, description, fieldType )
138 , mGlob( glob )
139{
140
141}
142
143QgsGlobFieldDomain::QgsGlobFieldDomain( const QString &name, const QString &description, QVariant::Type fieldType, const QString &glob )
144 : QgsGlobFieldDomain( name, description, QgsVariantUtils::variantTypeToMetaType( fieldType ), glob )
145{
146}
147
152
154{
155 return QObject::tr( "Glob" );
156}
157
159{
160 std::unique_ptr< QgsGlobFieldDomain > res = std::make_unique< QgsGlobFieldDomain >( mName, mDescription, mFieldType, mGlob );
161 res->mSplitPolicy = mSplitPolicy;
162 res->mMergePolicy = mMergePolicy;
163 return res.release();
164}
FieldDomainType
Types of field domain.
Definition qgis.h:3665
@ Coded
Coded field domain.
@ Range
Numeric range field domain (min/max)
@ Glob
Glob string pattern field domain.
Definition of a coded / enumerated field domain.
QgsCodedFieldDomain * clone() const override
Clones the field domain.
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.
QString typeName() const override
Returns a translated name of the field domain type.
Associates a code and a value.
bool operator==(const QgsCodedValue &other) const
bool operator!=(const QgsCodedValue &other) const
Base class for field domains.
Qgis::FieldDomainSplitPolicy mSplitPolicy
void setFieldType(QMetaType::Type type)
Sets the associated field type.
virtual ~QgsFieldDomain()
Qgis::FieldDomainMergePolicy mMergePolicy
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
QMetaType::Type mFieldType
QgsFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType)
Constructor for QgsFieldDomain, with the specified name, description and fieldType.
Definition of a field domain for field content validated by a glob.
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 * clone() const override
Clones the field domain.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
Definition of a numeric field domain with a range of validity for values.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
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.
QgsRangeFieldDomain * clone() const override
Clones the field domain.
QString typeName() const override
Returns a translated name of the field domain type.
Contains utility functions for working with QVariants and QVariant types.
static QMetaType::Type variantTypeToMetaType(QVariant::Type variantType)
Converts a QVariant::Type to a QMetaType::Type.