##// END OF EJS Templates
Merge pull request 169 from SCIQLOP-Initialisation develop...
perrinel -
r301:870a641b8528 merge
parent child
Show More
@@ -0,0 +1,37
1 #ifndef SCIQLOP_VARIABLEMENUHEADERWIDGET_H
2 #define SCIQLOP_VARIABLEMENUHEADERWIDGET_H
3
4 #include <QLoggingCategory>
5 #include <QWidget>
6
7 #include <memory>
8
9 namespace Ui {
10 class VariableMenuHeaderWidget;
11 } // Ui
12
13 class Variable;
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget)
16
17 /**
18 * @brief The VariableMenuHeaderWidget class represents the widget used as a header of a menu in the
19 * variable inspector
20 * @sa VariableInspectorWidget
21 */
22 class VariableMenuHeaderWidget : public QWidget {
23 public:
24 /**
25 * Ctor
26 * @param variables the list of variables used to generate the header
27 * @param parent the parent widget
28 */
29 explicit VariableMenuHeaderWidget(const QVector<std::shared_ptr<Variable> > &variables,
30 QWidget *parent = 0);
31 virtual ~VariableMenuHeaderWidget() noexcept;
32
33 private:
34 Ui::VariableMenuHeaderWidget *ui;
35 };
36
37 #endif // SCIQLOP_VARIABLEMENUHEADERWIDGET_H
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,38
1 #include "Variable/VariableMenuHeaderWidget.h"
2 #include "Variable/Variable.h"
3
4 #include <ui_VariableMenuHeaderWidget.h>
5
6 Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget")
7
8 VariableMenuHeaderWidget::VariableMenuHeaderWidget(
9 const QVector<std::shared_ptr<Variable> > &variables, QWidget *parent)
10 : QWidget{parent}, ui{new Ui::VariableMenuHeaderWidget}
11 {
12 ui->setupUi(this);
13
14 // Generates label according to the state of the variables. The label contains :
15 // - the variable name if there is only one variable in the list
16 // - 'x variables' where x is the number of variables otherwise
17 const auto nbVariables = variables.size();
18 if (nbVariables == 1) {
19 if (auto variable = variables.first()) {
20 ui->label->setText(variable->name());
21 }
22 else {
23 qCCritical(LOG_VariableMenuHeaderWidget())
24 << tr("Can't get the name of the variable : variable is null");
25 }
26 }
27 else if (nbVariables > 1) {
28 ui->label->setText(tr("%1 variables").arg(nbVariables));
29 }
30 else {
31 ui->label->setText(tr("No variable"));
32 }
33 }
34
35 VariableMenuHeaderWidget::~VariableMenuHeaderWidget() noexcept
36 {
37 delete ui;
38 }
@@ -0,0 +1,31
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>VariableMenuHeaderWidget</class>
4 <widget class="QWidget" name="VariableMenuHeaderWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>110</width>
10 <height>34</height>
11 </rect>
12 </property>
13 <layout class="QGridLayout" name="gridLayout">
14 <item row="0" column="0">
15 <widget class="QLabel" name="label">
16 <property name="styleSheet">
17 <string notr="true">background-color: rgba(127, 127, 127, 127);</string>
18 </property>
19 <property name="text">
20 <string>TextLabel</string>
21 </property>
22 <property name="alignment">
23 <set>Qt::AlignCenter</set>
24 </property>
25 </widget>
26 </item>
27 </layout>
28 </widget>
29 <resources/>
30 <connections/>
31 </ui>
@@ -189,9 +189,11 MainWindow::MainWindow(QWidget *parent)
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
190 // The order of connections is also important, since it determines the order in which each
190 // The order of connections is also important, since it determines the order in which each
191 // widget will attach its menu
191 // widget will attach its menu
192 connect(m_Ui->variableInspectorWidget,
192 connect(
193 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view,
193 m_Ui->variableInspectorWidget,
194 SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection);
194 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
195 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 Qt::DirectConnection);
195
197
196 /* QLopGUI::registerMenuBar(menuBar());
198 /* QLopGUI::registerMenuBar(menuBar());
197 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
199 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
@@ -44,9 +44,9 public:
44 * @remarks this method is only available for a unidimensional ArrayData
44 * @remarks this method is only available for a unidimensional ArrayData
45 */
45 */
46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
47 QVector<double> data() const noexcept
47 const QVector<double> &data() const noexcept
48 {
48 {
49 return m_Data.at(0);
49 return m_Data[0];
50 }
50 }
51
51
52 /**
52 /**
@@ -61,10 +61,10 public:
61
61
62 // TODO Comment
62 // TODO Comment
63 template <int D = Dim, typename = std::enable_if_t<D == 1> >
63 template <int D = Dim, typename = std::enable_if_t<D == 1> >
64 void merge(ArrayData<1> *arrayData)
64 void merge(const ArrayData<1> &arrayData)
65 {
65 {
66 if (!m_Data.empty()) {
66 if (!m_Data.empty()) {
67 m_Data[0] += arrayData->data();
67 m_Data[0] += arrayData.data();
68 }
68 }
69 }
69 }
70
70
@@ -40,8 +40,8 public:
40 void merge(IDataSeries *dataSeries) override
40 void merge(IDataSeries *dataSeries) override
41 {
41 {
42 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
42 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
43 m_XAxisData->merge(dimDataSeries->xAxisData().get());
43 m_XAxisData->merge(*dimDataSeries->xAxisData());
44 m_ValuesData->merge(dimDataSeries->valuesData().get());
44 m_ValuesData->merge(*dimDataSeries->valuesData());
45 }
45 }
46 else {
46 else {
47 qCWarning(LOG_DataSeries())
47 qCWarning(LOG_DataSeries())
@@ -2,6 +2,10
2 #define SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
3
4 #include <QObject>
4 #include <QObject>
5
6 #include <QDateTime>
7 #include <QDebug>
8
5 /**
9 /**
6 * @brief The SqpDateTime struct holds the information of time parameters
10 * @brief The SqpDateTime struct holds the information of time parameters
7 */
11 */
@@ -22,6 +26,16 struct SqpDateTime {
22 }
26 }
23 };
27 };
24
28
29 inline QDebug operator<<(QDebug d, SqpDateTime obj)
30 {
31 auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000);
32 auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000);
33
34 // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
35 d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
36 return d;
37 }
38
25 // Required for using shared_ptr in signals/slots
39 // Required for using shared_ptr in signals/slots
26 Q_DECLARE_METATYPE(SqpDateTime)
40 Q_DECLARE_METATYPE(SqpDateTime)
27
41
@@ -42,7 +42,7 public slots:
42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43
43
44 signals:
44 signals:
45 void dataCacheUpdated();
45 void updated();
46
46
47
47
48 private:
48 private:
@@ -5,10 +5,15
5
5
6 #include <Data/SqpDateTime.h>
6 #include <Data/SqpDateTime.h>
7
7
8 #include <QLoggingCategory>
9
8 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
9
11
10 class Variable;
12 class Variable;
11
13
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
15
16
12 /// This class aims to store in the cache all of the dateTime already requested to the variable.
17 /// This class aims to store in the cache all of the dateTime already requested to the variable.
13 class VariableCacheController : public QObject {
18 class VariableCacheController : public QObject {
14 Q_OBJECT
19 Q_OBJECT
@@ -25,6 +30,8 public:
25
30
26 QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept;
31 QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept;
27
32
33 void displayCache(std::shared_ptr<Variable> variable);
34
28 private:
35 private:
29 class VariableCacheControllerPrivate;
36 class VariableCacheControllerPrivate;
30 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
37 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
@@ -30,14 +30,13 public:
30 void setTimeController(TimeController *timeController) noexcept;
30 void setTimeController(TimeController *timeController) noexcept;
31
31
32
32
33 /// Request the data loading of the variable whithin dateTime
34 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
35
36 signals:
33 signals:
37 /// Signal emitted when a variable has been created
34 /// Signal emitted when a variable has been created
38 void variableCreated(std::shared_ptr<Variable> variable);
35 void variableCreated(std::shared_ptr<Variable> variable);
39
36
40 public slots:
37 public slots:
38 /// Request the data loading of the variable whithin dateTime
39 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
41 /**
40 /**
42 * Creates a new variable and adds it to the model
41 * Creates a new variable and adds it to the model
43 * @param name the name of the new variable
42 * @param name the name of the new variable
@@ -67,7 +67,7 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
67 if (impl->m_DataSeries) {
67 if (impl->m_DataSeries) {
68 impl->m_DataSeries->merge(dataSeries.get());
68 impl->m_DataSeries->merge(dataSeries.get());
69
69
70 emit dataCacheUpdated();
70 emit updated();
71 }
71 }
72 }
72 }
73
73
@@ -3,6 +3,8
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4 #include <unordered_map>
4 #include <unordered_map>
5
5
6 Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController")
7
6 struct VariableCacheController::VariableCacheControllerPrivate {
8 struct VariableCacheController::VariableCacheControllerPrivate {
7
9
8 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> >
10 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> >
@@ -156,15 +158,26 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataBySt
156 // ts localised between to interval: let's localized te
158 // ts localised between to interval: let's localized te
157 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart);
159 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart);
158 }
160 }
159 else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) {
161 else if (currentTStart < currentDateTimeI.m_TEnd) {
162 if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) {
160 // ts not localised before the current interval: we need to look at the next interval
163 // ts not localised before the current interval: we need to look at the next interval
161 // We can assume now current tstart is the last interval tend, because data between them are
164 // We can assume now current tstart is the last interval tend, because data between them
165 // are
162 // in the cache
166 // in the cache
163 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
167 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
164 currentDateTimeI.m_TEnd);
168 currentDateTimeI.m_TEnd);
165 }
169 }
170 }
166 else {
171 else {
167 // ts not localised before the current interval: we need to look at the next interval
172 // ts not localised before the current interval: we need to look at the next interval
168 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
173 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
169 }
174 }
170 }
175 }
176
177
178 void VariableCacheController::displayCache(std::shared_ptr<Variable> variable)
179 {
180 auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.at(variable);
181 qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache")
182 << variableDateTimeList;
183 }
@@ -9,7 +9,6
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QElapsedTimer>
13 #include <QMutex>
12 #include <QMutex>
14 #include <QThread>
13 #include <QThread>
15
14
@@ -112,7 +111,7 void VariableController::createVariable(const QString &name,
112 }
111 }
113
112
114
113
115 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable,
114 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
116 const SqpDateTime &dateTime)
115 const SqpDateTime &dateTime)
117 {
116 {
118 // we want to load data of the variable for the dateTime.
117 // we want to load data of the variable for the dateTime.
@@ -120,25 +119,19 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable,
120 // For the other, we ask the provider to give them.
119 // For the other, we ask the provider to give them.
121 if (variable) {
120 if (variable) {
122
121
123 QElapsedTimer timer;
124 timer.start();
125 qCInfo(LOG_VariableController()) << "TORM: The slow s0 operation took" << timer.elapsed()
126 << "milliseconds";
127 auto dateTimeListNotInCache
122 auto dateTimeListNotInCache
128 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
123 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
129 qCInfo(LOG_VariableController()) << "TORM: The slow s1 operation took" << timer.elapsed()
130 << "milliseconds";
131
124
125 if (!dateTimeListNotInCache.empty()) {
132 // Ask the provider for each data on the dateTimeListNotInCache
126 // Ask the provider for each data on the dateTimeListNotInCache
133 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache);
127 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
134
128 std::move(dateTimeListNotInCache));
135 qCInfo(LOG_VariableController()) << "TORM: The slow s2 operation took" << timer.elapsed()
136 << "milliseconds";
137
138 // store in cache
129 // store in cache
139 impl->m_VariableCacheController->addDateTime(variable, dateTime);
130 impl->m_VariableCacheController->addDateTime(variable, dateTime);
140 qCInfo(LOG_VariableController()) << "TORM: The slow s3 operation took" << timer.elapsed()
131 }
141 << "milliseconds";
132 else {
133 emit variable->updated();
134 }
142 }
135 }
143 else {
136 else {
144 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
137 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
@@ -241,6 +241,16 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
241 notInCacheSqp = notInCach.at(1);
241 notInCacheSqp = notInCach.at(1);
242 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
242 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
243 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
243 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
244
245
246 // 12th case ts0 < ts < te0
247 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}};
248 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}};
249 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
250 static_cast<double>(te.toMSecsSinceEpoch())};
251
252 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
253 QCOMPARE(notInCach.size(), 0);
244 }
254 }
245
255
246
256
@@ -29,14 +29,15 public:
29
29
30 signals:
30 signals:
31 /**
31 /**
32 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
32 * Signal emitted before a menu concerning variables is displayed. It is used for other widgets
33 * to complete the menu.
33 * to complete the menu.
34 * @param tableMenu the menu to be completed
34 * @param tableMenu the menu to be completed
35 * @param variable the variable concerned by the menu
35 * @param variables the variables concerned by the menu
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
37 * in Qt :: DirectConnection
37 * in Qt :: DirectConnection
38 */
38 */
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu,
40 const QVector<std::shared_ptr<Variable> > &variables);
40
41
41 private:
42 private:
42 Ui::VariableInspectorWidget *ui;
43 Ui::VariableInspectorWidget *ui;
@@ -13,6 +13,7
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14
14
15 class QCPRange;
15 class QCPRange;
16 class SqpDateTime;
16 class Variable;
17 class Variable;
17
18
18 namespace Ui {
19 namespace Ui {
@@ -37,6 +38,9 public:
37
38
38 void updateDisplay(std::shared_ptr<Variable> variable);
39 void updateDisplay(std::shared_ptr<Variable> variable);
39
40
41 signals:
42 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
43
40
44
41 private:
45 private:
42 Ui::VisualizationGraphWidget *ui;
46 Ui::VisualizationGraphWidget *ui;
@@ -30,11 +30,12 public:
30
30
31 public slots:
31 public slots:
32 /**
32 /**
33 * Attaches to a menu the menu relating to the visualization of a variable
33 * Attaches to a menu the menu relative to the visualization of variables
34 * @param menu the parent menu of the generated menu
34 * @param menu the parent menu of the generated menu
35 * @param variable the variable for which to generate the menu
35 * @param variables the variables for which to generate the menu
36 */
36 */
37 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
37 void attachVariableMenu(QMenu *menu,
38 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
38
39
39 private:
40 private:
40 Ui::VisualizationWidget *ui;
41 Ui::VisualizationWidget *ui;
@@ -1,5 +1,6
1 <RCC>
1 <RCC>
2 <qresource prefix="/">
2 <qresource prefix="/">
3 <file>icones/delete.png</file>
3 <file>icones/openInspector.png</file>
4 <file>icones/openInspector.png</file>
4 <file>icones/next.png</file>
5 <file>icones/next.png</file>
5 <file>icones/previous.png</file>
6 <file>icones/previous.png</file>
@@ -1,10 +1,12
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableInspectorWidget.h>
2 #include <Variable/VariableInspectorWidget.h>
3 #include <Variable/VariableMenuHeaderWidget.h>
3 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
4
5
5 #include <ui_VariableInspectorWidget.h>
6 #include <ui_VariableInspectorWidget.h>
6
7
7 #include <QSortFilterProxyModel>
8 #include <QSortFilterProxyModel>
9 #include <QWidgetAction>
8
10
9 #include <SqpApplication.h>
11 #include <SqpApplication.h>
10
12
@@ -29,6 +31,10 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
31 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
32 }
31
33
34 // Sets selection options
35 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
36 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
37
32 // Connection to show a menu when right clicking on the tree
38 // Connection to show a menu when right clicking on the tree
33 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
39 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
34 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
40 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
@@ -42,24 +48,41 VariableInspectorWidget::~VariableInspectorWidget()
42
48
43 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
49 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
44 {
50 {
45 auto selectedIndex = ui->tableView->indexAt(pos);
51 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
46 if (selectedIndex.isValid()) {
52
47 // Gets the model to retrieve the underlying selected variable
53 // Gets the model to retrieve the underlying selected variables
48 auto model = sqpApp->variableController().variableModel();
54 auto model = sqpApp->variableController().variableModel();
49 if (auto selectedVariable = model->variable(selectedIndex.row())) {
55 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
56 for (const auto &selectedRow : qAsConst(selectedRows)) {
57 if (auto selectedVariable = model->variable(selectedRow.row())) {
58 selectedVariables.push_back(selectedVariable);
59 }
60 }
61
50 QMenu tableMenu{};
62 QMenu tableMenu{};
51
63
52 // Emit a signal so that potential receivers can populate the menu before displaying it
64 // Emits a signal so that potential receivers can populate the menu before displaying it
53 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable);
65 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
66
67 // Adds menu-specific actions
68 if (!selectedVariables.isEmpty()) {
69 // 'Delete' action
70 auto deleteFun = []() {
71 /// @todo ALX : call variable deletion
72 };
73
74 tableMenu.addSeparator();
75 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
76 }
54
77
55 if (!tableMenu.isEmpty()) {
78 if (!tableMenu.isEmpty()) {
79 // Generates menu header (inserted before first action)
80 auto firstAction = tableMenu.actions().first();
81 auto headerAction = new QWidgetAction{&tableMenu};
82 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
83 tableMenu.insertAction(firstAction, headerAction);
84
85 // Displays menu
56 tableMenu.exec(mapToGlobal(pos));
86 tableMenu.exec(mapToGlobal(pos));
57 }
87 }
58 }
88 }
59 }
60 else {
61 qCCritical(LOG_VariableInspectorWidget())
62 << tr("Can't display menu : invalid index (%1;%2)")
63 .arg(selectedIndex.row(), selectedIndex.column());
64 }
65 }
@@ -37,30 +37,32 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
37 timer.start();
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
39 // Clean the graph
40 qCDebug(LOG_VisualizationGraphHelper()) << "The slow s1 operation took" << timer.elapsed()
41 << "milliseconds";
42 // NAIVE approch
40 // NAIVE approch
43 const auto &xData = scalarSeries.xAxisData()->data();
41 const auto &xData = scalarSeries.xAxisData()->data();
44 const auto &valuesData = scalarSeries.valuesData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
45
46 auto xValue = QVector<double>();
46 auto xValue = QVector<double>(count);
47 auto vValue = QVector<double>();
47 auto vValue = QVector<double>(count);
48
48
49 const auto count = xData.count();
49 int n = 0;
50 auto ite = 0;
51 for (auto i = 0; i < count; ++i) {
50 for (auto i = 0; i < count; ++i) {
52 const auto x = xData.at(i);
51 const auto x = xData[i];
53 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
52 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
54 xValue.push_back(x);
53 xValue[n] = x;
55 vValue.push_back(valuesData.at(i));
54 vValue[n] = valuesData[i];
56 ++ite;
55 ++n;
57 }
56 }
58 }
57 }
59
58
60 qcpGraph->setData(xValue, vValue);
59 xValue.resize(n);
60 vValue.resize(n);
61
61
62 qCDebug(LOG_VisualizationGraphHelper()) << "The slow s2 operation took" << timer.elapsed()
62 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
63 << "milliseconds";
63 << xValue.count();
64
65 qcpGraph->setData(xValue, vValue);
64 }
66 }
65 else {
67 else {
66 /// @todo DEBUG
68 /// @todo DEBUG
@@ -57,6 +57,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
59 &VisualizationGraphWidget::onGraphMenuRequested);
59 &VisualizationGraphWidget::onGraphMenuRequested);
60
61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
62 &VariableController::onRequestDataLoading);
60 }
63 }
61
64
62
65
@@ -74,7 +77,7 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
74 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
75 }
78 }
76
79
77 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
78 }
81 }
79
82
80 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
83 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
@@ -142,9 +145,6 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
142 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
145 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
143
146
144 auto variable = it->first;
147 auto variable = it->first;
145 qCInfo(LOG_VisualizationGraphWidget())
146 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
147 << variable->dataSeries()->xAxisData()->size();
148 auto dateTime = SqpDateTime{t2.lower, t2.upper};
148 auto dateTime = SqpDateTime{t2.lower, t2.upper};
149
149
150 if (!variable->contains(dateTime)) {
150 if (!variable->contains(dateTime)) {
@@ -179,8 +179,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
179 variable->setDateTime(dateTime);
179 variable->setDateTime(dateTime);
180
180
181 // CHangement detected, we need to ask controller to request data loading
181 // CHangement detected, we need to ask controller to request data loading
182 sqpApp->variableController().requestDataLoading(variable,
182 emit requestDataLoading(variable, variableDateTimeWithTolerance);
183 variableDateTimeWithTolerance);
184 }
183 }
185 }
184 }
186 }
185 }
@@ -106,10 +106,24 QString VisualizationWidget::name() const
106 return QStringLiteral("MainView");
106 return QStringLiteral("MainView");
107 }
107 }
108
108
109 void VisualizationWidget::attachVariableMenu(QMenu *menu,
109 void VisualizationWidget::attachVariableMenu(
110 std::shared_ptr<Variable> variable) noexcept
110 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
111 {
112 // Menu is generated only if there is a single variable
113 if (variables.size() == 1) {
114 if (auto variable = variables.first()) {
112 // Generates the actions that make it possible to visualize the variable
115 // Generates the actions that make it possible to visualize the variable
113 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
116 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
114 accept(&generateVariableMenuOperation);
117 accept(&generateVariableMenuOperation);
115 }
118 }
119 else {
120 qCCritical(LOG_VisualizationWidget()) << tr(
121 "Can't generate the menu relative to the visualization: the variable is null");
122 }
123 }
124 else {
125 qCDebug(LOG_VisualizationWidget())
126 << tr("No generation of the menu related to the visualization: several variables are "
127 "selected");
128 }
129 }
@@ -5,6 +5,8
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 #include <QDateTime>
9
8 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
9
11
10 std::unique_ptr<IDataSeries>
12 std::unique_ptr<IDataSeries>
@@ -16,6 +18,7 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
16 auto start = dateTime.m_TStart;
18 auto start = dateTime.m_TStart;
17 auto end = dateTime.m_TEnd;
19 auto end = dateTime.m_TEnd;
18
20
21
19 // We assure that timerange is valid
22 // We assure that timerange is valid
20 if (end < start) {
23 if (end < start) {
21 std::swap(start, end);
24 std::swap(start, end);
@@ -47,10 +50,12 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeLis
47
50
48 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
51 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
49 {
52 {
53 auto dataIndex = 0;
50
54
51 // Gets the timerange from the parameters
55 // Gets the timerange from the parameters
52 auto start = dateTime.m_TStart;
56 double freq = 100.0;
53 auto end = dateTime.m_TEnd;
57 double start = dateTime.m_TStart * freq; // 100 htz
58 double end = dateTime.m_TEnd * freq; // 100 htz
54
59
55 // We assure that timerange is valid
60 // We assure that timerange is valid
56 if (end < start) {
61 if (end < start) {
@@ -61,11 +66,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTi
61 auto scalarSeries
66 auto scalarSeries
62 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
67 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
63
68
64 auto dataIndex = 0;
65 for (auto time = start; time < end; ++time, ++dataIndex) {
69 for (auto time = start; time < end; ++time, ++dataIndex) {
66 scalarSeries->setData(dataIndex, time, std::cos(time));
70 const auto timeOnFreq = time / freq;
71 scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq));
67 }
72 }
68
69
70 return scalarSeries;
73 return scalarSeries;
71 }
74 }
General Comments 0
You need to be logged in to leave comments. Login now