QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
31 void QgsPointCloudAttributeComboBox::setFilters( QgsPointCloudAttributeProxyModel::Filters filters )
32 {
33  mProxyModel->setFilters( filters );
34 }
35 
37 {
38  mAttributeModel->setAllowEmptyAttributeName( allowEmpty );
39 }
40 
42 {
43  return mAttributeModel->allowEmptyAttributeName();
44 }
45 
47 {
48  QgsPointCloudLayer *pcl = qobject_cast<QgsPointCloudLayer *>( layer );
49  mAttributeModel->setLayer( pcl );
50 }
51 
53 {
54  return mAttributeModel->layer();
55 }
56 
58 {
59  mAttributeModel->setAttributes( attributes );
60 }
61 
63 {
64  return mAttributeModel->attributes();
65 }
66 
68 {
69  const QString prevAttribute = currentAttribute();
70  const QModelIndex idx = mAttributeModel->indexFromName( name );
71  if ( idx.isValid() )
72  {
73  const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
74  if ( proxyIdx.isValid() )
75  {
76  setCurrentIndex( proxyIdx.row() );
77  }
78  else
79  {
80  setCurrentIndex( -1 );
81  }
82  }
83  else
84  {
85  setCurrentIndex( -1 );
86  }
87 
88  if ( prevAttribute != currentAttribute() )
90 }
91 
93 {
94  const int i = currentIndex();
95 
96  const QModelIndex proxyIndex = mProxyModel->index( i, 0 );
97  if ( !proxyIndex.isValid() )
98  {
99  return QString();
100  }
101 
102  return mProxyModel->data( proxyIndex, QgsPointCloudAttributeModel::AttributeNameRole ).toString();
103 }
104 
105 void QgsPointCloudAttributeComboBox::indexChanged( int i )
106 {
107  Q_UNUSED( i )
108  const QString name = currentAttribute();
109  emit attributeChanged( name );
110 }
qgsfieldproxymodel.h
QgsPointCloudAttributeModel::AttributeNameRole
@ AttributeNameRole
Attribute name.
Definition: qgspointcloudattributemodel.h:45
QgsPointCloudLayer
Represents a map layer supporting display of point clouds.
Definition: qgspointcloudlayer.h:45
QgsPointCloudAttributeModel::setAttributes
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes to include in the model.
Definition: qgspointcloudattributemodel.cpp:45
QgsPointCloudAttributeProxyModel::setFilters
QgsPointCloudAttributeProxyModel * setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Set flags that affect how fields are filtered in the model.
Definition: qgspointcloudattributemodel.cpp:264
QgsPointCloudAttributeComboBox::QgsPointCloudAttributeComboBox
QgsPointCloudAttributeComboBox(QWidget *parent=nullptr)
QgsPointCloudAttributeComboBox creates a combo box to display the fields of a layer.
Definition: qgspointcloudattributecombobox.cpp:21
QgsPointCloudAttributeComboBox::allowEmptyAttributeName
bool allowEmptyAttributeName
Definition: qgspointcloudattributecombobox.h:39
QgsPointCloudAttributeModel::layer
QgsPointCloudLayer * layer()
Returns the layer associated with the model.
Definition: qgspointcloudattributemodel.cpp:40
QgsPointCloudAttributeModel::indexFromName
QModelIndex indexFromName(const QString &name)
Returns the index corresponding to a given attribute name.
Definition: qgspointcloudattributemodel.cpp:71
qgspointcloudattributecombobox.h
QgsPointCloudAttributeComboBox::setAttribute
void setAttribute(const QString &name)
Sets the currently selected attribute by name.
Definition: qgspointcloudattributecombobox.cpp:67
qgspointcloudlayer.h
QgsPointCloudAttributeComboBox::setAllowEmptyAttributeName
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is shown in the combo box.
Definition: qgspointcloudattributecombobox.cpp:36
qgsmaplayer.h
QgsPointCloudAttributeCollection
Collection of point cloud attributes.
Definition: qgspointcloudattribute.h:141
QgsPointCloudAttributeComboBox::filters
QgsPointCloudAttributeProxyModel::Filters filters
Definition: qgspointcloudattributecombobox.h:38
QgsPointCloudAttributeComboBox::setFilters
void setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Sets filters to allow filtering available attributes according to the attribute properties.
Definition: qgspointcloudattributecombobox.cpp:31
QgsPointCloudAttributeComboBox::attributeChanged
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
QgsPointCloudAttributeComboBox::currentAttribute
QString currentAttribute() const
Returns the currently selected attribute.
Definition: qgspointcloudattributecombobox.cpp:92
QgsPointCloudAttributeModel::attributes
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the model.
Definition: qgspointcloudattributemodel.h:85
QgsPointCloudAttributeProxyModel
A proxy model for filtering available attributes from a point cloud attribute model.
Definition: qgspointcloudattributemodel.h:137
QgsPointCloudAttributeComboBox::layer
QgsPointCloudLayer * layer() const
Returns the layer currently associated with the combobox.
Definition: qgspointcloudattributecombobox.cpp:52
QgsPointCloudAttributeModel
A model for display of available attributes from a point cloud.
Definition: qgspointcloudattributemodel.h:36
QgsPointCloudAttributeModel::setAllowEmptyAttributeName
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is present in the model.
Definition: qgspointcloudattributemodel.cpp:52
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsPointCloudAttributeModel::allowEmptyAttributeName
bool allowEmptyAttributeName() const
Returns true if the model allows the empty attribute ("not set") choice.
Definition: qgspointcloudattributemodel.h:102
QgsPointCloudAttributeModel::setLayer
void setLayer(QgsPointCloudLayer *layer)
Sets the layer associated with the model.
Definition: qgspointcloudattributemodel.cpp:29
QgsPointCloudAttributeComboBox::setAttributes
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Manually sets the attributes to use for the combo box.
Definition: qgspointcloudattributecombobox.cpp:57
QgsPointCloudAttributeComboBox::setLayer
void setLayer(QgsMapLayer *layer)
Sets the layer for which fields are listed in the combobox.
Definition: qgspointcloudattributecombobox.cpp:46
QgsPointCloudAttributeComboBox::attributes
QgsPointCloudAttributeCollection attributes() const
Returns the attributes currently shown in the combobox.
Definition: qgspointcloudattributecombobox.cpp:62