##// END OF EJS Templates
Deletes close() method defined for a visualization widget...
Alexandre Leroux -
r244:419e3cbb9021
parent child
Show More
@@ -1,26 +1,25
1 1 #ifndef SCIQLOP_IVISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_IVISUALIZATIONWIDGET_H
3 3
4 4 #include "Visualization/IVariableContainer.h"
5 5
6 6 #include <QString>
7 7 #include <memory>
8 8
9 9 class IVisualizationWidgetVisitor;
10 10
11 11 /**
12 12 * @brief The IVisualizationWidget handles the visualization widget.
13 13 */
14 14 class IVisualizationWidget : public IVariableContainer {
15 15
16 16 public:
17 17 virtual ~IVisualizationWidget() = default;
18 18
19 19 /// Initializes the plugin
20 20 virtual void accept(IVisualizationWidgetVisitor *visitor) = 0;
21 virtual void close() = 0;
22 21 virtual QString name() const = 0;
23 22 };
24 23
25 24
26 25 #endif // SCIQLOP_IVISUALIZATIONWIDGET_H
@@ -1,56 +1,55
1 1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 #include <memory>
10 10
11 11 #include <Common/spimpl.h>
12 12
13 13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14 14
15 15 class QCPRange;
16 16 class Variable;
17 17
18 18 namespace Ui {
19 19 class VisualizationGraphWidget;
20 20 } // namespace Ui
21 21
22 22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
23 23 Q_OBJECT
24 24
25 25 public:
26 26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
27 27 virtual ~VisualizationGraphWidget();
28 28
29 29 void addVariable(std::shared_ptr<Variable> variable);
30 30
31 31 // IVisualizationWidget interface
32 32 void accept(IVisualizationWidgetVisitor *visitor) override;
33 33 bool canDrop(const Variable &variable) const override;
34 void close() override;
35 34 QString name() const override;
36 35
37 36 void updateDisplay(std::shared_ptr<Variable> variable);
38 37
39 38
40 39 private:
41 40 Ui::VisualizationGraphWidget *ui;
42 41
43 42 class VisualizationGraphWidgetPrivate;
44 43 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
45 44
46 45 private slots:
47 46
48 47 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
49 48
50 49 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
51 50 void onMouseWheel(QWheelEvent *event) noexcept;
52 51
53 52 void onDataCacheVariableUpdated();
54 53 };
55 54
56 55 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,54 +1,53
1 1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <Common/spimpl.h>
7 7
8 8 #include <QLoggingCategory>
9 9 #include <QWidget>
10 10
11 11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
12 12
13 13 class Variable;
14 14 class VisualizationZoneWidget;
15 15
16 16 namespace Ui {
17 17 class VisualizationTabWidget;
18 18 } // namespace Ui
19 19
20 20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
21 21 Q_OBJECT
22 22
23 23 public:
24 24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
25 25 virtual ~VisualizationTabWidget();
26 26
27 27 /// Add a zone widget
28 28 void addZone(VisualizationZoneWidget *zoneWidget);
29 29
30 30 /**
31 31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
32 32 * zone.
33 33 * @param variable the variable for which to create the zone
34 34 * @return the pointer to the created zone
35 35 */
36 36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
37 37
38 38 /// Remove a zone
39 39 void removeZone(VisualizationZoneWidget *zone);
40 40
41 41 // IVisualizationWidget interface
42 42 void accept(IVisualizationWidgetVisitor *visitor) override;
43 43 bool canDrop(const Variable &variable) const override;
44 void close() override;
45 44 QString name() const override;
46 45
47 46 private:
48 47 Ui::VisualizationTabWidget *ui;
49 48
50 49 class VisualizationTabWidgetPrivate;
51 50 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
52 51 };
53 52
54 53 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,53 +1,52
1 1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10 10
11 11 class QMenu;
12 12 class Variable;
13 13 class VisualizationTabWidget;
14 14
15 15 namespace Ui {
16 16 class VisualizationWidget;
17 17 } // namespace Ui
18 18
19 19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
20 20 Q_OBJECT
21 21
22 22 public:
23 23 explicit VisualizationWidget(QWidget *parent = 0);
24 24 virtual ~VisualizationWidget();
25 25
26 26 /// Add a zone widget
27 27 virtual void addTab(VisualizationTabWidget *tabWidget);
28 28
29 29 /// Create a tab using a Variable
30 30 VisualizationTabWidget *createTab();
31 31
32 32 /// Remove a tab
33 33 void removeTab(VisualizationTabWidget *tab);
34 34
35 35 // IVisualizationWidget interface
36 36 void accept(IVisualizationWidgetVisitor *visitor) override;
37 37 bool canDrop(const Variable &variable) const override;
38 void close() override;
39 38 QString name() const override;
40 39
41 40 public slots:
42 41 /**
43 42 * Attaches to a menu the menu relating to the visualization of a variable
44 43 * @param menu the parent menu of the generated menu
45 44 * @param variable the variable for which to generate the menu
46 45 */
47 46 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
48 47
49 48 private:
50 49 Ui::VisualizationWidget *ui;
51 50 };
52 51
53 52 #endif // VISUALIZATIONWIDGET_H
@@ -1,48 +1,47
1 1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
10 10
11 11 namespace Ui {
12 12 class VisualizationZoneWidget;
13 13 } // Ui
14 14
15 15 class Variable;
16 16 class VisualizationGraphWidget;
17 17
18 18 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
19 19 Q_OBJECT
20 20
21 21 public:
22 22 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
23 23 virtual ~VisualizationZoneWidget();
24 24
25 25 /// Add a graph widget
26 26 void addGraph(VisualizationGraphWidget *graphWidget);
27 27
28 28 /**
29 29 * Creates a graph using a variable. The variable will be displayed in the new graph.
30 30 * @param variable the variable for which to create the graph
31 31 * @return the pointer to the created graph
32 32 */
33 33 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
34 34
35 35 /// Remove a graph
36 36 void removeGraph(VisualizationGraphWidget *graph);
37 37
38 38 // IVisualizationWidget interface
39 39 void accept(IVisualizationWidgetVisitor *visitor) override;
40 40 bool canDrop(const Variable &variable) const override;
41 void close() override;
42 41 QString name() const override;
43 42
44 43 private:
45 44 Ui::VisualizationZoneWidget *ui;
46 45 };
47 46
48 47 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -1,208 +1,202
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphHelper.h"
4 4 #include "ui_VisualizationGraphWidget.h"
5 5
6 6 #include <Data/ArrayData.h>
7 7 #include <Data/IDataSeries.h>
8 8 #include <SqpApplication.h>
9 9 #include <Variable/Variable.h>
10 10 #include <Variable/VariableController.h>
11 11
12 12 #include <unordered_map>
13 13
14 14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15 15
16 16 namespace {
17 17
18 18 /// Key pressed to enable zoom on horizontal axis
19 19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20 20
21 21 /// Key pressed to enable zoom on vertical axis
22 22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23 23
24 24 } // namespace
25 25
26 26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27 27
28 28 // 1 variable -> n qcpplot
29 29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 30 m_VariableToPlotMultiMap;
31 31 };
32 32
33 33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
34 34 : QWidget{parent},
35 35 ui{new Ui::VisualizationGraphWidget},
36 36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
37 37 {
38 38 ui->setupUi(this);
39 39
40 40 // qcpplot title
41 41 ui->widget->plotLayout()->insertRow(0);
42 42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
43 43
44 44 // Set qcpplot properties :
45 45 // - Drag (on x-axis) and zoom are enabled
46 46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
47 47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
48 48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
49 49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
50 50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
51 51 &QCPAxis::rangeChanged),
52 52 this, &VisualizationGraphWidget::onRangeChanged);
53 53 }
54 54
55 55
56 56 VisualizationGraphWidget::~VisualizationGraphWidget()
57 57 {
58 58 delete ui;
59 59 }
60 60
61 61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
62 62 {
63 63 // Uses delegate to create the qcpplot components according to the variable
64 64 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
65 65
66 66 for (auto createdPlottable : qAsConst(createdPlottables)) {
67 67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
68 68 }
69 69
70 70 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
71 71 }
72 72
73 73 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
74 74 {
75 75 if (visitor) {
76 76 visitor->visit(this);
77 77 }
78 78 else {
79 79 qCCritical(LOG_VisualizationGraphWidget())
80 80 << tr("Can't visit widget : the visitor is null");
81 81 }
82 82 }
83 83
84 84 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
85 85 {
86 86 /// @todo : for the moment, a graph can always accomodate a variable
87 87 Q_UNUSED(variable);
88 88 return true;
89 89 }
90 90
91 void VisualizationGraphWidget::close()
92 {
93 // The main view cannot be directly closed.
94 return;
95 }
96
97 91 QString VisualizationGraphWidget::name() const
98 92 {
99 93 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
100 94 return title->text();
101 95 }
102 96 else {
103 97 return QString{};
104 98 }
105 99 }
106 100
107 101 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
108 102 {
109 103
110 104 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
111 105
112 106 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
113 107 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
114 108
115 109 auto variable = it->first;
116 110 qCInfo(LOG_VisualizationGraphWidget())
117 111 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
118 112 << variable->dataSeries()->xAxisData()->size();
119 113 auto dateTime = SqpDateTime{t2.lower, t2.upper};
120 114
121 115 if (!variable->contains(dateTime)) {
122 116
123 117 auto variableDateTimeWithTolerance = dateTime;
124 118 if (variable->intersect(dateTime)) {
125 119 auto variableDateTime = variable->dateTime();
126 120 if (variableDateTime.m_TStart < dateTime.m_TStart) {
127 121
128 122 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
129 123 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
130 124 // Tolerance have to be added to the right
131 125 // add 10% tolerance for right (end) side
132 126 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
133 127 variableDateTimeWithTolerance.m_TEnd += tolerance;
134 128 }
135 129 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
136 130 auto diffStartToKeepDelta = dateTime.m_TStart - dateTime.m_TStart;
137 131 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
138 132 // Tolerance have to be added to the left
139 133 // add 10% tolerance for left (start) side
140 134 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
141 135 variableDateTimeWithTolerance.m_TStart -= tolerance;
142 136 }
143 137 }
144 138 else {
145 139 // add 10% tolerance for each side
146 140 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
147 141 variableDateTimeWithTolerance.m_TStart -= tolerance;
148 142 variableDateTimeWithTolerance.m_TEnd += tolerance;
149 143 }
150 144 variable->setDateTime(dateTime);
151 145
152 146 // CHangement detected, we need to ask controller to request data loading
153 147 sqpApp->variableController().requestDataLoading(variable,
154 148 variableDateTimeWithTolerance);
155 149 }
156 150 }
157 151 }
158 152
159 153 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
160 154 {
161 155 auto zoomOrientations = QFlags<Qt::Orientation>{};
162 156
163 157 // Lambda that enables a zoom orientation if the key modifier related to this orientation
164 158 // has
165 159 // been pressed
166 160 auto enableOrientation
167 161 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
168 162 auto orientationEnabled = event->modifiers().testFlag(modifier);
169 163 zoomOrientations.setFlag(orientation, orientationEnabled);
170 164 };
171 165 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
172 166 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
173 167
174 168 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
175 169 }
176 170
177 171 void VisualizationGraphWidget::onDataCacheVariableUpdated()
178 172 {
179 173 // NOTE:
180 174 // We don't want to call the method for each component of a variable unitarily, but for
181 175 // all
182 176 // its components at once (eg its three components in the case of a vector).
183 177
184 178 // The unordered_multimap does not do this easily, so the question is whether to:
185 179 // - use an ordered_multimap and the algos of std to group the values by key
186 180 // - use a map (unique keys) and store as values directly the list of components
187 181
188 182 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
189 183 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
190 184 auto variable = it->first;
191 185 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
192 186 variable->dataSeries(), variable->dateTime());
193 187 }
194 188 }
195 189
196 190 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
197 191 {
198 192 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
199 193
200 194 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
201 195
202 196 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
203 197 abstractPlotableVect.push_back(it->second);
204 198 }
205 199
206 200 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
207 201 variable->dateTime());
208 202 }
@@ -1,105 +1,99
1 1 #include "Visualization/VisualizationTabWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "ui_VisualizationTabWidget.h"
4 4
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6
7 7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8 8
9 9 namespace {
10 10
11 11 /// Generates a default name for a new zone, according to the number of zones already displayed in
12 12 /// the tab
13 13 QString defaultZoneName(const QLayout &layout)
14 14 {
15 15 auto count = 0;
16 16 for (auto i = 0; i < layout.count(); ++i) {
17 17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
18 18 count++;
19 19 }
20 20 }
21 21
22 22 return QObject::tr("Zone %1").arg(count + 1);
23 23 }
24 24
25 25 } // namespace
26 26
27 27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
28 28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
29 29
30 30 QString m_Name;
31 31 };
32 32
33 33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
34 34 : QWidget{parent},
35 35 ui{new Ui::VisualizationTabWidget},
36 36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
37 37 {
38 38 ui->setupUi(this);
39 39 }
40 40
41 41 VisualizationTabWidget::~VisualizationTabWidget()
42 42 {
43 43 delete ui;
44 44 }
45 45
46 46 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
47 47 {
48 48 this->layout()->addWidget(zoneWidget);
49 49 }
50 50
51 51 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
52 52 {
53 53 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
54 54 this->addZone(zoneWidget);
55 55
56 56 // Creates a new graph into the zone
57 57 zoneWidget->createGraph(variable);
58 58
59 59 return zoneWidget;
60 60 }
61 61
62 62 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
63 63 {
64 64 }
65 65
66 66 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
67 67 {
68 68 if (visitor) {
69 69 visitor->visitEnter(this);
70 70
71 71 // Apply visitor to zone children
72 72 for (auto i = 0; i < layout()->count(); ++i) {
73 73 if (auto item = layout()->itemAt(i)) {
74 74 // Widgets different from zones are not visited (no action)
75 75 if (auto visualizationZoneWidget
76 76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
77 77 visualizationZoneWidget->accept(visitor);
78 78 }
79 79 }
80 80 }
81 81
82 82 visitor->visitLeave(this);
83 83 }
84 84 else {
85 85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
86 86 }
87 87 }
88 88
89 89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
90 90 {
91 91 // A tab can always accomodate a variable
92 92 Q_UNUSED(variable);
93 93 return true;
94 94 }
95 95
96 void VisualizationTabWidget::close()
97 {
98 // The main view cannot be directly closed.
99 return;
100 }
101
102 96 QString VisualizationTabWidget::name() const
103 97 {
104 98 return impl->m_Name;
105 99 }
@@ -1,131 +1,125
1 1 #include "Visualization/VisualizationWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphWidget.h"
4 4 #include "Visualization/VisualizationTabWidget.h"
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 7 #include "Visualization/qcustomplot.h"
8 8
9 9 #include "ui_VisualizationWidget.h"
10 10
11 11 #include <QToolButton>
12 12
13 13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
14 14
15 15 VisualizationWidget::VisualizationWidget(QWidget *parent)
16 16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
17 17 {
18 18 ui->setupUi(this);
19 19
20 20 auto addTabViewButton = new QToolButton{ui->tabWidget};
21 21 addTabViewButton->setText(tr("Add View"));
22 22 addTabViewButton->setCursor(Qt::ArrowCursor);
23 23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
24 24
25 25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
26 26
27 27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
28 28 auto width = enable ? tabViewCornerWidget->width() : 0;
29 29 auto height = enable ? tabViewCornerWidget->height() : 0;
30 30 tabViewCornerWidget->setMinimumHeight(height);
31 31 tabViewCornerWidget->setMinimumWidth(width);
32 32 ui->tabWidget->setMinimumHeight(height);
33 33 ui->tabWidget->setMinimumWidth(width);
34 34 };
35 35
36 36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
37 37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
38 38 ui->tabWidget};
39 39 auto index = ui->tabWidget->addTab(widget, widget->name());
40 40 if (ui->tabWidget->count() > 0) {
41 41 enableMinimumCornerWidgetSize(false);
42 42 }
43 43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
44 44 };
45 45
46 46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
47 47 if (ui->tabWidget->count() == 1) {
48 48 enableMinimumCornerWidgetSize(true);
49 49 }
50 50
51 51 ui->tabWidget->removeTab(index);
52 52 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
53 53
54 54 };
55 55
56 56 ui->tabWidget->setTabsClosable(true);
57 57
58 58 connect(addTabViewButton, &QToolButton::clicked, addTabView);
59 59 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
60 60
61 61 // Adds default tab
62 62 addTabView();
63 63 }
64 64
65 65 VisualizationWidget::~VisualizationWidget()
66 66 {
67 67 delete ui;
68 68 }
69 69
70 70 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
71 71 {
72 72 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
73 73 // lambda function (in the constructor)
74 74 }
75 75
76 76 VisualizationTabWidget *VisualizationWidget::createTab()
77 77 {
78 78 }
79 79
80 80 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
81 81 {
82 82 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
83 83 // lambda function (in the constructor)
84 84 }
85 85
86 86 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
87 87 {
88 88 if (visitor) {
89 89 visitor->visitEnter(this);
90 90
91 91 // Apply visitor for tab children
92 92 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
93 93 // Widgets different from tabs are not visited (no action)
94 94 if (auto visualizationTabWidget
95 95 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
96 96 visualizationTabWidget->accept(visitor);
97 97 }
98 98 }
99 99
100 100 visitor->visitLeave(this);
101 101 }
102 102 else {
103 103 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
104 104 }
105 105 }
106 106
107 107 bool VisualizationWidget::canDrop(const Variable &variable) const
108 108 {
109 109 // The main widget can never accomodate a variable
110 110 Q_UNUSED(variable);
111 111 return false;
112 112 }
113 113
114 void VisualizationWidget::close()
115 {
116 // The main view cannot be directly closed.
117 return;
118 }
119
120 114 QString VisualizationWidget::name() const
121 115 {
122 116 return QStringLiteral("MainView");
123 117 }
124 118
125 119 void VisualizationWidget::attachVariableMenu(QMenu *menu,
126 120 std::shared_ptr<Variable> variable) noexcept
127 121 {
128 122 // Generates the actions that make it possible to visualize the variable
129 123 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
130 124 accept(&generateVariableMenuOperation);
131 125 }
@@ -1,100 +1,94
1 1 #include "Visualization/VisualizationZoneWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "ui_VisualizationZoneWidget.h"
4 4
5 5 #include "Visualization/VisualizationGraphWidget.h"
6 6
7 7 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
8 8
9 9 namespace {
10 10
11 11 /// Generates a default name for a new graph, according to the number of graphs already displayed in
12 12 /// the zone
13 13 QString defaultGraphName(const QLayout &layout)
14 14 {
15 15 auto count = 0;
16 16 for (auto i = 0; i < layout.count(); ++i) {
17 17 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
18 18 count++;
19 19 }
20 20 }
21 21
22 22 return QObject::tr("Graph %1").arg(count + 1);
23 23 }
24 24
25 25 } // namespace
26 26
27 27 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
28 28 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
29 29 {
30 30 ui->setupUi(this);
31 31
32 32 ui->zoneNameLabel->setText(name);
33 33 }
34 34
35 35 VisualizationZoneWidget::~VisualizationZoneWidget()
36 36 {
37 37 delete ui;
38 38 }
39 39
40 40 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
41 41 {
42 42 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
43 43 }
44 44
45 45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
46 46 {
47 47 auto graphWidget = new VisualizationGraphWidget{
48 48 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
49 49 this->addGraph(graphWidget);
50 50
51 51 graphWidget->addVariable(variable);
52 52
53 53 return graphWidget;
54 54 }
55 55
56 56 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
57 57 {
58 58 }
59 59
60 60 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
61 61 {
62 62 if (visitor) {
63 63 visitor->visitEnter(this);
64 64
65 65 // Apply visitor to graph children
66 66 auto layout = ui->visualizationZoneFrame->layout();
67 67 for (auto i = 0; i < layout->count(); ++i) {
68 68 if (auto item = layout->itemAt(i)) {
69 69 // Widgets different from graphs are not visited (no action)
70 70 if (auto visualizationGraphWidget
71 71 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
72 72 visualizationGraphWidget->accept(visitor);
73 73 }
74 74 }
75 75 }
76 76
77 77 visitor->visitLeave(this);
78 78 }
79 79 else {
80 80 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
81 81 }
82 82 }
83 83
84 84 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
85 85 {
86 86 // A tab can always accomodate a variable
87 87 Q_UNUSED(variable);
88 88 return true;
89 89 }
90 90
91 void VisualizationZoneWidget::close()
92 {
93 // The main view cannot be directly closed.
94 return;
95 }
96
97 91 QString VisualizationZoneWidget::name() const
98 92 {
99 93 return ui->zoneNameLabel->text();
100 94 }
General Comments 0
You need to be logged in to leave comments. Login now