QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgspointcloudattributecombobox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudattributecombobox.cpp
3 --------------------------------------
4 begin : November 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
17#include "qgsfieldproxymodel.h"
18#include "qgsmaplayer.h"
19#include "qgspointcloudlayer.h"
20
22 : QComboBox( parent )
23{
24 mAttributeModel = new QgsPointCloudAttributeModel( this );
25 mProxyModel = new QgsPointCloudAttributeProxyModel( mAttributeModel, this );
26 setModel( mProxyModel );
27
28 connect( this, static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::activated ), this, &QgsPointCloudAttributeComboBox::indexChanged );
29}
30
32{
33 mProxyModel->setFilters( filters );
34}
35
37{
38 mAttributeModel->setAllowEmptyAttributeName( allowEmpty );
39}
40
42{
43 return mAttributeModel->allowEmptyAttributeName();
44}
45
47{
48 if ( !layer )
49 {
50 setCurrentIndex( -1 );
51 mAttributeModel->setLayer( nullptr );
52 return;
53 }
54
55 QgsPointCloudLayer *pcl = qobject_cast<QgsPointCloudLayer *>( layer );
56 mAttributeModel->setLayer( pcl );
57}
58
60{
61 return mAttributeModel->layer();
62}
63
65{
66 mAttributeModel->setAttributes( attributes );
67}
68
70{
71 return mAttributeModel->attributes();
72}
73
75{
76 const QString prevAttribute = currentAttribute();
77 const QModelIndex idx = mAttributeModel->indexFromName( name );
78 if ( idx.isValid() )
79 {
80 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
81 if ( proxyIdx.isValid() )
82 {
83 setCurrentIndex( proxyIdx.row() );
84 }
85 else
86 {
87 setCurrentIndex( -1 );
88 }
89 }
90 else
91 {
92 setCurrentIndex( -1 );
93 }
94
95 if ( prevAttribute != currentAttribute() )
97}
98
100{
101 const int i = currentIndex();
102
103 const QModelIndex proxyIndex = mProxyModel->index( i, 0 );
104 if ( !proxyIndex.isValid() )
105 {
106 return QString();
107 }
108
109 return mProxyModel->data( proxyIndex, static_cast< int >( QgsPointCloudAttributeModel::CustomRole::AttributeName ) ).toString();
110}
111
112void QgsPointCloudAttributeComboBox::indexChanged( int i )
113{
114 Q_UNUSED( i )
115 const QString name = currentAttribute();
116 emit attributeChanged( name );
117}
Base class for all map layer types.
Definition: qgsmaplayer.h:75
Collection of point cloud attributes.
void setLayer(QgsMapLayer *layer)
Sets the layer for which fields are listed in the combobox.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Manually sets the attributes to use for the combo box.
QgsPointCloudAttributeProxyModel::Filters filters
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is shown in the combo box.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes currently shown in the combobox.
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
QgsPointCloudAttributeComboBox(QWidget *parent=nullptr)
QgsPointCloudAttributeComboBox creates a combo box to display the fields of a layer.
QgsPointCloudLayer * layer() const
Returns the layer currently associated with the combobox.
QString currentAttribute() const
Returns the currently selected attribute.
void setAttribute(const QString &name)
Sets the currently selected attribute by name.
void setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Sets filters to allow filtering available attributes according to the attribute properties.
A model for display of available attributes from a point cloud.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the model.
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is present in the model.
void setLayer(QgsPointCloudLayer *layer)
Sets the layer associated with the model.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes to include in the model.
QModelIndex indexFromName(const QString &name)
Returns the index corresponding to a given attribute name.
QgsPointCloudLayer * layer()
Returns the layer associated with the model.
bool allowEmptyAttributeName() const
Returns true if the model allows the empty attribute ("not set") choice.
A proxy model for filtering available attributes from a point cloud attribute model.
QgsPointCloudAttributeProxyModel * setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Set flags that affect how fields are filtered in the model.
Represents a map layer supporting display of point clouds.