##// END OF EJS Templates
Fixes after review
Alexandre Leroux -
r188:a02da6065266
parent child
Show More
@@ -1,50 +1,50
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Data/ArrayData.h>
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
5 #include <Data/IDataSeries.h>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 /**
9 /**
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
11 *
11 *
12 * It proposes to set a dimension for the values ​​data
12 * It proposes to set a dimension for the values ​​data
13 *
13 *
14 * @tparam Dim The dimension of the values data
14 * @tparam Dim The dimension of the values data
15 *
15 *
16 */
16 */
17 template <int Dim>
17 template <int Dim>
18 class DataSeries : public IDataSeries {
18 class DataSeries : public IDataSeries {
19 public:
19 public:
20 /// @sa IDataSeries::xAxisData()
20 /// @sa IDataSeries::xAxisData()
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
22
22
23 /// @sa IDataSeries::xAxisUnit()
23 /// @sa IDataSeries::xAxisUnit()
24 Unit xAxisUnit() const override { return m_XAxisUnit; }
24 Unit xAxisUnit() const override { return m_XAxisUnit; }
25
25
26 /// @return the values dataset
26 /// @return the values dataset
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
28
28
29 /// @sa IDataSeries::valuesUnit()
29 /// @sa IDataSeries::valuesUnit()
30 Unit valuesUnit() const override { return m_ValuesUnit; }
30 Unit valuesUnit() const override { return m_ValuesUnit; }
31
31
32 protected:
32 protected:
33 /// Protected ctor (DataSeries is abstract)
33 /// Protected ctor (DataSeries is abstract)
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, Unit xAxisUnit,
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
35 std::shared_ptr<ArrayData<Dim> > valuesData, Unit valuesUnit)
35 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
36 : m_XAxisData{xAxisData},
36 : m_XAxisData{xAxisData},
37 m_XAxisUnit{std::move(xAxisUnit)},
37 m_XAxisUnit{xAxisUnit},
38 m_ValuesData{valuesData},
38 m_ValuesData{valuesData},
39 m_ValuesUnit{std::move(valuesUnit)}
39 m_ValuesUnit{valuesUnit}
40 {
40 {
41 }
41 }
42
42
43 private:
43 private:
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
45 Unit m_XAxisUnit;
45 Unit m_XAxisUnit;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
47 Unit m_ValuesUnit;
47 Unit m_ValuesUnit;
48 };
48 };
49
49
50 #endif // SCIQLOP_DATASERIES_H
50 #endif // SCIQLOP_DATASERIES_H
@@ -1,28 +1,28
1 #ifndef SCIQLOP_SCALARSERIES_H
1 #ifndef SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
3
3
4 #include <Data/DataSeries.h>
4 #include <Data/DataSeries.h>
5
5
6 /**
6 /**
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
8 */
8 */
9 class ScalarSeries : public DataSeries<1> {
9 class ScalarSeries : public DataSeries<1> {
10 public:
10 public:
11 /**
11 /**
12 * Ctor
12 * Ctor
13 * @param size the number of data the series will hold
13 * @param size the number of data the series will hold
14 * @param xAxisUnit x-axis unit
14 * @param xAxisUnit x-axis unit
15 * @param valuesUnit values unit
15 * @param valuesUnit values unit
16 */
16 */
17 explicit ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit);
17 explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit);
18
18
19 /**
19 /**
20 * Sets data for a specific index. The index has to be valid to be effective
20 * Sets data for a specific index. The index has to be valid to be effective
21 * @param index the index to which the data will be set
21 * @param index the index to which the data will be set
22 * @param x the x-axis data
22 * @param x the x-axis data
23 * @param value the value data
23 * @param value the value data
24 */
24 */
25 void setData(int index, double x, double value) noexcept;
25 void setData(int index, double x, double value) noexcept;
26 };
26 };
27
27
28 #endif // SCIQLOP_SCALARSERIES_H
28 #endif // SCIQLOP_SCALARSERIES_H
@@ -1,13 +1,13
1 #include <Data/ScalarSeries.h>
1 #include <Data/ScalarSeries.h>
2
2
3 ScalarSeries::ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit)
3 ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit)
4 : DataSeries{std::make_shared<ArrayData<1> >(size), std::move(xAxisUnit),
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
5 std::make_shared<ArrayData<1> >(size), std::move(valuesUnit)}
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
6 {
6 {
7 }
7 }
8
8
9 void ScalarSeries::setData(int index, double x, double value) noexcept
9 void ScalarSeries::setData(int index, double x, double value) noexcept
10 {
10 {
11 xAxisData()->setData(index, x);
11 xAxisData()->setData(index, x);
12 valuesData()->setData(index, value);
12 valuesData()->setData(index, value);
13 }
13 }
@@ -1,117 +1,117
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationTabWidget.h"
3 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationZoneWidget.h"
4 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/qcustomplot.h"
5 #include "Visualization/qcustomplot.h"
6
6
7 #include "ui_VisualizationWidget.h"
7 #include "ui_VisualizationWidget.h"
8
8
9 #include <QToolButton>
9 #include <QToolButton>
10
10
11 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
11 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
12
12
13 VisualizationWidget::VisualizationWidget(QWidget *parent)
13 VisualizationWidget::VisualizationWidget(QWidget *parent)
14 : QWidget{parent}, ui{new Ui::VisualizationWidget}
14 : QWidget{parent}, ui{new Ui::VisualizationWidget}
15 {
15 {
16 ui->setupUi(this);
16 ui->setupUi(this);
17
17
18 auto addTabViewButton = new QToolButton{ui->tabWidget};
18 auto addTabViewButton = new QToolButton{ui->tabWidget};
19 addTabViewButton->setText(tr("Add View"));
19 addTabViewButton->setText(tr("Add View"));
20 addTabViewButton->setCursor(Qt::ArrowCursor);
20 addTabViewButton->setCursor(Qt::ArrowCursor);
21 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
21 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
22
22
23 auto enableMinimunCornerWidgetSize = [this](bool enable) {
23 auto enableMinimumCornerWidgetSize = [this](bool enable) {
24
24
25 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
25 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
26 auto width = enable ? tabViewCornerWidget->width() : 0;
26 auto width = enable ? tabViewCornerWidget->width() : 0;
27 auto height = enable ? tabViewCornerWidget->height() : 0;
27 auto height = enable ? tabViewCornerWidget->height() : 0;
28 tabViewCornerWidget->setMinimumHeight(height);
28 tabViewCornerWidget->setMinimumHeight(height);
29 tabViewCornerWidget->setMinimumWidth(width);
29 tabViewCornerWidget->setMinimumWidth(width);
30 ui->tabWidget->setMinimumHeight(height);
30 ui->tabWidget->setMinimumHeight(height);
31 ui->tabWidget->setMinimumWidth(width);
31 ui->tabWidget->setMinimumWidth(width);
32 };
32 };
33
33
34 auto addTabView = [this, enableMinimunCornerWidgetSize]() {
34 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
35 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
35 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
36 QString("View %1").arg(ui->tabWidget->count() + 1));
36 QString("View %1").arg(ui->tabWidget->count() + 1));
37 if (ui->tabWidget->count() > 0) {
37 if (ui->tabWidget->count() > 0) {
38 enableMinimunCornerWidgetSize(false);
38 enableMinimumCornerWidgetSize(false);
39 }
39 }
40 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
40 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
41 };
41 };
42
42
43 auto removeTabView = [this, enableMinimunCornerWidgetSize](int index) {
43 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
44 if (ui->tabWidget->count() == 1) {
44 if (ui->tabWidget->count() == 1) {
45 enableMinimunCornerWidgetSize(true);
45 enableMinimumCornerWidgetSize(true);
46 }
46 }
47
47
48 ui->tabWidget->removeTab(index);
48 ui->tabWidget->removeTab(index);
49 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
49 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
50
50
51 };
51 };
52
52
53 ui->tabWidget->setTabsClosable(true);
53 ui->tabWidget->setTabsClosable(true);
54
54
55 connect(addTabViewButton, &QToolButton::clicked, addTabView);
55 connect(addTabViewButton, &QToolButton::clicked, addTabView);
56 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
56 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
57 }
57 }
58
58
59 VisualizationWidget::~VisualizationWidget()
59 VisualizationWidget::~VisualizationWidget()
60 {
60 {
61 delete ui;
61 delete ui;
62 }
62 }
63
63
64 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
64 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
65 {
65 {
66 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
66 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
67 // lambda function (in the constructor)
67 // lambda function (in the constructor)
68 }
68 }
69
69
70 VisualizationTabWidget *VisualizationWidget::createTab()
70 VisualizationTabWidget *VisualizationWidget::createTab()
71 {
71 {
72 }
72 }
73
73
74 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
74 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
75 {
75 {
76 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
76 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
77 // lambda function (in the constructor)
77 // lambda function (in the constructor)
78 }
78 }
79
79
80 void VisualizationWidget::accept(IVisualizationWidget *visitor)
80 void VisualizationWidget::accept(IVisualizationWidget *visitor)
81 {
81 {
82 // TODO: manage the visitor
82 // TODO: manage the visitor
83 }
83 }
84
84
85 void VisualizationWidget::close()
85 void VisualizationWidget::close()
86 {
86 {
87 // The main view cannot be directly closed.
87 // The main view cannot be directly closed.
88 return;
88 return;
89 }
89 }
90
90
91 QString VisualizationWidget::name() const
91 QString VisualizationWidget::name() const
92 {
92 {
93 return QStringLiteral("MainView");
93 return QStringLiteral("MainView");
94 }
94 }
95
95
96 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
96 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
97 {
97 {
98 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
98 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
99 if (auto newZone = currentTab->createZone()) {
99 if (auto newZone = currentTab->createZone()) {
100 if (auto newGraph = newZone->createGraph()) {
100 if (auto newGraph = newZone->createGraph()) {
101 newGraph->addVariable(variable);
101 newGraph->addVariable(variable);
102 }
102 }
103 else {
103 else {
104 qCDebug(LOG_VisualizationWidget())
104 qCCritical(LOG_VisualizationWidget())
105 << tr("Can't display the variable : can't create the graph");
105 << tr("Can't display the variable : can't create the graph");
106 }
106 }
107 }
107 }
108 else {
108 else {
109 qCDebug(LOG_VisualizationWidget())
109 qCCritical(LOG_VisualizationWidget())
110 << tr("Can't display the variable : can't create a new zone in the current tab");
110 << tr("Can't display the variable : can't create a new zone in the current tab");
111 }
111 }
112 }
112 }
113 else {
113 else {
114 qCDebug(LOG_VisualizationWidget())
114 qCCritical(LOG_VisualizationWidget())
115 << tr("Can't display the variable : there is no current tab");
115 << tr("Can't display the variable : there is no current tab");
116 }
116 }
117 }
117 }
General Comments 0
You need to be logged in to leave comments. Login now