parent can be null. don"t use do while :)
@@ -2,6 +2,7 | |||||
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
|
5 | #include "Visualization/VisualizationDragWidget.h" | |||
5 |
|
6 | |||
6 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
8 | #include <QWidget> | |
@@ -16,12 +17,13 class QCPRange; | |||||
16 | class QCustomPlot; |
|
17 | class QCustomPlot; | |
17 | class SqpRange; |
|
18 | class SqpRange; | |
18 | class Variable; |
|
19 | class Variable; | |
|
20 | class VisualizationZoneWidget; | |||
19 |
|
21 | |||
20 | namespace Ui { |
|
22 | namespace Ui { | |
21 | class VisualizationGraphWidget; |
|
23 | class VisualizationGraphWidget; | |
22 | } // namespace Ui |
|
24 | } // namespace Ui | |
23 |
|
25 | |||
24 |
class VisualizationGraphWidget : public |
|
26 | class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { | |
25 | Q_OBJECT |
|
27 | Q_OBJECT | |
26 |
|
28 | |||
27 | friend class QCustomPlotSynchronizer; |
|
29 | friend class QCustomPlotSynchronizer; | |
@@ -31,6 +33,8 public: | |||||
31 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
33 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
32 | virtual ~VisualizationGraphWidget(); |
|
34 | virtual ~VisualizationGraphWidget(); | |
33 |
|
35 | |||
|
36 | VisualizationZoneWidget* parentZoneWidget() const noexcept; | |||
|
37 | ||||
34 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
38 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit | |
35 | void enableAcquisition(bool enable); |
|
39 | void enableAcquisition(bool enable); | |
36 |
|
40 | |||
@@ -39,6 +43,9 public: | |||||
39 | /// Removes a variable from the graph |
|
43 | /// Removes a variable from the graph | |
40 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
44 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
41 |
|
45 | |||
|
46 | /// Returns the list of all variables used in the graph | |||
|
47 | QList<std::shared_ptr<Variable>> variables() const; | |||
|
48 | ||||
42 | void setYRange(const SqpRange &range); |
|
49 | void setYRange(const SqpRange &range); | |
43 | SqpRange graphRange() const noexcept; |
|
50 | SqpRange graphRange() const noexcept; | |
44 | void setGraphRange(const SqpRange &range); |
|
51 | void setGraphRange(const SqpRange &range); | |
@@ -49,6 +56,9 public: | |||||
49 | bool contains(const Variable &variable) const override; |
|
56 | bool contains(const Variable &variable) const override; | |
50 | QString name() const override; |
|
57 | QString name() const override; | |
51 |
|
58 | |||
|
59 | // VisualisationDragWidget | |||
|
60 | QMimeData* mimeData() const override; | |||
|
61 | bool isDragAllowed() const override; | |||
52 |
|
62 | |||
53 | signals: |
|
63 | signals: | |
54 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
|
64 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
@@ -7,6 +7,7 | |||||
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 | #include <QWidget> |
|
9 | #include <QWidget> | |
|
10 | #include <QMimeData> | |||
10 |
|
11 | |||
11 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) | |
12 |
|
13 | |||
@@ -27,14 +28,25 public: | |||||
27 | /// Add a zone widget |
|
28 | /// Add a zone widget | |
28 | void addZone(VisualizationZoneWidget *zoneWidget); |
|
29 | void addZone(VisualizationZoneWidget *zoneWidget); | |
29 |
|
30 | |||
|
31 | void insertZone(int index, VisualizationZoneWidget *zoneWidget); | |||
|
32 | ||||
30 | /** |
|
33 | /** | |
31 | * Creates a zone using a variable. The variable will be displayed in a new graph of the new |
|
34 | * Creates a zone using a variable. The variable will be displayed in a new graph of the new | |
32 | * zone. |
|
35 | * zone. The zone is added at the end. | |
33 | * @param variable the variable for which to create the zone |
|
36 | * @param variable the variable for which to create the zone | |
34 | * @return the pointer to the created zone |
|
37 | * @return the pointer to the created zone | |
35 | */ |
|
38 | */ | |
36 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); |
|
39 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); | |
37 |
|
40 | |||
|
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. | |||
|
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 | |||
|
46 | * @return the pointer to the created zone | |||
|
47 | */ | |||
|
48 | VisualizationZoneWidget *createZone(const QList<std::shared_ptr<Variable>>& variables, int index); | |||
|
49 | ||||
38 | // IVisualizationWidget interface |
|
50 | // IVisualizationWidget interface | |
39 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
51 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
40 | bool canDrop(const Variable &variable) const override; |
|
52 | bool canDrop(const Variable &variable) const override; | |
@@ -52,6 +64,9 private: | |||||
52 |
|
64 | |||
53 | class VisualizationTabWidgetPrivate; |
|
65 | class VisualizationTabWidgetPrivate; | |
54 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; |
|
66 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; | |
|
67 | ||||
|
68 | private slots: | |||
|
69 | void dropMimeData(int index, const QMimeData *mimeData); | |||
55 | }; |
|
70 | }; | |
56 |
|
71 | |||
57 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
|
72 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
@@ -2,6 +2,7 | |||||
2 | #define SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONZONEWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
|
5 | #include "Visualization/VisualizationDragWidget.h" | |||
5 |
|
6 | |||
6 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
8 | #include <QWidget> | |
@@ -19,29 +20,55 class VisualizationZoneWidget; | |||||
19 | class Variable; |
|
20 | class Variable; | |
20 | class VisualizationGraphWidget; |
|
21 | class VisualizationGraphWidget; | |
21 |
|
22 | |||
22 |
class VisualizationZoneWidget : public |
|
23 | class VisualizationZoneWidget : public VisualizationDragWidget, public IVisualizationWidget { | |
23 | Q_OBJECT |
|
24 | Q_OBJECT | |
24 |
|
25 | |||
25 | public: |
|
26 | public: | |
26 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); |
|
27 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); | |
27 | virtual ~VisualizationZoneWidget(); |
|
28 | virtual ~VisualizationZoneWidget(); | |
28 |
|
29 | |||
29 | /// Add a graph widget |
|
30 | /// Adds a graph widget | |
30 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
31 | void addGraph(VisualizationGraphWidget *graphWidget); | |
31 |
|
32 | |||
|
33 | /// Inserts a graph widget | |||
|
34 | void insertGraph(int index, VisualizationGraphWidget *graphWidget); | |||
|
35 | ||||
32 | /** |
|
36 | /** | |
33 | * Creates a graph using a variable. The variable will be displayed in the new graph. |
|
37 | * Creates a graph using a variable. The variable will be displayed in the new graph. | |
|
38 | * The graph is added at the end. | |||
34 | * @param variable the variable for which to create the graph |
|
39 | * @param variable the variable for which to create the graph | |
35 | * @return the pointer to the created graph |
|
40 | * @return the pointer to the created graph | |
36 | */ |
|
41 | */ | |
37 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable); |
|
42 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable); | |
38 |
|
43 | |||
|
44 | /** | |||
|
45 | * Creates a graph using a variable. The variable will be displayed in the new graph. | |||
|
46 | * The graph is inserted at the specified index. | |||
|
47 | * @param variable the variable for which to create the graph | |||
|
48 | * @param index The index where the graph should be inserted in the layout | |||
|
49 | * @return the pointer to the created graph | |||
|
50 | */ | |||
|
51 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable, int index); | |||
|
52 | ||||
|
53 | /** | |||
|
54 | * Creates a graph using a list of variables. The variables will be displayed in the new graph. | |||
|
55 | * The graph is inserted at the specified index. | |||
|
56 | * @param variables List of variables to be added to the graph | |||
|
57 | * @param index The index where the graph should be inserted in the layout | |||
|
58 | * @return the pointer to the created graph | |||
|
59 | */ | |||
|
60 | VisualizationGraphWidget *createGraph(const QList<std::shared_ptr<Variable>> variables, int index); | |||
|
61 | ||||
39 | // IVisualizationWidget interface |
|
62 | // IVisualizationWidget interface | |
40 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
63 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
41 | bool canDrop(const Variable &variable) const override; |
|
64 | bool canDrop(const Variable &variable) const override; | |
42 | bool contains(const Variable &variable) const override; |
|
65 | bool contains(const Variable &variable) const override; | |
43 | QString name() const override; |
|
66 | QString name() const override; | |
44 |
|
67 | |||
|
68 | // VisualisationDragWidget | |||
|
69 | QMimeData* mimeData() const override; | |||
|
70 | bool isDragAllowed() const override; | |||
|
71 | ||||
45 | protected: |
|
72 | protected: | |
46 | void closeEvent(QCloseEvent *event) override; |
|
73 | void closeEvent(QCloseEvent *event) override; | |
47 |
|
74 | |||
@@ -55,6 +82,8 private slots: | |||||
55 | void onVariableAdded(std::shared_ptr<Variable> variable); |
|
82 | void onVariableAdded(std::shared_ptr<Variable> variable); | |
56 | /// Slot called when a variable is about to be removed from a graph contained in the zone |
|
83 | /// Slot called when a variable is about to be removed from a graph contained in the zone | |
57 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); |
|
84 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); | |
|
85 | ||||
|
86 | void dropMimeData(int index, const QMimeData* mimeData); | |||
58 | }; |
|
87 | }; | |
59 |
|
88 | |||
60 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
89 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -3,12 +3,14 | |||||
3 | #include "Visualization/VisualizationDefs.h" |
|
3 | #include "Visualization/VisualizationDefs.h" | |
4 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | #include "Visualization/VisualizationGraphHelper.h" | |
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
|
6 | #include "Visualization/VisualizationZoneWidget.h" | |||
6 | #include "ui_VisualizationGraphWidget.h" |
|
7 | #include "ui_VisualizationGraphWidget.h" | |
7 |
|
8 | |||
8 | #include <Data/ArrayData.h> |
|
9 | #include <Data/ArrayData.h> | |
9 | #include <Data/IDataSeries.h> |
|
10 | #include <Data/IDataSeries.h> | |
10 | #include <Settings/SqpSettingsDefs.h> |
|
11 | #include <Settings/SqpSettingsDefs.h> | |
11 | #include <SqpApplication.h> |
|
12 | #include <SqpApplication.h> | |
|
13 | #include <DragDropHelper.h> | |||
12 | #include <Variable/Variable.h> |
|
14 | #include <Variable/Variable.h> | |
13 | #include <Variable/VariableController.h> |
|
15 | #include <Variable/VariableController.h> | |
14 |
|
16 | |||
@@ -47,7 +49,7 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
47 | }; |
|
49 | }; | |
48 |
|
50 | |||
49 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
51 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
50 |
: |
|
52 | : VisualizationDragWidget{parent}, | |
51 | ui{new Ui::VisualizationGraphWidget}, |
|
53 | ui{new Ui::VisualizationGraphWidget}, | |
52 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
54 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
53 | { |
|
55 | { | |
@@ -92,6 +94,17 VisualizationGraphWidget::~VisualizationGraphWidget() | |||||
92 | delete ui; |
|
94 | delete ui; | |
93 | } |
|
95 | } | |
94 |
|
96 | |||
|
97 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |||
|
98 | { | |||
|
99 | auto parent = parentWidget(); | |||
|
100 | do | |||
|
101 | { | |||
|
102 |
parent = parent->parentWidget();
|
|||
|
103 | } while (parent != nullptr && !qobject_cast<VisualizationZoneWidget*>(parent)); | |||
|
104 | ||||
|
105 | return qobject_cast<VisualizationZoneWidget*>(parent); | |||
|
106 | } | |||
|
107 | ||||
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
108 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
96 | { |
|
109 | { | |
97 | impl->m_DoAcquisition = enable; |
|
110 | impl->m_DoAcquisition = enable; | |
@@ -152,6 +165,17 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable | |||||
152 | ui->widget->replot(); |
|
165 | ui->widget->replot(); | |
153 | } |
|
166 | } | |
154 |
|
167 | |||
|
168 | QList<std::shared_ptr<Variable>> VisualizationGraphWidget::variables() const | |||
|
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 | { | |||
|
173 | variables << it->first; | |||
|
174 | } | |||
|
175 | ||||
|
176 | return variables; | |||
|
177 | } | |||
|
178 | ||||
155 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
179 | void VisualizationGraphWidget::setYRange(const SqpRange &range) | |
156 | { |
|
180 | { | |
157 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
181 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); | |
@@ -206,6 +230,19 QString VisualizationGraphWidget::name() const | |||||
206 | return impl->m_Name; |
|
230 | return impl->m_Name; | |
207 | } |
|
231 | } | |
208 |
|
232 | |||
|
233 | QMimeData *VisualizationGraphWidget::mimeData() const | |||
|
234 | { | |||
|
235 |
auto *mimeData = new QMimeData;
auto mimeData |
|||
|
236 | mimeData->setData(DragDropHelper::MIME_TYPE_GRAPH, QByteArray()); | |||
|
237 | ||||
|
238 | return mimeData; | |||
|
239 | } | |||
|
240 | ||||
|
241 | bool VisualizationGraphWidget::isDragAllowed() const | |||
|
242 | { | |||
|
243 | return true; | |||
|
244 | } | |||
|
245 | ||||
209 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
246 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
210 | { |
|
247 | { | |
211 | Q_UNUSED(event); |
|
248 | Q_UNUSED(event); | |
@@ -284,6 +321,8 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||||
284 | { |
|
321 | { | |
285 | // Handles plot rendering when mouse is moving |
|
322 | // Handles plot rendering when mouse is moving | |
286 | impl->m_RenderingDelegate->onMouseMove(event); |
|
323 | impl->m_RenderingDelegate->onMouseMove(event); | |
|
324 | ||||
|
325 | VisualizationDragWidget::mouseMoveEvent(event); | |||
287 | } |
|
326 | } | |
288 |
|
327 | |||
289 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
328 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
@@ -307,6 +346,10 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |||||
307 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
346 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
308 | { |
|
347 | { | |
309 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
348 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
|
349 | ||||
|
350 | plot().setInteraction(QCP::iRangeDrag, !event->modifiers().testFlag(Qt::AltModifier)); | |||
|
351 | ||||
|
352 | VisualizationDragWidget::mousePressEvent(event); | |||
310 | } |
|
353 | } | |
311 |
|
354 | |||
312 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
355 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
@@ -3,6 +3,10 | |||||
3 | #include "ui_VisualizationTabWidget.h" |
|
3 | #include "ui_VisualizationTabWidget.h" | |
4 |
|
4 | |||
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
|
6 | #include "Visualization/VisualizationGraphWidget.h" | |||
|
7 | ||||
|
8 | #include "SqpApplication.h" | |||
|
9 | #include "DragDropHelper.h" | |||
6 |
|
10 | |||
7 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") |
|
11 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") | |
8 |
|
12 | |||
@@ -55,6 +59,9 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par | |||||
55 | { |
|
59 | { | |
56 | ui->setupUi(this); |
|
60 | ui->setupUi(this); | |
57 |
|
61 | |||
|
62 | ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH, DragDropHelper::MIME_TYPE_ZONE}); | |||
|
63 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, &VisualizationTabWidget::dropMimeData); | |||
|
64 | ||||
58 | // Widget is deleted when closed |
|
65 | // Widget is deleted when closed | |
59 | setAttribute(Qt::WA_DeleteOnClose); |
|
66 | setAttribute(Qt::WA_DeleteOnClose); | |
60 | } |
|
67 | } | |
@@ -66,16 +73,26 VisualizationTabWidget::~VisualizationTabWidget() | |||||
66 |
|
73 | |||
67 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
74 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | |
68 | { |
|
75 | { | |
69 |
|
|
76 | ui->dragDropContainer->addDragWidget(zoneWidget); | |
|
77 | } | |||
|
78 | ||||
|
79 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) | |||
|
80 | { | |||
|
81 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); | |||
70 | } |
|
82 | } | |
71 |
|
83 | |||
72 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
84 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | |
73 | { |
|
85 | { | |
74 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this}; |
|
86 | return createZone({variable}, -1); | |
75 | this->addZone(zoneWidget); |
|
87 | } | |
|
88 | ||||
|
89 | VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) | |||
|
90 | { | |||
|
91 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; | |||
|
92 | this->insertZone(index, zoneWidget); | |||
76 |
|
93 | |||
77 | // Creates a new graph into the zone |
|
94 | // Creates a new graph into the zone | |
78 | zoneWidget->createGraph(variable); |
|
95 | zoneWidget->createGraph(variables, index); | |
79 |
|
96 | |||
80 | return zoneWidget; |
|
97 | return zoneWidget; | |
81 | } |
|
98 | } | |
@@ -125,5 +142,40 void VisualizationTabWidget::closeEvent(QCloseEvent *event) | |||||
125 |
|
142 | |||
126 | QLayout &VisualizationTabWidget::tabLayout() const noexcept |
|
143 | QLayout &VisualizationTabWidget::tabLayout() const noexcept | |
127 | { |
|
144 | { | |
128 |
return *ui-> |
|
145 | return *ui->dragDropContainer->layout(); | |
|
146 | } | |||
|
147 | ||||
|
148 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) | |||
|
149 | { | |||
|
150 | auto& helper = sqpApp->dragDropHelper(); | |||
|
151 | if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH)) | |||
|
152 | { | |||
|
153 | auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget()); | |||
|
154 | auto parentDragDropContainer = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget()); | |||
|
155 | Q_ASSERT(parentDragDropContainer); | |||
|
156 | ||||
|
157 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |||
|
158 | if (nbGraph == 1) | |||
|
159 | { | |||
|
160 | //This is the only graph in the previous zone, close the zone | |||
|
161 | graphWidget->parentZoneWidget()->close(); | |||
|
162 | } | |||
|
163 | else | |||
|
164 | { | |||
|
165 | //Close the graph | |||
|
166 | graphWidget->close(); | |||
|
167 | } | |||
|
168 | ||||
|
169 | const auto& variables = graphWidget->variables(); | |||
|
170 | createZone(variables, index); | |||
|
171 | } | |||
|
172 | else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) | |||
|
173 | { | |||
|
174 | //Simple move of the zone, no variable operation associated | |||
|
175 | auto zoneWidget = static_cast<VisualizationZoneWidget*>(helper.getCurrentDragWidget()); | |||
|
176 | auto parentDragDropContainer = zoneWidget->parentWidget(); | |||
|
177 | parentDragDropContainer->layout()->removeWidget(zoneWidget); | |||
|
178 | ||||
|
179 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); | |||
|
180 | } | |||
129 | } |
|
181 | } |
@@ -11,8 +11,11 | |||||
11 |
|
11 | |||
12 | #include <QUuid> |
|
12 | #include <QUuid> | |
13 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
|
14 | #include <DragDropHelper.h> | |||
14 | #include <cmath> |
|
15 | #include <cmath> | |
15 |
|
16 | |||
|
17 | #include <QLayout> | |||
|
18 | ||||
16 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
19 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
17 |
|
20 | |||
18 | namespace { |
|
21 | namespace { | |
@@ -66,7 +69,7 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |||||
66 | }; |
|
69 | }; | |
67 |
|
70 | |||
68 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
71 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
69 |
: |
|
72 | : VisualizationDragWidget{parent}, | |
70 | ui{new Ui::VisualizationZoneWidget}, |
|
73 | ui{new Ui::VisualizationZoneWidget}, | |
71 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
74 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} | |
72 | { |
|
75 | { | |
@@ -74,6 +77,9 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p | |||||
74 |
|
77 | |||
75 | ui->zoneNameLabel->setText(name); |
|
78 | ui->zoneNameLabel->setText(name); | |
76 |
|
79 | |||
|
80 | ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH}); | |||
|
81 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, &VisualizationZoneWidget::dropMimeData); | |||
|
82 | ||||
77 | // 'Close' options : widget is deleted when closed |
|
83 | // 'Close' options : widget is deleted when closed | |
78 | setAttribute(Qt::WA_DeleteOnClose); |
|
84 | setAttribute(Qt::WA_DeleteOnClose); | |
79 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
85 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
@@ -94,13 +100,26 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |||||
94 | // Synchronize new graph with others in the zone |
|
100 | // Synchronize new graph with others in the zone | |
95 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
101 | impl->m_Synchronizer->addGraph(*graphWidget); | |
96 |
|
102 | |||
97 |
ui-> |
|
103 | ui->dragDropContainer->addDragWidget(graphWidget); | |
|
104 | } | |||
|
105 | ||||
|
106 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *graphWidget) | |||
|
107 | { | |||
|
108 | // Synchronize new graph with others in the zone | |||
|
109 | impl->m_Synchronizer->addGraph(*graphWidget); | |||
|
110 | ||||
|
111 | ui->dragDropContainer->insertDragWidget(index, graphWidget); | |||
98 | } |
|
112 | } | |
99 |
|
113 | |||
100 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
114 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
101 | { |
|
115 | { | |
|
116 | return createGraph(variable, -1); | |||
|
117 | } | |||
|
118 | ||||
|
119 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, int index) | |||
|
120 | { | |||
102 | auto graphWidget = new VisualizationGraphWidget{ |
|
121 | auto graphWidget = new VisualizationGraphWidget{ | |
103 |
defaultGraphName(*ui-> |
|
122 | defaultGraphName(*ui->dragDropContainer->layout()), this}; | |
104 |
|
123 | |||
105 |
|
124 | |||
106 | // Set graph properties |
|
125 | // Set graph properties | |
@@ -113,7 +132,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
113 | const SqpRange &oldGraphRange) { |
|
132 | const SqpRange &oldGraphRange) { | |
114 |
|
133 | |||
115 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
134 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
116 |
auto frameLayout = ui-> |
|
135 | auto frameLayout = ui->dragDropContainer->layout(); | |
117 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
136 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
118 | auto graphChild |
|
137 | auto graphChild | |
119 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
138 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
@@ -203,7 +222,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
203 | auto range = SqpRange{}; |
|
222 | auto range = SqpRange{}; | |
204 |
|
223 | |||
205 | // Apply visitor to graph children |
|
224 | // Apply visitor to graph children | |
206 |
auto layout = ui-> |
|
225 | auto layout = ui->dragDropContainer->layout(); | |
207 | if (layout->count() > 0) { |
|
226 | if (layout->count() > 0) { | |
208 | // Case of a new graph in a existant zone |
|
227 | // Case of a new graph in a existant zone | |
209 | if (auto visualizationGraphWidget |
|
228 | if (auto visualizationGraphWidget | |
@@ -216,7 +235,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
216 | range = variable->range(); |
|
235 | range = variable->range(); | |
217 | } |
|
236 | } | |
218 |
|
237 | |||
219 |
this-> |
|
238 | this->insertGraph(index, graphWidget); | |
220 |
|
239 | |||
221 | graphWidget->addVariable(variable, range); |
|
240 | graphWidget->addVariable(variable, range); | |
222 |
|
241 | |||
@@ -240,6 +259,20 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
240 | return graphWidget; |
|
259 | return graphWidget; | |
241 | } |
|
260 | } | |
242 |
|
261 | |||
|
262 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) | |||
|
263 | { | |||
|
264 | if (variables.isEmpty()) | |||
|
265 | return nullptr; | |||
|
266 | ||||
|
267 | auto graphWidget = createGraph(variables.first(), index); | |||
|
268 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) | |||
|
269 | { | |||
|
270 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); | |||
|
271 | } | |||
|
272 | ||||
|
273 | return graphWidget; | |||
|
274 | } | |||
|
275 | ||||
243 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
276 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
244 | { |
|
277 | { | |
245 | if (visitor) { |
|
278 | if (visitor) { | |
@@ -248,7 +281,7 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |||||
248 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
281 | // Apply visitor to graph children: widgets different from graphs are not visited (no | |
249 | // action) |
|
282 | // action) | |
250 | processGraphs( |
|
283 | processGraphs( | |
251 |
*ui-> |
|
284 | *ui->dragDropContainer->layout(), | |
252 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); |
|
285 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); | |
253 |
|
286 | |||
254 | visitor->visitLeave(this); |
|
287 | visitor->visitLeave(this); | |
@@ -276,10 +309,23 QString VisualizationZoneWidget::name() const | |||||
276 | return ui->zoneNameLabel->text(); |
|
309 | return ui->zoneNameLabel->text(); | |
277 | } |
|
310 | } | |
278 |
|
311 | |||
|
312 | QMimeData *VisualizationZoneWidget::mimeData() const | |||
|
313 | { | |||
|
314 | auto *mimeData = new QMimeData; | |||
|
315 | mimeData->setData(DragDropHelper::MIME_TYPE_ZONE, QByteArray()); | |||
|
316 | ||||
|
317 | return mimeData; | |||
|
318 | } | |||
|
319 | ||||
|
320 | bool VisualizationZoneWidget::isDragAllowed() const | |||
|
321 | { | |||
|
322 | return true; | |||
|
323 | } | |||
|
324 | ||||
279 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) |
|
325 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) | |
280 | { |
|
326 | { | |
281 | // Closes graphs in the zone |
|
327 | // Closes graphs in the zone | |
282 |
processGraphs(*ui-> |
|
328 | processGraphs(*ui->dragDropContainer->layout(), | |
283 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); |
|
329 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); | |
284 |
|
330 | |||
285 | // Delete synchronization group from variable controller |
|
331 | // Delete synchronization group from variable controller | |
@@ -302,3 +348,47 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variabl | |||||
302 | Q_ARG(std::shared_ptr<Variable>, variable), |
|
348 | Q_ARG(std::shared_ptr<Variable>, variable), | |
303 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
349 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
304 | } |
|
350 | } | |
|
351 | ||||
|
352 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) | |||
|
353 | { | |||
|
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()); | |||
|
359 | Q_ASSERT(parentDragDropContainer); | |||
|
360 | ||||
|
361 | const auto& variables = graphWidget->variables(); | |||
|
362 | ||||
|
363 | if (!variables.empty()) | |||
|
364 | { | |||
|
365 | if (parentDragDropContainer != ui->dragDropContainer) | |||
|
366 | { | |||
|
367 | //The drop didn't occur in the same zone | |||
|
368 | ||||
|
369 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); | |||
|
370 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |||
|
371 | if (nbGraph == 1) | |||
|
372 | { | |||
|
373 | //This is the only graph in the previous zone, close the zone | |||
|
374 | previousParentZoneWidget->close(); | |||
|
375 | } | |||
|
376 | else | |||
|
377 | { | |||
|
378 | //Close the graph | |||
|
379 | graphWidget->close(); | |||
|
380 | } | |||
|
381 | ||||
|
382 | //Creates the new graph in the zone | |||
|
383 | createGraph(variables, index); | |||
|
384 | } | |||
|
385 | else | |||
|
386 | { | |||
|
387 | //The drop occurred in the same zone | |||
|
388 | //Simple move of the graph, no variable operation associated | |||
|
389 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |||
|
390 | ui->dragDropContainer->insertDragWidget(index, graphWidget); | |||
|
391 | } | |||
|
392 | } | |||
|
393 | } | |||
|
394 | } |
@@ -62,12 +62,23 | |||||
62 | <property name="bottomMargin"> |
|
62 | <property name="bottomMargin"> | |
63 | <number>0</number> |
|
63 | <number>0</number> | |
64 | </property> |
|
64 | </property> | |
|
65 | <item> | |||
|
66 | <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/> | |||
|
67 | </item> | |||
65 | </layout> |
|
68 | </layout> | |
66 | </widget> |
|
69 | </widget> | |
67 | </widget> |
|
70 | </widget> | |
68 | </item> |
|
71 | </item> | |
69 | </layout> |
|
72 | </layout> | |
70 | </widget> |
|
73 | </widget> | |
|
74 | <customwidgets> | |||
|
75 | <customwidget> | |||
|
76 | <class>VisualizationDragDropContainer</class> | |||
|
77 | <extends>QWidget</extends> | |||
|
78 | <header>Visualization/VisualizationDragDropContainer.h</header> | |||
|
79 | <container>1</container> | |||
|
80 | </customwidget> | |||
|
81 | </customwidgets> | |||
71 | <resources/> |
|
82 | <resources/> | |
72 | <connections/> |
|
83 | <connections/> | |
73 | </ui> |
|
84 | </ui> |
@@ -107,11 +107,22 | |||||
107 | <property name="bottomMargin"> |
|
107 | <property name="bottomMargin"> | |
108 | <number>0</number> |
|
108 | <number>0</number> | |
109 | </property> |
|
109 | </property> | |
|
110 | <item> | |||
|
111 | <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/> | |||
|
112 | </item> | |||
110 | </layout> |
|
113 | </layout> | |
111 | </widget> |
|
114 | </widget> | |
112 | </item> |
|
115 | </item> | |
113 | </layout> |
|
116 | </layout> | |
114 | </widget> |
|
117 | </widget> | |
|
118 | <customwidgets> | |||
|
119 | <customwidget> | |||
|
120 | <class>VisualizationDragDropContainer</class> | |||
|
121 | <extends>QWidget</extends> | |||
|
122 | <header>Visualization/VisualizationDragDropContainer.h</header> | |||
|
123 | <container>1</container> | |||
|
124 | </customwidget> | |||
|
125 | </customwidgets> | |||
115 | <resources/> |
|
126 | <resources/> | |
116 | <connections/> |
|
127 | <connections/> | |
117 | </ui> |
|
128 | </ui> |
General Comments 6
Pull request updated. Auto status change to "Under Review"
Changed commits: * 1 added * 0 removed Changed files: * M gui/include/Visualization/VisualizationDragDropContainer.h * M gui/include/Visualization/VisualizationDragWidget.h * M gui/src/Visualization/VisualizationDragDropContainer.cpp * M gui/src/Visualization/VisualizationGraphWidget.cpp * M gui/src/Visualization/VisualizationZoneWidget.cpp
Status change > Approved
You need to be logged in to leave comments.
Login now