QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
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
16
#include "
qgspointcloudattributecombobox.h
"
17
18
#include "
qgsfieldproxymodel.h
"
19
#include "
qgsmaplayer.h
"
20
#include "
qgspointcloudlayer.h
"
21
22
#include "moc_qgspointcloudattributecombobox.cpp"
23
24
QgsPointCloudAttributeComboBox::QgsPointCloudAttributeComboBox
( QWidget *parent )
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
34
void
QgsPointCloudAttributeComboBox::setFilters
(
QgsPointCloudAttributeProxyModel::Filters
filters
)
35
{
36
mProxyModel->setFilters(
filters
);
37
}
38
39
void
QgsPointCloudAttributeComboBox::setAllowEmptyAttributeName
(
bool
allowEmpty )
40
{
41
mAttributeModel->setAllowEmptyAttributeName( allowEmpty );
42
}
43
44
bool
QgsPointCloudAttributeComboBox::allowEmptyAttributeName
()
const
45
{
46
return
mAttributeModel->allowEmptyAttributeName();
47
}
48
49
void
QgsPointCloudAttributeComboBox::setLayer
(
QgsMapLayer
*
layer
)
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
62
QgsPointCloudLayer
*
QgsPointCloudAttributeComboBox::layer
()
const
63
{
64
return
mAttributeModel->layer();
65
}
66
67
void
QgsPointCloudAttributeComboBox::setAttributes
(
const
QgsPointCloudAttributeCollection
&
attributes
)
68
{
69
mAttributeModel->setAttributes(
attributes
);
70
}
71
72
QgsPointCloudAttributeCollection
QgsPointCloudAttributeComboBox::attributes
()
const
73
{
74
return
mAttributeModel->
attributes
();
75
}
76
77
void
QgsPointCloudAttributeComboBox::setAttribute
(
const
QString &name )
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
() )
99
emit
attributeChanged
(
currentAttribute
() );
100
}
101
102
QString
QgsPointCloudAttributeComboBox::currentAttribute
()
const
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
115
void
QgsPointCloudAttributeComboBox::indexChanged(
int
i )
116
{
117
Q_UNUSED( i )
118
const
QString name =
currentAttribute
();
119
emit
attributeChanged
( name );
120
}
QgsMapLayer
Base class for all map layer types.
Definition
qgsmaplayer.h:83
QgsPointCloudAttributeCollection
A collection of point cloud attributes.
Definition
qgspointcloudattribute.h:157
QgsPointCloudAttributeCollection::attributes
QVector< QgsPointCloudAttribute > attributes() const
Returns all attributes.
Definition
qgspointcloudattribute.cpp:164
QgsPointCloudAttributeComboBox::setLayer
void setLayer(QgsMapLayer *layer)
Sets the layer for which fields are listed in the combobox.
Definition
qgspointcloudattributecombobox.cpp:49
QgsPointCloudAttributeComboBox::setAttributes
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Manually sets the attributes to use for the combo box.
Definition
qgspointcloudattributecombobox.cpp:67
QgsPointCloudAttributeComboBox::filters
QgsPointCloudAttributeProxyModel::Filters filters
Definition
qgspointcloudattributecombobox.h:38
QgsPointCloudAttributeComboBox::setAllowEmptyAttributeName
void setAllowEmptyAttributeName(bool allowEmpty)
Sets whether an optional empty attribute ("not set") option is shown in the combo box.
Definition
qgspointcloudattributecombobox.cpp:39
QgsPointCloudAttributeComboBox::attributes
QgsPointCloudAttributeCollection attributes() const
Returns the attributes currently shown in the combobox.
Definition
qgspointcloudattributecombobox.cpp:72
QgsPointCloudAttributeComboBox::attributeChanged
void attributeChanged(const QString &name)
Emitted when the currently selected attribute changes.
QgsPointCloudAttributeComboBox::QgsPointCloudAttributeComboBox
QgsPointCloudAttributeComboBox(QWidget *parent=nullptr)
QgsPointCloudAttributeComboBox creates a combo box to display the fields of a layer.
Definition
qgspointcloudattributecombobox.cpp:24
QgsPointCloudAttributeComboBox::allowEmptyAttributeName
bool allowEmptyAttributeName
Definition
qgspointcloudattributecombobox.h:39
QgsPointCloudAttributeComboBox::layer
QgsPointCloudLayer * layer() const
Returns the layer currently associated with the combobox.
Definition
qgspointcloudattributecombobox.cpp:62
QgsPointCloudAttributeComboBox::currentAttribute
QString currentAttribute() const
Returns the currently selected attribute.
Definition
qgspointcloudattributecombobox.cpp:102
QgsPointCloudAttributeComboBox::setAttribute
void setAttribute(const QString &name)
Sets the currently selected attribute by name.
Definition
qgspointcloudattributecombobox.cpp:77
QgsPointCloudAttributeComboBox::setFilters
void setFilters(QgsPointCloudAttributeProxyModel::Filters filters)
Sets filters to allow filtering available attributes according to the attribute properties.
Definition
qgspointcloudattributecombobox.cpp:34
QgsPointCloudAttributeModel
A model for display of available attributes from a point cloud.
Definition
qgspointcloudattributemodel.h:37
QgsPointCloudAttributeModel::CustomRole::AttributeName
@ AttributeName
Attribute name.
Definition
qgspointcloudattributemodel.h:51
QgsPointCloudAttributeProxyModel
A proxy model for filtering available attributes from a point cloud attribute model.
Definition
qgspointcloudattributemodel.h:145
QgsPointCloudAttributeProxyModel::Filters
QFlags< Filter > Filters
Definition
qgspointcloudattributemodel.h:159
QgsPointCloudLayer
Represents a map layer supporting display of point clouds.
Definition
qgspointcloudlayer.h:49
qgsfieldproxymodel.h
qgsmaplayer.h
qgspointcloudattributecombobox.h
qgspointcloudlayer.h
Generated on
for QGIS API Documentation by
1.17.0