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

Status change > Approved

You need to be logged in to leave comments. Login now