##// END OF EJS Templates
Format changes
trabillard -
r847:90e991aec5fa
parent child
Show More
@@ -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,8 +13,7 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:
@@ -37,15 +36,14 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
44 DragDropHelper();
45 virtual ~DragDropHelper();
46
49 void setCurrentDragWidget(VisualizationDragWidget* dragWidget);
47 void setCurrentDragWidget(VisualizationDragWidget *dragWidget);
50 VisualizationDragWidget* getCurrentDragWidget() const;
48 VisualizationDragWidget *getCurrentDragWidget() const;
51
49
@@ -64,4 +62,4 private:
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
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -1,15 +1,14
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:
@@ -33,8 +32,6 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
@@ -1,12 +1,11
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:
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -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 the new
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>>& variables, int index);
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;
@@ -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, int index);
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;
@@ -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 <QDragMoveEvent>
5 #include <QDir>
6 #include <QDragEnterEvent>
6 #include <QDragEnterEvent>
7 #include <QScrollBar>
7 #include <QDragMoveEvent>
8 #include <QScrollArea>
8 #include <QScrollArea>
9 #include <QVBoxLayout>
9 #include <QScrollBar>
10 #include <QTimer>
10 #include <QTimer>
11 #include <QDir>
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_scrollAreas;
21 QList<QScrollArea *> m_ScrollAreas;
22 QScrollArea* m_currentScrollArea = nullptr;
22 QScrollArea *m_CurrentScrollArea = nullptr;
23 std::unique_ptr<QTimer> m_timer = nullptr;
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_direction = ScrollDirection::unknown;
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_timer->setInterval(0);
31 m_Timer->setInterval(0);
33 }
32 }
34 };
33 };
35
34
36 DragDropScroller::DragDropScroller(QObject* parent)
35 DragDropScroller::DragDropScroller(QObject *parent)
37 : QObject{parent}, impl{spimpl::make_unique_impl<DragDropScrollerPrivate>()}
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 scrollArea->viewport()->setAcceptDrops(true);
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 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 {
58 auto w = static_cast<QWidget*>(obj);
56 auto w = static_cast<QWidget *>(obj);
59
57
60 if (impl->m_currentScrollArea && impl->m_currentScrollArea->isAncestorOf(w))
58 if (impl->m_CurrentScrollArea && impl->m_CurrentScrollArea->isAncestorOf(w)) {
61 {
62 auto moveEvent = static_cast<QDragMoveEvent*>(event);
59 auto moveEvent = static_cast<QDragMoveEvent *>(event);
63
60
64 auto pos = moveEvent->pos();
61 auto pos = moveEvent->pos();
65 if (impl->m_currentScrollArea->viewport() != w)
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_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 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_timer->isActive())
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_timer->start();
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 {
88 auto w = static_cast<QWidget*>(obj);
83 auto w = static_cast<QWidget *>(obj);
89
84
90 for (auto scrollArea : impl-> m_scrollAreas)
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))
93 {
94 auto enterEvent = static_cast<QDragEnterEvent*>(event);
87 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_currentScrollArea = scrollArea;
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 {
104 auto w = static_cast<QWidget*>(obj);
96 auto w = static_cast<QWidget *>(obj);
105 if (impl->m_currentScrollArea)
97 if (impl->m_CurrentScrollArea) {
106 {
98 if (!QRect(QPoint(), impl->m_CurrentScrollArea->size())
107 if (!QRect(QPoint(), impl->m_currentScrollArea->size()).contains(impl->m_currentScrollArea->mapFromGlobal(QCursor::pos())))
99 .contains(impl->m_CurrentScrollArea->mapFromGlobal(QCursor::pos()))) {
108 {
100 impl->m_CurrentScrollArea = nullptr;
109 impl->m_currentScrollArea = nullptr;
101 impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown;
110 impl->m_direction = DragDropScrollerPrivate::ScrollDirection::unknown;
102 impl->m_Timer->stop();
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 {
117 auto w = static_cast<QWidget*>(obj);
107 auto w = static_cast<QWidget *>(obj);
118 if (impl->m_currentScrollArea)
108 if (impl->m_CurrentScrollArea) {
119 {
109 impl->m_CurrentScrollArea = nullptr;
120 impl->m_currentScrollArea = nullptr;
110 impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown;
121 impl->m_direction = DragDropScrollerPrivate::ScrollDirection::unknown;
111 impl->m_Timer->stop();
122 impl->m_timer->stop();
123 }
112 }
124 }
113 }
125
114
@@ -128,11 +117,9 bool DragDropScroller::eventFilter(QObject *obj, QEvent *event)
128
117
129 void DragDropScroller::onTimer()
118 void DragDropScroller::onTimer()
130 {
119 {
131 if (impl->m_currentScrollArea)
120 if (impl->m_CurrentScrollArea) {
132 {
133 auto mvt = 0;
121 auto mvt = 0;
134 switch (impl->m_direction)
122 switch (impl->m_Direction) {
135 {
136 case DragDropScrollerPrivate::ScrollDirection::up:
123 case DragDropScrollerPrivate::ScrollDirection::up:
137 mvt = SCROLL_SPEED;
124 mvt = SCROLL_SPEED;
138 break;
125 break;
@@ -143,106 +130,101 void DragDropScroller::onTimer()
143 break;
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 struct DragDropHelper::DragDropHelperPrivate {
138 struct DragDropHelper::DragDropHelperPrivate {
151
139
152 VisualizationDragWidget* m_currentDragWidget = nullptr;
140 VisualizationDragWidget *m_CurrentDragWidget = nullptr;
153 std::unique_ptr<QWidget> m_placeHolder = nullptr;
141 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
154 std::unique_ptr<DragDropScroller> m_dragDropScroller = nullptr;
142 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.
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_placeHolder{std::make_unique<QWidget>()},
147 : m_PlaceHolder{std::make_unique<QWidget>()},
159 m_dragDropScroller{std::make_unique<DragDropScroller>()}
148 m_DragDropScroller{std::make_unique<DragDropScroller>()}
160 {
149 {
161 m_placeHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4");
150 m_PlaceHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4");
162 sqpApp->installEventFilter(m_dragDropScroller.get());
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 void preparePlaceHolder() const
157 void preparePlaceHolder() const
169 {
158 {
170 if (m_currentDragWidget)
159 if (m_CurrentDragWidget) {
171 {
160 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
172 m_placeHolder->setMinimumSize(m_currentDragWidget->size());
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_imageTempUrl);
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_currentDragWidget = dragWidget;
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_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 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_placeHolder.get());
197 layout->insertWidget(index, impl->m_PlaceHolder.get());
214 impl->m_placeHolder->show();
198 impl->m_PlaceHolder->show();
215 }
199 }
216
200
217 void DragDropHelper::removePlaceHolder()
201 void DragDropHelper::removePlaceHolder()
218 {
202 {
219 auto parentWidget = impl->m_placeHolder->parentWidget();
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_placeHolder->setParent(nullptr);
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_placeHolder->parentWidget();
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_dragDropScroller->addScrollArea(scrollArea);
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_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);
228 image.save(impl->m_ImageTempUrl);
246 return QUrl::fromLocalFile(impl->m_imageTempUrl);
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,64 +1,61
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* m_layout;
14 QVBoxLayout *m_Layout;
15 QStringList m_acceptedMimeTypes;
15 QStringList m_AcceptedMimeTypes;
16 QStringList m_mergeAllowedMimeTypes;
16 QStringList m_MergeAllowedMimeTypes;
17
17
18 explicit VisualizationDragDropContainerPrivate(QWidget* widget)
18 explicit VisualizationDragDropContainerPrivate(QWidget *widget)
19 {
19 {
20 m_layout = new QVBoxLayout(widget);
20 m_Layout = new QVBoxLayout(widget);
21 m_layout->setContentsMargins(0,0,0,0);
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)
26 for (const auto &type : m_AcceptedMimeTypes) {
27 {
27 if (data->hasFormat(type)) {
28 if (data->hasFormat(type))
29 return true;
28 return true;
30 }
29 }
30 }
31
31
32 return false;
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)
37 for (const auto &type : m_MergeAllowedMimeTypes) {
38 {
38 if (data->hasFormat(type)) {
39 if (data->hasFormat(type))
40 return true;
39 return true;
41 }
40 }
41 }
42
42
43 return false;
43 return false;
44 }
44 }
45
45
46 bool hasPlaceHolder() const
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;
53 VisualizationDragWidget *dragWidget = nullptr;
54
54
55 for (auto child : parent->children())
55 for (auto child : parent->children()) {
56 {
57 auto widget = qobject_cast<VisualizationDragWidget*>(child);
56 auto widget = qobject_cast<VisualizationDragWidget *>(child);
58 if (widget && widget->isVisible())
57 if (widget && widget->isVisible()) {
59 {
58 if (widget->frameGeometry().contains(pos)) {
60 if (widget->frameGeometry().contains(pos))
61 {
62 dragWidget = widget;
59 dragWidget = widget;
63 break;
60 break;
64 }
61 }
@@ -71,51 +68,53 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
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
70 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);
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_layout->addWidget(dragWidget);
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, &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 disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr);
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 void VisualizationDragDropContainer::setAcceptedMimeTypes(const QStringList &mimeTypes)
102 void VisualizationDragDropContainer::setAcceptedMimeTypes(const QStringList &mimeTypes)
102 {
103 {
103 impl->m_acceptedMimeTypes = mimeTypes;
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_mergeAllowedMimeTypes = mimeTypes;
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,7 +122,8 int VisualizationDragDropContainer::countDragWidget() const
123 return nbGraph;
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
@@ -142,14 +142,12 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_layout->indexOf(dragWidget) >= 0)
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 }
@@ -160,35 +158,33 void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidg
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& helper = sqpApp->dragDropHelper();
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 hoveredWidgetIndex = impl->m_layout->indexOf(dragWidgetHovered);
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 if (dragWidgetIndex >= 0 && dragWidgetIndex <= hoveredWidgetIndex)
180 hoveredWidgetIndex
185 hoveredWidgetIndex += 1; //Correction of the index if the drop occurs in the same container
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
186 else {
190 {
187 helper.insertPlaceHolder(impl->m_Layout, 0);
191 helper.insertPlaceHolder(impl->m_layout, 0);
192 }
188 }
193 }
189 }
194 }
190 }
@@ -204,21 +200,18 void VisualizationDragDropContainer::dragLeaveEvent(QDragLeaveEvent *event)
204
200
205 auto& helper = sqpApp->dragDropHelper();
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 {
214 //Only if the drag is strated from the visualization
208 // Only if the drag is strated from the visualization
215 //Show the drag widget at its original place
209 // 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
210 // So the drag widget doesn't stay hidden if the drop occurs outside the visualization
217 //(It is not possible to catch a drop event outside of the application)
211 // drop zone (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);
@@ -247,27 +237,26 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event)
247 auto isOnBottom = event->pos().y() > (dropIndex + 1) * graphHeight - zoneSize;
237 auto isOnBottom = event->pos().y() > (dropIndex + 1) * graphHeight - zoneSize;
248
238
249 auto& helper = sqpApp->dragDropHelper();
239 auto &helper = sqpApp->dragDropHelper();
250 auto placeHolderIndex = impl->m_layout->indexOf(&(helper.placeHolder()));
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_layout->indexOf(helper.getCurrentDragWidget());
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 container
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 {
268 //drop on the middle -> merge
258 // drop on the middle -> merge
269 if (impl->hasPlaceHolder())
259 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 {
290 auto& helper = sqpApp->dragDropHelper();
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);
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_dragStartPosition;
9 QPoint m_DragStartPosition;
10 bool m_dragStartPositionValid = false;
10 bool m_DragStartPositionValid = false;
11
11
12 explicit VisualizationDragWidgetPrivate()
12 explicit VisualizationDragWidgetPrivate() {}
13 {
14 }
15 };
13 };
16
14
17 VisualizationDragWidget::VisualizationDragWidget(QWidget* parent)
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_dragStartPosition = event->pos();
23 impl->m_DragStartPosition = event->pos();
24 }
27
25
28 impl->m_dragStartPositionValid = isDragAllowed();
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_dragStartPositionValid || !isDragAllowed())
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_dragStartPosition).manhattanLength() < QApplication::startDragDistance())
45 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
46 < QApplication::startDragDistance()) {
45 return;
47 return;
48 }
46
49
47 emit dragDetected(this, impl->m_dragStartPosition);
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,8 +72,9 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 static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged),
77 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
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
@@ -97,8 +98,7 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
@@ -168,8 +168,8 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
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); it != std::cend(impl->m_VariableToPlotMultiMap); ++it)
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
@@ -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()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
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
@@ -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;
@@ -159,18 +163,17 QLayout &VisualizationTabWidget::tabLayout() const noexcept
159 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
163 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
160 {
164 {
161 auto& helper = sqpApp->dragDropHelper();
165 auto &helper = sqpApp->dragDropHelper();
162 if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH))
166 if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) {
163 {
164 auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget());
167 auto graphWidget = static_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget());
165 auto parentDragDropContainer = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget());
168 auto parentDragDropContainer
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& variables = graphWidget->variables();
174 const auto &variables = graphWidget->variables();
171
175
172 if (!variables.isEmpty())
176 if (!variables.isEmpty()) {
173 {
174 //Abort the requests for the variables (if any)
177 // Abort the requests for the variables (if any)
175 //Commented, because it's not sure if it's needed or not
178 // Commented, because it's not sure if it's needed or not
176 //for (const auto& var : variables)
179 // for (const auto& var : variables)
@@ -178,21 +181,18 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
178 // sqpApp->variableController().onAbortProgressRequested(var);
181 // sqpApp->variableController().onAbortProgressRequested(var);
179 //}
182 //}
180
183
181 if (nbGraph == 1)
184 if (nbGraph == 1) {
182 {
183 //This is the only graph in the previous zone, close the zone
185 // 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 {
188 //Close the graph
189 // 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();
@@ -203,12 +203,12 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
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 else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE))
210 }
211 {
211 else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) {
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();
@@ -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, &VisualizationZoneWidget::dropMimeData);
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, int index)
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()) << tr("TORM: deltaLeft")
151 qCDebug(LOG_VisualizationZoneWidget())
150 << deltaLeft;
152 << tr("TORM: deltaLeft") << deltaLeft;
151 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
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()) << tr("TORM: deltaLeft")
165 qCDebug(LOG_VisualizationZoneWidget())
164 << deltaLeft;
166 << tr("TORM: deltaLeft") << deltaLeft;
165 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
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()) << tr("TORM: Range before: ")
205 qCDebug(LOG_VisualizationZoneWidget())
204 << graphChild->graphRange();
206 << tr("TORM: Range before: ") << graphChild->graphRange();
205 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
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);
@@ -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
@@ -352,16 +355,15 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variabl
352 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
355 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
353 {
356 {
354 auto& helper = sqpApp->dragDropHelper();
357 auto &helper = sqpApp->dragDropHelper();
355 if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH))
358 if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) {
356 {
357 auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget());
359 auto graphWidget = static_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget());
358 auto parentDragDropContainer = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget());
360 auto parentDragDropContainer
361 = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget());
359 Q_ASSERT(parentDragDropContainer);
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())
366 if (parentDragDropContainer != ui->dragDropContainer && !variables.isEmpty()) {
364 {
365 //The drop didn't occur in the same zone
367 // 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)
@@ -373,13 +375,11 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
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 {
378 //This is the only graph in the previous zone, close the zone
379 // 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 }
@@ -387,21 +387,18 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
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 {
392 //The drop occurred in the same zone or the graph is empty
391 // The drop occurred in the same zone or the graph is empty
393 //Simple move of the graph, no variable operation associated
392 // 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 if (auto visualizationGraphWidget = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget()))
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 6
Approved

Status change > Approved

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