Skip to content
Permalink
Browse files

add configuration flags to QgsFields (#38634)

  • Loading branch information
3nids committed Sep 10, 2020
1 parent fa18514 commit 5dcca0ec2b3533e1d33b5fa9671730f9328e4366
Showing with 52 additions and 3 deletions.
  1. +3 −0 python/core/auto_generated/qgsfield.sip.in
  2. +11 −2 src/core/qgsfield.cpp
  3. +31 −0 src/core/qgsfield.h
  4. +7 −1 src/core/qgsfield_p.h
@@ -33,6 +33,7 @@ length, and if applicable, precision.

public:


QgsField( const QString &name = QString(),
QVariant::Type type = QVariant::Invalid,
const QString &typeName = QString(),
@@ -283,6 +284,8 @@ Sets the alias for the field (the friendly displayed name of the field ).
.. versionadded:: 3.0
%End



QString displayString( const QVariant &v ) const;
%Docstring
Formats string for display
@@ -45,8 +45,7 @@ QgsField::QgsField( QString nam, QString typ, int len, int prec, bool num,
}
#endif
QgsField::QgsField( const QString &name, QVariant::Type type,
const QString &typeName, int len, int prec, const QString &comment,
QVariant::Type subType )
const QString &typeName, int len, int prec, const QString &comment, QVariant::Type subType )
{
d = new QgsFieldPrivate( name, type, subType, typeName, len, prec, comment );
}
@@ -236,6 +235,16 @@ void QgsField::setAlias( const QString &alias )
d->alias = alias;
}

QgsField::ConfigurationFlags QgsField::configurationFlags() const
{
return d->flags;
}

void QgsField::setConfigurationFlags( QgsField::ConfigurationFlags flags )
{
d->flags = flags;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests in testqgsfield.cpp.
@@ -60,9 +60,28 @@ class CORE_EXPORT QgsField
Q_PROPERTY( QString alias READ alias WRITE setAlias )
Q_PROPERTY( QgsDefaultValue defaultValueDefinition READ defaultValueDefinition WRITE setDefaultValueDefinition )
Q_PROPERTY( QgsFieldConstraints constraints READ constraints WRITE setConstraints )
Q_PROPERTY( ConfigurationFlags configurationFlags READ configurationFlags WRITE setConfigurationFlags )


public:

#ifndef SIP_RUN

/**
* Configuration flags for fields
* These flags are meant to be user-configurable
* and are not describing any information from the data provider.
* \since QGIS 3.16
*/
enum class ConfigurationFlag : int
{
Searchable = 0x1, //!< Defines if the field is searchable (used in the locator search for instance)
DefaultFlags = Searchable, //!< Default set of flags for a field
};
Q_ENUM( ConfigurationFlag )
Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
#endif

/**
* Constructor. Constructs a new QgsField object.
* \param name Field name
@@ -282,6 +301,18 @@ class CORE_EXPORT QgsField
*/
void setAlias( const QString &alias );

/**
* Returns the Flags for the field (searchable, …)
* \since QGIS 3.16
*/
QgsField::ConfigurationFlags configurationFlags() const SIP_SKIP;

/**
* Sets the Flags for the field (searchable, …)
* \since QGIS 3.16
*/
void setConfigurationFlags( QgsField::ConfigurationFlags configurationFlags ) SIP_SKIP;

//! Formats string for display
QString displayString( const QVariant &v ) const;

@@ -32,6 +32,8 @@
#include "qgsfieldconstraints.h"
#include "qgseditorwidgetsetup.h"
#include "qgsdefaultvalue.h"
#include "qgsfield.h"

#include <QString>
#include <QVariant>
#include <QSharedData>
@@ -73,6 +75,7 @@ class QgsFieldPrivate : public QSharedData
, precision( other.precision )
, comment( other.comment )
, alias( other.alias )
, flags( other.flags )
, defaultValueDefinition( other.defaultValueDefinition )
, constraints( other.constraints )
{
@@ -85,7 +88,7 @@ class QgsFieldPrivate : public QSharedData
return ( ( name == other.name ) && ( type == other.type ) && ( subType == other.subType )
&& ( length == other.length ) && ( precision == other.precision )
&& ( alias == other.alias ) && ( defaultValueDefinition == other.defaultValueDefinition )
&& ( constraints == other.constraints ) );
&& ( constraints == other.constraints ) && ( flags == other.flags ) );
}

//! Name
@@ -112,6 +115,9 @@ class QgsFieldPrivate : public QSharedData
//! Alias for field name (friendly name shown to users)
QString alias;

//! Flags for the field (searchable, …)
QgsField::ConfigurationFlags flags = QgsField::ConfigurationFlag::DefaultFlags;

//! Default value
QgsDefaultValue defaultValueDefinition;

0 comments on commit 5dcca0e

Please sign in to comment.
You can’t perform that action at this time.