Skip to content
Permalink
Browse files

Add some more useful methods to QgsPointCloudAttribute

  • Loading branch information
nyalldawson committed Nov 9, 2020
1 parent ef0c472 commit d5ef807ecdae8f7ab0caa72bb452d464aac7e315
@@ -443,6 +443,8 @@
%Include auto_generated/mesh/qgsmeshtimesettings.sip
%Include auto_generated/mesh/qgsmeshtracerenderer.sip
%Include auto_generated/mesh/qgsmeshcalculator.sip
%Include auto_generated/pointcloud/qgspointcloudattribute.sip
%Include auto_generated/pointcloud/qgspointcloudattributemodel.sip
%Include auto_generated/pointcloud/qgspointcloudlayer.sip
%Include auto_generated/pointcloud/qgspointcloudrenderer.sip
%Include auto_generated/pointcloud/qgspointclouddataprovider.sip
@@ -27,6 +27,39 @@ QgsPointCloudAttribute::QgsPointCloudAttribute( const QString &name, DataType ty
updateSize();
}

QString QgsPointCloudAttribute::displayType() const
{
switch ( mType )
{
case DataType::Char:
return QObject::tr( "Character" );
case DataType::Short:
return QObject::tr( "Short" );
case DataType::Float:
return QObject::tr( "Float" );
case DataType::Int32:
return QObject::tr( "Integer" );
case DataType::Double:
return QObject::tr( "Double" );
}
return QString();
}

bool QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType type )
{
switch ( type )
{
case DataType::Char:
return false;
case DataType::Short:
case DataType::Float:
case DataType::Int32:
case DataType::Double:
return true;
}
return false;
}

void QgsPointCloudAttribute::updateSize()
{
switch ( mType )
@@ -60,6 +60,20 @@ class CORE_EXPORT QgsPointCloudAttribute
//! Returns the data type
DataType type() const { return mType; }

/**
* Returns the type to use when displaying this field.
*
* This will be used when the full datatype with details has to displayed to the user.
*
* \see type()
*/
QString displayType() const;

/**
* Returns TRUE if the specified data \a type is numeric.
*/
static bool isNumeric( DataType type );

private:
void updateSize();

@@ -88,6 +102,16 @@ class CORE_EXPORT QgsPointCloudAttributeCollection
//! Returns all attributes
QVector<QgsPointCloudAttribute> attributes() const;

/**
* Returns the number of attributes present in the collection.
*/
int count() const { return mAttributes.size(); }

/**
* Returns the attribute at the specified \a index.
*/
const QgsPointCloudAttribute &at( int index ) const { return mAttributes.at( index ); }

/**
* Finds the attribute with the name
*
@@ -39,6 +39,8 @@ class TestQgsPointCloudAttribute: public QObject
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void testAttribute();
void testAttributeDisplayType();
void testIsNumeric();
void testCollection();

private:
@@ -80,17 +82,38 @@ void TestQgsPointCloudAttribute::testAttribute()
QCOMPARE( attribute.size(), static_cast< std::size_t >( 4 ) );
}

void TestQgsPointCloudAttribute::testAttributeDisplayType()
{
QCOMPARE( QgsPointCloudAttribute( QStringLiteral( "x" ), QgsPointCloudAttribute::DataType::Char ).displayType(), QStringLiteral( "Character" ) );
QCOMPARE( QgsPointCloudAttribute( QStringLiteral( "x" ), QgsPointCloudAttribute::DataType::Short ).displayType(), QStringLiteral( "Short" ) );
QCOMPARE( QgsPointCloudAttribute( QStringLiteral( "x" ), QgsPointCloudAttribute::DataType::Int32 ).displayType(), QStringLiteral( "Integer" ) );
QCOMPARE( QgsPointCloudAttribute( QStringLiteral( "x" ), QgsPointCloudAttribute::DataType::Float ).displayType(), QStringLiteral( "Float" ) );
QCOMPARE( QgsPointCloudAttribute( QStringLiteral( "x" ), QgsPointCloudAttribute::DataType::Double ).displayType(), QStringLiteral( "Double" ) );
}

void TestQgsPointCloudAttribute::testIsNumeric()
{
QVERIFY( !QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType::Char ) );
QVERIFY( QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType::Short ) );
QVERIFY( QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType::Int32 ) );
QVERIFY( QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType::Float ) );
QVERIFY( QgsPointCloudAttribute::isNumeric( QgsPointCloudAttribute::DataType::Double ) );
}

void TestQgsPointCloudAttribute::testCollection()
{
// test collections
QgsPointCloudAttributeCollection collection;
QVERIFY( collection.attributes().empty() );
QCOMPARE( collection.count(), 0 );
QCOMPARE( collection.pointRecordSize(), static_cast< std::size_t >( 0 ) );
int offset = 0;
QVERIFY( !collection.find( QStringLiteral( "test" ), offset ) );

collection.push_back( QgsPointCloudAttribute( QStringLiteral( "at1" ), QgsPointCloudAttribute::DataType::Float ) );
QCOMPARE( collection.attributes().size(), 1 );
QCOMPARE( collection.count(), 1 );
QCOMPARE( collection.at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection.attributes().at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection.pointRecordSize(), static_cast< std::size_t >( 4 ) );
QVERIFY( !collection.find( QStringLiteral( "test" ), offset ) );
@@ -99,6 +122,9 @@ void TestQgsPointCloudAttribute::testCollection()

collection.push_back( QgsPointCloudAttribute( QStringLiteral( "at2" ), QgsPointCloudAttribute::DataType::Short ) );
QCOMPARE( collection.attributes().size(), 2 );
QCOMPARE( collection.count(), 2 );
QCOMPARE( collection.at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection.at( 1 ).name(), QStringLiteral( "at2" ) );
QCOMPARE( collection.attributes().at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection.attributes().at( 1 ).name(), QStringLiteral( "at2" ) );
QCOMPARE( collection.pointRecordSize(), static_cast< std::size_t >( 6 ) );
@@ -110,6 +136,7 @@ void TestQgsPointCloudAttribute::testCollection()

collection.push_back( QgsPointCloudAttribute( QStringLiteral( "at3" ), QgsPointCloudAttribute::DataType::Double ) );
QCOMPARE( collection.attributes().size(), 3 );
QCOMPARE( collection.count(), 3 );
QCOMPARE( collection.attributes().at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection.attributes().at( 1 ).name(), QStringLiteral( "at2" ) );
QCOMPARE( collection.attributes().at( 2 ).name(), QStringLiteral( "at3" ) );
@@ -128,6 +155,7 @@ void TestQgsPointCloudAttribute::testCollection()
<< QgsPointCloudAttribute( QStringLiteral( "at2" ), QgsPointCloudAttribute::DataType::Short )
<< QgsPointCloudAttribute( QStringLiteral( "at3" ), QgsPointCloudAttribute::DataType::Double ) );
QCOMPARE( collection2.attributes().size(), 3 );
QCOMPARE( collection2.count(), 3 );
QCOMPARE( collection2.attributes().at( 0 ).name(), QStringLiteral( "at1" ) );
QCOMPARE( collection2.attributes().at( 1 ).name(), QStringLiteral( "at2" ) );
QCOMPARE( collection2.attributes().at( 2 ).name(), QStringLiteral( "at3" ) );

0 comments on commit d5ef807

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