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