From e54ef254edaa578636e61b77c913b0ad0b9231ce 2017-06-28 12:46:45 From: leroux Date: 2017-06-28 12:46:45 Subject: [PATCH] Merge pull request #161 from SCIQLOP-Initialisation develop Develop --- diff --git a/app/src/MainWindow.cpp b/app/src/MainWindow.cpp index 2e6506b..3e6f828 100644 --- a/app/src/MainWindow.cpp +++ b/app/src/MainWindow.cpp @@ -182,10 +182,16 @@ MainWindow::MainWindow(QWidget *parent) connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), SLOT(onTimeToUpdate(SqpDateTime))); - // Variable + // Widgets / widgets connections qRegisterMetaType >(); - connect(&sqpApp->visualizationController(), SIGNAL(variableCreated(std::shared_ptr)), - m_Ui->view, SLOT(displayVariable(std::shared_ptr))); + + // For the following connections, we use DirectConnection to allow each widget that can + // potentially attach a menu to the variable's menu to do so before this menu is displayed. + // The order of connections is also important, since it determines the order in which each + // widget will attach its menu + connect(m_Ui->variableInspectorWidget, + SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr)), m_Ui->view, + SLOT(attachVariableMenu(QMenu *, std::shared_ptr)), Qt::DirectConnection); /* QLopGUI::registerMenuBar(menuBar()); this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); diff --git a/cmake/sciqlop_package.cmake b/cmake/sciqlop_package.cmake index 4337a56..3067f34 100644 --- a/cmake/sciqlop_package.cmake +++ b/cmake/sciqlop_package.cmake @@ -26,11 +26,11 @@ SET (CPACK_PACKAGE_VERSION_MAJOR "${SCIQLOP_VERSION_MAJOR}") SET (CPACK_PACKAGE_VERSION_MINOR "${SCIQLOP_VERSION_MINOR}") SET (CPACK_PACKAGE_VERSION_PATCH "${SCIQLOP_VERSION_PATCH}${SCIQLOP_VERSION_SUFFIX}") SET (CPACK_PACKAGE_VERSION "${SCIQLOP_VERSION}") -SET (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE) +SET (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING) SET (CPACK_PACKAGE_CONTACT "nicolas.aunai@lpp.polytechnique.fr") SET(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) # SET(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_SOURCE_DIR}/WARN.txt) -SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) +SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING) # SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}-${PROJECT_VERSION}) SET(FULLBUILD ON) diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index 6232a63..31825bd 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -4,8 +4,15 @@ #include #include +#include + #include + +Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries) +Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries") + + /** * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. * @@ -36,6 +43,10 @@ public: m_XAxisData->merge(dimDataSeries->xAxisData().get()); m_ValuesData->merge(dimDataSeries->valuesData().get()); } + else { + qCWarning(LOG_DataSeries()) + << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); + } } protected: diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index 5d025cf..cde7f5e 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -31,7 +31,7 @@ public: virtual void requestDataLoading(const QVector &dateTimeList) = 0; signals: - void dataProvided(std::shared_ptr dateSerie, SqpDateTime dateTime); + void dataProvided(std::shared_ptr dateSerie, const SqpDateTime &dateTime); }; // Required for using shared_ptr in signals/slots Q_DECLARE_METATYPE(std::shared_ptr) diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index c233bde..7ac0c1c 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -33,7 +33,7 @@ public: /// @return the data of the variable, nullptr if there is no data IDataSeries *dataSeries() const noexcept; - bool contains(SqpDateTime dateTime); + bool contains(const SqpDateTime &dateTime); void setDataSeries(std::unique_ptr dataSeries) noexcept; public slots: diff --git a/core/include/Variable/VariableCacheController.h b/core/include/Variable/VariableCacheController.h index edcc65d..2fd48b2 100644 --- a/core/include/Variable/VariableCacheController.h +++ b/core/include/Variable/VariableCacheController.h @@ -9,7 +9,7 @@ class Variable; -/// This class aims to store in the cash all of the dateTime already requested to the variable. +/// This class aims to store in the cache all of the dateTime already requested to the variable. class VariableCacheController : public QObject { Q_OBJECT public: diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index 490f43b..07f60fc 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -32,6 +32,8 @@ public: createVariable(const QString &name, const SqpDateTime &dateTime, std::unique_ptr defaultDataSeries) noexcept; + std::shared_ptr variable(int index) const; + // /////////////////////////// // // QAbstractTableModel methods // // /////////////////////////// // diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 43864d5..9db3be1 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -71,7 +71,7 @@ IDataSeries *Variable::dataSeries() const noexcept return impl->m_DataSeries.get(); } -bool Variable::contains(SqpDateTime dateTime) +bool Variable::contains(const SqpDateTime &dateTime) { if (!impl->m_DateTime.contains(dateTime)) { // The current variable dateTime isn't enough to display the dateTime requested. diff --git a/core/src/Variable/VariableCacheController.cpp b/core/src/Variable/VariableCacheController.cpp index 63209ce..34cb514 100644 --- a/core/src/Variable/VariableCacheController.cpp +++ b/core/src/Variable/VariableCacheController.cpp @@ -23,7 +23,7 @@ struct VariableCacheController::VariableCacheControllerPrivate { VariableCacheController::VariableCacheController(QObject *parent) - : QObject(parent), impl{spimpl::make_unique_impl()} + : QObject{parent}, impl{spimpl::make_unique_impl()} { } @@ -48,9 +48,8 @@ void VariableCacheController::addDateTime(std::shared_ptr variable, // will be compared to the next interval. The old one is remove from the list // C: if it is superior, we do the same with the next interval of the list - int cacheIndex = 0; impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), - cacheIndex); + 0); } } } @@ -94,7 +93,6 @@ void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse // The compared one is < to current one compared, we can insert it dateTimeList.insert(cacheIndex, dateTime); } - else if (dateTime.m_TStart > currentDateTime.m_TEnd) { // The compared one is > to current one compared we can comparet if to the next one addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); @@ -153,11 +151,10 @@ void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataBySt } auto currentDateTimeI = dateTimeList[cacheIndex]; - auto cacheIndexJ = cacheIndex; if (currentTStart < currentDateTimeI.m_TStart) { // ts localised between to interval: let's localized te - addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndexJ, currentTStart); + addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); } else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) { // ts not localised before the current interval: we need to look at the next interval diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 54124b6..90d1368 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -122,22 +122,22 @@ void VariableController::requestDataLoading(std::shared_ptr variable, QElapsedTimer timer; timer.start(); - qCInfo(LOG_VariableController()) << "The slow s0 operation took" << timer.elapsed() + qCInfo(LOG_VariableController()) << "TORM: The slow s0 operation took" << timer.elapsed() << "milliseconds"; auto dateTimeListNotInCache = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); - qCInfo(LOG_VariableController()) << "The slow s1 operation took" << timer.elapsed() + qCInfo(LOG_VariableController()) << "TORM: The slow s1 operation took" << timer.elapsed() << "milliseconds"; // Ask the provider for each data on the dateTimeListNotInCache impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache); - qCInfo(LOG_VariableController()) << "The slow s2 operation took" << timer.elapsed() + qCInfo(LOG_VariableController()) << "TORM: The slow s2 operation took" << timer.elapsed() << "milliseconds"; // store in cache impl->m_VariableCacheController->addDateTime(variable, dateTime); - qCInfo(LOG_VariableController()) << "The slow s3 operation took" << timer.elapsed() + qCInfo(LOG_VariableController()) << "TORM: The slow s3 operation took" << timer.elapsed() << "milliseconds"; } else { diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 601f3cb..044b2a9 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -44,6 +44,11 @@ VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, return variable; } +std::shared_ptr VariableModel::variable(int index) const +{ + return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; +} + int VariableModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); diff --git a/core/tests/Variable/TestVariableCacheController.cpp b/core/tests/Variable/TestVariableCacheController.cpp index ab5e726..37e357d 100644 --- a/core/tests/Variable/TestVariableCacheController.cpp +++ b/core/tests/Variable/TestVariableCacheController.cpp @@ -51,9 +51,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - auto notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + auto notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // second case ts < ts0 && ts0 < te <= te0 @@ -66,9 +66,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); // 3th case ts < ts0 && te0 < te <= ts1 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; @@ -80,13 +80,13 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 2); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(1); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(1); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 4th case ts < ts0 && ts1 < te <= te1 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; @@ -98,13 +98,13 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 2); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(1); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(1); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); // 5th case ts < ts0 && te3 < te ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; @@ -116,21 +116,21 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 4); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts0.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(1); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(1); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(2); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts2.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(2); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts2.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(3); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te2.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(3); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te2.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 6th case ts2 < ts @@ -143,9 +143,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 7th case ts = te0 && te < ts1 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; @@ -157,9 +157,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 8th case ts0 < ts < te0 && te < ts1 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; @@ -171,9 +171,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 9th case ts0 < ts < te0 && ts1 < te < te1 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; @@ -185,9 +185,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te0.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); // 10th case te1 < ts < te < ts2 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; @@ -199,9 +199,9 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 1); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 11th case te0 < ts < ts1 && te3 < te ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; @@ -213,17 +213,17 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 3); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(1); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts2.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(1); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts2.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(2); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te2.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(2); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te2.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); // 12th case te0 < ts < ts1 && te3 < te ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; @@ -234,13 +234,13 @@ void TestVariableCacheController::testProvideNotInCacheDateTimeList() notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); QCOMPARE(notInCach.size(), 2); - notInCashSqp = notInCach.first(); - QCOMPARE(notInCashSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.first(); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(ts.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(ts1.toMSecsSinceEpoch())); - notInCashSqp = notInCach.at(1); - QCOMPARE(notInCashSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); - QCOMPARE(notInCashSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); + notInCacheSqp = notInCach.at(1); + QCOMPARE(notInCacheSqp.m_TStart, static_cast(te1.toMSecsSinceEpoch())); + QCOMPARE(notInCacheSqp.m_TEnd, static_cast(te.toMSecsSinceEpoch())); } diff --git a/formatting/cmake/use_clangformat.cmake b/formatting/cmake/use_clangformat.cmake index 8daefc7..ce4bc89 100644 --- a/formatting/cmake/use_clangformat.cmake +++ b/formatting/cmake/use_clangformat.cmake @@ -91,7 +91,6 @@ FUNCTION(ADD_CLANGFORMAT_TARGETS) ENDFOREACH(item ${globs}) LIST(REMOVE_ITEM srcs ${UIS}) - message("format lang: ${srcs}" ) FOREACH (s ${srcs}) SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb}) IF(addToAll) diff --git a/gui/include/Variable/VariableInspectorWidget.h b/gui/include/Variable/VariableInspectorWidget.h index c4d5f41..cc6faee 100644 --- a/gui/include/Variable/VariableInspectorWidget.h +++ b/gui/include/Variable/VariableInspectorWidget.h @@ -1,8 +1,16 @@ #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H #define SCIQLOP_VARIABLEINSPECTORWIDGET_H +#include +#include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) + +class Variable; + namespace Ui { class VariableInspectorWidget; } // Ui @@ -19,8 +27,23 @@ public: explicit VariableInspectorWidget(QWidget *parent = 0); virtual ~VariableInspectorWidget(); +signals: + /** + * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets + * to complete the menu. + * @param tableMenu the menu to be completed + * @param variable the variable concerned by the menu + * @remarks To make the dynamic addition of menus work, the connections to this signal must be + * in Qt :: DirectConnection + */ + void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr variable); + private: Ui::VariableInspectorWidget *ui; + +private slots: + /// Slot called when right clicking on an variable in the table (displays a menu) + void onTableMenuRequested(const QPoint &pos) noexcept; }; #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H diff --git a/gui/include/Visualization/GraphPlottablesFactory.h b/gui/include/Visualization/VisualizationGraphHelper.h similarity index 80% rename from gui/include/Visualization/GraphPlottablesFactory.h rename to gui/include/Visualization/VisualizationGraphHelper.h index 35126e5..f8f5687 100644 --- a/gui/include/Visualization/GraphPlottablesFactory.h +++ b/gui/include/Visualization/VisualizationGraphHelper.h @@ -1,5 +1,5 @@ -#ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H -#define SCIQLOP_GRAPHPLOTTABLESFACTORY_H +#ifndef SCIQLOP_VISUALIZATIONGRAPHHELPER_H +#define SCIQLOP_VISUALIZATIONGRAPHHELPER_H #include @@ -8,7 +8,7 @@ #include -Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory) +Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphHelper) class IDataSeries; class QCPAbstractPlottable; @@ -16,10 +16,10 @@ class QCustomPlot; class Variable; /** - * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a + * @brief The VisualizationGraphHelper class aims to create the QCustomPlot components relative to a * variable, depending on the data series of this variable */ -struct GraphPlottablesFactory { +struct VisualizationGraphHelper { /** * Creates (if possible) the QCustomPlot components relative to the variable passed in * parameter, and adds these to the plot passed in parameter. @@ -35,4 +35,4 @@ struct GraphPlottablesFactory { const SqpDateTime &dateTime); }; -#endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H +#endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H diff --git a/gui/include/Visualization/VisualizationWidget.h b/gui/include/Visualization/VisualizationWidget.h index 52285c2..ca74bdf 100644 --- a/gui/include/Visualization/VisualizationWidget.h +++ b/gui/include/Visualization/VisualizationWidget.h @@ -8,6 +8,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) +class QMenu; class Variable; class VisualizationTabWidget; @@ -39,12 +40,11 @@ public: public slots: /** - * Displays a variable in a new graph of a new zone of the current tab - * @param variable the variable to display - * @todo this is a temporary method that will be replaced by own actions for each type of - * visualization widget + * Attaches to a menu the menu relating to the visualization of a variable + * @param menu the parent menu of the generated menu + * @param variable the variable for which to generate the menu */ - void displayVariable(std::shared_ptr variable) noexcept; + void attachVariableMenu(QMenu *menu, std::shared_ptr variable) noexcept; private: Ui::VisualizationWidget *ui; diff --git a/gui/src/Variable/VariableInspectorWidget.cpp b/gui/src/Variable/VariableInspectorWidget.cpp index 7a788b7..a31c7d0 100644 --- a/gui/src/Variable/VariableInspectorWidget.cpp +++ b/gui/src/Variable/VariableInspectorWidget.cpp @@ -8,6 +8,8 @@ #include +Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") + VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::VariableInspectorWidget} { @@ -18,9 +20,38 @@ VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); ui->tableView->setModel(sortFilterModel); + + // Connection to show a menu when right clicking on the tree + ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->tableView, &QTableView::customContextMenuRequested, this, + &VariableInspectorWidget::onTableMenuRequested); } VariableInspectorWidget::~VariableInspectorWidget() { delete ui; } + +void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept +{ + auto selectedIndex = ui->tableView->indexAt(pos); + if (selectedIndex.isValid()) { + // Gets the model to retrieve the underlying selected variable + auto model = sqpApp->variableController().variableModel(); + if (auto selectedVariable = model->variable(selectedIndex.row())) { + QMenu tableMenu{}; + + // Emit a signal so that potential receivers can populate the menu before displaying it + emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable); + + if (!tableMenu.isEmpty()) { + tableMenu.exec(mapToGlobal(pos)); + } + } + } + else { + qCCritical(LOG_VariableInspectorWidget()) + << tr("Can't display menu : invalid index (%1;%2)") + .arg(selectedIndex.row(), selectedIndex.column()); + } +} diff --git a/gui/src/Visualization/GraphPlottablesFactory.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp similarity index 90% rename from gui/src/Visualization/GraphPlottablesFactory.cpp rename to gui/src/Visualization/VisualizationGraphHelper.cpp index 3748d8f..f4a0122 100644 --- a/gui/src/Visualization/GraphPlottablesFactory.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -1,4 +1,4 @@ -#include "Visualization/GraphPlottablesFactory.h" +#include "Visualization/VisualizationGraphHelper.h" #include "Visualization/qcustomplot.h" #include @@ -7,7 +7,7 @@ #include -Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") +Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") namespace { @@ -37,8 +37,8 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie timer.start(); if (auto qcpGraph = dynamic_cast(component)) { // Clean the graph - qCDebug(LOG_GraphPlottablesFactory()) << "The slow s1 operation took" << timer.elapsed() - << "milliseconds"; + qCDebug(LOG_VisualizationGraphHelper()) << "The slow s1 operation took" << timer.elapsed() + << "milliseconds"; // NAIVE approch const auto &xData = scalarSeries.xAxisData()->data(); const auto &valuesData = scalarSeries.valuesData()->data(); @@ -59,8 +59,8 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie qcpGraph->setData(xValue, vValue); - qCDebug(LOG_GraphPlottablesFactory()) << "The slow s2 operation took" << timer.elapsed() - << "milliseconds"; + qCDebug(LOG_VisualizationGraphHelper()) << "The slow s2 operation took" << timer.elapsed() + << "milliseconds"; } else { /// @todo DEBUG @@ -99,7 +99,7 @@ QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QC plot.replot(); } else { - qCDebug(LOG_GraphPlottablesFactory()) + qCDebug(LOG_VisualizationGraphHelper()) << QObject::tr("Can't create graph for the scalar series"); } @@ -108,8 +108,8 @@ QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QC } // namespace -QVector GraphPlottablesFactory::create(std::shared_ptr variable, - QCustomPlot &plot) noexcept +QVector VisualizationGraphHelper::create(std::shared_ptr variable, + QCustomPlot &plot) noexcept { auto result = QVector{}; @@ -120,27 +120,27 @@ QVector GraphPlottablesFactory::create(std::shared_ptrdateTime())); } else { - qCDebug(LOG_GraphPlottablesFactory()) + qCDebug(LOG_VisualizationGraphHelper()) << QObject::tr("Can't create graph plottables : unmanaged data series type"); } } else { - qCDebug(LOG_GraphPlottablesFactory()) + qCDebug(LOG_VisualizationGraphHelper()) << QObject::tr("Can't create graph plottables : the variable is null"); } return result; } -void GraphPlottablesFactory::updateData(QVector plotableVect, - IDataSeries *dataSeries, const SqpDateTime &dateTime) +void VisualizationGraphHelper::updateData(QVector plotableVect, + IDataSeries *dataSeries, const SqpDateTime &dateTime) { if (auto scalarSeries = dynamic_cast(dataSeries)) { if (plotableVect.size() == 1) { updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); } else { - qCCritical(LOG_GraphPlottablesFactory()) << QObject::tr( + qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( "Can't update Data of a scalarSeries because there is not only one component " "associated"); } diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index c60b0f4..8f909b5 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -1,6 +1,6 @@ #include "Visualization/VisualizationGraphWidget.h" -#include "Visualization/GraphPlottablesFactory.h" #include "Visualization/IVisualizationWidgetVisitor.h" +#include "Visualization/VisualizationGraphHelper.h" #include "ui_VisualizationGraphWidget.h" #include @@ -61,7 +61,7 @@ VisualizationGraphWidget::~VisualizationGraphWidget() void VisualizationGraphWidget::addVariable(std::shared_ptr variable) { // Uses delegate to create the qcpplot components according to the variable - auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); + auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); for (auto createdPlottable : qAsConst(createdPlottables)) { impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); @@ -142,11 +142,19 @@ void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept void VisualizationGraphWidget::onDataCacheVariableUpdated() { + // NOTE: + // We don't want to call the method for each component of a variable unitarily, but for all + // its components at once (eg its three components in the case of a vector). + + // The unordered_multimap does not do this easily, so the question is whether to: + // - use an ordered_multimap and the algos of std to group the values by key + // - use a map (unique keys) and store as values directly the list of components + for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); it != impl->m_VariableToPlotMultiMap.cend(); ++it) { auto variable = it->first; - GraphPlottablesFactory::updateData(QVector{} << it->second, - variable->dataSeries(), variable->dateTime()); + VisualizationGraphHelper::updateData(QVector{} << it->second, + variable->dataSeries(), variable->dateTime()); } } @@ -160,6 +168,6 @@ void VisualizationGraphWidget::updateDisplay(std::shared_ptr variable) abstractPlotableVect.push_back(it->second); } - GraphPlottablesFactory::updateData(abstractPlotableVect, variable->dataSeries(), - variable->dateTime()); + VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), + variable->dateTime()); } diff --git a/gui/src/Visualization/VisualizationWidget.cpp b/gui/src/Visualization/VisualizationWidget.cpp index c0467e6..cccc592 100644 --- a/gui/src/Visualization/VisualizationWidget.cpp +++ b/gui/src/Visualization/VisualizationWidget.cpp @@ -3,6 +3,7 @@ #include "Visualization/VisualizationGraphWidget.h" #include "Visualization/VisualizationTabWidget.h" #include "Visualization/VisualizationZoneWidget.h" +#include "Visualization/operations/GenerateVariableMenuOperation.h" #include "Visualization/qcustomplot.h" #include "ui_VisualizationWidget.h" @@ -121,16 +122,10 @@ QString VisualizationWidget::name() const return QStringLiteral("MainView"); } -void VisualizationWidget::displayVariable(std::shared_ptr variable) noexcept +void VisualizationWidget::attachVariableMenu(QMenu *menu, + std::shared_ptr variable) noexcept { - if (auto currentTab = dynamic_cast(ui->tabWidget->currentWidget())) { - if (!currentTab->createZone(variable)) { - qCCritical(LOG_VisualizationWidget()) - << tr("Can't display the variable : can't create a new zone in the current tab"); - } - } - else { - qCCritical(LOG_VisualizationWidget()) - << tr("Can't display the variable : there is no current tab"); - } + // Generates the actions that make it possible to visualize the variable + auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; + accept(&generateVariableMenuOperation); } diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index d142c18..cd9ef2b 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -36,7 +36,7 @@ CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const void CosinusProvider::requestDataLoading(const QVector &dateTimeList) { // NOTE: Try to use multithread if possible - foreach (const auto &dateTime, dateTimeList) { + for (const auto &dateTime : dateTimeList) { auto scalarSeries = this->retrieveDataSeries(dateTime);