-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScalarAction.cpp
More file actions
157 lines (116 loc) · 4.87 KB
/
ScalarAction.cpp
File metadata and controls
157 lines (116 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "ScalarAction.h"
#include "ScalarSourceModel.h"
#include "ScatterplotPlugin.h"
#include <QHBoxLayout>
using namespace mv::gui;
ScalarAction::ScalarAction(QObject* parent, const QString& title, const float& minimum /*= 0.0f*/, const float& maximum /*= 100.0f*/, const float& value /*= 0.0f*/) :
GroupAction(parent, title),
_magnitudeAction(this, title, minimum, maximum, value),
_sourceAction(this, QString("%1 source").arg(title))
{
setDefaultWidgetFlags(GroupAction::Horizontal);
setShowLabels(false);
addAction(&_magnitudeAction);
addAction(&_sourceAction);
connect(&_sourceAction.getPickerAction(), &OptionAction::currentIndexChanged, this, [this](const std::uint32_t& currentIndex) {
emit sourceSelectionChanged(currentIndex);
});
connect(&_magnitudeAction, &DecimalAction::valueChanged, this, [this](const float& value) {
emit magnitudeChanged(value);
});
connect(&_sourceAction, &ScalarSourceAction::scalarRangeChanged, this, [this](const float& minimum, const float& maximum) {
emit scalarRangeChanged(minimum, maximum);
});
connect(&_sourceAction.getOffsetAction(), &DecimalAction::valueChanged, this, [this](const float& value) {
emit offsetChanged(value);
});
}
void ScalarAction::addDataset(const Dataset<DatasetImpl>& dataset)
{
auto& sourceModel = _sourceAction.getModel();
if (sourceModel.hasDataset(dataset))
return;
sourceModel.addDataset(dataset);
/* TODO: this connection is not removed when the dataset is removed from the model, but that should not cause any issues since the dataset will be invalid and the connection will not do anything in that case
connect(&sourceModel.getDatasets().last(), &Dataset<DatasetImpl>::dataChanged, this, [this, dataset]() {
const auto currentDataset = getCurrentDataset();
if (!currentDataset.isValid())
return;
_sourceAction.updateScalarRange();
if (currentDataset == dataset)
emit sourceDataChanged(dataset);
});
*/
connect(&_magnitudeAction, &DecimalAction::valueChanged, this, [this, dataset](const float& value) {
emit magnitudeChanged(value);
});
}
void ScalarAction::removeAllDatasets()
{
_sourceAction.getModel().removeAllDatasets();
}
Dataset<DatasetImpl> ScalarAction::getCurrentDataset()
{
auto& scalarSourceModel = _sourceAction.getModel();
const auto currentSourceIndex = _sourceAction.getPickerAction().getCurrentIndex();
if (currentSourceIndex < ScalarSourceModel::DefaultRow::DatasetStart)
return {};
return scalarSourceModel.getDataset(currentSourceIndex);
}
void ScalarAction::setCurrentDataset(const Dataset<DatasetImpl>& dataset)
{
const auto datasetRowIndex = _sourceAction.getModel().getRowIndex(dataset);
if (datasetRowIndex >= 0)
_sourceAction.getPickerAction().setCurrentIndex(datasetRowIndex);
}
void ScalarAction::setCurrentSourceIndex(std::int32_t sourceIndex)
{
_sourceAction.getPickerAction().setCurrentIndex(sourceIndex);
}
bool ScalarAction::isSourceConstant() const
{
return _sourceAction.getPickerAction().getCurrentIndex() == ScalarSourceModel::DefaultRow::Constant;
}
bool ScalarAction::isSourceSelection() const
{
return _sourceAction.getPickerAction().getCurrentIndex() == ScalarSourceModel::DefaultRow::Selection;
}
bool ScalarAction::isSourceDataset() const
{
return _sourceAction.getPickerAction().getCurrentIndex() >= ScalarSourceModel::DefaultRow::DatasetStart;
}
void ScalarAction::connectToPublicAction(WidgetAction* publicAction, bool recursive)
{
auto publicScalarAction = dynamic_cast<ScalarAction*>(publicAction);
Q_ASSERT(publicScalarAction != nullptr);
if (publicScalarAction == nullptr)
return;
if (recursive) {
actions().connectPrivateActionToPublicAction(&_magnitudeAction, &publicScalarAction->getMagnitudeAction(), recursive);
actions().connectPrivateActionToPublicAction(&_sourceAction, &publicScalarAction->getSourceAction(), recursive);
}
GroupAction::connectToPublicAction(publicAction, recursive);
}
void ScalarAction::disconnectFromPublicAction(bool recursive)
{
if (!isConnected())
return;
if (recursive) {
actions().disconnectPrivateActionFromPublicAction(&_magnitudeAction, recursive);
actions().disconnectPrivateActionFromPublicAction(&_sourceAction, recursive);
}
GroupAction::disconnectFromPublicAction(recursive);
}
void ScalarAction::fromVariantMap(const QVariantMap& variantMap)
{
GroupAction::fromVariantMap(variantMap);
_magnitudeAction.fromParentVariantMap(variantMap);
_sourceAction.fromParentVariantMap(variantMap);
}
QVariantMap ScalarAction::toVariantMap() const
{
auto variantMap = GroupAction::toVariantMap();
_magnitudeAction.insertIntoVariantMap(variantMap);
_sourceAction.insertIntoVariantMap(variantMap);
return variantMap;
}