QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
18#include "qgsfieldproxymodel.h"
19#include "qgsmaplayer.h"
20#include "qgspointcloudlayer.h"
21
22#include "moc_qgspointcloudattributecombobox.cpp"
23
25 : QComboBox( parent )
26{
27 mAttributeModel = new QgsPointCloudAttributeModel( this );
28 mProxyModel = new QgsPointCloudAttributeProxyModel( mAttributeModel, this );
29 setModel( mProxyModel );
30
31 connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsPointCloudAttributeComboBox::indexChanged );
32}
33
38
40{
41 mAttributeModel->setAllowEmptyAttributeName( allowEmpty );
42}
43
45{
46 return mAttributeModel->allowEmptyAttributeName();
47}
48
50{
51 if ( !layer )
52 {
53 setCurrentIndex( -1 );
54 mAttributeModel->setLayer( nullptr );
55 return;
56 }
57
58 QgsPointCloudLayer *pcl = qobject_cast<QgsPointCloudLayer *>( layer );
59 mAttributeModel->setLayer( pcl );
60}
61
63{
64 return mAttributeModel->layer();
65}
66
71
76
78{
79 const QString prevAttribute = currentAttribute();
80 const QModelIndex idx = mAttributeModel->indexFromName( name );
81 if ( idx.isValid() )
82 {
83 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
84 if ( proxyIdx.isValid() )
85 {
86 setCurrentIndex( proxyIdx.row() );
87 }
88 else
89 {
90 setCurrentIndex( -1 );
91 }
92 }
93 else
94 {
95 setCurrentIndex( -1 );
96 }
97
98 if ( prevAttribute != currentAttribute() )
100}
101
103{
104 const int i = currentIndex();
105
106 const QModelIndex proxyIndex = mProxyModel->index( i, 0 );
107 if ( !proxyIndex.isValid() )
108 {
109 return QString();
110 }
111
112 return mProxyModel->data( proxyIndex, static_cast<int>( QgsPointCloudAttributeModel::CustomRole::AttributeName ) ).toString();
113}
114
115void QgsPointCloudAttributeComboBox::indexChanged( int i )
116{
117 Q_UNUSED( i )
118 const QString name = currentAttribute();
119 emit attributeChanged( name );
120}
Base class for all map layer types.
Definition qgsmaplayer.h:80
A collection of point cloud attributes.
QVector< QgsPointCloudAttribute > attributes() const
Returns all 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.
A proxy model for filtering available attributes from a point cloud attribute model.
Represents a map layer supporting display of point clouds.