Skip to content
Permalink
Browse files

Add attribute index role to point cloud attribute model

  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent ead5ebc commit d8f6a2e15254ff2385579fbddddb18f3379cf6e6
@@ -28,6 +28,7 @@ A model for display of available attributes from a point cloud.
enum FieldRoles
{
AttributeNameRole,
AttributeIndexRole,
AttributeSizeRole,
AttributeTypeRole,
IsEmptyRole,
@@ -142,6 +142,15 @@ QVariant QgsPointCloudAttributeModel::data( const QModelIndex &index, int role )
return mAttributes.at( index.row() - fieldOffset ).name();
}

case AttributeIndexRole:
{
if ( isEmpty )
{
return QVariant();
}
return index.row() - fieldOffset;
}

case AttributeSizeRole:
{
if ( isEmpty )
@@ -42,6 +42,7 @@ class CORE_EXPORT QgsPointCloudAttributeModel : public QAbstractItemModel
enum FieldRoles
{
AttributeNameRole = Qt::UserRole + 1, //!< Attribute name
AttributeIndexRole, //!< Attribute index if index corresponds to an attribute
AttributeSizeRole, //!< Attribute size
AttributeTypeRole, //!< Attribute type, see QgsPointCloudAttribute::DataType
IsEmptyRole, //!< TRUE if the index corresponds to the empty value
@@ -102,6 +102,22 @@ def testAttributeNameRole(self):
self.assertEqual(m.data(m.index(2, 0), QgsPointCloudAttributeModel.AttributeNameRole), 'y')
self.assertEqual(m.data(m.index(5, 0), QgsPointCloudAttributeModel.AttributeNameRole), 'red')

def testAttributeIndexRole(self):
m = QgsPointCloudAttributeModel()
m.setAttributes(create_attributes())

self.assertEqual(m.data(m.index(0, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 0)
self.assertEqual(m.data(m.index(1, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 1)
self.assertEqual(m.data(m.index(2, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 2)
self.assertEqual(m.data(m.index(3, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 3)
self.assertEqual(m.data(m.index(4, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 4)
self.assertEqual(m.data(m.index(5, 0), QgsPointCloudAttributeModel.AttributeIndexRole), None)
m.setAllowEmptyAttributeName(True)
self.assertEqual(m.data(m.index(0, 0), QgsPointCloudAttributeModel.AttributeIndexRole), None)
self.assertEqual(m.data(m.index(1, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 0)
self.assertEqual(m.data(m.index(2, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 1)
self.assertEqual(m.data(m.index(5, 0), QgsPointCloudAttributeModel.AttributeIndexRole), 4)

def testSizeRole(self):
m = QgsPointCloudAttributeModel()
m.setAttributes(create_attributes())

0 comments on commit d8f6a2e

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