27#include "moc_qgspointcloudattributemodel.cpp"
29using namespace Qt::StringLiterals;
32 : QAbstractItemModel(
parent )
65 if ( allowEmpty == mAllowEmpty )
70 beginInsertRows( QModelIndex(), 0, 0 );
76 beginRemoveRows( QModelIndex(), 0, 0 );
84 if ( !name.isEmpty() )
86 const int idx = mAttributes.indexOf( name );
90 return index( 1 + idx, 0 );
92 return index( idx, 0 );
96 if ( mAllowEmpty && name.isEmpty() )
104 if ( hasIndex( row, column,
parent ) )
106 return createIndex( row, column, row );
109 return QModelIndex();
115 return QModelIndex();
125 return ( mAllowEmpty ? 1 : 0 ) + mAttributes.count();
136 if ( !
index.isValid() )
139 const bool isEmpty = mAllowEmpty &&
index.row() == 0;
140 const int fieldOffset = mAllowEmpty ? 1 : 0;
142 if ( !isEmpty && (
index.row() - fieldOffset >= mAttributes.count() ) )
153 return mAttributes.at(
index.row() - fieldOffset ).name();
162 return index.row() - fieldOffset;
171 return static_cast< int >( mAttributes.at(
index.row() - fieldOffset ).size() );
180 return static_cast< int >( mAttributes.at(
index.row() - fieldOffset ).type() );
197 case Qt::DisplayRole:
199 case Qt::ToolTipRole:
205 else if ( role == Qt::ToolTipRole )
210 return mAttributes.at(
index.row() - fieldOffset ).name();
213 case Qt::DecorationRole:
229 QString toolTip = u
"<b>%1</b>"_s.arg( attribute.
name() );
231 toolTip += u
"<br><font style='font-family:monospace; white-space: nowrap;'>%3</font>"_s.arg( attribute.
displayType() );
266 : QSortFilterProxyModel( parent )
269 setSourceModel( mModel );
281 const QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
283 if ( mFilters.testFlag(
AllTypes ) )
328 return leftId < rightId;
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A collection of point cloud attributes.
A model for display of available attributes from a point cloud.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the model.
QModelIndex parent(const QModelIndex &child) const override
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is present in the model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent) const override
@ IsNumeric
true if the index corresponds to a numeric attributre
@ AttributeIndex
Attribute index if index corresponds to an attribute.
@ AttributeType
Attribute type, see QgsPointCloudAttribute::DataType.
@ AttributeSize
Attribute size.
@ IsEmpty
true if the index corresponds to the empty value
@ AttributeName
Attribute name.
void setLayer(QgsPointCloudLayer *layer)
Sets the layer associated with the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
QgsPointCloudAttributeModel(QObject *parent=nullptr)
Constructor for QgsPointCloudAttributeModel, with the specified parent object.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes to include in the model.
static QString attributeToolTip(const QgsPointCloudAttribute &attribute)
Returns a HTML formatted tooltip string for a attribute, containing details like the attribute name a...
QModelIndex indexFromName(const QString &name)
Returns the index corresponding to a given attribute name.
QgsPointCloudLayer * layer()
Returns the layer associated with the model.
static QIcon iconForAttributeType(QgsPointCloudAttribute::DataType type)
Returns an icon corresponding to an attribute type.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Filters filters() const
Returns the filters controlling displayed attributes.
@ Double
Double attributes.
@ AllTypes
All attribute types.
@ Char
Character attributes.
QgsPointCloudAttributeProxyModel * setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Set flags that affect how fields are filtered in the model.
QgsPointCloudAttributeProxyModel(QgsPointCloudAttributeModel *source, QObject *parent=nullptr)
Constructor for QgsPointCloudAttributeProxyModel, with the specified source model and parent object.
Attribute for point cloud data pair of name and size in bytes.
DataType
Systems of unit measurement.
@ UShort
Unsigned short int 2 bytes.
@ Short
Short int 2 bytes.
@ UChar
Unsigned char 1 byte.
@ UInt32
Unsigned int32 4 bytes.
@ UInt64
Unsigned int64 8 bytes.
static bool isNumeric(DataType type)
Returns true if the specified data type is numeric.
QString displayType() const
Returns the type to use when displaying this field.
QString name() const
Returns name of the attribute.
Represents a map layer supporting display of point clouds.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.