mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add isNumeric and QML bindings to QgsField
This commit is contained in:
parent
34e2bea246
commit
af0947826b
@ -73,6 +73,14 @@ class QgsField
|
||||
*/
|
||||
QString comment() const;
|
||||
|
||||
/**
|
||||
* Returns if this field is numeric. Any integer or floating point type
|
||||
* will return true for this.
|
||||
*
|
||||
* @note added in QGIS 2.18
|
||||
*/
|
||||
bool isNumeric() const;
|
||||
|
||||
/**
|
||||
* Set the field name.
|
||||
* @param name Name of the field
|
||||
|
@ -455,6 +455,7 @@ SET(QGIS_CORE_MOC_HDRS
|
||||
qgsdbfilterproxymodel.h
|
||||
qgseditformconfig.h
|
||||
qgsfeedback.h
|
||||
qgsfield.h
|
||||
qgsgeometryvalidator.h
|
||||
qgsgml.h
|
||||
qgsgmlschema.h
|
||||
@ -644,7 +645,6 @@ SET(QGIS_CORE_HDRS
|
||||
qgsfeatureiterator.h
|
||||
qgsfeaturerequest.h
|
||||
qgsfeaturestore.h
|
||||
qgsfield.h
|
||||
qgsfield_p.h
|
||||
qgsfontutils.h
|
||||
qgsgeometrycache.h
|
||||
|
@ -111,6 +111,11 @@ QString QgsField::comment() const
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
bool QgsField::isNumeric() const
|
||||
{
|
||||
return d->type == QVariant::Double || d->type == QVariant::Int || d->type == QVariant::UInt || d->type == QVariant::LongLong || d->type == QVariant::ULongLong;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* This class is considered CRITICAL and any change MUST be accompanied with
|
||||
* full unit tests in testqgsfield.cpp.
|
||||
|
@ -43,6 +43,14 @@ class QgsFieldsPrivate;
|
||||
|
||||
class CORE_EXPORT QgsField
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
Q_PROPERTY( bool isNumeric READ isNumeric )
|
||||
Q_PROPERTY( int length READ length )
|
||||
Q_PROPERTY( int precision READ precision )
|
||||
Q_PROPERTY( QString comment READ comment )
|
||||
Q_PROPERTY( QString name READ name )
|
||||
|
||||
public:
|
||||
/** Constructor. Constructs a new QgsField object.
|
||||
* @param name Field name
|
||||
@ -107,6 +115,14 @@ class CORE_EXPORT QgsField
|
||||
*/
|
||||
QString comment() const;
|
||||
|
||||
/**
|
||||
* Returns if this field is numeric. Any integer or floating point type
|
||||
* will return true for this.
|
||||
*
|
||||
* @note added in QGIS 2.18
|
||||
*/
|
||||
bool isNumeric() const;
|
||||
|
||||
/**
|
||||
* Set the field name.
|
||||
* @param name Name of the field
|
||||
|
@ -34,6 +34,7 @@ class TestQgsField: public QObject
|
||||
void copy();// test cpy destruction (double delete)
|
||||
void assignment();
|
||||
void gettersSetters(); //test getters and setters
|
||||
void isNumeric(); //test isNumeric
|
||||
void equality(); //test equality operators
|
||||
void asVariant(); //test conversion to and from a QVariant
|
||||
void displayString();
|
||||
@ -117,6 +118,29 @@ void TestQgsField::gettersSetters()
|
||||
QCOMPARE( field.comment(), QString( "comment" ) );
|
||||
}
|
||||
|
||||
void TestQgsField::isNumeric()
|
||||
{
|
||||
QgsField field;
|
||||
field.setType( QVariant::Int );
|
||||
QVERIFY( field.isNumeric() );
|
||||
field.setType( QVariant::UInt );
|
||||
QVERIFY( field.isNumeric() );
|
||||
field.setType( QVariant::Double );
|
||||
QVERIFY( field.isNumeric() );
|
||||
field.setType( QVariant::LongLong );
|
||||
QVERIFY( field.isNumeric() );
|
||||
field.setType( QVariant::ULongLong );
|
||||
QVERIFY( field.isNumeric() );
|
||||
field.setType( QVariant::String );
|
||||
QVERIFY( !field.isNumeric() );
|
||||
field.setType( QVariant::DateTime );
|
||||
QVERIFY( !field.isNumeric() );
|
||||
field.setType( QVariant::Bool );
|
||||
QVERIFY( !field.isNumeric() );
|
||||
field.setType( QVariant::Invalid );
|
||||
QVERIFY( !field.isNumeric() );
|
||||
}
|
||||
|
||||
void TestQgsField::equality()
|
||||
{
|
||||
QgsField field1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user