QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
33 connect( mDatasetGroupTreeView, &QgsMeshActiveDatasetGroupTreeView::activeScalarGroupChanged, this, &QgsMeshRendererActiveDatasetWidget::onActiveScalarGroupChanged );
34 connect( mDatasetGroupTreeView, &QgsMeshActiveDatasetGroupTreeView::activeVectorGroupChanged, this, &QgsMeshRendererActiveDatasetWidget::onActiveVectorGroupChanged );
35}
36
38
39
41{
42 if ( mMeshLayer )
43 {
46 }
47
48 mMeshLayer = layer;
49
50 mDatasetGroupTreeView->setLayer( layer );
53}
54
56{
57 return mActiveScalarDatasetGroup;
58}
59
61{
62 return mActiveVectorDatasetGroup;
63}
64
65
66void QgsMeshRendererActiveDatasetWidget::onActiveScalarGroupChanged( int groupIndex )
67{
68 if ( groupIndex == mActiveScalarDatasetGroup )
69 return;
70
71 mActiveScalarDatasetGroup = groupIndex;
72 updateMetadata();
73 emit activeScalarGroupChanged( mActiveScalarDatasetGroup );
74 emit widgetChanged();
75}
76
77void QgsMeshRendererActiveDatasetWidget::onActiveVectorGroupChanged( int groupIndex )
78{
79 if ( groupIndex == mActiveVectorDatasetGroup )
80 return;
81
82 mActiveVectorDatasetGroup = groupIndex;
83 updateMetadata();
84 emit activeVectorGroupChanged( mActiveVectorDatasetGroup );
85 emit widgetChanged();
86}
87
88void QgsMeshRendererActiveDatasetWidget::updateMetadata()
89{
90 QString msg;
91
92 if ( !mMeshLayer || !mMeshLayer->dataProvider() )
93 {
94 msg += tr( "Invalid mesh layer selected" );
95 }
96 else
97 {
98 if ( mActiveScalarDatasetGroup > -1 )
99 {
100 if ( mActiveVectorDatasetGroup > -1 )
101 {
102 if ( mActiveScalarDatasetGroup == mActiveVectorDatasetGroup )
103 {
104 msg += metadata( mActiveScalarDatasetGroup );
105 }
106 else
107 {
108 msg += QStringLiteral( "<p> <h3> %1 </h3> " ).arg( tr( "Scalar dataset" ) );
109 msg += metadata( mActiveScalarDatasetGroup );
110 msg += QStringLiteral( "</p> <p> <h3> %1 </h3>" ).arg( tr( "Vector dataset" ) );
111 msg += metadata( mActiveVectorDatasetGroup );
112 msg += QLatin1String( "</p>" );
113 }
114 }
115 else
116 {
117 msg += metadata( mActiveScalarDatasetGroup );
118 }
119 }
120 else
121 {
122 if ( mActiveVectorDatasetGroup > -1 )
123 {
124 msg += metadata( mActiveVectorDatasetGroup );
125 }
126 else
127 {
128 msg += tr( "No mesh dataset selected" );
129 }
130 }
131 }
132
133 mActiveDatasetMetadata->setText( msg );
134}
135
136
137QString QgsMeshRendererActiveDatasetWidget::metadata( QgsMeshDatasetIndex datasetIndex )
138{
139 QString msg;
140 msg += QLatin1String( "<table>" );
141
142 QString definedOnMesh;
143 if ( mMeshLayer->contains( QgsMesh::ElementType::Face ) )
144 {
145 if ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) )
146 {
147 definedOnMesh = tr( "faces and edges" );
148 }
149 else
150 {
151 definedOnMesh = tr( "faces" );
152 }
153 }
154 else if ( mMeshLayer->contains( QgsMesh::ElementType::Edge ) )
155 {
156 definedOnMesh = tr( "edges" );
157 }
158 else
159 {
160 definedOnMesh = tr( "invalid mesh" );
161 }
162 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
163 .arg( tr( "Mesh type" ) )
164 .arg( definedOnMesh );
165
166 const QgsMeshDatasetGroupMetadata gmeta = mMeshLayer->datasetGroupMetadata( datasetIndex );
167 QString definedOn;
168 switch ( gmeta.dataType() )
169 {
171 definedOn = tr( "vertices" );
172 break;
174 definedOn = tr( "faces" );
175 break;
177 definedOn = tr( "volumes" );
178 break;
180 definedOn = tr( "edges" );
181 break;
182 }
183 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
184 .arg( tr( "Data type" ) )
185 .arg( definedOn );
186
187 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
188 .arg( tr( "Is vector" ) )
189 .arg( gmeta.isVector() ? tr( "Yes" ) : tr( "No" ) );
190
191 const auto options = gmeta.extraOptions();
192 for ( auto it = options.constBegin(); it != options.constEnd(); ++it )
193 {
194 if ( it.key() == QLatin1String( "classification" ) )
195 {
196 msg += QStringLiteral( "<tr><td>%1</td></tr>" ).arg( tr( "Classified values" ) );
197 continue;
198 }
199 msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( it.key() ).arg( it.value() );
200 }
201
202 msg += QLatin1String( "</table>" );
203
204 return msg;
205}
206
208{
209 setEnabled( mMeshLayer );
210
211 whileBlocking( mDatasetGroupTreeView )->syncToLayer();
212
213 mActiveScalarDatasetGroup = mDatasetGroupTreeView->activeScalarGroup();
214 mActiveVectorDatasetGroup = mDatasetGroupTreeView->activeVectorGroup();
215
216 updateMetadata();
217}
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:5970