Skip to content

Commit

Permalink
add configuration flags to QgsFields (#38634)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 10, 2020
1 parent fa18514 commit 5dcca0e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsfield.sip.in
Expand Up @@ -33,6 +33,7 @@ length, and if applicable, precision.

public:


QgsField( const QString &name = QString(),
QVariant::Type type = QVariant::Invalid,
const QString &typeName = QString(),
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/core/qgsfield.cpp
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions src/core/qgsfield.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsfield_p.h
Expand Up @@ -32,6 +32,8 @@
#include "qgsfieldconstraints.h"
#include "qgseditorwidgetsetup.h"
#include "qgsdefaultvalue.h"
#include "qgsfield.h"

#include <QString>
#include <QVariant>
#include <QSharedData>
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit 5dcca0e

Please sign in to comment.