From 3c3e24550401a099ec6b2255f8e4cbda1634de8c 2019-03-20 21:28:32 From: Alexis Jeandet Date: 2019-03-20 21:28:32 Subject: [PATCH] Switched to new TS impl but quite broken! Signed-off-by: Alexis Jeandet --- diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2363e36..f6106d2 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -13,8 +13,14 @@ QT5_WRAP_UI(UiGenerated_SRCS add_executable(sciqlopapp WIN32 ${app_SRCS} ${UiGenerated_SRCS}) if(NOT BUILD_SHARED_LIBS) add_definitions(-DQT_STATICPLUGIN) - target_link_libraries(sciqlopapp mockplugin) - target_link_libraries(sciqlopapp amdaplugin) + if(BUILD_PLUGINS) + target_link_libraries(sciqlopapp mockplugin) + target_link_libraries(sciqlopapp amdaplugin) + endif() +endif() + +if(NOT BUILD_PLUGINS) + add_definitions(-DSQP_NO_PLUGINS) endif() target_link_libraries(sciqlopapp diff --git a/app/src/Main.cpp b/app/src/Main.cpp index 85599d2..9d75277 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -44,10 +44,12 @@ const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); int main(int argc, char* argv[]) { #ifdef QT_STATICPLUGIN +#ifndef SQP_NO_PLUGINS Q_IMPORT_PLUGIN(MockPlugin) Q_IMPORT_PLUGIN(AmdaPlugin) Q_INIT_RESOURCE(amdaresources); #endif +#endif Q_INIT_RESOURCE(sqpguiresources); SqpApplication::setOrganizationName("LPP"); diff --git a/core b/core index 00b9e6e..a8a4e48 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 00b9e6e4b7f57c09175c396576ac6e30f45a14ff +Subproject commit a8a4e48c21af5a28ad3f56582db7bbec0fe76978 diff --git a/gui/include/Variable/VariableInspectorWidget.h b/gui/include/Variable/VariableInspectorWidget.h index 9039107..51f5078 100644 --- a/gui/include/Variable/VariableInspectorWidget.h +++ b/gui/include/Variable/VariableInspectorWidget.h @@ -11,11 +11,12 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) -class Variable; +class Variable2; class QProgressBarItemDelegate; -namespace Ui { +namespace Ui +{ class VariableInspectorWidget; } // Ui @@ -24,11 +25,12 @@ class VariableInspectorWidget; * which it is possible to view the loaded variables, handle them or trigger their display in * visualization */ -class VariableInspectorWidget : public QWidget { +class VariableInspectorWidget : public QWidget +{ Q_OBJECT public: - explicit VariableInspectorWidget(QWidget *parent = 0); + explicit VariableInspectorWidget(QWidget* parent = 0); virtual ~VariableInspectorWidget(); signals: @@ -40,18 +42,18 @@ signals: * @remarks To make the dynamic addition of menus work, the connections to this signal must be * in Qt :: DirectConnection */ - void tableMenuAboutToBeDisplayed(QMenu *tableMenu, - const QVector > &variables); + void tableMenuAboutToBeDisplayed( + QMenu* tableMenu, const QVector>& variables); private: - Ui::VariableInspectorWidget *ui; + Ui::VariableInspectorWidget* ui; - QProgressBarItemDelegate *m_ProgressBarItemDelegate; + QProgressBarItemDelegate* m_ProgressBarItemDelegate; VariableModel2* m_model; private slots: /// Slot called when right clicking on an variable in the table (displays a menu) - void onTableMenuRequested(const QPoint &pos) noexcept; + void onTableMenuRequested(const QPoint& pos) noexcept; /// Refreshes instantly the variable view void refresh() noexcept; }; diff --git a/gui/include/Variable/VariableMenuHeaderWidget.h b/gui/include/Variable/VariableMenuHeaderWidget.h index 009b0c5..8823a19 100644 --- a/gui/include/Variable/VariableMenuHeaderWidget.h +++ b/gui/include/Variable/VariableMenuHeaderWidget.h @@ -6,11 +6,12 @@ #include -namespace Ui { +namespace Ui +{ class VariableMenuHeaderWidget; } // Ui -class Variable; +class Variable2; Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget) @@ -19,19 +20,20 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget) * variable inspector * @sa VariableInspectorWidget */ -class VariableMenuHeaderWidget : public QWidget { +class VariableMenuHeaderWidget : public QWidget +{ public: /** * Ctor * @param variables the list of variables used to generate the header * @param parent the parent widget */ - explicit VariableMenuHeaderWidget(const QVector > &variables, - QWidget *parent = 0); + explicit VariableMenuHeaderWidget( + const QVector>& variables, QWidget* parent = 0); virtual ~VariableMenuHeaderWidget() noexcept; private: - Ui::VariableMenuHeaderWidget *ui; + Ui::VariableMenuHeaderWidget* ui; }; #endif // SCIQLOP_VARIABLEMENUHEADERWIDGET_H diff --git a/gui/include/Visualization/AxisRenderingUtils.h b/gui/include/Visualization/AxisRenderingUtils.h index dbf1709..fc55deb 100644 --- a/gui/include/Visualization/AxisRenderingUtils.h +++ b/gui/include/Visualization/AxisRenderingUtils.h @@ -12,33 +12,35 @@ class IDataSeries; class QCPAxis; class QCustomPlot; class SqpColorScale; -class Variable; +class Variable2; /// Formats a data value according to the axis on which it is present -QString formatValue(double value, const QCPAxis &axis); +QString formatValue(double value, const QCPAxis& axis); /** * Helper used to handle axes rendering */ -struct IAxisHelper { +struct IAxisHelper +{ virtual ~IAxisHelper() noexcept = default; /// Set properties of the plot's axes and the color scale associated to plot passed as /// parameters /// @param plot the plot for which to set axe properties /// @param colorScale the color scale for which to set properties - virtual void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) = 0; + virtual void setProperties(QCustomPlot& plot, SqpColorScale& colorScale) = 0; /// Set the units of the plot's axes and the color scale associated to plot passed as /// parameters /// @param plot the plot for which to set axe units /// @param colorScale the color scale for which to set unit - virtual void setUnits(QCustomPlot &plot, SqpColorScale &colorScale) = 0; + virtual void setUnits(QCustomPlot& plot, SqpColorScale& colorScale) = 0; }; -struct IAxisHelperFactory { +struct IAxisHelperFactory +{ /// Creates IPlottablesHelper according to the type of data series a variable holds - static std::unique_ptr create(const Variable &variable) noexcept; + static std::unique_ptr create(Variable2& variable) noexcept; }; #endif // SCIQLOP_AXISRENDERINGUTILS_H diff --git a/gui/include/Visualization/IVariableContainer.h b/gui/include/Visualization/IVariableContainer.h index ac49faa..ce724d4 100644 --- a/gui/include/Visualization/IVariableContainer.h +++ b/gui/include/Visualization/IVariableContainer.h @@ -1,21 +1,22 @@ #ifndef SCIQLOP_IVARIABLECONTAINER_H #define SCIQLOP_IVARIABLECONTAINER_H -class Variable; +class Variable2; /** * @brief The IVariableContainer interface represents an UI object that can accommodate a variable */ -class IVariableContainer { +class IVariableContainer +{ public: virtual ~IVariableContainer() = default; /// Checks if the container can handle the variable passed in parameter - virtual bool canDrop(const Variable &variable) const = 0; + virtual bool canDrop(Variable2& variable) const = 0; /// Checks if the container contains the variable passed in parameter - virtual bool contains(const Variable &variable) const = 0; + virtual bool contains(Variable2& variable) const = 0; }; diff --git a/gui/include/Visualization/PlottablesRenderingUtils.h b/gui/include/Visualization/PlottablesRenderingUtils.h index 6c958d3..dd48360 100644 --- a/gui/include/Visualization/PlottablesRenderingUtils.h +++ b/gui/include/Visualization/PlottablesRenderingUtils.h @@ -13,22 +13,24 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils) class QCPColorScale; class QCustomPlot; -class Variable; +class Variable2; /** * Helper used to handle plottables rendering */ -struct IPlottablesHelper { +struct IPlottablesHelper +{ virtual ~IPlottablesHelper() noexcept = default; /// Set properties of the plottables passed as parameter /// @param plottables the plottables for which to set properties - virtual void setProperties(PlottablesMap &plottables) = 0; + virtual void setProperties(PlottablesMap& plottables) = 0; }; -struct IPlottablesHelperFactory { +struct IPlottablesHelperFactory +{ /// Creates IPlottablesHelper according to the type of data series a variable holds - static std::unique_ptr create(const Variable &variable) noexcept; + static std::unique_ptr create(Variable2& variable) noexcept; }; #endif // SCIQLOP_PLOTTABLESRENDERINGUTILS_H diff --git a/gui/include/Visualization/VisualizationGraphHelper.h b/gui/include/Visualization/VisualizationGraphHelper.h index 56f53de..be83d01 100644 --- a/gui/include/Visualization/VisualizationGraphHelper.h +++ b/gui/include/Visualization/VisualizationGraphHelper.h @@ -15,13 +15,14 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphHelper) class IDataSeries; class QCPAbstractPlottable; class QCustomPlot; -class Variable; +class Variable2; /** * @brief The VisualizationGraphHelper class aims to create the QCustomPlot components relative to a * variable, depending on the data series of this variable */ -struct VisualizationGraphHelper { +struct VisualizationGraphHelper +{ /** * Creates (if possible) the QCustomPlot components relative to the variable passed in * parameter, and adds these to the plot passed in parameter. @@ -30,12 +31,12 @@ struct VisualizationGraphHelper { * components. * @return the list of the components created */ - static PlottablesMap create(std::shared_ptr variable, QCustomPlot &plot) noexcept; + static PlottablesMap create(std::shared_ptr variable, QCustomPlot& plot) noexcept; - static void updateData(PlottablesMap &plottables, std::shared_ptr variable, - const DateTimeRange &dateTime); + static void updateData(PlottablesMap& plottables, std::shared_ptr variable, + const DateTimeRange& dateTime); - static void setYAxisRange(std::shared_ptr variable, QCustomPlot &plot) noexcept; + static void setYAxisRange(std::shared_ptr variable, QCustomPlot& plot) noexcept; }; #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H diff --git a/gui/include/Visualization/VisualizationGraphRenderingDelegate.h b/gui/include/Visualization/VisualizationGraphRenderingDelegate.h index f3a2bdf..46d805d 100644 --- a/gui/include/Visualization/VisualizationGraphRenderingDelegate.h +++ b/gui/include/Visualization/VisualizationGraphRenderingDelegate.h @@ -9,28 +9,29 @@ class IDataSeries; class QCustomPlot; class QMouseEvent; class Unit; -class Variable; +class Variable2; class VisualizationGraphWidget; -class VisualizationGraphRenderingDelegate { +class VisualizationGraphRenderingDelegate +{ public: /// Ctor /// @param graphWidget the graph widget to which the delegate is associated /// @remarks the graph widget must exist throughout the life cycle of the delegate - explicit VisualizationGraphRenderingDelegate(VisualizationGraphWidget &graphWidget); + explicit VisualizationGraphRenderingDelegate(VisualizationGraphWidget& graphWidget); - void onMouseDoubleClick(QMouseEvent *event) noexcept; - void updateTooltip(QMouseEvent *event) noexcept; + void onMouseDoubleClick(QMouseEvent* event) noexcept; + void updateTooltip(QMouseEvent* event) noexcept; /// Updates rendering when data of plot changed void onPlotUpdated() noexcept; /// Sets units of the plot's axes according to the properties of the variable passed as /// parameter - void setAxesUnits(const Variable &variable) noexcept; + void setAxesUnits(Variable2& variable) noexcept; /// Sets graph properties of the plottables passed as parameter, from the variable that /// generated these - void setGraphProperties(const Variable &variable, PlottablesMap &plottables) noexcept; + void setGraphProperties(Variable2& variable, PlottablesMap& plottables) noexcept; /// Shows or hides graph overlay (name, close button, etc.) diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index e1d64d6..c935e8e 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -5,8 +5,8 @@ #include "Visualization/VisualizationDragWidget.h" #include -#include #include +#include #include @@ -18,18 +18,20 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) class QCPRange; class QCustomPlot; -class Variable; +class Variable2; class VisualizationWidget; class VisualizationZoneWidget; class VisualizationSelectionZoneItem; -namespace Ui { +namespace Ui +{ class VisualizationGraphWidget; } // namespace Ui /// Defines options that can be associated with the graph -enum GraphFlag { - DisableAll = 0x0, ///< Disables acquisition and synchronization +enum GraphFlag +{ + DisableAll = 0x0, ///< Disables acquisition and synchronization EnableAcquisition = 0x1, ///< When this flag is set, the change of the graph's range leads to /// the acquisition of data EnableSynchronization = 0x2, ///< When this flag is set, the change of the graph's range causes @@ -41,66 +43,68 @@ enum GraphFlag { Q_DECLARE_FLAGS(GraphFlags, GraphFlag) Q_DECLARE_OPERATORS_FOR_FLAGS(GraphFlags) -class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { +class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget +{ Q_OBJECT friend class QCustomPlotSynchronizer; friend class VisualizationGraphRenderingDelegate; public: - explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); + explicit VisualizationGraphWidget(const QString& name = {}, QWidget* parent = 0); virtual ~VisualizationGraphWidget(); /// Returns the VisualizationZoneWidget which contains the graph or nullptr - VisualizationZoneWidget *parentZoneWidget() const noexcept; + VisualizationZoneWidget* parentZoneWidget() const noexcept; /// Returns the main VisualizationWidget which contains the graph or nullptr - VisualizationWidget *parentVisualizationWidget() const; + VisualizationWidget* parentVisualizationWidget() const; /// Sets graph options void setFlags(GraphFlags flags); - void addVariable(std::shared_ptr variable, DateTimeRange range); + void addVariable(std::shared_ptr variable, DateTimeRange range); /// Removes a variable from the graph - void removeVariable(std::shared_ptr variable) noexcept; + void removeVariable(std::shared_ptr variable) noexcept; /// Returns the list of all variables used in the graph - std::vector > variables() const; + std::vector> variables() const; /// Sets the y-axis range based on the data of a variable - void setYRange(std::shared_ptr variable); + void setYRange(std::shared_ptr variable); DateTimeRange graphRange() const noexcept; - void setGraphRange(const DateTimeRange &range, bool updateVar=false, bool forward=false); + void setGraphRange(const DateTimeRange& range, bool updateVar = false, bool forward = false); void setAutoRangeOnVariableInitialization(bool value); // Zones /// Returns the ranges of all the selection zones on the graph QVector selectionZoneRanges() const; /// Adds new selection zones in the graph - void addSelectionZones(const QVector &ranges); + void addSelectionZones(const QVector& ranges); /// Adds a new selection zone in the graph - VisualizationSelectionZoneItem *addSelectionZone(const QString &name, const DateTimeRange &range); + VisualizationSelectionZoneItem* addSelectionZone( + const QString& name, const DateTimeRange& range); /// Removes the specified selection zone - void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone); + void removeSelectionZone(VisualizationSelectionZoneItem* selectionZone); /// Undo the last zoom done with a zoom box void undoZoom(); - void zoom(double factor, int center, Qt::Orientation orientation, bool forward=true); - void move(double factor, Qt::Orientation orientation, bool forward=true); - void move(double dx, double dy, bool forward=true); - void transform(const DateTimeRangeTransformation& tranformation, bool forward=true); + void zoom(double factor, int center, Qt::Orientation orientation, bool forward = true); + void move(double factor, Qt::Orientation orientation, bool forward = true); + void move(double dx, double dy, bool forward = true); + void transform(const DateTimeRangeTransformation& tranformation, bool forward = true); // IVisualizationWidget interface - void accept(IVisualizationWidgetVisitor *visitor) override; - bool canDrop(const Variable &variable) const override; - bool contains(const Variable &variable) const override; + void accept(IVisualizationWidgetVisitor* visitor) override; + bool canDrop(Variable2& variable) const override; + bool contains(Variable2& variable) const override; QString name() const override; // VisualisationDragWidget - QMimeData *mimeData(const QPoint &position) const override; - QPixmap customDragPixmap(const QPoint &dragPosition) override; + QMimeData* mimeData(const QPoint& position) const override; + QPixmap customDragPixmap(const QPoint& dragPosition) override; bool isDragAllowed() const override; void highlightForMerge(bool highlighted) override; @@ -117,65 +121,65 @@ public: void removeHorizontalCursor(); signals: - void synchronize(const DateTimeRange &range, const DateTimeRange &oldRange); - void changeRange(const std::shared_ptr& variable, const DateTimeRange &range); + void synchronize(const DateTimeRange& range, const DateTimeRange& oldRange); + void changeRange(const std::shared_ptr& variable, const DateTimeRange& range); /// Signal emitted when the variable is about to be removed from the graph - void variableAboutToBeRemoved(std::shared_ptr var); + void variableAboutToBeRemoved(std::shared_ptr var); /// Signal emitted when the variable has been added to the graph - void variableAdded(std::shared_ptr var); + void variableAdded(std::shared_ptr var); - void zoom_sig(double factor, int center, Qt::Orientation orientation, bool forward=true); - void move_sig(double factor, Qt::Orientation orientation, bool forward=true); - void move_sig(double dx, double dy, bool forward=true); - void transform_sig(const DateTimeRangeTransformation& tranformation, bool forward=true); - void setrange_sig(const DateTimeRange& range, bool updateVar=false, bool forward=true); + void zoom_sig(double factor, int center, Qt::Orientation orientation, bool forward = true); + void move_sig(double factor, Qt::Orientation orientation, bool forward = true); + void move_sig(double dx, double dy, bool forward = true); + void transform_sig(const DateTimeRangeTransformation& tranformation, bool forward = true); + void setrange_sig(const DateTimeRange& range, bool updateVar = false, bool forward = true); protected: - void closeEvent(QCloseEvent *event) override; - void enterEvent(QEvent *event) override; - void leaveEvent(QEvent *event) override; - void wheelEvent(QWheelEvent * event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseDoubleClickEvent(QMouseEvent *event) override; - void keyReleaseEvent(QKeyEvent * event) override; - void keyPressEvent(QKeyEvent * event) override; - - QCustomPlot &plot() const noexcept; + void closeEvent(QCloseEvent* event) override; + void enterEvent(QEvent* event) override; + void leaveEvent(QEvent* event) override; + void wheelEvent(QWheelEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; + void mouseDoubleClickEvent(QMouseEvent* event) override; + void keyReleaseEvent(QKeyEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; + + QCustomPlot& plot() const noexcept; private: - Ui::VisualizationGraphWidget *ui; + Ui::VisualizationGraphWidget* ui; class VisualizationGraphWidgetPrivate; spimpl::unique_impl_ptr impl; private slots: /// Slot called when right clicking on the graph (displays a menu) - void onGraphMenuRequested(const QPoint &pos) noexcept; + void onGraphMenuRequested(const QPoint& pos) noexcept; /// Rescale the X axe to range parameter - // void onRangeChanged(const QCPRange &newRange, const QCPRange &oldRange); + // void onRangeChanged(const QCPRange &newRange, const QCPRange &oldRange); /// Slot called when a mouse double click was made - void onMouseDoubleClick(QMouseEvent *event) noexcept; + void onMouseDoubleClick(QMouseEvent* event) noexcept; /// Slot called when a mouse move was made - void onMouseMove(QMouseEvent *event) noexcept; + void onMouseMove(QMouseEvent* event) noexcept; /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done - void onMouseWheel(QWheelEvent *event) noexcept; + void onMouseWheel(QWheelEvent* event) noexcept; /// Slot called when a mouse press was made, to activate the calibration of a graph - void onMousePress(QMouseEvent *event) noexcept; + void onMousePress(QMouseEvent* event) noexcept; /// Slot called when a mouse release was made, to deactivate the calibration of a graph - void onMouseRelease(QMouseEvent *event) noexcept; + void onMouseRelease(QMouseEvent* event) noexcept; void onDataCacheVariableUpdated(); - void onUpdateVarDisplaying(std::shared_ptr variable, const DateTimeRange &range); + void onUpdateVarDisplaying(std::shared_ptr variable, const DateTimeRange& range); void variableUpdated(QUuid id); - void variableDeleted(const std::shared_ptr&); + void variableDeleted(const std::shared_ptr&); }; #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H diff --git a/gui/include/Visualization/VisualizationTabWidget.h b/gui/include/Visualization/VisualizationTabWidget.h index a9f8db8..f840f8b 100644 --- a/gui/include/Visualization/VisualizationTabWidget.h +++ b/gui/include/Visualization/VisualizationTabWidget.h @@ -14,29 +14,31 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) class Variable; class VisualizationZoneWidget; -namespace Ui { +namespace Ui +{ class VisualizationTabWidget; } // namespace Ui -class VisualizationTabWidget : public QWidget, public IVisualizationWidget { +class VisualizationTabWidget : public QWidget, public IVisualizationWidget +{ Q_OBJECT public: - explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0); + explicit VisualizationTabWidget(const QString& name = {}, QWidget* parent = 0); virtual ~VisualizationTabWidget(); /// Adds a zone widget - void addZone(VisualizationZoneWidget *zoneWidget); + void addZone(VisualizationZoneWidget* zoneWidget); /// Inserts a zone widget at the specified position - void insertZone(int index, VisualizationZoneWidget *zoneWidget); + void insertZone(int index, VisualizationZoneWidget* zoneWidget); /// Returns the list of zone widget names in the order they are displayed QStringList availableZoneWidgets() const; /// Returns the zone with the specified name. /// If multiple zone with the same name exist, the first one is returned. - VisualizationZoneWidget *getZoneWithName(const QString &zoneName); + VisualizationZoneWidget* getZoneWithName(const QString& zoneName); /** * Creates a zone using a variable. The variable will be displayed in a new graph of the new @@ -44,7 +46,7 @@ public: * @param variable the variable for which to create the zone * @return the pointer to the created zone */ - VisualizationZoneWidget *createZone(std::shared_ptr variable); + VisualizationZoneWidget* createZone(std::shared_ptr variable); /** * Creates a zone using a list of variables. The variables will be displayed in a new graph of @@ -53,36 +55,36 @@ public: * @param index The index where the zone should be inserted in the layout * @return the pointer to the created zone */ - VisualizationZoneWidget *createZone(const std::vector > &variables, - int index); + VisualizationZoneWidget* createZone( + const std::vector>& variables, int index); /** * Creates a zone which is empty (no variables). The zone is inserted at the specified index. * @param index The index where the zone should be inserted in the layout * @return the pointer to the created zone */ - VisualizationZoneWidget *createEmptyZone(int index); + VisualizationZoneWidget* createEmptyZone(int index); // IVisualizationWidget interface - void accept(IVisualizationWidgetVisitor *visitor) override; - bool canDrop(const Variable &variable) const override; - bool contains(const Variable &variable) const override; + void accept(IVisualizationWidgetVisitor* visitor) override; + bool canDrop(Variable2& variable) const override; + bool contains(Variable2& variable) const override; QString name() const override; protected: - void closeEvent(QCloseEvent *event) override; + void closeEvent(QCloseEvent* event) override; private: /// @return the layout of tab in which zones are added - QLayout &tabLayout() const noexcept; + QLayout& tabLayout() const noexcept; - Ui::VisualizationTabWidget *ui; + Ui::VisualizationTabWidget* ui; class VisualizationTabWidgetPrivate; spimpl::unique_impl_ptr impl; private slots: - void dropMimeData(int index, const QMimeData *mimeData); + void dropMimeData(int index, const QMimeData* mimeData); }; #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H diff --git a/gui/include/Visualization/VisualizationWidget.h b/gui/include/Visualization/VisualizationWidget.h index 955f10b..88592a7 100644 --- a/gui/include/Visualization/VisualizationWidget.h +++ b/gui/include/Visualization/VisualizationWidget.h @@ -12,30 +12,32 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) class QMenu; -class Variable; +class Variable2; class VisualizationTabWidget; class VisualizationSelectionZoneManager; -namespace Ui { +namespace Ui +{ class VisualizationWidget; } // namespace Ui -class VisualizationWidget : public QWidget, public IVisualizationWidget { +class VisualizationWidget : public QWidget, public IVisualizationWidget +{ Q_OBJECT public: - explicit VisualizationWidget(QWidget *parent = 0); + explicit VisualizationWidget(QWidget* parent = 0); virtual ~VisualizationWidget(); /// Returns the class which manage the selection of selection zone across the visualization - VisualizationSelectionZoneManager &selectionZoneManager() const; + VisualizationSelectionZoneManager& selectionZoneManager() const; - VisualizationTabWidget *currentTabWidget() const; + VisualizationTabWidget* currentTabWidget() const; // IVisualizationWidget interface - void accept(IVisualizationWidgetVisitor *visitor) override; - bool canDrop(const Variable &variable) const override; - bool contains(const Variable &variable) const override; + void accept(IVisualizationWidgetVisitor* visitor) override; + bool canDrop(Variable2& variable) const override; + bool contains(Variable2& variable) const override; QString name() const override; public slots: @@ -44,19 +46,19 @@ public slots: * @param menu the parent menu of the generated menu * @param variables the variables for which to generate the menu */ - void attachVariableMenu(QMenu *menu, - const QVector > &variables) noexcept; + void attachVariableMenu( + QMenu* menu, const QVector>& variables) noexcept; /// Slot called when a variable is about to be deleted from SciQlop - void onVariableAboutToBeDeleted(std::shared_ptr variable) noexcept; + void onVariableAboutToBeDeleted(std::shared_ptr variable) noexcept; - void onRangeChanged(std::shared_ptr variable, const DateTimeRange &range) noexcept; + void onRangeChanged(std::shared_ptr variable, const DateTimeRange& range) noexcept; protected: - void closeEvent(QCloseEvent *event) override; + void closeEvent(QCloseEvent* event) override; private: - Ui::VisualizationWidget *ui; + Ui::VisualizationWidget* ui; class VisualizationWidgetPrivate; spimpl::unique_impl_ptr impl; diff --git a/gui/include/Visualization/VisualizationZoneWidget.h b/gui/include/Visualization/VisualizationZoneWidget.h index 7b5216a..462e1ea 100644 --- a/gui/include/Visualization/VisualizationZoneWidget.h +++ b/gui/include/Visualization/VisualizationZoneWidget.h @@ -14,29 +14,31 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget) -namespace Ui { +namespace Ui +{ class VisualizationZoneWidget; } // namespace Ui -class Variable; +class Variable2; class VisualizationGraphWidget; -class VisualizationZoneWidget : public VisualizationDragWidget, public IVisualizationWidget { +class VisualizationZoneWidget : public VisualizationDragWidget, public IVisualizationWidget +{ Q_OBJECT public: - explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); + explicit VisualizationZoneWidget(const QString& name = {}, QWidget* parent = 0); virtual ~VisualizationZoneWidget(); /// Sets the range of the zone, only works if there is at least one graph in the zone /// Note: calibrations between graphs are lost. - void setZoneRange(const DateTimeRange &range); + void setZoneRange(const DateTimeRange& range); /// Adds a graph widget - void addGraph(VisualizationGraphWidget *graphWidget); + void addGraph(VisualizationGraphWidget* graphWidget); /// Inserts a graph widget - void insertGraph(int index, VisualizationGraphWidget *graphWidget); + void insertGraph(int index, VisualizationGraphWidget* graphWidget); /** * Creates a graph using a variable. The variable will be displayed in the new graph. @@ -44,7 +46,7 @@ public: * @param variable the variable for which to create the graph * @return the pointer to the created graph */ - VisualizationGraphWidget *createGraph(std::shared_ptr variable); + VisualizationGraphWidget* createGraph(std::shared_ptr variable); /** * Creates a graph using a variable. The variable will be displayed in the new graph. @@ -53,7 +55,7 @@ public: * @param index The index where the graph should be inserted in the layout * @return the pointer to the created graph */ - VisualizationGraphWidget *createGraph(std::shared_ptr variable, int index); + VisualizationGraphWidget* createGraph(std::shared_ptr variable, int index); /** * Creates a graph using a list of variables. The variables will be displayed in the new graph. @@ -62,45 +64,45 @@ public: * @param index The index where the graph should be inserted in the layout * @return the pointer to the created graph */ - VisualizationGraphWidget *createGraph( std::vector > variables, - int index); + VisualizationGraphWidget* createGraph( + std::vector> variables, int index); /// Returns the first graph in the zone or nullptr if there is no graph inside - VisualizationGraphWidget *firstGraph() const; + VisualizationGraphWidget* firstGraph() const; /// Closes all graphes inside the zone void closeAllGraphs(); // IVisualizationWidget interface - void accept(IVisualizationWidgetVisitor *visitor) override; - bool canDrop(const Variable &variable) const override; - bool contains(const Variable &variable) const override; + void accept(IVisualizationWidgetVisitor* visitor) override; + bool canDrop(Variable2& variable) const override; + bool contains(Variable2& variable) const override; QString name() const override; // VisualisationDragWidget - QMimeData *mimeData(const QPoint &position) const override; + QMimeData* mimeData(const QPoint& position) const override; bool isDragAllowed() const override; - void notifyMouseMoveInGraph(const QPointF &graphPosition, const QPointF &plotPosition, - VisualizationGraphWidget *graphWidget); - void notifyMouseLeaveGraph(VisualizationGraphWidget *graphWidget); + void notifyMouseMoveInGraph(const QPointF& graphPosition, const QPointF& plotPosition, + VisualizationGraphWidget* graphWidget); + void notifyMouseLeaveGraph(VisualizationGraphWidget* graphWidget); protected: - void closeEvent(QCloseEvent *event) override; + void closeEvent(QCloseEvent* event) override; private: - Ui::VisualizationZoneWidget *ui; + Ui::VisualizationZoneWidget* ui; class VisualizationZoneWidgetPrivate; spimpl::unique_impl_ptr impl; private slots: - void onVariableAdded(std::shared_ptr variable); + void onVariableAdded(std::shared_ptr variable); /// Slot called when a variable is about to be removed from a graph contained in the zone - void onVariableAboutToBeRemoved(std::shared_ptr variable); + void onVariableAboutToBeRemoved(std::shared_ptr variable); - void dropMimeData(int index, const QMimeData *mimeData); - void dropMimeDataOnGraph(VisualizationDragWidget *dragWidget, const QMimeData *mimeData); + void dropMimeData(int index, const QMimeData* mimeData); + void dropMimeDataOnGraph(VisualizationDragWidget* dragWidget, const QMimeData* mimeData); }; #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H diff --git a/gui/include/Visualization/operations/FindVariableOperation.h b/gui/include/Visualization/operations/FindVariableOperation.h index afad39e..711f9d5 100644 --- a/gui/include/Visualization/operations/FindVariableOperation.h +++ b/gui/include/Visualization/operations/FindVariableOperation.h @@ -8,31 +8,32 @@ #include class IVisualizationWidget; -class Variable; +class Variable2; /** * @brief The FindVariableOperation class defines an operation that traverses all of visualization * widgets to determine which ones contain the variable passed as parameter. The result of the * operation is the list of widgets that contain the variable. */ -class FindVariableOperation : public IVisualizationWidgetVisitor { +class FindVariableOperation : public IVisualizationWidgetVisitor +{ public: /** * Ctor * @param variable the variable to find */ - explicit FindVariableOperation(std::shared_ptr variable); + explicit FindVariableOperation(std::shared_ptr variable); - void visitEnter(VisualizationWidget *widget) override final; - void visitLeave(VisualizationWidget *widget) override final; - void visitEnter(VisualizationTabWidget *tabWidget) override final; - void visitLeave(VisualizationTabWidget *tabWidget) override final; - void visitEnter(VisualizationZoneWidget *zoneWidget) override final; - void visitLeave(VisualizationZoneWidget *zoneWidget) override final; - void visit(VisualizationGraphWidget *graphWidget) override final; + void visitEnter(VisualizationWidget* widget) override final; + void visitLeave(VisualizationWidget* widget) override final; + void visitEnter(VisualizationTabWidget* tabWidget) override final; + void visitLeave(VisualizationTabWidget* tabWidget) override final; + void visitEnter(VisualizationZoneWidget* zoneWidget) override final; + void visitLeave(VisualizationZoneWidget* zoneWidget) override final; + void visit(VisualizationGraphWidget* graphWidget) override final; /// @return the widgets that contain the variable - std::set result() const noexcept; + std::set result() const noexcept; private: class FindVariableOperationPrivate; diff --git a/gui/include/Visualization/operations/GenerateVariableMenuOperation.h b/gui/include/Visualization/operations/GenerateVariableMenuOperation.h index 53475ba..fad3a55 100644 --- a/gui/include/Visualization/operations/GenerateVariableMenuOperation.h +++ b/gui/include/Visualization/operations/GenerateVariableMenuOperation.h @@ -11,7 +11,7 @@ class QMenu; class IVisualizationWidget; -class Variable; +class Variable2; Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation) @@ -20,7 +20,8 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation) * visualization widgets to determine which can accommodate a variable. The result of the operation * is a menu that contains actions to add the variable into the containers. */ -class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor { +class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor +{ public: /** * Ctor @@ -29,16 +30,16 @@ public: * @param variableContainers the containers that already contain the variable for which to * generate the menu */ - explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr variable, - std::set variableContainers); - - void visitEnter(VisualizationWidget *widget) override final; - void visitLeave(VisualizationWidget *widget) override final; - void visitEnter(VisualizationTabWidget *tabWidget) override final; - void visitLeave(VisualizationTabWidget *tabWidget) override final; - void visitEnter(VisualizationZoneWidget *zoneWidget) override final; - void visitLeave(VisualizationZoneWidget *zoneWidget) override final; - void visit(VisualizationGraphWidget *graphWidget) override final; + explicit GenerateVariableMenuOperation(QMenu* menu, std::shared_ptr variable, + std::set variableContainers); + + void visitEnter(VisualizationWidget* widget) override final; + void visitLeave(VisualizationWidget* widget) override final; + void visitEnter(VisualizationTabWidget* tabWidget) override final; + void visitLeave(VisualizationTabWidget* tabWidget) override final; + void visitEnter(VisualizationZoneWidget* zoneWidget) override final; + void visitLeave(VisualizationZoneWidget* zoneWidget) override final; + void visit(VisualizationGraphWidget* graphWidget) override final; private: class GenerateVariableMenuOperationPrivate; diff --git a/gui/include/Visualization/operations/RemoveVariableOperation.h b/gui/include/Visualization/operations/RemoveVariableOperation.h index 055e1cf..af1d691 100644 --- a/gui/include/Visualization/operations/RemoveVariableOperation.h +++ b/gui/include/Visualization/operations/RemoveVariableOperation.h @@ -9,7 +9,7 @@ #include -class Variable; +class Variable2; Q_DECLARE_LOGGING_CATEGORY(LOG_RemoveVariableOperation) @@ -17,21 +17,22 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_RemoveVariableOperation) * @brief The RemoveVariableOperation class defines an operation that traverses all of visualization * widgets to remove a variable if they contain it */ -class RemoveVariableOperation : public IVisualizationWidgetVisitor { +class RemoveVariableOperation : public IVisualizationWidgetVisitor +{ public: /** * Ctor * @param variable the variable to remove from widgets */ - explicit RemoveVariableOperation(std::shared_ptr variable); - - void visitEnter(VisualizationWidget *widget) override final; - void visitLeave(VisualizationWidget *widget) override final; - void visitEnter(VisualizationTabWidget *tabWidget) override final; - void visitLeave(VisualizationTabWidget *tabWidget) override final; - void visitEnter(VisualizationZoneWidget *zoneWidget) override final; - void visitLeave(VisualizationZoneWidget *zoneWidget) override final; - void visit(VisualizationGraphWidget *graphWidget) override final; + explicit RemoveVariableOperation(std::shared_ptr variable); + + void visitEnter(VisualizationWidget* widget) override final; + void visitLeave(VisualizationWidget* widget) override final; + void visitEnter(VisualizationTabWidget* tabWidget) override final; + void visitLeave(VisualizationTabWidget* tabWidget) override final; + void visitEnter(VisualizationZoneWidget* zoneWidget) override final; + void visitLeave(VisualizationZoneWidget* zoneWidget) override final; + void visit(VisualizationGraphWidget* graphWidget) override final; private: class RemoveVariableOperationPrivate; diff --git a/gui/include/Visualization/operations/RescaleAxeOperation.h b/gui/include/Visualization/operations/RescaleAxeOperation.h index 7d4d8f3..18fcdd7 100644 --- a/gui/include/Visualization/operations/RescaleAxeOperation.h +++ b/gui/include/Visualization/operations/RescaleAxeOperation.h @@ -10,7 +10,7 @@ #include -class Variable; +class Variable2; Q_DECLARE_LOGGING_CATEGORY(LOG_RescaleAxeOperation) @@ -18,21 +18,22 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_RescaleAxeOperation) * @brief The RescaleAxeOperation class defines an operation that traverses all of visualization * widgets to remove a variable if they contain it */ -class RescaleAxeOperation : public IVisualizationWidgetVisitor { +class RescaleAxeOperation : public IVisualizationWidgetVisitor +{ public: /** * Ctor * @param variable the variable to remove from widgets */ - explicit RescaleAxeOperation(std::shared_ptr variable, const DateTimeRange &range); - - void visitEnter(VisualizationWidget *widget) override final; - void visitLeave(VisualizationWidget *widget) override final; - void visitEnter(VisualizationTabWidget *tabWidget) override final; - void visitLeave(VisualizationTabWidget *tabWidget) override final; - void visitEnter(VisualizationZoneWidget *zoneWidget) override final; - void visitLeave(VisualizationZoneWidget *zoneWidget) override final; - void visit(VisualizationGraphWidget *graphWidget) override final; + explicit RescaleAxeOperation(std::shared_ptr variable, const DateTimeRange& range); + + void visitEnter(VisualizationWidget* widget) override final; + void visitLeave(VisualizationWidget* widget) override final; + void visitEnter(VisualizationTabWidget* tabWidget) override final; + void visitLeave(VisualizationTabWidget* tabWidget) override final; + void visitEnter(VisualizationZoneWidget* zoneWidget) override final; + void visitLeave(VisualizationZoneWidget* zoneWidget) override final; + void visit(VisualizationGraphWidget* graphWidget) override final; private: class RescaleAxeOperationPrivate; diff --git a/gui/src/DragAndDrop/DragDropGuiController.cpp b/gui/src/DragAndDrop/DragDropGuiController.cpp index 1067065..29c2e7d 100644 --- a/gui/src/DragAndDrop/DragDropGuiController.cpp +++ b/gui/src/DragAndDrop/DragDropGuiController.cpp @@ -23,39 +23,40 @@ Q_LOGGING_CATEGORY(LOG_DragDropGuiController, "DragDropGuiController") -struct DragDropGuiController::DragDropGuiControllerPrivate { +struct DragDropGuiController::DragDropGuiControllerPrivate +{ - VisualizationDragWidget *m_CurrentDragWidget = nullptr; + VisualizationDragWidget* m_CurrentDragWidget = nullptr; std::unique_ptr m_PlaceHolder = nullptr; - QLabel *m_PlaceHolderLabel; - QWidget *m_PlaceBackground; + QLabel* m_PlaceHolderLabel; + QWidget* m_PlaceBackground; std::unique_ptr m_DragDropScroller = nullptr; std::unique_ptr m_DragDropTabSwitcher = nullptr; QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using // QTemporaryFile to have a name which is not generated. - VisualizationDragWidget *m_HighlightedDragWidget = nullptr; + VisualizationDragWidget* m_HighlightedDragWidget = nullptr; QMetaObject::Connection m_DragWidgetDestroyedConnection; QMetaObject::Connection m_HighlightedWidgetDestroyedConnection; - QList m_WidgetToClose; + QList m_WidgetToClose; explicit DragDropGuiControllerPrivate() - : m_PlaceHolder{std::make_unique()}, - m_DragDropScroller{std::make_unique()}, - m_DragDropTabSwitcher{std::make_unique()} + : m_PlaceHolder { std::make_unique() } + , m_DragDropScroller { std::make_unique() } + , m_DragDropTabSwitcher { std::make_unique() } { - auto layout = new QVBoxLayout{m_PlaceHolder.get()}; + auto layout = new QVBoxLayout { m_PlaceHolder.get() }; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); - m_PlaceHolderLabel = new QLabel{"", m_PlaceHolder.get()}; + m_PlaceHolderLabel = new QLabel { "", m_PlaceHolder.get() }; m_PlaceHolderLabel->setMinimumHeight(25); layout->addWidget(m_PlaceHolderLabel); - m_PlaceBackground = new QWidget{m_PlaceHolder.get()}; + m_PlaceBackground = new QWidget { m_PlaceHolder.get() }; m_PlaceBackground->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout->addWidget(m_PlaceBackground); @@ -65,14 +66,16 @@ struct DragDropGuiController::DragDropGuiControllerPrivate { m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png"); } - void preparePlaceHolder(DragDropGuiController::PlaceHolderType type, - const QString &topLabelText) const + void preparePlaceHolder( + DragDropGuiController::PlaceHolderType type, const QString& topLabelText) const { - if (m_CurrentDragWidget) { + if (m_CurrentDragWidget) + { m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size()); m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy()); } - else { + else + { // Configuration of the placeHolder when there is no dragWidget // (for instance with a drag from a variable) @@ -80,7 +83,8 @@ struct DragDropGuiController::DragDropGuiControllerPrivate { m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } - switch (type) { + switch (type) + { case DragDropGuiController::PlaceHolderType::Graph: m_PlaceBackground->setStyleSheet( "background-color: #BBD5EE; border: 1px solid #2A7FD4"); @@ -100,7 +104,7 @@ struct DragDropGuiController::DragDropGuiControllerPrivate { DragDropGuiController::DragDropGuiController() - : impl{spimpl::make_unique_impl()} + : impl { spimpl::make_unique_impl() } { } @@ -115,35 +119,36 @@ void DragDropGuiController::resetDragAndDrop() impl->m_HighlightedDragWidget = nullptr; } -void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget *dragWidget) +void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget* dragWidget) { - if (impl->m_CurrentDragWidget) { + if (impl->m_CurrentDragWidget) + { QObject::disconnect(impl->m_DragWidgetDestroyedConnection); } - if (dragWidget) { + if (dragWidget) + { // ensures the impl->m_CurrentDragWidget is reset when the widget is destroyed - impl->m_DragWidgetDestroyedConnection - = QObject::connect(dragWidget, &VisualizationDragWidget::destroyed, - [this]() { impl->m_CurrentDragWidget = nullptr; }); + impl->m_DragWidgetDestroyedConnection = QObject::connect(dragWidget, + &VisualizationDragWidget::destroyed, [this]() { impl->m_CurrentDragWidget = nullptr; }); } impl->m_CurrentDragWidget = dragWidget; } -VisualizationDragWidget *DragDropGuiController::getCurrentDragWidget() const +VisualizationDragWidget* DragDropGuiController::getCurrentDragWidget() const { return impl->m_CurrentDragWidget; } -QWidget &DragDropGuiController::placeHolder() const +QWidget& DragDropGuiController::placeHolder() const { return *impl->m_PlaceHolder; } -void DragDropGuiController::insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type, - const QString &topLabelText) +void DragDropGuiController::insertPlaceHolder( + QVBoxLayout* layout, int index, PlaceHolderType type, const QString& topLabelText) { removePlaceHolder(); impl->preparePlaceHolder(type, topLabelText); @@ -154,7 +159,8 @@ void DragDropGuiController::insertPlaceHolder(QVBoxLayout *layout, int index, Pl void DragDropGuiController::removePlaceHolder() { auto parentWidget = impl->m_PlaceHolder->parentWidget(); - if (parentWidget) { + if (parentWidget) + { parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get()); impl->m_PlaceHolder->setParent(nullptr); impl->m_PlaceHolder->hide(); @@ -166,57 +172,59 @@ bool DragDropGuiController::isPlaceHolderSet() const return impl->m_PlaceHolder->parentWidget(); } -void DragDropGuiController::addDragDropScrollArea(QScrollArea *scrollArea) +void DragDropGuiController::addDragDropScrollArea(QScrollArea* scrollArea) { impl->m_DragDropScroller->addScrollArea(scrollArea); } -void DragDropGuiController::removeDragDropScrollArea(QScrollArea *scrollArea) +void DragDropGuiController::removeDragDropScrollArea(QScrollArea* scrollArea) { impl->m_DragDropScroller->removeScrollArea(scrollArea); } -void DragDropGuiController::addDragDropTabBar(QTabBar *tabBar) +void DragDropGuiController::addDragDropTabBar(QTabBar* tabBar) { impl->m_DragDropTabSwitcher->addTabBar(tabBar); } -void DragDropGuiController::removeDragDropTabBar(QTabBar *tabBar) +void DragDropGuiController::removeDragDropTabBar(QTabBar* tabBar) { impl->m_DragDropTabSwitcher->removeTabBar(tabBar); } -QUrl DragDropGuiController::imageTemporaryUrl(const QImage &image) const +QUrl DragDropGuiController::imageTemporaryUrl(const QImage& image) const { image.save(impl->m_ImageTempUrl); return QUrl::fromLocalFile(impl->m_ImageTempUrl); } -void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget *dragWidget) +void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget* dragWidget) { - if (impl->m_HighlightedDragWidget) { + if (impl->m_HighlightedDragWidget) + { impl->m_HighlightedDragWidget->highlightForMerge(false); QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection); } - if (dragWidget) { + if (dragWidget) + { dragWidget->highlightForMerge(true); // ensures the impl->m_HighlightedDragWidget is reset when the widget is destroyed impl->m_DragWidgetDestroyedConnection = QObject::connect(dragWidget, &VisualizationDragWidget::destroyed, - [this]() { impl->m_HighlightedDragWidget = nullptr; }); + [this]() { impl->m_HighlightedDragWidget = nullptr; }); } impl->m_HighlightedDragWidget = dragWidget; } -VisualizationDragWidget *DragDropGuiController::getHightlightedDragWidget() const +VisualizationDragWidget* DragDropGuiController::getHightlightedDragWidget() const { return impl->m_HighlightedDragWidget; } -void DragDropGuiController::delayedCloseWidget(QWidget *widget) +void DragDropGuiController::delayedCloseWidget(QWidget* widget) { widget->hide(); impl->m_WidgetToClose << widget; @@ -224,7 +232,8 @@ void DragDropGuiController::delayedCloseWidget(QWidget *widget) void DragDropGuiController::doCloseWidgets() { - for (auto widget : impl->m_WidgetToClose) { + for (auto widget : impl->m_WidgetToClose) + { widget->close(); } @@ -232,9 +241,10 @@ void DragDropGuiController::doCloseWidgets() } bool DragDropGuiController::checkMimeDataForVisualization( - const QMimeData *mimeData, VisualizationDragDropContainer *dropContainer) + const QMimeData* mimeData, VisualizationDragDropContainer* dropContainer) { - if (!mimeData || !dropContainer) { + if (!mimeData || !dropContainer) + { qCWarning(LOG_DragDropGuiController()) << QObject::tr( "DragDropGuiController::checkMimeDataForVisualization, invalid input parameters."); Q_ASSERT(false); @@ -243,61 +253,75 @@ bool DragDropGuiController::checkMimeDataForVisualization( auto result = false; - if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { + if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) + { auto variables = sqpApp->variableController().variables( Variable::variablesIDs(mimeData->data(MIME_TYPE_VARIABLE_LIST))); - if (variables.size() == 1) { + if (variables.size() == 1) + { auto variable = variables[0]; - if (variable->dataSeries() != nullptr) { + if (variable->data() != nullptr) + { // Check that the variable is not already in a graph auto parent = dropContainer->parentWidget(); - while (parent && qobject_cast(parent) == nullptr) { + while (parent && qobject_cast(parent) == nullptr) + { parent = parent->parentWidget(); // Search for the top level VisualizationWidget } - if (parent) { - auto visualizationWidget = static_cast(parent); + if (parent) + { + auto visualizationWidget = static_cast(parent); - FindVariableOperation findVariableOperation{variable}; + FindVariableOperation findVariableOperation { variable }; visualizationWidget->accept(&findVariableOperation); auto variableContainers = findVariableOperation.result(); - if (variableContainers.empty()) { + if (variableContainers.empty()) + { result = true; } - else { + else + { // result = false: the variable already exist in the visualisation } } - else { + else + { qCWarning(LOG_DragDropGuiController()) << QObject::tr( "DragDropGuiController::checkMimeDataForVisualization, the parent " "VisualizationWidget cannot be found. Cannot check if the variable is " "already used or not."); } } - else { + else + { // result = false: the variable is not fully loaded } } - else { + else + { // result = false: cannot drop multiple variables in the visualisation } } - else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) { + else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) + { auto productDataList = sqpApp->dataSourceController().productsDataForMimeData( mimeData->data(MIME_TYPE_PRODUCT_LIST)); - if (productDataList.count() == 1) { + if (productDataList.count() == 1) + { result = true; } - else { + else + { // result = false: cannot drop multiple products in the visualisation } } - else { + else + { // Other MIME data // no special rules, accepted by default result = true; diff --git a/gui/src/Variable/VariableInspectorWidget.cpp b/gui/src/Variable/VariableInspectorWidget.cpp index 925f56e..f3e75f3 100644 --- a/gui/src/Variable/VariableInspectorWidget.cpp +++ b/gui/src/Variable/VariableInspectorWidget.cpp @@ -1,10 +1,10 @@ +#include #include #include #include #include #include #include -#include #include @@ -19,22 +19,25 @@ Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") -class QProgressBarItemDelegate : public QStyledItemDelegate { +class QProgressBarItemDelegate : public QStyledItemDelegate +{ public: - QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} + QProgressBarItemDelegate(QObject* parent) : QStyledItemDelegate { parent } {} - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const + void paint( + QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { auto data = index.data(Qt::DisplayRole); auto progressData = index.data(VariableRoles::ProgressRole); - if (data.isValid() && progressData.isValid()) { + if (data.isValid() && progressData.isValid()) + { auto name = data.value(); auto progress = progressData.value(); - if (progress > 0) { + if (progress > 0) + { auto cancelButtonWidth = 20; - auto progressBarOption = QStyleOptionProgressBar{}; + auto progressBarOption = QStyleOptionProgressBar {}; auto progressRect = option.rect; progressRect.setWidth(progressRect.width() - cancelButtonWidth); progressBarOption.rect = progressRect; @@ -47,66 +50,75 @@ public: progressBarOption.textAlignment = Qt::AlignCenter; - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, - painter); + QApplication::style()->drawControl( + QStyle::CE_ProgressBar, &progressBarOption, painter); // Cancel button auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, - option.rect.height()); - auto buttonOption = QStyleOptionButton{}; + option.rect.height()); + auto buttonOption = QStyleOptionButton {}; buttonOption.rect = buttonRect; buttonOption.text = "X"; QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); } - else { + else + { QStyledItemDelegate::paint(painter, option, index); } } - else { + else + { QStyledItemDelegate::paint(painter, option, index); } } - bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, - const QModelIndex &index) + bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, + const QModelIndex& index) { - if (event->type() == QEvent::MouseButtonRelease) { + if (event->type() == QEvent::MouseButtonRelease) + { auto data = index.data(Qt::DisplayRole); auto progressData = index.data(VariableRoles::ProgressRole); - if (data.isValid() && progressData.isValid()) { + if (data.isValid() && progressData.isValid()) + { auto cancelButtonWidth = 20; auto progressRect = option.rect; progressRect.setWidth(progressRect.width() - cancelButtonWidth); // Cancel button auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, - option.rect.height()); + option.rect.height()); - auto e = (QMouseEvent *)event; + auto e = (QMouseEvent*)event; auto clickX = e->x(); auto clickY = e->y(); - auto x = buttonRect.left(); // the X coordinate - auto y = buttonRect.top(); // the Y coordinate - auto w = buttonRect.width(); // button width + auto x = buttonRect.left(); // the X coordinate + auto y = buttonRect.top(); // the Y coordinate + auto w = buttonRect.width(); // button width auto h = buttonRect.height(); // button height - if (clickX > x && clickX < x + w) { - if (clickY > y && clickY < y + h) { - //auto& variableModel = sqpApp->variableModel(); - //variableModel->abortProgress(index); + if (clickX > x && clickX < x + w) + { + if (clickY > y && clickY < y + h) + { + // auto& variableModel = sqpApp->variableModel(); + // variableModel->abortProgress(index); } return true; } - else { + else + { return QStyledItemDelegate::editorEvent(event, model, option, index); } } - else { + else + { return QStyledItemDelegate::editorEvent(event, model, option, index); } } - else { + else + { return QStyledItemDelegate::editorEvent(event, model, option, index); } @@ -115,10 +127,10 @@ public: } }; -VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) - : QWidget{parent}, - ui{new Ui::VariableInspectorWidget}, - m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}} +VariableInspectorWidget::VariableInspectorWidget(QWidget* parent) + : QWidget { parent } + , ui { new Ui::VariableInspectorWidget } + , m_ProgressBarItemDelegate { new QProgressBarItemDelegate { this } } { ui->setupUi(this); @@ -128,9 +140,7 @@ VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) m_model = new VariableModel2(); ui->tableView->setModel(m_model); - connect(m_model, &VariableModel2::createVariable, - [](const QVariantHash &productData) - { + connect(m_model, &VariableModel2::createVariable, [](const QVariantHash& productData) { sqpApp->dataSourceController().requestVariable(productData); }); auto vc = &(sqpApp->variableController()); @@ -140,16 +150,17 @@ VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) // Adds extra signal/slot between view and model, so the view can be updated instantly when // there is a change of data in the model - //connect(m_model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, + // connect(m_model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, // SLOT(refresh())); - //ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); + // ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); // Fixes column sizes auto model = ui->tableView->model(); const auto count = model->columnCount(); - for (auto i = 0; i < count; ++i) { + for (auto i = 0; i < count; ++i) + { ui->tableView->setColumnWidth( i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); } @@ -161,7 +172,7 @@ VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) // 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::onTableMenuRequested); } VariableInspectorWidget::~VariableInspectorWidget() @@ -169,50 +180,55 @@ VariableInspectorWidget::~VariableInspectorWidget() delete ui; } -void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept +void VariableInspectorWidget::onTableMenuRequested(const QPoint& pos) noexcept { auto selectedRows = ui->tableView->selectionModel()->selectedRows(); - auto selectedVariables = QVector >{}; - for (const auto &selectedRow : qAsConst(selectedRows)) { - if (auto selectedVariable = this->m_model->variables()[selectedRow.row()]) { + auto selectedVariables = QVector> {}; + for (const auto& selectedRow : qAsConst(selectedRows)) + { + if (auto selectedVariable = this->m_model->variables()[selectedRow.row()]) + { selectedVariables.push_back(selectedVariable); } } - QMenu tableMenu{}; + QMenu tableMenu {}; // Emits a signal so that potential receivers can populate the menu before displaying it emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); // Adds menu-specific actions - if (!selectedVariables.isEmpty()) { + if (!selectedVariables.isEmpty()) + { tableMenu.addSeparator(); // 'Rename' and 'Duplicate' actions (only if one variable selected) - if (selectedVariables.size() == 1) { + if (selectedVariables.size() == 1) + { auto selectedVariable = selectedVariables.front(); - auto duplicateFun = [varW = std::weak_ptr(selectedVariable)]() - { - if (auto var = varW.lock()) { + auto duplicateFun = [varW = std::weak_ptr(selectedVariable)]() { + if (auto var = varW.lock()) + { sqpApp->variableController().cloneVariable(var); } }; tableMenu.addAction(tr("Duplicate"), duplicateFun); - auto renameFun = [ varW = std::weak_ptr(selectedVariable), this ]() - { - if (auto var = varW.lock()) { + auto renameFun = [varW = std::weak_ptr(selectedVariable), this]() { + if (auto var = varW.lock()) + { // Generates forbidden names (names associated to existing variables) auto allVariables = sqpApp->variableController().variables(); auto forbiddenNames = QVector(allVariables.size()); std::transform(allVariables.cbegin(), allVariables.cend(), - forbiddenNames.begin(), - [](const auto &variable) { return variable->name(); }); + forbiddenNames.begin(), + [](const auto& variable) { return variable->name(); }); - RenameVariableDialog dialog{var->name(), forbiddenNames, this}; - if (dialog.exec() == QDialog::Accepted) { + RenameVariableDialog dialog { var->name(), forbiddenNames, this }; + if (dialog.exec() == QDialog::Accepted) + { var->setName(dialog.name()); } } @@ -223,18 +239,20 @@ void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept // 'Delete' action auto deleteFun = [&selectedVariables]() { - for(const auto& var:selectedVariables) + for (const auto& var : selectedVariables) sqpApp->variableController().deleteVariable(var); }; - tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); + tableMenu.addAction(QIcon { ":/icones/delete.png" }, tr("Delete"), deleteFun); } - if (!tableMenu.isEmpty()) { + if (!tableMenu.isEmpty()) + { // Generates menu header (inserted before first action) auto firstAction = tableMenu.actions().first(); - auto headerAction = new QWidgetAction{&tableMenu}; - headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); + auto headerAction = new QWidgetAction { &tableMenu }; + headerAction->setDefaultWidget( + new VariableMenuHeaderWidget { selectedVariables, &tableMenu }); tableMenu.insertAction(firstAction, headerAction); // Displays menu diff --git a/gui/src/Variable/VariableMenuHeaderWidget.cpp b/gui/src/Variable/VariableMenuHeaderWidget.cpp index 7baf824..48358ec 100644 --- a/gui/src/Variable/VariableMenuHeaderWidget.cpp +++ b/gui/src/Variable/VariableMenuHeaderWidget.cpp @@ -1,13 +1,13 @@ #include "Variable/VariableMenuHeaderWidget.h" -#include "Variable/Variable.h" +#include "Variable/Variable2.h" #include Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget") VariableMenuHeaderWidget::VariableMenuHeaderWidget( - const QVector > &variables, QWidget *parent) - : QWidget{parent}, ui{new Ui::VariableMenuHeaderWidget} + const QVector>& variables, QWidget* parent) + : QWidget { parent }, ui { new Ui::VariableMenuHeaderWidget } { ui->setupUi(this); @@ -15,19 +15,24 @@ VariableMenuHeaderWidget::VariableMenuHeaderWidget( // - the variable name if there is only one variable in the list // - 'x variables' where x is the number of variables otherwise const auto nbVariables = variables.size(); - if (nbVariables == 1) { - if (auto variable = variables.first()) { + if (nbVariables == 1) + { + if (auto variable = variables.first()) + { ui->label->setText(variable->name()); } - else { + else + { qCCritical(LOG_VariableMenuHeaderWidget()) << tr("Can't get the name of the variable : variable is null"); } } - else if (nbVariables > 1) { + else if (nbVariables > 1) + { ui->label->setText(tr("%1 variables").arg(nbVariables)); } - else { + else + { ui->label->setText(tr("No variable")); } } diff --git a/gui/src/Visualization/AxisRenderingUtils.cpp b/gui/src/Visualization/AxisRenderingUtils.cpp index 2ff3f44..dbb2209 100644 --- a/gui/src/Visualization/AxisRenderingUtils.cpp +++ b/gui/src/Visualization/AxisRenderingUtils.cpp @@ -1,17 +1,18 @@ #include "Visualization/AxisRenderingUtils.h" -#include -#include -#include +#include +#include +#include -#include +#include #include #include Q_LOGGING_CATEGORY(LOG_AxisRenderingUtils, "AxisRenderingUtils") -namespace { +namespace +{ /// Format for datetimes on a axis const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); @@ -23,17 +24,20 @@ const auto NUMBER_PRECISION = 9; /// non-time data QSharedPointer axisTicker(bool isTimeAxis, QCPAxis::ScaleType scaleType) { - if (isTimeAxis) { + if (isTimeAxis) + { auto dateTicker = QSharedPointer::create(); dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); dateTicker->setDateTimeSpec(Qt::UTC); return dateTicker; } - else if (scaleType == QCPAxis::stLogarithmic) { + else if (scaleType == QCPAxis::stLogarithmic) + { return QSharedPointer::create(); } - else { + else + { // default ticker return QSharedPointer::create(); } @@ -45,36 +49,38 @@ QSharedPointer axisTicker(bool isTimeAxis, QCPAxis::ScaleType sca * @param unit the unit to set for the axis * @param scaleType the scale type to set for the axis */ -void setAxisProperties(QCPAxis &axis, const Unit &unit, - QCPAxis::ScaleType scaleType = QCPAxis::stLinear) +void setAxisProperties(QCPAxis& axis, const std::string& unit, bool isTime, + QCPAxis::ScaleType scaleType = QCPAxis::stLinear) { // label (unit name) - axis.setLabel(unit.m_Name); + axis.setLabel(QString::fromStdString(unit)); // scale type axis.setScaleType(scaleType); - if (scaleType == QCPAxis::stLogarithmic) { + if (scaleType == QCPAxis::stLogarithmic) + { // Scientific notation axis.setNumberPrecision(0); axis.setNumberFormat("eb"); } // ticker (depending on the type of unit) - axis.setTicker(axisTicker(unit.m_TimeUnit, scaleType)); + axis.setTicker(axisTicker(isTime, scaleType)); } /** * Delegate used to set axes properties */ template -struct AxisSetter { - static void setProperties(QCustomPlot &, SqpColorScale &) +struct AxisSetter +{ + static void setProperties(QCustomPlot&, SqpColorScale&) { // Default implementation does nothing qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data"; } - static void setUnits(T &, QCustomPlot &, SqpColorScale &) + static void setUnits(T&, QCustomPlot&, SqpColorScale&) { // Default implementation does nothing qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis units: unmanaged type of data"; @@ -87,24 +93,20 @@ struct AxisSetter { * @sa VectorSeries */ template -struct AxisSetter::value - or std::is_base_of::value> > { - static void setProperties(QCustomPlot &, SqpColorScale &) +struct AxisSetter::value + or std::is_base_of::value>> +{ + static void setProperties(QCustomPlot&, SqpColorScale&) { // Nothing to do } - static void setUnits(T &dataSeries, QCustomPlot &plot, SqpColorScale &) + static void setUnits(T& dataSeries, QCustomPlot& plot, SqpColorScale&) { - dataSeries.lockRead(); - auto xAxisUnit = dataSeries.xAxisUnit(); - auto valuesUnit = dataSeries.valuesUnit(); - dataSeries.unlock(); - -// setAxisProperties(*plot.xAxis, xAxisUnit); - // This is cheating but it's ok ;) - setAxisProperties(*plot.xAxis, Unit{"s", true}); - setAxisProperties(*plot.yAxis, valuesUnit); + auto serie = dynamic_cast(&dataSeries); + setAxisProperties(*plot.xAxis, "s", true); + setAxisProperties(*plot.yAxis, serie->unit(1), false); } }; @@ -113,18 +115,20 @@ struct AxisSetter: * @sa SpectrogramSeries */ template -struct AxisSetter::value> > { - static void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) +struct AxisSetter::value>> +{ + static void setProperties(QCustomPlot& plot, SqpColorScale& colorScale) { // Displays color scale in plot plot.plotLayout()->insertRow(0); plot.plotLayout()->addElement(0, 0, colorScale.m_Scale); colorScale.m_Scale->setType(QCPAxis::atTop); - colorScale.m_Scale->setMinimumMargins(QMargins{0, 0, 0, 0}); + colorScale.m_Scale->setMinimumMargins(QMargins { 0, 0, 0, 0 }); // Aligns color scale with axes auto marginGroups = plot.axisRect()->marginGroups(); - for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) { + for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) + { colorScale.m_Scale->setMarginGroup(it.key(), it.value()); } @@ -132,19 +136,13 @@ struct AxisSetteraxis(), valuesUnit, QCPAxis::stLogarithmic); + auto serie = dynamic_cast(&dataSeries); + setAxisProperties(*plot.xAxis, "s", true); + setAxisProperties(*plot.yAxis, serie->unit(1), false, QCPAxis::stLogarithmic); + setAxisProperties( + *colorScale.m_Scale->axis(), serie->unit(2), false, QCPAxis::stLogarithmic); } }; @@ -153,57 +151,63 @@ struct AxisSetter -struct AxisHelper : public IAxisHelper { - explicit AxisHelper(std::shared_ptr dataSeries) : m_DataSeries{dataSeries} {} +struct AxisHelper : public IAxisHelper +{ + explicit AxisHelper(T* dataSeries) : m_DataSeries { dataSeries } {} - void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) override + void setProperties(QCustomPlot& plot, SqpColorScale& colorScale) override { AxisSetter::setProperties(plot, colorScale); } - void setUnits(QCustomPlot &plot, SqpColorScale &colorScale) override + void setUnits(QCustomPlot& plot, SqpColorScale& colorScale) override { - if (m_DataSeries) { + if (m_DataSeries) + { AxisSetter::setUnits(*m_DataSeries, plot, colorScale); } - else { + else + { qCCritical(LOG_AxisRenderingUtils()) << "Can't set units: inconsistency between the " "type of data series and the type supposed"; } } - std::shared_ptr m_DataSeries; + T* m_DataSeries; }; } // namespace -QString formatValue(double value, const QCPAxis &axis) +QString formatValue(double value, const QCPAxis& axis) { // If the axis is a time axis, formats the value as a date - if (auto axisTicker = qSharedPointerDynamicCast(axis.ticker())) { + if (auto axisTicker = qSharedPointerDynamicCast(axis.ticker())) + { return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT); } - else { + else + { return QString::number(value, NUMBER_FORMAT, NUMBER_PRECISION); } } -std::unique_ptr IAxisHelperFactory::create(const Variable &variable) noexcept +std::unique_ptr IAxisHelperFactory::create(Variable2& variable) noexcept { - switch (variable.type()) { + switch (variable.type()) + { case DataSeriesType::SCALAR: - return std::make_unique >( - std::dynamic_pointer_cast(variable.dataSeries())); + return std::make_unique>( + dynamic_cast(variable.data()->base())); case DataSeriesType::SPECTROGRAM: - return std::make_unique >( - std::dynamic_pointer_cast(variable.dataSeries())); + return std::make_unique>( + dynamic_cast(variable.data()->base())); case DataSeriesType::VECTOR: - return std::make_unique >( - std::dynamic_pointer_cast(variable.dataSeries())); + return std::make_unique>( + dynamic_cast(variable.data()->base())); default: // Creates default helper break; } - return std::make_unique >(nullptr); + return std::make_unique>(nullptr); } diff --git a/gui/src/Visualization/PlottablesRenderingUtils.cpp b/gui/src/Visualization/PlottablesRenderingUtils.cpp index b73fa91..e9b0080 100644 --- a/gui/src/Visualization/PlottablesRenderingUtils.cpp +++ b/gui/src/Visualization/PlottablesRenderingUtils.cpp @@ -6,20 +6,22 @@ #include #include -#include +#include #include Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils") -namespace { +namespace +{ /** * Delegate used to set plottables properties */ template -struct PlottablesSetter { - static void setProperties(PlottablesMap &) +struct PlottablesSetter +{ + static void setProperties(PlottablesMap&) { // Default implementation does nothing qCCritical(LOG_PlottablesRenderingUtils()) @@ -33,26 +35,28 @@ struct PlottablesSetter { * @sa VectorSeries */ template -struct PlottablesSetter::value - or std::is_base_of::value> > { - static void setProperties(PlottablesMap &plottables) +struct PlottablesSetter::value + or std::is_base_of::value>> +{ + static void setProperties(PlottablesMap& plottables) { // Finds the plottable with the highest index to determine the number of colors to generate auto end = plottables.cend(); - auto maxPlottableIndexIt - = std::max_element(plottables.cbegin(), end, [](const auto &it1, const auto &it2) { - return it1.first < it2.first; - }); + auto maxPlottableIndexIt = std::max_element(plottables.cbegin(), end, + [](const auto& it1, const auto& it2) { return it1.first < it2.first; }); auto componentCount = maxPlottableIndexIt != end ? maxPlottableIndexIt->first + 1 : 0; // Generates colors for each component auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount); // For each component of the data series, creates a QCPGraph to add to the plot - for (auto i = 0; i < componentCount; ++i) { + for (auto i = 0; i < componentCount; ++i) + { auto graphIt = plottables.find(i); - if (graphIt != end) { - graphIt->second->setPen(QPen{colors.at(i)}); + if (graphIt != end) + { + graphIt->second->setPen(QPen { colors.at(i) }); } } } @@ -64,30 +68,36 @@ struct PlottablesSetter struct PlottablesSetter::value> > { - static void setProperties(PlottablesMap &plottables) + typename std::enable_if_t::value>> +{ + static void setProperties(PlottablesMap& plottables) { // Checks that for a spectrogram there is only one plottable, that is a colormap - if (plottables.size() != 1) { + if (plottables.size() != 1) + { return; } - if (auto colormap = dynamic_cast(plottables.begin()->second)) { + if (auto colormap = dynamic_cast(plottables.begin()->second)) + { colormap->setInterpolate(false); // No value interpolation colormap->setTightBoundary(true); // Finds color scale in the colormap's plot to associate with it auto plot = colormap->parentPlot(); auto plotElements = plot->plotLayout()->elements(false); - for (auto plotElement : plotElements) { - if (auto colorScale = dynamic_cast(plotElement)) { + for (auto plotElement : plotElements) + { + if (auto colorScale = dynamic_cast(plotElement)) + { colormap->setColorScale(colorScale); } } colormap->rescaleDataRange(); } - else { + else + { qCCritical(LOG_PlottablesRenderingUtils()) << "Can't get colormap of the spectrogram"; } } @@ -98,8 +108,9 @@ struct PlottablesSetter -struct PlottablesHelper : public IPlottablesHelper { - void setProperties(PlottablesMap &plottables) override +struct PlottablesHelper : public IPlottablesHelper +{ + void setProperties(PlottablesMap& plottables) override { PlottablesSetter::setProperties(plottables); } @@ -107,20 +118,20 @@ struct PlottablesHelper : public IPlottablesHelper { } // namespace -std::unique_ptr -IPlottablesHelperFactory::create(const Variable &variable) noexcept +std::unique_ptr IPlottablesHelperFactory::create(Variable2& variable) noexcept { - switch (variable.type()) { + switch (variable.type()) + { case DataSeriesType::SCALAR: - return std::make_unique >(); + return std::make_unique>(); case DataSeriesType::SPECTROGRAM: - return std::make_unique >(); + return std::make_unique>(); case DataSeriesType::VECTOR: - return std::make_unique >(); + return std::make_unique>(); default: // Returns default helper break; } - return std::make_unique >(); + return std::make_unique>(); } diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index bf4d6d5..5157cdd 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -2,19 +2,21 @@ #include "Visualization/qcustomplot.h" #include -#include -#include -#include +#include +#include +#include -#include +#include Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") -namespace { +namespace +{ -class SqpDataContainer : public QCPGraphDataContainer { +class SqpDataContainer : public QCPGraphDataContainer +{ public: - void appendGraphData(const QCPGraphData &data) { mData.append(data); } + void appendGraphData(const QCPGraphData& data) { mData.append(data); } }; /** @@ -24,23 +26,20 @@ public: * @remarks Default implementation can't create plottables */ template -struct PlottablesCreator { - static PlottablesMap createPlottables(QCustomPlot &) - { - qCCritical(LOG_DataSeries()) - << QObject::tr("Can't create plottables: unmanaged data series type"); - return {}; - } +struct PlottablesCreator +{ + static PlottablesMap createPlottables(QCustomPlot&) { return {}; } }; -PlottablesMap createGraphs(QCustomPlot &plot, int nbGraphs) +PlottablesMap createGraphs(QCustomPlot& plot, int nbGraphs) { - PlottablesMap result{}; + PlottablesMap result {}; // Creates {nbGraphs} QCPGraph to add to the plot - for (auto i = 0; i < nbGraphs; ++i) { + for (auto i = 0; i < nbGraphs; ++i) + { auto graph = plot.addGraph(); - result.insert({i, graph}); + result.insert({ i, graph }); } plot.replot(); @@ -53,8 +52,9 @@ PlottablesMap createGraphs(QCustomPlot &plot, int nbGraphs) * @sa ScalarSeries */ template -struct PlottablesCreator::value> > { - static PlottablesMap createPlottables(QCustomPlot &plot) { return createGraphs(plot, 1); } +struct PlottablesCreator::value>> +{ + static PlottablesMap createPlottables(QCustomPlot& plot) { return createGraphs(plot, 1); } }; /** @@ -62,8 +62,9 @@ struct PlottablesCreator -struct PlottablesCreator::value> > { - static PlottablesMap createPlottables(QCustomPlot &plot) { return createGraphs(plot, 3); } +struct PlottablesCreator::value>> +{ + static PlottablesMap createPlottables(QCustomPlot& plot) { return createGraphs(plot, 3); } }; /** @@ -72,11 +73,12 @@ struct PlottablesCreator struct PlottablesCreator::value> > { - static PlottablesMap createPlottables(QCustomPlot &plot) + typename std::enable_if_t::value>> +{ + static PlottablesMap createPlottables(QCustomPlot& plot) { - PlottablesMap result{}; - result.insert({0, new QCPColorMap{plot.xAxis, plot.yAxis}}); + PlottablesMap result {}; + result.insert({ 0, new QCPColorMap { plot.xAxis, plot.yAxis } }); plot.replot(); @@ -91,14 +93,15 @@ struct PlottablesCreator -struct PlottablesUpdater { - static void setPlotYAxisRange(T &, const DateTimeRange &, QCustomPlot &) +struct PlottablesUpdater +{ + static void setPlotYAxisRange(T&, const DateTimeRange&, QCustomPlot&) { qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr("Can't set plot y-axis range: unmanaged data series type"); } - static void updatePlottables(T &, PlottablesMap &, const DateTimeRange &, bool) + static void updatePlottables(T&, PlottablesMap&, const DateTimeRange&, bool) { qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr("Can't update plottables: unmanaged data series type"); @@ -111,154 +114,223 @@ struct PlottablesUpdater { * @sa VectorSeries */ template -struct PlottablesUpdater::value - or std::is_base_of::value> > { - static void setPlotYAxisRange(T &dataSeries, const DateTimeRange &xAxisRange, QCustomPlot &plot) +struct PlottablesUpdater::value>> +{ + static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot) { auto minValue = 0., maxValue = 0.; - - dataSeries.lockRead(); - auto valuesBounds = dataSeries.valuesBounds(xAxisRange.m_TStart, xAxisRange.m_TEnd); - auto end = dataSeries.cend(); - if (valuesBounds.first != end && valuesBounds.second != end) { - auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; - - minValue = rangeValue(valuesBounds.first->minValue()); - maxValue = rangeValue(valuesBounds.second->maxValue()); + if (auto serie = dynamic_cast(&dataSeries)) + { + maxValue = (*std::max_element(std::begin(*serie), std::end(*serie))).v(); + minValue = (*std::min_element(std::begin(*serie), std::end(*serie))).v(); } - dataSeries.unlock(); - - plot.yAxis->setRange(QCPRange{minValue, maxValue}); + plot.yAxis->setRange(QCPRange { minValue, maxValue }); } - static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const DateTimeRange &range, - bool rescaleAxes) + static void updatePlottables( + T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) { // For each plottable to update, resets its data - std::map > dataContainers{}; - for (const auto &plottable : plottables) { - if (auto graph = dynamic_cast(plottable.second)) { + for (const auto& plottable : plottables) + { + if (auto graph = dynamic_cast(plottable.second)) + { auto dataContainer = QSharedPointer::create(); + if (auto serie = dynamic_cast(&dataSeries)) + { + std::for_each( + std::begin(*serie), std::end(*serie), [&dataContainer](const auto& value) { + dataContainer->appendGraphData(QCPGraphData(value.t(), value.v())); + }); + } graph->setData(dataContainer); - - dataContainers.insert({plottable.first, dataContainer}); - } - } - dataSeries.lockRead(); - - // - Gets the data of the series included in the current range - // - Updates each plottable by adding, for each data item, a point that takes x-axis data - // and value data. The correct value is retrieved according to the index of the component - auto subDataIts = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd); - for (auto it = subDataIts.first; it != subDataIts.second; ++it) { - for (const auto &dataContainer : dataContainers) { - auto componentIndex = dataContainer.first; - dataContainer.second->appendGraphData( - QCPGraphData(it->x(), it->value(componentIndex))); } } - dataSeries.unlock(); - - if (!plottables.empty()) { + if (!plottables.empty()) + { auto plot = plottables.begin()->second->parentPlot(); - if (rescaleAxes) { + if (rescaleAxes) + { plot->rescaleAxes(); } } } }; -/** - * Specialization of PlottablesUpdater for spectrograms - * @sa SpectrogramSeries - */ + template -struct PlottablesUpdater::value> > { - static void setPlotYAxisRange(T &dataSeries, const DateTimeRange &xAxisRange, QCustomPlot &plot) +struct PlottablesUpdater::value>> +{ + static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot) { - double min, max; - std::tie(min, max) = dataSeries.yBounds(); - - if (!std::isnan(min) && !std::isnan(max)) { - plot.yAxis->setRange(QCPRange{min, max}); + double minValue = 0., maxValue = 0.; + if (auto serie = dynamic_cast(&dataSeries)) + { + std::for_each( + std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) { + minValue = std::min({ minValue, v.v().x, v.v().y, v.v().z }); + maxValue = std::max({ maxValue, v.v().x, v.v().y, v.v().z }); + }); } + + plot.yAxis->setRange(QCPRange { minValue, maxValue }); } - static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const DateTimeRange &range, - bool rescaleAxes) + static void updatePlottables( + T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) { - if (plottables.empty()) { - qCDebug(LOG_VisualizationGraphHelper()) - << QObject::tr("Can't update spectrogram: no colormap has been associated"); - return; - } - - // Gets the colormap to update (normally there is only one colormap) - Q_ASSERT(plottables.size() == 1); - auto colormap = dynamic_cast(plottables.at(0)); - Q_ASSERT(colormap != nullptr); - - dataSeries.lockRead(); - - // Processing spectrogram data for display in QCustomPlot - auto its = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd); - // Computes logarithmic y-axis resolution for the spectrogram - auto yData = its.first->y(); - auto yResolution = DataSeriesUtils::resolution(yData.begin(), yData.end(), true); - - // Generates mesh for colormap - auto mesh = DataSeriesUtils::regularMesh( - its.first, its.second, DataSeriesUtils::Resolution{dataSeries.xResolution()}, - yResolution); - - dataSeries.unlock(); - - colormap->data()->setSize(mesh.m_NbX, mesh.m_NbY); - if (!mesh.isEmpty()) { - colormap->data()->setRange( - QCPRange{mesh.m_XMin, mesh.xMax()}, - // y-axis range is converted to linear values - QCPRange{std::pow(10, mesh.m_YMin), std::pow(10, mesh.yMax())}); - - // Sets values - auto index = 0; - for (auto it = mesh.m_Data.begin(), end = mesh.m_Data.end(); it != end; ++it, ++index) { - auto xIndex = index % mesh.m_NbX; - auto yIndex = index / mesh.m_NbX; - - colormap->data()->setCell(xIndex, yIndex, *it); - - // Makes the NaN values to be transparent in the colormap - if (std::isnan(*it)) { - colormap->data()->setAlpha(xIndex, yIndex, 0); + // For each plottable to update, resets its data + for (const auto& plottable : plottables) + { + if (auto graph = dynamic_cast(plottable.second)) + { + auto dataContainer = QSharedPointer::create(); + if (auto serie = dynamic_cast(&dataSeries)) + { + switch (plottable.first) + { + case 0: + std::for_each(std::begin(*serie), std::end(*serie), + [&dataContainer](const auto& value) { + dataContainer->appendGraphData( + QCPGraphData(value.t(), value.v().x)); + }); + break; + case 1: + std::for_each(std::begin(*serie), std::end(*serie), + [&dataContainer](const auto& value) { + dataContainer->appendGraphData( + QCPGraphData(value.t(), value.v().y)); + }); + break; + case 2: + std::for_each(std::begin(*serie), std::end(*serie), + [&dataContainer](const auto& value) { + dataContainer->appendGraphData( + QCPGraphData(value.t(), value.v().z)); + }); + break; + default: + break; + } } + graph->setData(dataContainer); } } - // Rescales axes - auto plot = colormap->parentPlot(); + if (!plottables.empty()) + { + auto plot = plottables.begin()->second->parentPlot(); - if (rescaleAxes) { - plot->rescaleAxes(); + if (rescaleAxes) + { + plot->rescaleAxes(); + } } } }; /** + * Specialization of PlottablesUpdater for spectrograms + * @sa SpectrogramSeries + */ +template +struct PlottablesUpdater::value>> +{ + static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot) + { + // TODO + // double min, max; + // std::tie(min, max) = dataSeries.yBounds(); + + // if (!std::isnan(min) && !std::isnan(max)) + // { + // plot.yAxis->setRange(QCPRange { min, max }); + // } + } + + static void updatePlottables( + T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) + { + // TODO + // if (plottables.empty()) + // { + // qCDebug(LOG_VisualizationGraphHelper()) + // << QObject::tr("Can't update spectrogram: no colormap has been + // associated"); + // return; + // } + + // // Gets the colormap to update (normally there is only one colormap) + // Q_ASSERT(plottables.size() == 1); + // auto colormap = dynamic_cast(plottables.at(0)); + // Q_ASSERT(colormap != nullptr); + + // dataSeries.lockRead(); + + // // Processing spectrogram data for display in QCustomPlot + // auto its = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd); + + // // Computes logarithmic y-axis resolution for the spectrogram + // auto yData = its.first->y(); + // auto yResolution = DataSeriesUtils::resolution(yData.begin(), yData.end(), true); + + // // Generates mesh for colormap + // auto mesh = DataSeriesUtils::regularMesh(its.first, its.second, + // DataSeriesUtils::Resolution { dataSeries.xResolution() }, yResolution); + + // dataSeries.unlock(); + + // colormap->data()->setSize(mesh.m_NbX, mesh.m_NbY); + // if (!mesh.isEmpty()) + // { + // colormap->data()->setRange(QCPRange { mesh.m_XMin, mesh.xMax() }, + // // y-axis range is converted to linear values + // QCPRange { std::pow(10, mesh.m_YMin), std::pow(10, mesh.yMax()) }); + + // // Sets values + // auto index = 0; + // for (auto it = mesh.m_Data.begin(), end = mesh.m_Data.end(); it != end; ++it, + // ++index) + // { + // auto xIndex = index % mesh.m_NbX; + // auto yIndex = index / mesh.m_NbX; + + // colormap->data()->setCell(xIndex, yIndex, *it); + + // // Makes the NaN values to be transparent in the colormap + // if (std::isnan(*it)) + // { + // colormap->data()->setAlpha(xIndex, yIndex, 0); + // } + // } + // } + + // // Rescales axes + // auto plot = colormap->parentPlot(); + + // if (rescaleAxes) + // { + // plot->rescaleAxes(); + // } + } +}; + +/** * Helper used to create/update plottables */ -struct IPlottablesHelper { +struct IPlottablesHelper +{ virtual ~IPlottablesHelper() noexcept = default; - virtual PlottablesMap create(QCustomPlot &plot) const = 0; - virtual void setYAxisRange(const DateTimeRange &xAxisRange, QCustomPlot &plot) const = 0; - virtual void update(PlottablesMap &plottables, const DateTimeRange &range, - bool rescaleAxes = false) const = 0; + virtual PlottablesMap create(QCustomPlot& plot) const = 0; + virtual void setYAxisRange(const DateTimeRange& xAxisRange, QCustomPlot& plot) const = 0; + virtual void update( + PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes = false) const = 0; }; /** @@ -266,95 +338,105 @@ struct IPlottablesHelper { * @tparam T the data series' type */ template -struct PlottablesHelper : public IPlottablesHelper { - explicit PlottablesHelper(std::shared_ptr dataSeries) : m_DataSeries{dataSeries} {} +struct PlottablesHelper : public IPlottablesHelper +{ + explicit PlottablesHelper(T* dataSeries) : m_DataSeries { dataSeries } {} - PlottablesMap create(QCustomPlot &plot) const override + PlottablesMap create(QCustomPlot& plot) const override { return PlottablesCreator::createPlottables(plot); } - void update(PlottablesMap &plottables, const DateTimeRange &range, bool rescaleAxes) const override + void update( + PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) const override { - if (m_DataSeries) { + if (m_DataSeries) + { PlottablesUpdater::updatePlottables(*m_DataSeries, plottables, range, rescaleAxes); } - else { + else + { qCCritical(LOG_VisualizationGraphHelper()) << "Can't update plottables: inconsistency " "between the type of data series and the " "type supposed"; } } - void setYAxisRange(const DateTimeRange &xAxisRange, QCustomPlot &plot) const override + void setYAxisRange(const DateTimeRange& xAxisRange, QCustomPlot& plot) const override { - if (m_DataSeries) { + if (m_DataSeries) + { PlottablesUpdater::setPlotYAxisRange(*m_DataSeries, xAxisRange, plot); } - else { + else + { qCCritical(LOG_VisualizationGraphHelper()) << "Can't update plottables: inconsistency " "between the type of data series and the " "type supposed"; } } - std::shared_ptr m_DataSeries; + T* m_DataSeries; }; /// Creates IPlottablesHelper according to the type of data series a variable holds -std::unique_ptr createHelper(std::shared_ptr variable) noexcept +std::unique_ptr createHelper(std::shared_ptr variable) noexcept { - switch (variable->type()) { + switch (variable->type()) + { case DataSeriesType::SCALAR: - return std::make_unique >( - std::dynamic_pointer_cast(variable->dataSeries())); + return std::make_unique>( + dynamic_cast(variable->data()->base())); case DataSeriesType::SPECTROGRAM: - return std::make_unique >( - std::dynamic_pointer_cast(variable->dataSeries())); + return std::make_unique>( + dynamic_cast(variable->data()->base())); case DataSeriesType::VECTOR: - return std::make_unique >( - std::dynamic_pointer_cast(variable->dataSeries())); + return std::make_unique>( + dynamic_cast(variable->data()->base())); default: // Creates default helper break; } - return std::make_unique >(nullptr); + return std::make_unique>(nullptr); } } // namespace -PlottablesMap VisualizationGraphHelper::create(std::shared_ptr variable, - QCustomPlot &plot) noexcept +PlottablesMap VisualizationGraphHelper::create( + std::shared_ptr variable, QCustomPlot& plot) noexcept { - if (variable) { + if (variable) + { auto helper = createHelper(variable); auto plottables = helper->create(plot); return plottables; } - else { + else + { qCDebug(LOG_VisualizationGraphHelper()) << QObject::tr("Can't create graph plottables : the variable is null"); - return PlottablesMap{}; + return PlottablesMap {}; } } -void VisualizationGraphHelper::setYAxisRange(std::shared_ptr variable, - QCustomPlot &plot) noexcept +void VisualizationGraphHelper::setYAxisRange( + std::shared_ptr variable, QCustomPlot& plot) noexcept { - if (variable) { + if (variable) + { auto helper = createHelper(variable); helper->setYAxisRange(variable->range(), plot); } - else { + else + { qCDebug(LOG_VisualizationGraphHelper()) << QObject::tr("Can't set y-axis range of plot: the variable is null"); } } -void VisualizationGraphHelper::updateData(PlottablesMap &plottables, - std::shared_ptr variable, - const DateTimeRange &dateTime) +void VisualizationGraphHelper::updateData( + PlottablesMap& plottables, std::shared_ptr variable, const DateTimeRange& dateTime) { auto helper = createHelper(variable); helper->update(plottables, dateTime); diff --git a/gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp b/gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp index 0c39021..c9b20db 100644 --- a/gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp +++ b/gui/src/Visualization/VisualizationGraphRenderingDelegate.cpp @@ -13,7 +13,8 @@ #include -namespace { +namespace +{ /// Name of the axes layer in QCustomPlot const auto AXES_LAYER = QStringLiteral("axes"); @@ -34,15 +35,15 @@ const auto GRAPH_TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); const auto COLORMAP_TOOLTIP_FORMAT = QStringLiteral("x: %1\ny: %2\nvalue: %3"); /// Offset used to shift the tooltip of the mouse -const auto TOOLTIP_OFFSET = QPoint{20, 20}; +const auto TOOLTIP_OFFSET = QPoint { 20, 20 }; /// Tooltip display rectangle (the tooltip is hidden when the mouse leaves this rectangle) -const auto TOOLTIP_RECT = QRect{10, 10, 10, 10}; +const auto TOOLTIP_RECT = QRect { 10, 10, 10, 10 }; /// Timeout after which the tooltip is displayed const auto TOOLTIP_TIMEOUT = 500; -void initPointTracerStyle(QCPItemTracer &tracer) noexcept +void initPointTracerStyle(QCPItemTracer& tracer) noexcept { tracer.setInterpolating(false); tracer.setStyle(QCPItemTracer::tsCircle); @@ -52,16 +53,16 @@ void initPointTracerStyle(QCPItemTracer &tracer) noexcept tracer.setSelectable(false); } -QPixmap pixmap(const QString &iconPath) noexcept +QPixmap pixmap(const QString& iconPath) noexcept { - return QIcon{iconPath}.pixmap(QSize{16, 16}); + return QIcon { iconPath }.pixmap(QSize { 16, 16 }); } -void initClosePixmapStyle(QCPItemPixmap &pixmap) noexcept +void initClosePixmapStyle(QCPItemPixmap& pixmap) noexcept { // Icon pixmap.setPixmap( - sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton).pixmap(QSize{16, 16})); + sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton).pixmap(QSize { 16, 16 })); // Position pixmap.topLeft->setType(QCPItemPosition::ptAxisRectRatio); @@ -72,7 +73,7 @@ void initClosePixmapStyle(QCPItemPixmap &pixmap) noexcept pixmap.setSelectable(true); } -void initXAxisPixmapStyle(QCPItemPixmap &itemPixmap) noexcept +void initXAxisPixmapStyle(QCPItemPixmap& itemPixmap) noexcept { // Icon itemPixmap.setPixmap(pixmap(HIDE_AXIS_ICON_PATH)); @@ -86,7 +87,7 @@ void initXAxisPixmapStyle(QCPItemPixmap &itemPixmap) noexcept itemPixmap.setSelectable(true); } -void initTitleTextStyle(QCPItemText &text) noexcept +void initTitleTextStyle(QCPItemText& text) noexcept { // Font and background styles text.setColor(Qt::gray); @@ -107,13 +108,14 @@ void initTitleTextStyle(QCPItemText &text) noexcept * @param xCoord calculates the x index if true, calculates y index if false * @return the cell index */ -int colorMapCellIndex(const QCPColorMap &colormap, double coord, bool xCoord) +int colorMapCellIndex(const QCPColorMap& colormap, double coord, bool xCoord) { // Determines the axis of the colormap according to xCoord, and whether it is logarithmic or not auto isLogarithmic = (xCoord ? colormap.keyAxis() : colormap.valueAxis())->scaleType() - == QCPAxis::stLogarithmic; + == QCPAxis::stLogarithmic; - if (isLogarithmic) { + if (isLogarithmic) + { // For a logarithmic axis we can't use the conversion method of colormap, so we calculate // the index manually based on the position of the coordinate on the axis @@ -127,13 +129,16 @@ int colorMapCellIndex(const QCPColorMap &colormap, double coord, bool xCoord) // According to the coord position, calculates the closest index in the range return std::round((std::log10(coord) - std::log10(range.lower)) / valueStep); } - else { + else + { // For a linear axis, we use the conversion method of colormap int index; - if (xCoord) { + if (xCoord) + { colormap.data()->coordToCell(coord, 0., &index, nullptr); } - else { + else + { colormap.data()->coordToCell(0., coord, nullptr, &index); } @@ -143,17 +148,18 @@ int colorMapCellIndex(const QCPColorMap &colormap, double coord, bool xCoord) } // namespace -struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { - explicit VisualizationGraphRenderingDelegatePrivate(VisualizationGraphWidget &graphWidget) - : m_Plot{graphWidget.plot()}, - m_PointTracer{new QCPItemTracer{&m_Plot}}, - m_TracerTimer{}, - m_ClosePixmap{new QCPItemPixmap{&m_Plot}}, - m_TitleText{new QCPItemText{&m_Plot}}, - m_XAxisPixmap{new QCPItemPixmap{&m_Plot}}, - m_ShowXAxis{true}, - m_XAxisLabel{}, - m_ColorScale{SqpColorScale{m_Plot}} +struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate +{ + explicit VisualizationGraphRenderingDelegatePrivate(VisualizationGraphWidget& graphWidget) + : m_Plot { graphWidget.plot() } + , m_PointTracer { new QCPItemTracer { &m_Plot } } + , m_TracerTimer {} + , m_ClosePixmap { new QCPItemPixmap { &m_Plot } } + , m_TitleText { new QCPItemText { &m_Plot } } + , m_XAxisPixmap { new QCPItemPixmap { &m_Plot } } + , m_ShowXAxis { true } + , m_XAxisLabel {} + , m_ColorScale { SqpColorScale { m_Plot } } { initPointTracerStyle(*m_PointTracer); @@ -165,12 +171,13 @@ struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP initClosePixmapStyle(*m_ClosePixmap); // Connects pixmap selection to graph widget closing - QObject::connect(&m_Plot, &QCustomPlot::itemClick, - [&graphWidget, this](auto item, auto mouseEvent) { - if (item == m_ClosePixmap) { - graphWidget.close(); - } - }); + QObject::connect( + &m_Plot, &QCustomPlot::itemClick, [&graphWidget, this](auto item, auto mouseEvent) { + if (item == m_ClosePixmap) + { + graphWidget.close(); + } + }); // Inits graph name in plot overlay m_TitleText->setLayer(OVERLAY_LAYER); @@ -183,7 +190,8 @@ struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP // Connects pixmap selection to graph x-axis showing/hiding QObject::connect(&m_Plot, &QCustomPlot::itemClick, [this](auto item, auto mouseEvent) { - if (m_XAxisPixmap == item) { + if (m_XAxisPixmap == item) + { // Changes the selection state and refreshes the x-axis m_ShowXAxis = !m_ShowXAxis; this->updateXAxisState(); @@ -202,38 +210,40 @@ struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP void updateXAxisState() noexcept { m_Plot.xAxis->setTickLabels(m_ShowXAxis); - m_Plot.xAxis->setLabel(m_ShowXAxis ? m_XAxisLabel : QString{}); + m_Plot.xAxis->setLabel(m_ShowXAxis ? m_XAxisLabel : QString {}); } - QCustomPlot &m_Plot; - QCPItemTracer *m_PointTracer; + QCustomPlot& m_Plot; + QCPItemTracer* m_PointTracer; QTimer m_TracerTimer; - QCPItemPixmap *m_ClosePixmap; /// Graph's close button - QCPItemText *m_TitleText; /// Graph's title - QCPItemPixmap *m_XAxisPixmap; + QCPItemPixmap* m_ClosePixmap; /// Graph's close button + QCPItemText* m_TitleText; /// Graph's title + QCPItemPixmap* m_XAxisPixmap; bool m_ShowXAxis; /// X-axis properties are shown or hidden QString m_XAxisLabel; SqpColorScale m_ColorScale; /// Color scale used for some types of graphs (as spectrograms) }; VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( - VisualizationGraphWidget &graphWidget) - : impl{spimpl::make_unique_impl(graphWidget)} + VisualizationGraphWidget& graphWidget) + : impl { spimpl::make_unique_impl(graphWidget) } { } -void VisualizationGraphRenderingDelegate::onMouseDoubleClick(QMouseEvent *event) noexcept +void VisualizationGraphRenderingDelegate::onMouseDoubleClick(QMouseEvent* event) noexcept { // Opens color scale editor if color scale is double clicked - auto colorScale = static_cast(impl->m_Plot.layoutElementAt(event->pos())); - if (impl->m_ColorScale.m_Scale == colorScale) { - if (ColorScaleEditor{impl->m_ColorScale}.exec() == QDialog::Accepted) { + auto colorScale = static_cast(impl->m_Plot.layoutElementAt(event->pos())); + if (impl->m_ColorScale.m_Scale == colorScale) + { + if (ColorScaleEditor { impl->m_ColorScale }.exec() == QDialog::Accepted) + { impl->m_Plot.replot(); } } } -void VisualizationGraphRenderingDelegate::updateTooltip(QMouseEvent *event) noexcept +void VisualizationGraphRenderingDelegate::updateTooltip(QMouseEvent* event) noexcept { // Cancels pending refresh impl->m_TracerTimer.disconnect(); @@ -243,17 +253,19 @@ void VisualizationGraphRenderingDelegate::updateTooltip(QMouseEvent *event) noex impl->m_PointTracer->setVisible(false); impl->m_Plot.replot(); - QString tooltip{}; + QString tooltip {}; // Gets the graph under the mouse position auto eventPos = event->pos(); - if (auto graph = qobject_cast(impl->m_Plot.plottableAt(eventPos))) { + if (auto graph = qobject_cast(impl->m_Plot.plottableAt(eventPos))) + { auto mouseKey = graph->keyAxis()->pixelToCoord(eventPos.x()); auto graphData = graph->data(); // Gets the closest data point to the mouse auto graphDataIt = graphData->findBegin(mouseKey); - if (graphDataIt != graphData->constEnd()) { + if (graphDataIt != graphData->constEnd()) + { // Sets tooltip auto key = formatValue(graphDataIt->key, *graph->keyAxis()); auto value = formatValue(graphDataIt->value, *graph->valueAxis()); @@ -268,7 +280,8 @@ void VisualizationGraphRenderingDelegate::updateTooltip(QMouseEvent *event) noex impl->m_Plot.replot(); } } - else if (auto colorMap = qobject_cast(impl->m_Plot.plottableAt(eventPos))) { + else if (auto colorMap = qobject_cast(impl->m_Plot.plottableAt(eventPos))) + { // Gets x and y coords auto x = colorMap->keyAxis()->pixelToCoord(eventPos.x()); auto y = colorMap->valueAxis()->pixelToCoord(eventPos.y()); @@ -280,15 +293,16 @@ void VisualizationGraphRenderingDelegate::updateTooltip(QMouseEvent *event) noex // Sets tooltips tooltip = COLORMAP_TOOLTIP_FORMAT.arg(formatValue(x, *colorMap->keyAxis()), - formatValue(y, *colorMap->valueAxis()), - formatValue(value, *colorMap->colorScale()->axis())); + formatValue(y, *colorMap->valueAxis()), + formatValue(value, *colorMap->colorScale()->axis())); } - if (!tooltip.isEmpty()) { + if (!tooltip.isEmpty()) + { // Starts timer to show tooltip after timeout auto showTooltip = [tooltip, eventPos, this]() { QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip, - &impl->m_Plot, TOOLTIP_RECT); + &impl->m_Plot, TOOLTIP_RECT); }; QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip); @@ -303,7 +317,7 @@ void VisualizationGraphRenderingDelegate::onPlotUpdated() noexcept impl->m_Plot.replot(); } -void VisualizationGraphRenderingDelegate::setAxesUnits(const Variable &variable) noexcept +void VisualizationGraphRenderingDelegate::setAxesUnits(Variable2& variable) noexcept { auto axisHelper = IAxisHelperFactory::create(variable); @@ -318,8 +332,8 @@ void VisualizationGraphRenderingDelegate::setAxesUnits(const Variable &variable) impl->m_Plot.layer(AXES_LAYER)->replot(); } -void VisualizationGraphRenderingDelegate::setGraphProperties(const Variable &variable, - PlottablesMap &plottables) noexcept +void VisualizationGraphRenderingDelegate::setGraphProperties( + Variable2& variable, PlottablesMap& plottables) noexcept { // Axes' properties auto axisHelper = IAxisHelperFactory::create(variable); diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index ba271d9..7fb9525 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -16,21 +16,22 @@ #include #include #include +#include #include #include #include #include #include #include