@@ -1,5 +1,5 | |||||
1 | #ifndef DRAGDROPHELPER_H |
|
1 | #ifndef SCIQLOP_DRAGDROPHELPER_H | |
2 | #define DRAGDROPHELPER_H |
|
2 | #define SCIQLOP_DRAGDROPHELPER_H | |
3 |
|
3 | |||
4 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
5 | #include <QWidget> |
|
5 | #include <QWidget> | |
@@ -13,15 +13,14 class QMimeData; | |||||
13 | * @brief Event filter class which manage the scroll of QScrollArea during a drag&drop operation. |
|
13 | * @brief Event filter class which manage the scroll of QScrollArea during a drag&drop operation. | |
14 | * @note A QScrollArea inside an other QScrollArea is not fully supported. |
|
14 | * @note A QScrollArea inside an other QScrollArea is not fully supported. | |
15 | */ |
|
15 | */ | |
16 | class DragDropScroller : public QObject |
|
16 | class DragDropScroller : public QObject { | |
17 | { |
|
|||
18 | Q_OBJECT |
|
17 | Q_OBJECT | |
19 |
|
18 | |||
20 | public: |
|
19 | public: | |
21 |
DragDropScroller(QObject* |
|
20 | DragDropScroller(QObject *parent = nullptr); | |
22 |
|
21 | |||
23 |
void addScrollArea(QScrollArea* |
|
22 | void addScrollArea(QScrollArea *scrollArea); | |
24 |
void removeScrollArea(QScrollArea* |
|
23 | void removeScrollArea(QScrollArea *scrollArea); | |
25 |
|
24 | |||
26 | protected: |
|
25 | protected: | |
27 | bool eventFilter(QObject *obj, QEvent *event); |
|
26 | bool eventFilter(QObject *obj, QEvent *event); | |
@@ -37,31 +36,30 private slots: | |||||
37 | /** |
|
36 | /** | |
38 | * @brief Helper class for drag&drop operations. |
|
37 | * @brief Helper class for drag&drop operations. | |
39 | */ |
|
38 | */ | |
40 | class DragDropHelper |
|
39 | class DragDropHelper { | |
41 | { |
|
|||
42 | public: |
|
40 | public: | |
43 | DragDropHelper(); |
|
|||
44 | ~DragDropHelper(); |
|
|||
45 |
|
||||
46 | static const QString MIME_TYPE_GRAPH; |
|
41 | static const QString MIME_TYPE_GRAPH; | |
47 | static const QString MIME_TYPE_ZONE; |
|
42 | static const QString MIME_TYPE_ZONE; | |
48 |
|
43 | |||
49 | void setCurrentDragWidget(VisualizationDragWidget* dragWidget); |
|
44 | DragDropHelper(); | |
50 | VisualizationDragWidget* getCurrentDragWidget() const; |
|
45 | virtual ~DragDropHelper(); | |
|
46 | ||||
|
47 | void setCurrentDragWidget(VisualizationDragWidget *dragWidget); | |||
|
48 | VisualizationDragWidget *getCurrentDragWidget() const; | |||
51 |
|
49 | |||
52 | QWidget &placeHolder() const; |
|
50 | QWidget &placeHolder() const; | |
53 |
void insertPlaceHolder(QVBoxLayout* |
|
51 | void insertPlaceHolder(QVBoxLayout *layout, int index); | |
54 | void removePlaceHolder(); |
|
52 | void removePlaceHolder(); | |
55 | bool isPlaceHolderSet() const; |
|
53 | bool isPlaceHolderSet() const; | |
56 |
|
54 | |||
57 |
void addDragDropScrollArea(QScrollArea* |
|
55 | void addDragDropScrollArea(QScrollArea *scrollArea); | |
58 |
void removeDragDropScrollArea(QScrollArea* |
|
56 | void removeDragDropScrollArea(QScrollArea *scrollArea); | |
59 |
|
57 | |||
60 |
QUrl imageTemporaryUrl(const QImage& |
|
58 | QUrl imageTemporaryUrl(const QImage &image) const; | |
61 |
|
59 | |||
62 | private: |
|
60 | private: | |
63 | class DragDropHelperPrivate; |
|
61 | class DragDropHelperPrivate; | |
64 | spimpl::unique_impl_ptr<DragDropHelperPrivate> impl; |
|
62 | spimpl::unique_impl_ptr<DragDropHelperPrivate> impl; | |
65 | }; |
|
63 | }; | |
66 |
|
64 | |||
67 | #endif // DRAGDROPHELPER_H |
|
65 | #endif // SCIQLOP_DRAGDROPHELPER_H |
@@ -45,7 +45,7 public: | |||||
45 | VariableController &variableController() noexcept; |
|
45 | VariableController &variableController() noexcept; | |
46 | VisualizationController &visualizationController() noexcept; |
|
46 | VisualizationController &visualizationController() noexcept; | |
47 |
|
47 | |||
48 |
|
|
48 | /// Accessors for the differents sciqlop helpers | |
49 | DragDropHelper &dragDropHelper() noexcept; |
|
49 | DragDropHelper &dragDropHelper() noexcept; | |
50 |
|
50 | |||
51 | private: |
|
51 | private: |
@@ -1,28 +1,27 | |||||
1 | #ifndef VISUALIZATIONDRAGDROPCONTAINER_H |
|
1 | #ifndef VISUALIZATIONDRAGDROPCONTAINER_H | |
2 | #define VISUALIZATIONDRAGDROPCONTAINER_H |
|
2 | #define VISUALIZATIONDRAGDROPCONTAINER_H | |
3 |
|
3 | |||
4 | #include <QWidget> |
|
|||
5 | #include <QVBoxLayout> |
|
|||
6 | #include <QMimeData> |
|
|||
7 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QMimeData> | |||
|
6 | #include <QVBoxLayout> | |||
|
7 | #include <QWidget> | |||
8 |
|
8 | |||
9 | class VisualizationDragWidget; |
|
9 | class VisualizationDragWidget; | |
10 |
|
10 | |||
11 | class VisualizationDragDropContainer : public QWidget |
|
11 | class VisualizationDragDropContainer : public QWidget { | |
12 | { |
|
|||
13 | Q_OBJECT |
|
12 | Q_OBJECT | |
14 |
|
13 | |||
15 | signals: |
|
14 | signals: | |
16 |
void dropOccured(int dropIndex, const QMimeData* |
|
15 | void dropOccured(int dropIndex, const QMimeData *mimeData); | |
17 |
|
16 | |||
18 | public: |
|
17 | public: | |
19 |
VisualizationDragDropContainer(QWidget* |
|
18 | VisualizationDragDropContainer(QWidget *parent = nullptr); | |
20 |
|
19 | |||
21 |
void addDragWidget(VisualizationDragWidget* |
|
20 | void addDragWidget(VisualizationDragWidget *dragWidget); | |
22 |
void insertDragWidget(int index, VisualizationDragWidget* |
|
21 | void insertDragWidget(int index, VisualizationDragWidget *dragWidget); | |
23 |
|
22 | |||
24 |
void setAcceptedMimeTypes(const QStringList& |
|
23 | void setAcceptedMimeTypes(const QStringList &mimeTypes); | |
25 |
void setMergeAllowedMimeTypes(const QStringList& |
|
24 | void setMergeAllowedMimeTypes(const QStringList &mimeTypes); | |
26 |
|
25 | |||
27 | int countDragWidget() const; |
|
26 | int countDragWidget() const; | |
28 |
|
27 | |||
@@ -33,13 +32,11 protected: | |||||
33 | void dropEvent(QDropEvent *event); |
|
32 | void dropEvent(QDropEvent *event); | |
34 |
|
33 | |||
35 | private: |
|
34 | private: | |
36 |
|
||||
37 |
|
||||
38 | class VisualizationDragDropContainerPrivate; |
|
35 | class VisualizationDragDropContainerPrivate; | |
39 | spimpl::unique_impl_ptr<VisualizationDragDropContainerPrivate> impl; |
|
36 | spimpl::unique_impl_ptr<VisualizationDragDropContainerPrivate> impl; | |
40 |
|
37 | |||
41 | private slots: |
|
38 | private slots: | |
42 |
void startDrag(VisualizationDragWidget* |
|
39 | void startDrag(VisualizationDragWidget *dragWidget, const QPoint &dragPosition); | |
43 | }; |
|
40 | }; | |
44 |
|
41 | |||
45 | #endif // VISUALIZATIONDRAGDROPCONTAINER_H |
|
42 | #endif // VISUALIZATIONDRAGDROPCONTAINER_H |
@@ -1,18 +1,17 | |||||
1 | #ifndef VISUALIZATIONDRAGWIDGET_H |
|
1 | #ifndef VISUALIZATIONDRAGWIDGET_H | |
2 | #define VISUALIZATIONDRAGWIDGET_H |
|
2 | #define VISUALIZATIONDRAGWIDGET_H | |
3 |
|
3 | |||
4 | #include <QWidget> |
|
|||
5 | #include <QMimeData> |
|
|||
6 | #include <Common/spimpl.h> |
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QMimeData> | |||
|
6 | #include <QWidget> | |||
7 |
|
7 | |||
8 | class VisualizationDragWidget : public QWidget |
|
8 | class VisualizationDragWidget : public QWidget { | |
9 | { |
|
|||
10 | Q_OBJECT |
|
9 | Q_OBJECT | |
11 |
|
10 | |||
12 | public: |
|
11 | public: | |
13 |
VisualizationDragWidget(QWidget* |
|
12 | VisualizationDragWidget(QWidget *parent = nullptr); | |
14 |
|
13 | |||
15 |
virtual QMimeData* |
|
14 | virtual QMimeData *mimeData() const = 0; | |
16 | virtual bool isDragAllowed() const = 0; |
|
15 | virtual bool isDragAllowed() const = 0; | |
17 |
|
16 | |||
18 | protected: |
|
17 | protected: | |
@@ -24,7 +23,7 private: | |||||
24 | spimpl::unique_impl_ptr<VisualizationDragWidgetPrivate> impl; |
|
23 | spimpl::unique_impl_ptr<VisualizationDragWidgetPrivate> impl; | |
25 |
|
24 | |||
26 | signals: |
|
25 | signals: | |
27 |
void dragDetected(VisualizationDragWidget* |
|
26 | void dragDetected(VisualizationDragWidget *dragWidget, const QPoint &dragPosition); | |
28 | }; |
|
27 | }; | |
29 |
|
28 | |||
30 | #endif // VISUALIZATIONDRAGWIDGET_H |
|
29 | #endif // VISUALIZATIONDRAGWIDGET_H |
@@ -33,7 +33,7 public: | |||||
33 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
33 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
34 | virtual ~VisualizationGraphWidget(); |
|
34 | virtual ~VisualizationGraphWidget(); | |
35 |
|
35 | |||
36 |
VisualizationZoneWidget* |
|
36 | VisualizationZoneWidget *parentZoneWidget() const noexcept; | |
37 |
|
37 | |||
38 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
38 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit | |
39 | void enableAcquisition(bool enable); |
|
39 | void enableAcquisition(bool enable); | |
@@ -44,7 +44,7 public: | |||||
44 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
44 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
45 |
|
45 | |||
46 | /// Returns the list of all variables used in the graph |
|
46 | /// Returns the list of all variables used in the graph | |
47 | QList<std::shared_ptr<Variable>> variables() const; |
|
47 | QList<std::shared_ptr<Variable> > variables() const; | |
48 |
|
48 | |||
49 | void setYRange(const SqpRange &range); |
|
49 | void setYRange(const SqpRange &range); | |
50 | SqpRange graphRange() const noexcept; |
|
50 | SqpRange graphRange() const noexcept; | |
@@ -57,7 +57,7 public: | |||||
57 | QString name() const override; |
|
57 | QString name() const override; | |
58 |
|
58 | |||
59 | // VisualisationDragWidget |
|
59 | // VisualisationDragWidget | |
60 |
QMimeData* |
|
60 | QMimeData *mimeData() const override; | |
61 | bool isDragAllowed() const override; |
|
61 | bool isDragAllowed() const override; | |
62 |
|
62 | |||
63 | signals: |
|
63 | signals: |
@@ -6,8 +6,8 | |||||
6 | #include <Common/spimpl.h> |
|
6 | #include <Common/spimpl.h> | |
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 | #include <QWidget> |
|
|||
10 | #include <QMimeData> |
|
9 | #include <QMimeData> | |
|
10 | #include <QWidget> | |||
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) | |
13 |
|
13 | |||
@@ -39,13 +39,14 public: | |||||
39 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); |
|
39 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); | |
40 |
|
40 | |||
41 | /** |
|
41 | /** | |
42 |
* Creates a zone using a list of variables. The variables will be displayed in a new graph of |
|
42 | * Creates a zone using a list of variables. The variables will be displayed in a new graph of | |
43 | * zone. The zone is inserted at the specified index. |
|
43 | * the new zone. The zone is inserted at the specified index. | |
44 | * @param variables the variables for which to create the zone |
|
44 | * @param variables the variables for which to create the zone | |
45 | * @param index The index where the zone should be inserted in the layout |
|
45 | * @param index The index where the zone should be inserted in the layout | |
46 | * @return the pointer to the created zone |
|
46 | * @return the pointer to the created zone | |
47 | */ |
|
47 | */ | |
48 |
VisualizationZoneWidget *createZone(const QList<std::shared_ptr<Variable>>& |
|
48 | VisualizationZoneWidget *createZone(const QList<std::shared_ptr<Variable> > &variables, | |
|
49 | int index); | |||
49 |
|
50 | |||
50 | /** |
|
51 | /** | |
51 | * Creates a zone which is empty (no variables). The zone is inserted at the specified index. |
|
52 | * Creates a zone which is empty (no variables). The zone is inserted at the specified index. |
@@ -15,7 +15,7 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget) | |||||
15 |
|
15 | |||
16 | namespace Ui { |
|
16 | namespace Ui { | |
17 | class VisualizationZoneWidget; |
|
17 | class VisualizationZoneWidget; | |
18 | } // Ui |
|
18 | } // namespace Ui | |
19 |
|
19 | |||
20 | class Variable; |
|
20 | class Variable; | |
21 | class VisualizationGraphWidget; |
|
21 | class VisualizationGraphWidget; | |
@@ -30,7 +30,7 public: | |||||
30 | /// Adds a graph widget |
|
30 | /// Adds a graph widget | |
31 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
31 | void addGraph(VisualizationGraphWidget *graphWidget); | |
32 |
|
32 | |||
33 |
|
|
33 | /// Inserts a graph widget | |
34 | void insertGraph(int index, VisualizationGraphWidget *graphWidget); |
|
34 | void insertGraph(int index, VisualizationGraphWidget *graphWidget); | |
35 |
|
35 | |||
36 | /** |
|
36 | /** | |
@@ -57,7 +57,8 public: | |||||
57 | * @param index The index where the graph should be inserted in the layout |
|
57 | * @param index The index where the graph should be inserted in the layout | |
58 | * @return the pointer to the created graph |
|
58 | * @return the pointer to the created graph | |
59 | */ |
|
59 | */ | |
60 |
VisualizationGraphWidget *createGraph(const QList<std::shared_ptr<Variable>> variables, |
|
60 | VisualizationGraphWidget *createGraph(const QList<std::shared_ptr<Variable> > variables, | |
|
61 | int index); | |||
61 |
|
62 | |||
62 | // IVisualizationWidget interface |
|
63 | // IVisualizationWidget interface | |
63 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
64 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
@@ -66,7 +67,7 public: | |||||
66 | QString name() const override; |
|
67 | QString name() const override; | |
67 |
|
68 | |||
68 | // VisualisationDragWidget |
|
69 | // VisualisationDragWidget | |
69 |
QMimeData* |
|
70 | QMimeData *mimeData() const override; | |
70 | bool isDragAllowed() const override; |
|
71 | bool isDragAllowed() const override; | |
71 |
|
72 | |||
72 | protected: |
|
73 | protected: | |
@@ -83,7 +84,7 private slots: | |||||
83 | /// Slot called when a variable is about to be removed from a graph contained in the zone |
|
84 | /// Slot called when a variable is about to be removed from a graph contained in the zone | |
84 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); |
|
85 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); | |
85 |
|
86 | |||
86 |
void dropMimeData(int index, const QMimeData* |
|
87 | void dropMimeData(int index, const QMimeData *mimeData); | |
87 | }; |
|
88 | }; | |
88 |
|
89 | |||
89 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
90 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -1,14 +1,14 | |||||
1 | #include "DragDropHelper.h" |
|
1 | #include "DragDropHelper.h" | |
2 | #include "Visualization/VisualizationDragWidget.h" |
|
|||
3 | #include "SqpApplication.h" |
|
2 | #include "SqpApplication.h" | |
|
3 | #include "Visualization/VisualizationDragWidget.h" | |||
4 |
|
4 | |||
5 |
#include <QDr |
|
5 | #include <QDir> | |
6 | #include <QDragEnterEvent> |
|
6 | #include <QDragEnterEvent> | |
7 |
#include <Q |
|
7 | #include <QDragMoveEvent> | |
8 | #include <QScrollArea> |
|
8 | #include <QScrollArea> | |
9 |
#include <Q |
|
9 | #include <QScrollBar> | |
10 | #include <QTimer> |
|
10 | #include <QTimer> | |
11 |
#include <Q |
|
11 | #include <QVBoxLayout> | |
12 |
|
12 | |||
13 | const QString DragDropHelper::MIME_TYPE_GRAPH = "scqlop/graph"; |
|
13 | const QString DragDropHelper::MIME_TYPE_GRAPH = "scqlop/graph"; | |
14 | const QString DragDropHelper::MIME_TYPE_ZONE = "scqlop/zone"; |
|
14 | const QString DragDropHelper::MIME_TYPE_ZONE = "scqlop/zone"; | |
@@ -18,108 +18,97 const int SCROLL_ZONE_SIZE = 50; | |||||
18 |
|
18 | |||
19 | struct DragDropScroller::DragDropScrollerPrivate { |
|
19 | struct DragDropScroller::DragDropScrollerPrivate { | |
20 |
|
20 | |||
21 |
QList<QScrollArea*> m_ |
|
21 | QList<QScrollArea *> m_ScrollAreas; | |
22 |
QScrollArea* |
|
22 | QScrollArea *m_CurrentScrollArea = nullptr; | |
23 |
std::unique_ptr<QTimer> m_ |
|
23 | std::unique_ptr<QTimer> m_Timer = nullptr; | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | enum class ScrollDirection {up, down, unknown}; |
|
26 | enum class ScrollDirection { up, down, unknown }; | |
27 |
ScrollDirection m_ |
|
27 | ScrollDirection m_Direction = ScrollDirection::unknown; | |
28 |
|
28 | |||
29 | explicit DragDropScrollerPrivate() |
|
29 | explicit DragDropScrollerPrivate() : m_Timer{std::make_unique<QTimer>()} | |
30 | : m_timer{std::make_unique<QTimer>()} |
|
|||
31 | { |
|
30 | { | |
32 |
m_ |
|
31 | m_Timer->setInterval(0); | |
33 | } |
|
32 | } | |
34 | }; |
|
33 | }; | |
35 |
|
34 | |||
36 |
DragDropScroller::DragDropScroller(QObject* |
|
35 | DragDropScroller::DragDropScroller(QObject *parent) | |
37 |
: QObject{parent}, |
|
36 | : QObject{parent}, impl{spimpl::make_unique_impl<DragDropScrollerPrivate>()} | |
38 | { |
|
37 | { | |
39 |
connect(impl->m_ |
|
38 | connect(impl->m_Timer.get(), &QTimer::timeout, this, &DragDropScroller::onTimer); | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 |
void DragDropScroller::addScrollArea(QScrollArea* |
|
41 | void DragDropScroller::addScrollArea(QScrollArea *scrollArea) | |
43 | { |
|
42 | { | |
44 |
impl->m_ |
|
43 | impl->m_ScrollAreas << scrollArea; | |
45 | scrollArea->viewport()->setAcceptDrops(true); |
|
44 | scrollArea->viewport()->setAcceptDrops(true); | |
46 | } |
|
45 | } | |
47 |
|
46 | |||
48 |
void DragDropScroller::removeScrollArea(QScrollArea* |
|
47 | void DragDropScroller::removeScrollArea(QScrollArea *scrollArea) | |
49 | { |
|
48 | { | |
50 |
impl->m_ |
|
49 | impl->m_ScrollAreas.removeAll(scrollArea); | |
51 | scrollArea->viewport()->setAcceptDrops(false); |
|
50 | scrollArea->viewport()->setAcceptDrops(false); | |
52 | } |
|
51 | } | |
53 |
|
52 | |||
54 | bool DragDropScroller::eventFilter(QObject *obj, QEvent *event) |
|
53 | bool DragDropScroller::eventFilter(QObject *obj, QEvent *event) | |
55 | { |
|
54 | { | |
56 | if (event->type() == QEvent::DragMove) |
|
55 | if (event->type() == QEvent::DragMove) { | |
57 | { |
|
56 | auto w = static_cast<QWidget *>(obj); | |
58 | auto w = static_cast<QWidget*>(obj); |
|
|||
59 |
|
57 | |||
60 |
if (impl->m_ |
|
58 | if (impl->m_CurrentScrollArea && impl->m_CurrentScrollArea->isAncestorOf(w)) { | |
61 | { |
|
59 | auto moveEvent = static_cast<QDragMoveEvent *>(event); | |
62 | auto moveEvent = static_cast<QDragMoveEvent*>(event); |
|
|||
63 |
|
60 | |||
64 | auto pos = moveEvent->pos(); |
|
61 | auto pos = moveEvent->pos(); | |
65 |
if (impl->m_ |
|
62 | if (impl->m_CurrentScrollArea->viewport() != w) { | |
66 | { |
|
|||
67 | auto globalPos = w->mapToGlobal(moveEvent->pos()); |
|
63 | auto globalPos = w->mapToGlobal(moveEvent->pos()); | |
68 |
pos = impl->m_ |
|
64 | pos = impl->m_CurrentScrollArea->viewport()->mapFromGlobal(globalPos); | |
69 | } |
|
65 | } | |
70 |
|
66 | |||
71 |
auto isInTopZone = pos.y() > impl->m_ |
|
67 | auto isInTopZone = pos.y() > impl->m_CurrentScrollArea->viewport()->size().height() | |
|
68 | - SCROLL_ZONE_SIZE; | |||
72 | auto isInBottomZone = pos.y() < SCROLL_ZONE_SIZE; |
|
69 | auto isInBottomZone = pos.y() < SCROLL_ZONE_SIZE; | |
73 |
|
70 | |||
74 | if (!isInTopZone && !isInBottomZone) |
|
71 | if (!isInTopZone && !isInBottomZone) { | |
75 | { |
|
72 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; | |
76 | impl->m_direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
73 | impl->m_Timer->stop(); | |
77 | impl->m_timer->stop(); |
|
|||
78 | } |
|
74 | } | |
79 |
else if (!impl->m_ |
|
75 | else if (!impl->m_Timer->isActive()) { | |
80 | { |
|
76 | impl->m_Direction = isInTopZone ? DragDropScrollerPrivate::ScrollDirection::up | |
81 | impl->m_direction = isInTopZone ? DragDropScrollerPrivate::ScrollDirection::up : DragDropScrollerPrivate::ScrollDirection::down; |
|
77 | : DragDropScrollerPrivate::ScrollDirection::down; | |
82 |
impl->m_ |
|
78 | impl->m_Timer->start(); | |
83 | } |
|
79 | } | |
84 | } |
|
80 | } | |
85 | } |
|
81 | } | |
86 | else if (event->type() == QEvent::DragEnter) |
|
82 | else if (event->type() == QEvent::DragEnter) { | |
87 | { |
|
83 | auto w = static_cast<QWidget *>(obj); | |
88 | auto w = static_cast<QWidget*>(obj); |
|
|||
89 |
|
84 | |||
90 |
for (auto scrollArea : impl-> |
|
85 | for (auto scrollArea : impl->m_ScrollAreas) { | |
91 | { |
|
86 | if (impl->m_CurrentScrollArea != scrollArea && scrollArea->isAncestorOf(w)) { | |
92 | if (impl->m_currentScrollArea != scrollArea && scrollArea->isAncestorOf(w)) |
|
87 | auto enterEvent = static_cast<QDragEnterEvent *>(event); | |
93 | { |
|
|||
94 | auto enterEvent = static_cast<QDragEnterEvent*>(event); |
|
|||
95 | enterEvent->acceptProposedAction(); |
|
88 | enterEvent->acceptProposedAction(); | |
96 | enterEvent->setDropAction(Qt::IgnoreAction); |
|
89 | enterEvent->setDropAction(Qt::IgnoreAction); | |
97 |
impl->m_ |
|
90 | impl->m_CurrentScrollArea = scrollArea; | |
98 | break; |
|
91 | break; | |
99 | } |
|
92 | } | |
100 | } |
|
93 | } | |
101 | } |
|
94 | } | |
102 | else if (event->type() == QEvent::DragLeave) |
|
95 | else if (event->type() == QEvent::DragLeave) { | |
103 | { |
|
96 | auto w = static_cast<QWidget *>(obj); | |
104 | auto w = static_cast<QWidget*>(obj); |
|
97 | if (impl->m_CurrentScrollArea) { | |
105 |
if (impl->m_ |
|
98 | if (!QRect(QPoint(), impl->m_CurrentScrollArea->size()) | |
106 | { |
|
99 | .contains(impl->m_CurrentScrollArea->mapFromGlobal(QCursor::pos()))) { | |
107 | if (!QRect(QPoint(), impl->m_currentScrollArea->size()).contains(impl->m_currentScrollArea->mapFromGlobal(QCursor::pos()))) |
|
100 | impl->m_CurrentScrollArea = nullptr; | |
108 | { |
|
101 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; | |
109 |
impl->m_ |
|
102 | impl->m_Timer->stop(); | |
110 | impl->m_direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
|||
111 | impl->m_timer->stop(); |
|
|||
112 | } |
|
103 | } | |
113 | } |
|
104 | } | |
114 | } |
|
105 | } | |
115 | else if (event->type() == QEvent::Drop) |
|
106 | else if (event->type() == QEvent::Drop) { | |
116 | { |
|
107 | auto w = static_cast<QWidget *>(obj); | |
117 | auto w = static_cast<QWidget*>(obj); |
|
108 | if (impl->m_CurrentScrollArea) { | |
118 |
|
|
109 | impl->m_CurrentScrollArea = nullptr; | |
119 | { |
|
110 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; | |
120 |
impl->m_ |
|
111 | impl->m_Timer->stop(); | |
121 | impl->m_direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
|||
122 | impl->m_timer->stop(); |
|
|||
123 | } |
|
112 | } | |
124 | } |
|
113 | } | |
125 |
|
114 | |||
@@ -128,121 +117,114 bool DragDropScroller::eventFilter(QObject *obj, QEvent *event) | |||||
128 |
|
117 | |||
129 | void DragDropScroller::onTimer() |
|
118 | void DragDropScroller::onTimer() | |
130 | { |
|
119 | { | |
131 |
if (impl->m_ |
|
120 | if (impl->m_CurrentScrollArea) { | |
132 | { |
|
|||
133 | auto mvt = 0; |
|
121 | auto mvt = 0; | |
134 |
switch (impl->m_ |
|
122 | switch (impl->m_Direction) { | |
135 | { |
|
123 | case DragDropScrollerPrivate::ScrollDirection::up: | |
136 | case DragDropScrollerPrivate::ScrollDirection::up: |
|
124 | mvt = SCROLL_SPEED; | |
137 | mvt = SCROLL_SPEED; |
|
125 | break; | |
138 | break; |
|
126 | case DragDropScrollerPrivate::ScrollDirection::down: | |
139 | case DragDropScrollerPrivate::ScrollDirection::down: |
|
127 | mvt = -SCROLL_SPEED; | |
140 | mvt = -SCROLL_SPEED; |
|
128 | break; | |
141 |
|
|
129 | default: | |
142 | default: |
|
130 | break; | |
143 | break; |
|
|||
144 | } |
|
131 | } | |
145 |
|
132 | |||
146 |
impl->m_ |
|
133 | impl->m_CurrentScrollArea->verticalScrollBar()->setValue( | |
|
134 | impl->m_CurrentScrollArea->verticalScrollBar()->value() + mvt); | |||
147 | } |
|
135 | } | |
148 | } |
|
136 | } | |
149 |
|
137 | |||
150 | struct DragDropHelper::DragDropHelperPrivate { |
|
138 | struct DragDropHelper::DragDropHelperPrivate { | |
151 |
|
139 | |||
152 |
VisualizationDragWidget* |
|
140 | VisualizationDragWidget *m_CurrentDragWidget = nullptr; | |
153 |
std::unique_ptr<QWidget> m_ |
|
141 | std::unique_ptr<QWidget> m_PlaceHolder = nullptr; | |
154 |
std::unique_ptr<DragDropScroller> m_ |
|
142 | std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr; | |
155 |
QString m_ |
|
143 | QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using | |
|
144 | // QTemporaryFile to have a name which is not generated. | |||
156 |
|
145 | |||
157 | explicit DragDropHelperPrivate() |
|
146 | explicit DragDropHelperPrivate() | |
158 |
: m_ |
|
147 | : m_PlaceHolder{std::make_unique<QWidget>()}, | |
159 |
|
|
148 | m_DragDropScroller{std::make_unique<DragDropScroller>()} | |
160 | { |
|
149 | { | |
161 |
|
|
150 | m_PlaceHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4"); | |
162 |
|
|
151 | sqpApp->installEventFilter(m_DragDropScroller.get()); | |
163 |
|
152 | |||
164 |
|
153 | |||
165 |
|
|
154 | m_ImageTempUrl = QDir::temp().absoluteFilePath("Scqlop_graph.png"); | |
166 | } |
|
155 | } | |
167 |
|
156 | |||
168 | void preparePlaceHolder() const |
|
157 | void preparePlaceHolder() const | |
169 | { |
|
158 | { | |
170 |
if (m_ |
|
159 | if (m_CurrentDragWidget) { | |
171 | { |
|
160 | m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size()); | |
172 |
m_ |
|
161 | m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy()); | |
173 | m_placeHolder->setSizePolicy(m_currentDragWidget->sizePolicy()); |
|
|||
174 | } |
|
162 | } | |
175 | else |
|
163 | else { | |
176 | { |
|
164 | m_PlaceHolder->setMinimumSize(200, 200); | |
177 | m_placeHolder->setMinimumSize(200, 200); |
|
|||
178 | } |
|
165 | } | |
179 | } |
|
166 | } | |
180 | }; |
|
167 | }; | |
181 |
|
168 | |||
182 |
|
169 | |||
183 | DragDropHelper::DragDropHelper() : |
|
170 | DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} {} | |
184 | impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} |
|
|||
185 | { |
|
|||
186 | } |
|
|||
187 |
|
171 | |||
188 | DragDropHelper::~DragDropHelper() |
|
172 | DragDropHelper::~DragDropHelper() | |
189 | { |
|
173 | { | |
190 |
QFile::remove(impl->m_ |
|
174 | QFile::remove(impl->m_ImageTempUrl); | |
191 | } |
|
175 | } | |
192 |
|
176 | |||
193 | void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget) |
|
177 | void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget) | |
194 | { |
|
178 | { | |
195 |
impl->m_ |
|
179 | impl->m_CurrentDragWidget = dragWidget; | |
196 | } |
|
180 | } | |
197 |
|
181 | |||
198 | VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const |
|
182 | VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const | |
199 | { |
|
183 | { | |
200 |
return impl->m_ |
|
184 | return impl->m_CurrentDragWidget; | |
201 | } |
|
185 | } | |
202 |
|
186 | |||
203 |
|
187 | |||
204 |
QWidget& |
|
188 | QWidget &DragDropHelper::placeHolder() const | |
205 | { |
|
189 | { | |
206 |
return *impl->m_ |
|
190 | return *impl->m_PlaceHolder; | |
207 | } |
|
191 | } | |
208 |
|
192 | |||
209 | void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index) |
|
193 | void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index) | |
210 | { |
|
194 | { | |
211 | removePlaceHolder(); |
|
195 | removePlaceHolder(); | |
212 | impl->preparePlaceHolder(); |
|
196 | impl->preparePlaceHolder(); | |
213 |
layout->insertWidget(index, impl->m_ |
|
197 | layout->insertWidget(index, impl->m_PlaceHolder.get()); | |
214 |
impl->m_ |
|
198 | impl->m_PlaceHolder->show(); | |
215 | } |
|
199 | } | |
216 |
|
200 | |||
217 | void DragDropHelper::removePlaceHolder() |
|
201 | void DragDropHelper::removePlaceHolder() | |
218 | { |
|
202 | { | |
219 |
auto parentWidget = impl->m_ |
|
203 | auto parentWidget = impl->m_PlaceHolder->parentWidget(); | |
220 | if (parentWidget) |
|
204 | if (parentWidget) { | |
221 | { |
|
205 | parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get()); | |
222 | parentWidget->layout()->removeWidget(impl->m_placeHolder.get()); |
|
206 | impl->m_PlaceHolder->setParent(nullptr); | |
223 |
impl->m_ |
|
207 | impl->m_PlaceHolder->hide(); | |
224 | impl->m_placeHolder->hide(); |
|
|||
225 | } |
|
208 | } | |
226 | } |
|
209 | } | |
227 |
|
210 | |||
228 | bool DragDropHelper::isPlaceHolderSet() const |
|
211 | bool DragDropHelper::isPlaceHolderSet() const | |
229 | { |
|
212 | { | |
230 |
return impl->m_ |
|
213 | return impl->m_PlaceHolder->parentWidget(); | |
231 | } |
|
214 | } | |
232 |
|
215 | |||
233 | void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea) |
|
216 | void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea) | |
234 | { |
|
217 | { | |
235 |
impl->m_ |
|
218 | impl->m_DragDropScroller->addScrollArea(scrollArea); | |
236 | } |
|
219 | } | |
237 |
|
220 | |||
238 | void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea) |
|
221 | void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea) | |
239 | { |
|
222 | { | |
240 |
impl->m_ |
|
223 | impl->m_DragDropScroller->removeScrollArea(scrollArea); | |
241 | } |
|
224 | } | |
242 |
|
225 | |||
243 |
QUrl DragDropHelper::imageTemporaryUrl(const QImage& |
|
226 | QUrl DragDropHelper::imageTemporaryUrl(const QImage &image) const | |
244 | { |
|
227 | { | |
245 |
image.save(impl->m_ |
|
228 | image.save(impl->m_ImageTempUrl); | |
246 |
return QUrl::fromLocalFile(impl->m_ |
|
229 | return QUrl::fromLocalFile(impl->m_ImageTempUrl); | |
247 | } |
|
230 | } | |
248 |
|
@@ -2,13 +2,13 | |||||
2 |
|
2 | |||
3 | #include <Data/IDataProvider.h> |
|
3 | #include <Data/IDataProvider.h> | |
4 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
|
5 | #include <DragDropHelper.h> | |||
5 | #include <Network/NetworkController.h> |
|
6 | #include <Network/NetworkController.h> | |
6 | #include <QThread> |
|
7 | #include <QThread> | |
7 | #include <Time/TimeController.h> |
|
8 | #include <Time/TimeController.h> | |
8 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
9 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
10 | #include <Visualization/VisualizationController.h> |
|
11 | #include <Visualization/VisualizationController.h> | |
11 | #include <DragDropHelper.h> |
|
|||
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
13 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | |
14 |
|
14 | |||
@@ -120,13 +120,9 SqpApplication::SqpApplication(int &argc, char **argv) | |||||
120 | impl->m_VisualizationControllerThread.start(); |
|
120 | impl->m_VisualizationControllerThread.start(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | SqpApplication::~SqpApplication() |
|
123 | SqpApplication::~SqpApplication() {} | |
124 | { |
|
|||
125 | } |
|
|||
126 |
|
124 | |||
127 | void SqpApplication::initialize() |
|
125 | void SqpApplication::initialize() {} | |
128 | { |
|
|||
129 | } |
|
|||
130 |
|
126 | |||
131 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
127 | DataSourceController &SqpApplication::dataSourceController() noexcept | |
132 | { |
|
128 | { |
@@ -1,43 +1,43 | |||||
1 | #include "Visualization/VisualizationDragDropContainer.h" |
|
1 | #include "Visualization/VisualizationDragDropContainer.h" | |
2 | #include "Visualization/VisualizationDragWidget.h" |
|
|||
3 | #include "SqpApplication.h" |
|
|||
4 | #include "DragDropHelper.h" |
|
2 | #include "DragDropHelper.h" | |
|
3 | #include "SqpApplication.h" | |||
|
4 | #include "Visualization/VisualizationDragWidget.h" | |||
5 |
|
5 | |||
6 | #include <QDrag> |
|
6 | #include <QDrag> | |
7 | #include <QVBoxLayout> |
|
|||
8 | #include <QDragEnterEvent> |
|
7 | #include <QDragEnterEvent> | |
|
8 | #include <QVBoxLayout> | |||
9 |
|
9 | |||
10 | #include <memory> |
|
10 | #include <memory> | |
11 |
|
11 | |||
12 | struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { |
|
12 | struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |
13 |
|
13 | |||
14 |
QVBoxLayout* |
|
14 | QVBoxLayout *m_Layout; | |
15 |
QStringList m_ |
|
15 | QStringList m_AcceptedMimeTypes; | |
16 |
QStringList m_ |
|
16 | QStringList m_MergeAllowedMimeTypes; | |
17 |
|
17 | |||
18 |
explicit VisualizationDragDropContainerPrivate(QWidget* |
|
18 | explicit VisualizationDragDropContainerPrivate(QWidget *widget) | |
19 | { |
|
19 | { | |
20 |
m_ |
|
20 | m_Layout = new QVBoxLayout(widget); | |
21 |
m_ |
|
21 | m_Layout->setContentsMargins(0, 0, 0, 0); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 |
bool acceptMimeData(const QMimeData* |
|
24 | bool acceptMimeData(const QMimeData *data) const | |
25 | { |
|
25 | { | |
26 |
for (const auto& |
|
26 | for (const auto &type : m_AcceptedMimeTypes) { | |
27 | { |
|
27 | if (data->hasFormat(type)) { | |
28 | if (data->hasFormat(type)) |
|
|||
29 | return true; |
|
28 | return true; | |
|
29 | } | |||
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | return false; |
|
32 | return false; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 |
bool allowMergeMimeData(const QMimeData* |
|
35 | bool allowMergeMimeData(const QMimeData *data) const | |
36 | { |
|
36 | { | |
37 |
for (const auto& |
|
37 | for (const auto &type : m_MergeAllowedMimeTypes) { | |
38 | { |
|
38 | if (data->hasFormat(type)) { | |
39 | if (data->hasFormat(type)) |
|
|||
40 | return true; |
|
39 | return true; | |
|
40 | } | |||
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | return false; |
|
43 | return false; | |
@@ -45,20 +45,17 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||||
45 |
|
45 | |||
46 | bool hasPlaceHolder() const |
|
46 | bool hasPlaceHolder() const | |
47 | { |
|
47 | { | |
48 |
return sqpApp->dragDropHelper().placeHolder().parentWidget() == m_ |
|
48 | return sqpApp->dragDropHelper().placeHolder().parentWidget() == m_Layout->parentWidget(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 |
VisualizationDragWidget* |
|
51 | VisualizationDragWidget *getChildDragWidgetAt(QWidget *parent, const QPoint &pos) const | |
52 | { |
|
52 | { | |
53 |
VisualizationDragWidget* |
|
53 | VisualizationDragWidget *dragWidget = nullptr; | |
54 |
|
54 | |||
55 | for (auto child : parent->children()) |
|
55 | for (auto child : parent->children()) { | |
56 | { |
|
56 | auto widget = qobject_cast<VisualizationDragWidget *>(child); | |
57 | auto widget = qobject_cast<VisualizationDragWidget*>(child); |
|
57 | if (widget && widget->isVisible()) { | |
58 | if (widget && widget->isVisible()) |
|
58 | if (widget->frameGeometry().contains(pos)) { | |
59 | { |
|
|||
60 | if (widget->frameGeometry().contains(pos)) |
|
|||
61 | { |
|
|||
62 | dragWidget = widget; |
|
59 | dragWidget = widget; | |
63 | break; |
|
60 | break; | |
64 | } |
|
61 | } | |
@@ -68,54 +65,56 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||||
68 | return dragWidget; |
|
65 | return dragWidget; | |
69 | } |
|
66 | } | |
70 |
|
67 | |||
71 |
bool cursorIsInContainer(QWidget* |
|
68 | bool cursorIsInContainer(QWidget *container) const | |
72 | { |
|
69 | { | |
73 | auto adustNum = 18; //to be safe, in case of scrollbar on the side |
|
70 | auto adustNum = 18; // to be safe, in case of scrollbar on the side | |
74 |
auto containerRect = QRect(QPoint(), container->contentsRect().size()) |
|
71 | auto containerRect = QRect(QPoint(), container->contentsRect().size()) | |
|
72 | .adjusted(adustNum, adustNum, -adustNum, -adustNum); | |||
75 | qDebug() << containerRect << container->mapFromGlobal(QCursor::pos()); |
|
73 | qDebug() << containerRect << container->mapFromGlobal(QCursor::pos()); | |
76 | return containerRect.contains(container->mapFromGlobal(QCursor::pos())); |
|
74 | return containerRect.contains(container->mapFromGlobal(QCursor::pos())); | |
77 | } |
|
75 | } | |
78 |
|
||||
79 | }; |
|
76 | }; | |
80 |
|
77 | |||
81 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) |
|
78 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) | |
82 | : QWidget{parent}, impl{spimpl::make_unique_impl<VisualizationDragDropContainerPrivate>(this)} |
|
79 | : QWidget{parent}, | |
|
80 | impl{spimpl::make_unique_impl<VisualizationDragDropContainerPrivate>(this)} | |||
83 | { |
|
81 | { | |
84 | setAcceptDrops(true); |
|
82 | setAcceptDrops(true); | |
85 | } |
|
83 | } | |
86 |
|
84 | |||
87 | void VisualizationDragDropContainer::addDragWidget(VisualizationDragWidget *dragWidget) |
|
85 | void VisualizationDragDropContainer::addDragWidget(VisualizationDragWidget *dragWidget) | |
88 | { |
|
86 | { | |
89 |
impl->m_ |
|
87 | impl->m_Layout->addWidget(dragWidget); | |
90 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); |
|
88 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); | |
91 |
connect(dragWidget, &VisualizationDragWidget::dragDetected, this, |
|
89 | connect(dragWidget, &VisualizationDragWidget::dragDetected, this, | |
|
90 | &VisualizationDragDropContainer::startDrag); | |||
92 | } |
|
91 | } | |
93 |
|
92 | |||
94 |
void VisualizationDragDropContainer::insertDragWidget(int index, |
|
93 | void VisualizationDragDropContainer::insertDragWidget(int index, | |
|
94 | VisualizationDragWidget *dragWidget) | |||
95 | { |
|
95 | { | |
96 |
impl->m_ |
|
96 | impl->m_Layout->insertWidget(index, dragWidget); | |
97 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); |
|
97 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); | |
98 |
connect(dragWidget, &VisualizationDragWidget::dragDetected, this, |
|
98 | connect(dragWidget, &VisualizationDragWidget::dragDetected, this, | |
|
99 | &VisualizationDragDropContainer::startDrag); | |||
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | void VisualizationDragDropContainer::setAcceptedMimeTypes(const QStringList &mimeTypes) |
|
102 | void VisualizationDragDropContainer::setAcceptedMimeTypes(const QStringList &mimeTypes) | |
102 | { |
|
103 | { | |
103 |
impl->m_ |
|
104 | impl->m_AcceptedMimeTypes = mimeTypes; | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | void VisualizationDragDropContainer::setMergeAllowedMimeTypes(const QStringList &mimeTypes) |
|
107 | void VisualizationDragDropContainer::setMergeAllowedMimeTypes(const QStringList &mimeTypes) | |
107 | { |
|
108 | { | |
108 |
impl->m_ |
|
109 | impl->m_MergeAllowedMimeTypes = mimeTypes; | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | int VisualizationDragDropContainer::countDragWidget() const |
|
112 | int VisualizationDragDropContainer::countDragWidget() const | |
112 | { |
|
113 | { | |
113 | auto nbGraph = 0; |
|
114 | auto nbGraph = 0; | |
114 | for (auto child : children()) |
|
115 | for (auto child : children()) { | |
115 | { |
|
116 | auto widget = qobject_cast<VisualizationDragWidget *>(child); | |
116 | auto widget = qobject_cast<VisualizationDragWidget*>(child); |
|
117 | if (widget) { | |
117 | if (widget) |
|
|||
118 | { |
|
|||
119 | nbGraph += 1; |
|
118 | nbGraph += 1; | |
120 | } |
|
119 | } | |
121 | } |
|
120 | } | |
@@ -123,11 +122,12 int VisualizationDragDropContainer::countDragWidget() const | |||||
123 | return nbGraph; |
|
122 | return nbGraph; | |
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 |
void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget, |
|
125 | void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget, | |
|
126 | const QPoint &dragPosition) | |||
127 | { |
|
127 | { | |
128 |
auto& |
|
128 | auto &helper = sqpApp->dragDropHelper(); | |
129 |
|
129 | |||
130 | //Note: The management of the drag object is done by Qt |
|
130 | // Note: The management of the drag object is done by Qt | |
131 | auto *drag = new QDrag{dragWidget}; |
|
131 | auto *drag = new QDrag{dragWidget}; | |
132 | drag->setHotSpot(dragPosition); |
|
132 | drag->setHotSpot(dragPosition); | |
133 |
|
133 | |||
@@ -142,53 +142,49 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidg | |||||
142 | mimeData->setImageData(image); |
|
142 | mimeData->setImageData(image); | |
143 | mimeData->setUrls({helper.imageTemporaryUrl(image)}); |
|
143 | mimeData->setUrls({helper.imageTemporaryUrl(image)}); | |
144 |
|
144 | |||
145 |
if (impl->m_ |
|
145 | if (impl->m_Layout->indexOf(dragWidget) >= 0) { | |
146 | { |
|
|||
147 | helper.setCurrentDragWidget(dragWidget); |
|
146 | helper.setCurrentDragWidget(dragWidget); | |
148 |
|
147 | |||
149 | if (impl->cursorIsInContainer(this)) |
|
148 | if (impl->cursorIsInContainer(this)) { | |
150 | { |
|
149 | auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget); | |
151 | auto dragWidgetIndex = impl->m_layout->indexOf(dragWidget); |
|
150 | helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex); | |
152 | helper.insertPlaceHolder(impl->m_layout, dragWidgetIndex); |
|
|||
153 | dragWidget->setVisible(false); |
|
151 | dragWidget->setVisible(false); | |
154 | } |
|
152 | } | |
155 | } |
|
153 | } | |
156 |
|
154 | |||
157 | //Note: The exec() is blocking on windows but not on linux and macOS |
|
155 | // Note: The exec() is blocking on windows but not on linux and macOS | |
158 | drag->exec(Qt::MoveAction | Qt::CopyAction); |
|
156 | drag->exec(Qt::MoveAction | Qt::CopyAction); | |
159 | } |
|
157 | } | |
160 |
|
158 | |||
161 | void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event) |
|
159 | void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event) | |
162 | { |
|
160 | { | |
163 | if (impl->acceptMimeData(event->mimeData())) |
|
161 | if (impl->acceptMimeData(event->mimeData())) { | |
164 | { |
|
|||
165 | event->acceptProposedAction(); |
|
162 | event->acceptProposedAction(); | |
166 |
|
163 | |||
167 |
auto& |
|
164 | auto &helper = sqpApp->dragDropHelper(); | |
168 |
|
165 | |||
169 | if (!impl->hasPlaceHolder()) |
|
166 | if (!impl->hasPlaceHolder()) { | |
170 | { |
|
|||
171 | auto dragWidget = helper.getCurrentDragWidget(); |
|
167 | auto dragWidget = helper.getCurrentDragWidget(); | |
172 | auto parentWidget = qobject_cast<VisualizationDragDropContainer*>(dragWidget->parentWidget()); |
|
168 | auto parentWidget | |
173 | if (parentWidget) |
|
169 | = qobject_cast<VisualizationDragDropContainer *>(dragWidget->parentWidget()); | |
174 | { |
|
170 | if (parentWidget) { | |
175 | dragWidget->setVisible(false); |
|
171 | dragWidget->setVisible(false); | |
176 | } |
|
172 | } | |
177 |
|
173 | |||
178 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); |
|
174 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); | |
179 |
|
175 | |||
180 | if (dragWidgetHovered) |
|
176 | if (dragWidgetHovered) { | |
181 | { |
|
177 | auto hoveredWidgetIndex = impl->m_Layout->indexOf(dragWidgetHovered); | |
182 |
auto |
|
178 | auto dragWidgetIndex = impl->m_Layout->indexOf(helper.getCurrentDragWidget()); | |
183 | auto dragWidgetIndex = impl->m_layout->indexOf(helper.getCurrentDragWidget()); |
|
179 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= hoveredWidgetIndex) { | |
184 |
|
|
180 | hoveredWidgetIndex | |
185 |
|
|
181 | += 1; // Correction of the index if the drop occurs in the same container | |
|
182 | } | |||
186 |
|
183 | |||
187 |
helper.insertPlaceHolder(impl->m_ |
|
184 | helper.insertPlaceHolder(impl->m_Layout, hoveredWidgetIndex); | |
188 | } |
|
185 | } | |
189 | else |
|
186 | else { | |
190 | { |
|
187 | helper.insertPlaceHolder(impl->m_Layout, 0); | |
191 | helper.insertPlaceHolder(impl->m_layout, 0); |
|
|||
192 | } |
|
188 | } | |
193 | } |
|
189 | } | |
194 | } |
|
190 | } | |
@@ -202,23 +198,20 void VisualizationDragDropContainer::dragLeaveEvent(QDragLeaveEvent *event) | |||||
202 | { |
|
198 | { | |
203 | Q_UNUSED(event); |
|
199 | Q_UNUSED(event); | |
204 |
|
200 | |||
205 |
auto& |
|
201 | auto &helper = sqpApp->dragDropHelper(); | |
206 |
|
202 | |||
207 | if (!impl->cursorIsInContainer(this)) |
|
203 | if (!impl->cursorIsInContainer(this)) { | |
208 | { |
|
|||
209 | helper.removePlaceHolder(); |
|
204 | helper.removePlaceHolder(); | |
210 |
|
205 | |||
211 | bool isInternal = true; |
|
206 | bool isInternal = true; | |
212 | if (isInternal) |
|
207 | if (isInternal) { | |
213 | { |
|
208 | // Only if the drag is strated from the visualization | |
214 | //Only if the drag is strated from the visualization |
|
209 | // Show the drag widget at its original place | |
215 | //Show the drag widget at its original place |
|
210 | // So the drag widget doesn't stay hidden if the drop occurs outside the visualization | |
216 | //So the drag widget doesn't stay hidden if the drop occurs outside the visualization drop zone |
|
211 | // drop zone (It is not possible to catch a drop event outside of the application) | |
217 | //(It is not possible to catch a drop event outside of the application) |
|
|||
218 |
|
212 | |||
219 | auto dragWidget = sqpApp->dragDropHelper().getCurrentDragWidget(); |
|
213 | auto dragWidget = sqpApp->dragDropHelper().getCurrentDragWidget(); | |
220 | if (dragWidget) |
|
214 | if (dragWidget) { | |
221 | { |
|
|||
222 | dragWidget->setVisible(true); |
|
215 | dragWidget->setVisible(true); | |
223 | } |
|
216 | } | |
224 | } |
|
217 | } | |
@@ -229,16 +222,13 void VisualizationDragDropContainer::dragLeaveEvent(QDragLeaveEvent *event) | |||||
229 |
|
222 | |||
230 | void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) |
|
223 | void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) | |
231 | { |
|
224 | { | |
232 | if (impl->acceptMimeData(event->mimeData())) |
|
225 | if (impl->acceptMimeData(event->mimeData())) { | |
233 | { |
|
|||
234 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); |
|
226 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); | |
235 | if (dragWidgetHovered) |
|
227 | if (dragWidgetHovered) { | |
236 | { |
|
|||
237 | auto canMerge = impl->allowMergeMimeData(event->mimeData()); |
|
228 | auto canMerge = impl->allowMergeMimeData(event->mimeData()); | |
238 |
|
229 | |||
239 | auto nbDragWidget = countDragWidget(); |
|
230 | auto nbDragWidget = countDragWidget(); | |
240 | if (nbDragWidget > 0) |
|
231 | if (nbDragWidget > 0) { | |
241 | { |
|
|||
242 | auto graphHeight = size().height() / nbDragWidget; |
|
232 | auto graphHeight = size().height() / nbDragWidget; | |
243 | auto dropIndex = floor(event->pos().y() / graphHeight); |
|
233 | auto dropIndex = floor(event->pos().y() / graphHeight); | |
244 | auto zoneSize = qMin(graphHeight / 3.0, 150.0); |
|
234 | auto zoneSize = qMin(graphHeight / 3.0, 150.0); | |
@@ -246,28 +236,27 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) | |||||
246 | auto isOnTop = event->pos().y() < dropIndex * graphHeight + zoneSize; |
|
236 | auto isOnTop = event->pos().y() < dropIndex * graphHeight + zoneSize; | |
247 | auto isOnBottom = event->pos().y() > (dropIndex + 1) * graphHeight - zoneSize; |
|
237 | auto isOnBottom = event->pos().y() > (dropIndex + 1) * graphHeight - zoneSize; | |
248 |
|
238 | |||
249 |
auto& |
|
239 | auto &helper = sqpApp->dragDropHelper(); | |
250 |
auto placeHolderIndex = impl->m_ |
|
240 | auto placeHolderIndex = impl->m_Layout->indexOf(&(helper.placeHolder())); | |
251 |
|
241 | |||
252 | if (isOnTop || isOnBottom) |
|
242 | if (isOnTop || isOnBottom) { | |
253 | { |
|
243 | if (isOnBottom) { | |
254 | if (isOnBottom) |
|
|||
255 | dropIndex += 1; |
|
244 | dropIndex += 1; | |
|
245 | } | |||
256 |
|
246 | |||
257 |
auto dragWidgetIndex = impl->m_ |
|
247 | auto dragWidgetIndex = impl->m_Layout->indexOf(helper.getCurrentDragWidget()); | |
258 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= dropIndex) |
|
248 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= dropIndex) { | |
259 |
dropIndex += 1; //Correction of the index if the drop occurs in the same |
|
249 | dropIndex += 1; // Correction of the index if the drop occurs in the same | |
|
250 | // container | |||
|
251 | } | |||
260 |
|
252 | |||
261 | if (dropIndex != placeHolderIndex) |
|
253 | if (dropIndex != placeHolderIndex) { | |
262 | { |
|
254 | helper.insertPlaceHolder(impl->m_Layout, dropIndex); | |
263 | helper.insertPlaceHolder(impl->m_layout, dropIndex); |
|
|||
264 | } |
|
255 | } | |
265 | } |
|
256 | } | |
266 | else if (canMerge) |
|
257 | else if (canMerge) { | |
267 | { |
|
258 | // drop on the middle -> merge | |
268 | //drop on the middle -> merge |
|
259 | if (impl->hasPlaceHolder()) { | |
269 | if (impl->hasPlaceHolder()) |
|
|||
270 | { |
|
|||
271 | helper.removePlaceHolder(); |
|
260 | helper.removePlaceHolder(); | |
272 | } |
|
261 | } | |
273 | } |
|
262 | } | |
@@ -282,18 +271,18 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) | |||||
282 |
|
271 | |||
283 | void VisualizationDragDropContainer::dropEvent(QDropEvent *event) |
|
272 | void VisualizationDragDropContainer::dropEvent(QDropEvent *event) | |
284 | { |
|
273 | { | |
285 | if (impl->acceptMimeData(event->mimeData())) |
|
274 | if (impl->acceptMimeData(event->mimeData())) { | |
286 | { |
|
|||
287 | auto dragWidget = sqpApp->dragDropHelper().getCurrentDragWidget(); |
|
275 | auto dragWidget = sqpApp->dragDropHelper().getCurrentDragWidget(); | |
288 | if (impl->hasPlaceHolder() && dragWidget) |
|
276 | if (impl->hasPlaceHolder() && dragWidget) { | |
289 | { |
|
277 | auto &helper = sqpApp->dragDropHelper(); | |
290 | auto& helper = sqpApp->dragDropHelper(); |
|
|||
291 |
|
278 | |||
292 |
auto droppedIndex = impl->m_ |
|
279 | auto droppedIndex = impl->m_Layout->indexOf(&helper.placeHolder()); | |
293 |
|
280 | |||
294 |
auto dragWidgetIndex = impl->m_ |
|
281 | auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget); | |
295 | if (dragWidgetIndex >= 0 && dragWidgetIndex < droppedIndex) |
|
282 | if (dragWidgetIndex >= 0 && dragWidgetIndex < droppedIndex) { | |
296 | droppedIndex -= 1; //Correction of the index if the drop occurs in the same container |
|
283 | droppedIndex | |
|
284 | -= 1; // Correction of the index if the drop occurs in the same container | |||
|
285 | } | |||
297 |
|
286 | |||
298 | dragWidget->setVisible(true); |
|
287 | dragWidget->setVisible(true); | |
299 | dragWidget->setStyleSheet(""); |
|
288 | dragWidget->setStyleSheet(""); |
@@ -1,50 +1,53 | |||||
1 | #include "Visualization/VisualizationDragWidget.h" |
|
1 | #include "Visualization/VisualizationDragWidget.h" | |
2 | #include "Visualization/VisualizationDragDropContainer.h" |
|
2 | #include "Visualization/VisualizationDragDropContainer.h" | |
3 |
|
3 | |||
4 | #include <QMouseEvent> |
|
|||
5 | #include <QApplication> |
|
4 | #include <QApplication> | |
|
5 | #include <QMouseEvent> | |||
6 |
|
6 | |||
7 | struct VisualizationDragWidget::VisualizationDragWidgetPrivate { |
|
7 | struct VisualizationDragWidget::VisualizationDragWidgetPrivate { | |
8 |
|
8 | |||
9 |
QPoint m_ |
|
9 | QPoint m_DragStartPosition; | |
10 |
bool m_ |
|
10 | bool m_DragStartPositionValid = false; | |
11 |
|
11 | |||
12 | explicit VisualizationDragWidgetPrivate() |
|
12 | explicit VisualizationDragWidgetPrivate() {} | |
13 | { |
|
|||
14 | } |
|
|||
15 | }; |
|
13 | }; | |
16 |
|
14 | |||
17 |
VisualizationDragWidget::VisualizationDragWidget(QWidget* |
|
15 | VisualizationDragWidget::VisualizationDragWidget(QWidget *parent) | |
18 | : QWidget{parent}, impl{spimpl::make_unique_impl<VisualizationDragWidgetPrivate>()} |
|
16 | : QWidget{parent}, impl{spimpl::make_unique_impl<VisualizationDragWidgetPrivate>()} | |
19 | { |
|
17 | { | |
20 |
|
||||
21 | } |
|
18 | } | |
22 |
|
19 | |||
23 | void VisualizationDragWidget::mousePressEvent(QMouseEvent *event) |
|
20 | void VisualizationDragWidget::mousePressEvent(QMouseEvent *event) | |
24 | { |
|
21 | { | |
25 | if (event->button() == Qt::LeftButton) |
|
22 | if (event->button() == Qt::LeftButton) { | |
26 |
impl->m_ |
|
23 | impl->m_DragStartPosition = event->pos(); | |
|
24 | } | |||
27 |
|
25 | |||
28 |
impl->m_ |
|
26 | impl->m_DragStartPositionValid = isDragAllowed(); | |
29 |
|
27 | |||
30 | QWidget::mousePressEvent(event); |
|
28 | QWidget::mousePressEvent(event); | |
31 | } |
|
29 | } | |
32 |
|
30 | |||
33 | void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event) |
|
31 | void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event) | |
34 | { |
|
32 | { | |
35 |
if (!impl->m_ |
|
33 | if (!impl->m_DragStartPositionValid || !isDragAllowed()) { | |
36 | return; |
|
34 | return; | |
|
35 | } | |||
37 |
|
36 | |||
38 | if (!(event->buttons() & Qt::LeftButton)) |
|
37 | if (!(event->buttons() & Qt::LeftButton)) { | |
39 | return; |
|
38 | return; | |
|
39 | } | |||
40 |
|
40 | |||
41 | if (!event->modifiers().testFlag(Qt::AltModifier)) |
|
41 | if (!event->modifiers().testFlag(Qt::AltModifier)) { | |
42 | return; |
|
42 | return; | |
|
43 | } | |||
43 |
|
44 | |||
44 |
if ((event->pos() - impl->m_ |
|
45 | if ((event->pos() - impl->m_DragStartPosition).manhattanLength() | |
|
46 | < QApplication::startDragDistance()) { | |||
45 | return; |
|
47 | return; | |
|
48 | } | |||
46 |
|
49 | |||
47 |
emit dragDetected(this, impl->m_ |
|
50 | emit dragDetected(this, impl->m_DragStartPosition); | |
48 |
|
51 | |||
49 | QWidget::mouseMoveEvent(event); |
|
52 | QWidget::mouseMoveEvent(event); | |
50 | } |
|
53 | } |
@@ -8,9 +8,9 | |||||
8 |
|
8 | |||
9 | #include <Data/ArrayData.h> |
|
9 | #include <Data/ArrayData.h> | |
10 | #include <Data/IDataSeries.h> |
|
10 | #include <Data/IDataSeries.h> | |
|
11 | #include <DragDropHelper.h> | |||
11 | #include <Settings/SqpSettingsDefs.h> |
|
12 | #include <Settings/SqpSettingsDefs.h> | |
12 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
13 | #include <DragDropHelper.h> |
|
|||
14 | #include <Variable/Variable.h> |
|
14 | #include <Variable/Variable.h> | |
15 | #include <Variable/VariableController.h> |
|
15 | #include <Variable/VariableController.h> | |
16 |
|
16 | |||
@@ -72,9 +72,10 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||||
72 | &VisualizationGraphWidget::onMouseRelease); |
|
72 | &VisualizationGraphWidget::onMouseRelease); | |
73 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
73 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
74 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
74 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
75 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
75 | connect( | |
76 | &QCPAxis::rangeChanged), |
|
76 | ui->widget->xAxis, | |
77 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
77 | static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged), | |
|
78 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |||
78 |
|
79 | |||
79 | // Activates menu when right clicking on the graph |
|
80 | // Activates menu when right clicking on the graph | |
80 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
81 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
@@ -97,12 +98,11 VisualizationGraphWidget::~VisualizationGraphWidget() | |||||
97 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
98 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
98 | { |
|
99 | { | |
99 | auto parent = parentWidget(); |
|
100 | auto parent = parentWidget(); | |
100 | do |
|
101 | do { | |
101 | { |
|
|||
102 | parent = parent->parentWidget(); |
|
102 | parent = parent->parentWidget(); | |
103 | } while (parent != nullptr && !qobject_cast<VisualizationZoneWidget*>(parent)); |
|
103 | } while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)); | |
104 |
|
104 | |||
105 | return qobject_cast<VisualizationZoneWidget*>(parent); |
|
105 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
108 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
@@ -165,11 +165,11 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable | |||||
165 | ui->widget->replot(); |
|
165 | ui->widget->replot(); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QList<std::shared_ptr<Variable>> VisualizationGraphWidget::variables() const |
|
168 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
169 | { |
|
169 | { | |
170 | auto variables = QList<std::shared_ptr<Variable>>{}; |
|
170 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
171 |
for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
171 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
172 | { |
|
172 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
173 | variables << it->first; |
|
173 | variables << it->first; | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
@@ -232,10 +232,10 QString VisualizationGraphWidget::name() const | |||||
232 |
|
232 | |||
233 | QMimeData *VisualizationGraphWidget::mimeData() const |
|
233 | QMimeData *VisualizationGraphWidget::mimeData() const | |
234 | { |
|
234 | { | |
235 |
|
|
235 | auto *mimeData = new QMimeData; | |
236 |
|
|
236 | mimeData->setData(DragDropHelper::MIME_TYPE_GRAPH, QByteArray()); | |
237 |
|
237 | |||
238 |
|
|
238 | return mimeData; | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | bool VisualizationGraphWidget::isDragAllowed() const |
|
241 | bool VisualizationGraphWidget::isDragAllowed() const | |
@@ -290,9 +290,9 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||||
290 |
|
290 | |||
291 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
291 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
292 | { |
|
292 | { | |
293 |
qCDebug(LOG_VisualizationGraphWidget()) |
|
293 | qCDebug(LOG_VisualizationGraphWidget()) | |
294 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
294 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
295 | << impl->m_DoAcquisition; |
|
295 | << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition; | |
296 |
|
296 | |||
297 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
297 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
298 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
298 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
@@ -2,13 +2,13 | |||||
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "ui_VisualizationTabWidget.h" |
|
3 | #include "ui_VisualizationTabWidget.h" | |
4 |
|
4 | |||
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
|||
6 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
|
6 | #include "Visualization/VisualizationZoneWidget.h" | |||
7 |
|
7 | |||
8 | #include "Variable/VariableController.h" |
|
8 | #include "Variable/VariableController.h" | |
9 |
|
9 | |||
10 | #include "SqpApplication.h" |
|
|||
11 | #include "DragDropHelper.h" |
|
10 | #include "DragDropHelper.h" | |
|
11 | #include "SqpApplication.h" | |||
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") | |
14 |
|
14 | |||
@@ -61,8 +61,10 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par | |||||
61 | { |
|
61 | { | |
62 | ui->setupUi(this); |
|
62 | ui->setupUi(this); | |
63 |
|
63 | |||
64 | ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH, DragDropHelper::MIME_TYPE_ZONE}); |
|
64 | ui->dragDropContainer->setAcceptedMimeTypes( | |
65 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, &VisualizationTabWidget::dropMimeData); |
|
65 | {DragDropHelper::MIME_TYPE_GRAPH, DragDropHelper::MIME_TYPE_ZONE}); | |
|
66 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, | |||
|
67 | &VisualizationTabWidget::dropMimeData); | |||
66 | sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea); |
|
68 | sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea); | |
67 |
|
69 | |||
68 | // Widget is deleted when closed |
|
70 | // Widget is deleted when closed | |
@@ -82,7 +84,7 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | |||||
82 |
|
84 | |||
83 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) |
|
85 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) | |
84 | { |
|
86 | { | |
85 |
|
|
87 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); | |
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
90 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | |
@@ -90,7 +92,8 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Vari | |||||
90 | return createZone({variable}, -1); |
|
92 | return createZone({variable}, -1); | |
91 | } |
|
93 | } | |
92 |
|
94 | |||
93 | VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) |
|
95 | VisualizationZoneWidget * | |
|
96 | VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) | |||
94 | { |
|
97 | { | |
95 | auto zoneWidget = createEmptyZone(index); |
|
98 | auto zoneWidget = createEmptyZone(index); | |
96 |
|
99 | |||
@@ -102,7 +105,8 VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::sha | |||||
102 |
|
105 | |||
103 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) |
|
106 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) | |
104 | { |
|
107 | { | |
105 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; |
|
108 | auto zoneWidget | |
|
109 | = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; | |||
106 | this->insertZone(index, zoneWidget); |
|
110 | this->insertZone(index, zoneWidget); | |
107 |
|
111 | |||
108 | return zoneWidget; |
|
112 | return zoneWidget; | |
@@ -158,42 +162,38 QLayout &VisualizationTabWidget::tabLayout() const noexcept | |||||
158 |
|
162 | |||
159 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
163 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) | |
160 | { |
|
164 | { | |
161 |
auto& |
|
165 | auto &helper = sqpApp->dragDropHelper(); | |
162 | if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) |
|
166 | if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) { | |
163 | { |
|
167 | auto graphWidget = static_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); | |
164 | auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget()); |
|
168 | auto parentDragDropContainer | |
165 |
|
|
169 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); | |
166 | Q_ASSERT(parentDragDropContainer); |
|
170 | Q_ASSERT(parentDragDropContainer); | |
167 |
|
171 | |||
168 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
172 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
169 |
|
173 | |||
170 |
const auto& |
|
174 | const auto &variables = graphWidget->variables(); | |
171 |
|
175 | |||
172 | if (!variables.isEmpty()) |
|
176 | if (!variables.isEmpty()) { | |
173 | { |
|
177 | // Abort the requests for the variables (if any) | |
174 | //Abort the requests for the variables (if any) |
|
178 | // Commented, because it's not sure if it's needed or not | |
175 | //Commented, because it's not sure if it's needed or not |
|
179 | // for (const auto& var : variables) | |
176 | //for (const auto& var : variables) |
|
|||
177 | //{ |
|
180 | //{ | |
178 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
181 | // sqpApp->variableController().onAbortProgressRequested(var); | |
179 | //} |
|
182 | //} | |
180 |
|
183 | |||
181 | if (nbGraph == 1) |
|
184 | if (nbGraph == 1) { | |
182 | { |
|
185 | // This is the only graph in the previous zone, close the zone | |
183 | //This is the only graph in the previous zone, close the zone |
|
|||
184 | graphWidget->parentZoneWidget()->close(); |
|
186 | graphWidget->parentZoneWidget()->close(); | |
185 | } |
|
187 | } | |
186 | else |
|
188 | else { | |
187 | { |
|
189 | // Close the graph | |
188 | //Close the graph |
|
|||
189 | graphWidget->close(); |
|
190 | graphWidget->close(); | |
190 | } |
|
191 | } | |
191 |
|
192 | |||
192 | createZone(variables, index); |
|
193 | createZone(variables, index); | |
193 | } |
|
194 | } | |
194 | else |
|
195 | else { | |
195 | { |
|
196 | // The graph is empty, create an empty zone and move the graph inside | |
196 | //The graph is empty, create an empty zone and move the graph inside |
|
|||
197 |
|
197 | |||
198 | auto parentZoneWidget = graphWidget->parentZoneWidget(); |
|
198 | auto parentZoneWidget = graphWidget->parentZoneWidget(); | |
199 |
|
199 | |||
@@ -202,15 +202,15 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) | |||||
202 | auto zoneWidget = createEmptyZone(index); |
|
202 | auto zoneWidget = createEmptyZone(index); | |
203 | zoneWidget->addGraph(graphWidget); |
|
203 | zoneWidget->addGraph(graphWidget); | |
204 |
|
204 | |||
205 | //Close the old zone if it was the only graph inside |
|
205 | // Close the old zone if it was the only graph inside | |
206 | if (nbGraph == 1) |
|
206 | if (nbGraph == 1) { | |
207 | parentZoneWidget->close(); |
|
207 | parentZoneWidget->close(); | |
|
208 | } | |||
208 | } |
|
209 | } | |
209 | } |
|
210 | } | |
210 | else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) |
|
211 | else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) { | |
211 | { |
|
212 | // Simple move of the zone, no variable operation associated | |
212 | //Simple move of the zone, no variable operation associated |
|
213 | auto zoneWidget = static_cast<VisualizationZoneWidget *>(helper.getCurrentDragWidget()); | |
213 | auto zoneWidget = static_cast<VisualizationZoneWidget*>(helper.getCurrentDragWidget()); |
|
|||
214 | auto parentDragDropContainer = zoneWidget->parentWidget(); |
|
214 | auto parentDragDropContainer = zoneWidget->parentWidget(); | |
215 | parentDragDropContainer->layout()->removeWidget(zoneWidget); |
|
215 | parentDragDropContainer->layout()->removeWidget(zoneWidget); | |
216 |
|
216 |
@@ -9,9 +9,9 | |||||
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
|
12 | #include <DragDropHelper.h> | |||
12 | #include <QUuid> |
|
13 | #include <QUuid> | |
13 | #include <SqpApplication.h> |
|
14 | #include <SqpApplication.h> | |
14 | #include <DragDropHelper.h> |
|
|||
15 | #include <cmath> |
|
15 | #include <cmath> | |
16 |
|
16 | |||
17 | #include <QLayout> |
|
17 | #include <QLayout> | |
@@ -78,7 +78,8 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p | |||||
78 | ui->zoneNameLabel->setText(name); |
|
78 | ui->zoneNameLabel->setText(name); | |
79 |
|
79 | |||
80 | ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH}); |
|
80 | ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH}); | |
81 |
connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, |
|
81 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, | |
|
82 | &VisualizationZoneWidget::dropMimeData); | |||
82 |
|
83 | |||
83 | // 'Close' options : widget is deleted when closed |
|
84 | // 'Close' options : widget is deleted when closed | |
84 | setAttribute(Qt::WA_DeleteOnClose); |
|
85 | setAttribute(Qt::WA_DeleteOnClose); | |
@@ -116,10 +117,11 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
116 | return createGraph(variable, -1); |
|
117 | return createGraph(variable, -1); | |
117 | } |
|
118 | } | |
118 |
|
119 | |||
119 |
VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, |
|
120 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, | |
|
121 | int index) | |||
120 | { |
|
122 | { | |
121 | auto graphWidget = new VisualizationGraphWidget{ |
|
123 | auto graphWidget | |
122 | defaultGraphName(*ui->dragDropContainer->layout()), this}; |
|
124 | = new VisualizationGraphWidget{defaultGraphName(*ui->dragDropContainer->layout()), this}; | |
123 |
|
125 | |||
124 |
|
126 | |||
125 | // Set graph properties |
|
127 | // Set graph properties | |
@@ -146,10 +148,10 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
146 | graphChildRange.m_TStart += deltaLeft; |
|
148 | graphChildRange.m_TStart += deltaLeft; | |
147 | graphChildRange.m_TEnd -= deltaRight; |
|
149 | graphChildRange.m_TEnd -= deltaRight; | |
148 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
150 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
149 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
151 | qCDebug(LOG_VisualizationZoneWidget()) | |
150 | << deltaLeft; |
|
152 | << tr("TORM: deltaLeft") << deltaLeft; | |
151 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
153 | qCDebug(LOG_VisualizationZoneWidget()) | |
152 | << deltaRight; |
|
154 | << tr("TORM: deltaRight") << deltaRight; | |
153 | qCDebug(LOG_VisualizationZoneWidget()) |
|
155 | qCDebug(LOG_VisualizationZoneWidget()) | |
154 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
156 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
155 |
|
157 | |||
@@ -160,10 +162,10 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
160 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
162 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
161 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
163 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
162 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
164 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
163 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
165 | qCDebug(LOG_VisualizationZoneWidget()) | |
164 | << deltaLeft; |
|
166 | << tr("TORM: deltaLeft") << deltaLeft; | |
165 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
167 | qCDebug(LOG_VisualizationZoneWidget()) | |
166 | << deltaRight; |
|
168 | << tr("TORM: deltaRight") << deltaRight; | |
167 | qCDebug(LOG_VisualizationZoneWidget()) |
|
169 | qCDebug(LOG_VisualizationZoneWidget()) | |
168 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
170 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
169 | graphChildRange.m_TStart -= deltaLeft; |
|
171 | graphChildRange.m_TStart -= deltaLeft; | |
@@ -200,10 +202,10 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
200 | break; |
|
202 | break; | |
201 | } |
|
203 | } | |
202 | graphChild->enableAcquisition(false); |
|
204 | graphChild->enableAcquisition(false); | |
203 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
205 | qCDebug(LOG_VisualizationZoneWidget()) | |
204 |
|
|
206 | << tr("TORM: Range before: ") << graphChild->graphRange(); | |
205 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
207 | qCDebug(LOG_VisualizationZoneWidget()) | |
206 | << graphChildRange; |
|
208 | << tr("TORM: Range after : ") << graphChildRange; | |
207 | qCDebug(LOG_VisualizationZoneWidget()) |
|
209 | qCDebug(LOG_VisualizationZoneWidget()) | |
208 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
210 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
209 | graphChild->setGraphRange(graphChildRange); |
|
211 | graphChild->setGraphRange(graphChildRange); | |
@@ -226,7 +228,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
226 | if (layout->count() > 0) { |
|
228 | if (layout->count() > 0) { | |
227 | // Case of a new graph in a existant zone |
|
229 | // Case of a new graph in a existant zone | |
228 | if (auto visualizationGraphWidget |
|
230 | if (auto visualizationGraphWidget | |
229 |
|
|
231 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
230 | range = visualizationGraphWidget->graphRange(); |
|
232 | range = visualizationGraphWidget->graphRange(); | |
231 | } |
|
233 | } | |
232 | } |
|
234 | } | |
@@ -243,7 +245,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
243 | if (auto dataSeries = variable->dataSeries()) { |
|
245 | if (auto dataSeries = variable->dataSeries()) { | |
244 | dataSeries->lockRead(); |
|
246 | dataSeries->lockRead(); | |
245 | auto valuesBounds |
|
247 | auto valuesBounds | |
246 |
|
|
248 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); | |
247 | auto end = dataSeries->cend(); |
|
249 | auto end = dataSeries->cend(); | |
248 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
250 | if (valuesBounds.first != end && valuesBounds.second != end) { | |
249 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
251 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |
@@ -259,14 +261,15 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
259 | return graphWidget; |
|
261 | return graphWidget; | |
260 | } |
|
262 | } | |
261 |
|
263 | |||
262 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) |
|
264 | VisualizationGraphWidget * | |
|
265 | VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) | |||
263 | { |
|
266 | { | |
264 | if (variables.isEmpty()) |
|
267 | if (variables.isEmpty()) { | |
265 | return nullptr; |
|
268 | return nullptr; | |
|
269 | } | |||
266 |
|
270 | |||
267 | auto graphWidget = createGraph(variables.first(), index); |
|
271 | auto graphWidget = createGraph(variables.first(), index); | |
268 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) |
|
272 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) { | |
269 | { |
|
|||
270 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); |
|
273 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); | |
271 | } |
|
274 | } | |
272 |
|
275 | |||
@@ -351,57 +354,51 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variabl | |||||
351 |
|
354 | |||
352 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
355 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) | |
353 | { |
|
356 | { | |
354 |
auto& |
|
357 | auto &helper = sqpApp->dragDropHelper(); | |
355 | if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) |
|
358 | if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) { | |
356 | { |
|
359 | auto graphWidget = static_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); | |
357 | auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget()); |
|
360 | auto parentDragDropContainer | |
358 |
|
|
361 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); | |
359 | Q_ASSERT(parentDragDropContainer); |
|
362 | Q_ASSERT(parentDragDropContainer); | |
360 |
|
363 | |||
361 |
const auto& |
|
364 | const auto &variables = graphWidget->variables(); | |
362 |
|
365 | |||
363 | if (parentDragDropContainer != ui->dragDropContainer && !variables.isEmpty()) |
|
366 | if (parentDragDropContainer != ui->dragDropContainer && !variables.isEmpty()) { | |
364 | { |
|
367 | // The drop didn't occur in the same zone | |
365 | //The drop didn't occur in the same zone |
|
|||
366 |
|
368 | |||
367 | //Abort the requests for the variables (if any) |
|
369 | // Abort the requests for the variables (if any) | |
368 | //Commented, because it's not sure if it's needed or not |
|
370 | // Commented, because it's not sure if it's needed or not | |
369 | //for (const auto& var : variables) |
|
371 | // for (const auto& var : variables) | |
370 | //{ |
|
372 | //{ | |
371 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
373 | // sqpApp->variableController().onAbortProgressRequested(var); | |
372 | //} |
|
374 | //} | |
373 |
|
375 | |||
374 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); |
|
376 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); | |
375 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
377 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
376 | if (nbGraph == 1) |
|
378 | if (nbGraph == 1) { | |
377 | { |
|
379 | // This is the only graph in the previous zone, close the zone | |
378 | //This is the only graph in the previous zone, close the zone |
|
|||
379 | previousParentZoneWidget->close(); |
|
380 | previousParentZoneWidget->close(); | |
380 | } |
|
381 | } | |
381 | else |
|
382 | else { | |
382 | { |
|
383 | // Close the graph | |
383 | //Close the graph |
|
|||
384 | graphWidget->close(); |
|
384 | graphWidget->close(); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | //Creates the new graph in the zone |
|
387 | // Creates the new graph in the zone | |
388 | createGraph(variables, index); |
|
388 | createGraph(variables, index); | |
389 | } |
|
389 | } | |
390 | else |
|
390 | else { | |
391 | { |
|
391 | // The drop occurred in the same zone or the graph is empty | |
392 | //The drop occurred in the same zone or the graph is empty |
|
392 | // Simple move of the graph, no variable operation associated | |
393 | //Simple move of the graph, no variable operation associated |
|
|||
394 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
393 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |
395 |
|
394 | |||
396 | if (variables.isEmpty() && parentDragDropContainer != ui->dragDropContainer) |
|
395 | if (variables.isEmpty() && parentDragDropContainer != ui->dragDropContainer) { | |
397 | { |
|
|||
398 | // The graph is empty and dropped in a different zone. |
|
396 | // The graph is empty and dropped in a different zone. | |
399 | // Take the range of the first graph in the zone (if existing). |
|
397 | // Take the range of the first graph in the zone (if existing). | |
400 | auto layout = ui->dragDropContainer->layout(); |
|
398 | auto layout = ui->dragDropContainer->layout(); | |
401 | if (layout->count() > 0) |
|
399 | if (layout->count() > 0) { | |
402 | { |
|
400 | if (auto visualizationGraphWidget | |
403 |
|
|
401 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
404 | { |
|
|||
405 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); |
|
402 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); | |
406 | } |
|
403 | } | |
407 | } |
|
404 | } |
General Comments 0
You need to be logged in to leave comments.
Login now