QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
mesh
qgsmeshstaticdatasetwidget.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsmeshstaticdatasetwidget.cpp
3
-------------------------------------
4
begin : March 2020
5
copyright : (C) 2020 by Vincent Cloarec
6
email : vcloarec 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 "
qgsmeshstaticdatasetwidget.h
"
17
18
#include "
qgsmeshlayer.h
"
19
20
#include "moc_qgsmeshstaticdatasetwidget.cpp"
21
22
QgsMeshStaticDatasetWidget::QgsMeshStaticDatasetWidget
( QWidget *parent )
23
: QWidget( parent )
24
{
25
setupUi(
this
);
26
27
this->layout()->setContentsMargins( 0, 0, 0, 0 );
28
mDatasetScalarModel =
new
QgsMeshDatasetListModel
(
this
);
29
mScalarDatasetComboBox->setModel( mDatasetScalarModel );
30
mDatasetVectorModel =
new
QgsMeshDatasetListModel
(
this
);
31
mVectorDatasetComboBox->setModel( mDatasetVectorModel );
32
}
33
34
void
QgsMeshStaticDatasetWidget::setLayer
(
QgsMeshLayer
*layer )
35
{
36
mLayer = layer;
37
}
38
39
void
QgsMeshStaticDatasetWidget::syncToLayer
()
40
{
41
if
( !mLayer )
42
return
;
43
44
mDatasetScalarModel->setMeshLayer( mLayer );
45
mDatasetVectorModel->setMeshLayer( mLayer );
46
setScalarDatasetGroup
( mLayer->rendererSettings().activeScalarDatasetGroup() );
47
setVectorDatasetGroup
( mLayer->rendererSettings().activeVectorDatasetGroup() );
48
}
49
50
void
QgsMeshStaticDatasetWidget::apply
()
51
{
52
if
( !mLayer )
53
return
;
54
55
int
scalarIndex;
56
// if only one item, there is no active dataset group.
57
// Set to 0 instead of -1 to avoid none dataset (item 0) when the group is reactivate
58
if
( mScalarDatasetComboBox->count() == 1 )
59
scalarIndex = 0;
60
else
61
scalarIndex = mScalarDatasetComboBox->currentIndex() - 1;
62
int
vectorIndex;
63
// Same as scalar
64
if
( mVectorDatasetComboBox->count() == 1 )
65
vectorIndex = 0;
66
else
67
vectorIndex = mVectorDatasetComboBox->currentIndex() - 1;
68
69
mLayer->setStaticScalarDatasetIndex(
QgsMeshDatasetIndex
( mScalarDatasetGroup, scalarIndex ) );
70
mLayer->setStaticVectorDatasetIndex(
QgsMeshDatasetIndex
( mVectorDatasetGroup, vectorIndex ) );
71
}
72
73
void
QgsMeshStaticDatasetWidget::setScalarDatasetGroup
(
int
index )
74
{
75
mScalarDatasetGroup = index;
76
mDatasetScalarModel->setDatasetGroup( index );
77
mScalarDatasetComboBox->setEnabled( mScalarDatasetGroup >= 0 );
78
if
( mLayer )
79
{
80
mScalarName->setText( mLayer->datasetGroupMetadata( index ).name() );
81
setScalarDatasetIndex( mLayer->staticScalarDatasetIndex().dataset() );
82
}
83
}
84
85
void
QgsMeshStaticDatasetWidget::setVectorDatasetGroup
(
int
index )
86
{
87
mVectorDatasetGroup = index;
88
mDatasetVectorModel->setDatasetGroup( index );
89
mVectorDatasetComboBox->setEnabled( mVectorDatasetGroup >= 0 );
90
if
( mLayer )
91
{
92
mVectorName->setText( mLayer->datasetGroupMetadata( index ).name() );
93
setVectorDatasetIndex( mLayer->staticVectorDatasetIndex().dataset() );
94
}
95
}
96
97
void
QgsMeshStaticDatasetWidget::setScalarDatasetIndex(
int
index )
98
{
99
if
( index < mLayer->datasetCount( mScalarDatasetGroup ) )
100
mScalarDatasetComboBox->setCurrentIndex( index + 1 );
101
else
102
mScalarDatasetComboBox->setCurrentIndex( 0 );
103
}
104
105
void
QgsMeshStaticDatasetWidget::setVectorDatasetIndex(
int
index )
106
{
107
if
( index < mLayer->datasetCount( mVectorDatasetGroup ) )
108
mVectorDatasetComboBox->setCurrentIndex( index + 1 );
109
else
110
mVectorDatasetComboBox->setCurrentIndex( 0 );
111
}
112
113
QgsMeshDatasetListModel::QgsMeshDatasetListModel
( QObject *parent )
114
: QAbstractListModel( parent )
115
{}
116
117
void
QgsMeshDatasetListModel::setMeshLayer
(
QgsMeshLayer
*layer )
118
{
119
beginResetModel();
120
mLayer = layer;
121
endResetModel();
122
}
123
124
void
QgsMeshDatasetListModel::setDatasetGroup
(
int
group )
125
{
126
beginResetModel();
127
mDatasetGroup = group;
128
endResetModel();
129
}
130
131
int
QgsMeshDatasetListModel::rowCount
(
const
QModelIndex &parent )
const
132
{
133
Q_UNUSED( parent )
134
135
if
( mLayer )
136
return
mLayer->datasetCount( mDatasetGroup ) + 1;
137
else
138
return
0;
139
}
140
141
QVariant
QgsMeshDatasetListModel::data
(
const
QModelIndex &index,
int
role )
const
142
{
143
if
( !index.isValid() )
144
return
QVariant();
145
146
if
( role == Qt::DisplayRole )
147
{
148
if
( !mLayer || mDatasetGroup < 0 || index.row() == 0 )
149
return
tr(
"none"
);
150
151
else
if
( index.row() == 1 && mLayer->datasetCount( mDatasetGroup ) == 1 )
152
{
153
return
tr(
"Display dataset"
);
154
}
155
else
156
{
157
const
QgsInterval
time = mLayer->datasetRelativeTime(
QgsMeshDatasetIndex
( mDatasetGroup, index.row() - 1 ) );
158
return
mLayer->formatTime( time.
hours
() );
159
}
160
}
161
162
return
QVariant();
163
}
QgsInterval
A representation of the interval between two datetime values.
Definition
qgsinterval.h:52
QgsInterval::hours
double hours() const
Returns the interval duration in hours.
Definition
qgsinterval.cpp:181
QgsMeshDatasetIndex
An index that identifies the dataset group (e.g.
Definition
qgsmeshdataset.h:53
QgsMeshDatasetListModel
List model for dataset contained in dataset group, used to display by time dataset in widget.
Definition
qgsmeshstaticdatasetwidget.h:38
QgsMeshDatasetListModel::setDatasetGroup
void setDatasetGroup(int group)
Sets the dataset group.
Definition
qgsmeshstaticdatasetwidget.cpp:124
QgsMeshDatasetListModel::setMeshLayer
void setMeshLayer(QgsMeshLayer *layer)
Sets the layer.
Definition
qgsmeshstaticdatasetwidget.cpp:117
QgsMeshDatasetListModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition
qgsmeshstaticdatasetwidget.cpp:131
QgsMeshDatasetListModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition
qgsmeshstaticdatasetwidget.cpp:141
QgsMeshDatasetListModel::QgsMeshDatasetListModel
QgsMeshDatasetListModel(QObject *parent)
Constructor.
Definition
qgsmeshstaticdatasetwidget.cpp:113
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition
qgsmeshlayer.h:105
QgsMeshStaticDatasetWidget::QgsMeshStaticDatasetWidget
QgsMeshStaticDatasetWidget(QWidget *parent=nullptr)
Constructor.
Definition
qgsmeshstaticdatasetwidget.cpp:22
QgsMeshStaticDatasetWidget::apply
void apply()
Applies the settings made in the widget.
Definition
qgsmeshstaticdatasetwidget.cpp:50
QgsMeshStaticDatasetWidget::syncToLayer
void syncToLayer()
Synchronizes widgets state with associated mesh layer.
Definition
qgsmeshstaticdatasetwidget.cpp:39
QgsMeshStaticDatasetWidget::setScalarDatasetGroup
void setScalarDatasetGroup(int index)
Sets the scalar dataset group.
Definition
qgsmeshstaticdatasetwidget.cpp:73
QgsMeshStaticDatasetWidget::setLayer
void setLayer(QgsMeshLayer *layer)
Sets the layer.
Definition
qgsmeshstaticdatasetwidget.cpp:34
QgsMeshStaticDatasetWidget::setVectorDatasetGroup
void setVectorDatasetGroup(int index)
Sets the vector dataset group.
Definition
qgsmeshstaticdatasetwidget.cpp:85
qgsmeshlayer.h
qgsmeshstaticdatasetwidget.h
Generated on
for QGIS API Documentation by
1.17.0