QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsmeshrendereractivedatasetwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshrendereractivedatasetwidget.cpp
3 ---------------------------------------
4 begin : June 2018
5 copyright : (C) 2018 by Peter Petrik
6 email : zilolv 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 "moc_qgsmeshrendereractivedatasetwidget.cpp"
18
19#include <QDateTime>
20#include <QIcon>
21
22#include "qgis.h"
23#include "qgsapplication.h"
24#include "qgsmeshlayer.h"
25#include "qgsmessagelog.h"
27
29 : QWidget( parent )
30{
31 setupUi( this );
32
34 this, &QgsMeshRendererActiveDatasetWidget::onActiveScalarGroupChanged );
36 this, &QgsMeshRendererActiveDatasetWidget::onActiveVectorGroupChanged );
37}
38
40
41
43{
44 if ( mMeshLayer )
45 {
46 disconnect( mMeshLayer, &QgsMeshLayer::activeScalarDatasetGroupChanged,
48 disconnect( mMeshLayer, &QgsMeshLayer::activeVectorDatasetGroupChanged,
50 }
51
52 mMeshLayer = layer;
53
54 mDatasetGroupTreeView->setLayer( layer );
59}
60
62{
63 return mActiveScalarDatasetGroup;
64}
65
67{
68 return mActiveVectorDatasetGroup;
69}
70
71
72void QgsMeshRendererActiveDatasetWidget::onActiveScalarGroupChanged( int groupIndex )
73{
74 if ( groupIndex == mActiveScalarDatasetGroup )
75 return;
76
77 mActiveScalarDatasetGroup = groupIndex;
78 updateMetadata();
79 emit activeScalarGroupChanged( mActiveScalarDatasetGroup );
80 emit widgetChanged();
81}
82
83void QgsMeshRendererActiveDatasetWidget::onActiveVectorGroupChanged( int groupIndex )
84{
85 if ( groupIndex == mActiveVectorDatasetGroup )
86 return;
87
88 mActiveVectorDatasetGroup = groupIndex;
89 updateMetadata();
90 emit activeVectorGroupChanged( mActiveVectorDatasetGroup );
91 emit widgetChanged();
92}
93
94void QgsMeshRendererActiveDatasetWidget::updateMetadata()
95{
96 QString msg;
97
98 if ( !mMeshLayer ||
99 !mMeshLayer->dataProvider() )
100 {
101 msg += tr( "Invalid mesh layer selected" );
102 }
103 else
104 {
105 if ( mActiveScalarDatasetGroup > -1 )
106 {
107 if ( mActiveVectorDatasetGroup > -1 )
108 {
109 if ( mActiveScalarDatasetGroup == mActiveVectorDatasetGroup )
110 {
111 msg += metadata( mActiveScalarDatasetGroup );
112 }
113 else
114 {
115 msg += QStringLiteral( "<p> <h3> %1 </h3> " ).arg( tr( "Scalar dataset" ) );
116 msg += metadata( mActiveScalarDatasetGroup );
117 msg += QStringLiteral( "</p> <p> <h3> %1 </h3>" ).arg( tr( "Vector dataset" ) );
118 msg += metadata( mActiveVectorDatasetGroup );
119 msg += QLatin1String( "</p>" );
120 }
121 }
122 else
123 {
124 msg += metadata( mActiveScalarDatasetGroup );
125 }
126 }
127 else
128 {
129 if ( mActiveVectorDatasetGroup > -1 )
130 {
131 msg += metadata( mActiveVectorDatasetGroup );
132 }
133 else
134 {
135 msg += tr( "No mesh dataset selected" );
136 }
137 }
138 }
139
140 mActiveDatasetMetadata->setText( msg );
141}
142
143
144QString QgsMeshRendererActiveDatasetWidget::metadata( QgsMeshDatasetIndex datasetIndex )
145{
146
147 QString msg;
148 msg += QLatin1String( "<table>" );
149
150 QString definedOnMesh;
151 if ( mMeshLayer->contains( QgsMesh::ElementType::Face ) )
152 {
153 if ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) )
154 {
155 definedOnMesh = tr( "faces and edges" );
156 }
157 else
158 {
159 definedOnMesh = tr( "faces" );
160 }
161 }
162 else if ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) )
163 {
164 definedOnMesh = tr( "edges" );
165 }
166 else
167 {
168 definedOnMesh = tr( "invalid mesh" );
169 }
170 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
171 .arg( tr( "Mesh type" ) )
172 .arg( definedOnMesh );
173
174 const QgsMeshDatasetGroupMetadata gmeta = mMeshLayer->datasetGroupMetadata( datasetIndex );
175 QString definedOn;
176 switch ( gmeta.dataType() )
177 {
179 definedOn = tr( "vertices" );
180 break;
182 definedOn = tr( "faces" );
183 break;
185 definedOn = tr( "volumes" );
186 break;
188 definedOn = tr( "edges" );
189 break;
190 }
191 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
192 .arg( tr( "Data type" ) )
193 .arg( definedOn );
194
195 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
196 .arg( tr( "Is vector" ) )
197 .arg( gmeta.isVector() ? tr( "Yes" ) : tr( "No" ) );
198
199 const auto options = gmeta.extraOptions();
200 for ( auto it = options.constBegin(); it != options.constEnd(); ++it )
201 {
202 if ( it.key() == QLatin1String( "classification" ) )
203 {
204 msg += QStringLiteral( "<tr><td>%1</td></tr>" ).arg( tr( "Classified values" ) );
205 continue;
206 }
207 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( it.key() ).arg( it.value() );
208 }
209
210 msg += QLatin1String( "</table>" );
211
212 return msg;
213}
214
216{
217 setEnabled( mMeshLayer );
218
219 whileBlocking( mDatasetGroupTreeView )->syncToLayer();
220
221 mActiveScalarDatasetGroup = mDatasetGroupTreeView->activeScalarGroup();
222 mActiveVectorDatasetGroup = mDatasetGroupTreeView->activeVectorGroup();
223
224 updateMetadata();
225}
void setActiveScalarGroup(int group)
Sets active group for contours.
void setActiveVectorGroup(int group)
Sets active vector group.
void activeVectorGroupChanged(int groupIndex)
Selected dataset group for vectors changed. -1 for invalid group.
void activeScalarGroupChanged(int groupIndex)
Selected dataset group for contours changed. -1 for invalid group.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QMap< QString, QString > extraOptions() const
Returns extra metadata options, for example description.
bool isVector() const
Returns whether dataset group has vector data.
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces or volumes.
@ DataOnEdges
Data is defined on edges.
@ DataOnFaces
Data is defined on faces.
@ DataOnVertices
Data is defined on vertices.
@ DataOnVolumes
Data is defined on volumes.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
QgsMeshRendererActiveDatasetWidget(QWidget *parent=nullptr)
A widget to hold the renderer scalar settings for a mesh layer.
int activeVectorDatasetGroup() const
Returns index of the active vector dataset group.
void syncToLayer()
Synchronizes widgets state with associated mesh layer.
void widgetChanged()
Emitted when any settings related to rendering changed.
int activeScalarDatasetGroup() const
Returns index of the active scalar dataset group.
void setLayer(QgsMeshLayer *layer)
Associates mesh layer with the widget.
void activeScalarGroupChanged(int groupIndex)
Emitted when the current scalar group gets changed.
void activeVectorGroupChanged(int groupIndex)
Emitted when the current vector group gets changed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5862