parent can be null. don"t use do while :)
@@ -2,6 +2,7 | |||
|
2 | 2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | #include "Visualization/VisualizationDragWidget.h" | |
|
5 | 6 | |
|
6 | 7 | #include <QLoggingCategory> |
|
7 | 8 | #include <QWidget> |
@@ -16,12 +17,13 class QCPRange; | |||
|
16 | 17 | class QCustomPlot; |
|
17 | 18 | class SqpRange; |
|
18 | 19 | class Variable; |
|
20 | class VisualizationZoneWidget; | |
|
19 | 21 | |
|
20 | 22 | namespace Ui { |
|
21 | 23 | class VisualizationGraphWidget; |
|
22 | 24 | } // namespace Ui |
|
23 | 25 | |
|
24 |
class VisualizationGraphWidget : public |
|
|
26 | class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { | |
|
25 | 27 | Q_OBJECT |
|
26 | 28 | |
|
27 | 29 | friend class QCustomPlotSynchronizer; |
@@ -31,6 +33,8 public: | |||
|
31 | 33 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
32 | 34 | virtual ~VisualizationGraphWidget(); |
|
33 | 35 | |
|
36 | VisualizationZoneWidget* parentZoneWidget() const noexcept; | |
|
37 | ||
|
34 | 38 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
35 | 39 | void enableAcquisition(bool enable); |
|
36 | 40 | |
@@ -39,6 +43,9 public: | |||
|
39 | 43 | /// Removes a variable from the graph |
|
40 | 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 | 49 | void setYRange(const SqpRange &range); |
|
43 | 50 | SqpRange graphRange() const noexcept; |
|
44 | 51 | void setGraphRange(const SqpRange &range); |
@@ -49,6 +56,9 public: | |||
|
49 | 56 | bool contains(const Variable &variable) const override; |
|
50 | 57 | QString name() const override; |
|
51 | 58 | |
|
59 | // VisualisationDragWidget | |
|
60 | QMimeData* mimeData() const override; | |
|
61 | bool isDragAllowed() const override; | |
|
52 | 62 | |
|
53 | 63 | signals: |
|
54 | 64 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
@@ -7,6 +7,7 | |||
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QWidget> |
|
10 | #include <QMimeData> | |
|
10 | 11 | |
|
11 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget) |
|
12 | 13 | |
@@ -27,14 +28,25 public: | |||
|
27 | 28 | /// Add a zone widget |
|
28 | 29 | void addZone(VisualizationZoneWidget *zoneWidget); |
|
29 | 30 | |
|
31 | void insertZone(int index, VisualizationZoneWidget *zoneWidget); | |
|
32 | ||
|
30 | 33 | /** |
|
31 | 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 | 36 | * @param variable the variable for which to create the zone |
|
34 | 37 | * @return the pointer to the created zone |
|
35 | 38 | */ |
|
36 | 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 | 50 | // IVisualizationWidget interface |
|
39 | 51 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
40 | 52 | bool canDrop(const Variable &variable) const override; |
@@ -52,6 +64,9 private: | |||
|
52 | 64 | |
|
53 | 65 | class VisualizationTabWidgetPrivate; |
|
54 | 66 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; |
|
67 | ||
|
68 | private slots: | |
|
69 | void dropMimeData(int index, const QMimeData *mimeData); | |
|
55 | 70 | }; |
|
56 | 71 | |
|
57 | 72 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
@@ -2,6 +2,7 | |||
|
2 | 2 | #define SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | #include "Visualization/VisualizationDragWidget.h" | |
|
5 | 6 | |
|
6 | 7 | #include <QLoggingCategory> |
|
7 | 8 | #include <QWidget> |
@@ -19,29 +20,55 class VisualizationZoneWidget; | |||
|
19 | 20 | class Variable; |
|
20 | 21 | class VisualizationGraphWidget; |
|
21 | 22 | |
|
22 |
class VisualizationZoneWidget : public |
|
|
23 | class VisualizationZoneWidget : public VisualizationDragWidget, public IVisualizationWidget { | |
|
23 | 24 | Q_OBJECT |
|
24 | 25 | |
|
25 | 26 | public: |
|
26 | 27 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); |
|
27 | 28 | virtual ~VisualizationZoneWidget(); |
|
28 | 29 | |
|
29 | /// Add a graph widget | |
|
30 | /// Adds a graph widget | |
|
30 | 31 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
31 | 32 | |
|
33 | /// Inserts a graph widget | |
|
34 | void insertGraph(int index, VisualizationGraphWidget *graphWidget); | |
|
35 | ||
|
32 | 36 | /** |
|
33 | 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 | 39 | * @param variable the variable for which to create the graph |
|
35 | 40 | * @return the pointer to the created graph |
|
36 | 41 | */ |
|
37 | 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 | 62 | // IVisualizationWidget interface |
|
40 | 63 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
41 | 64 | bool canDrop(const Variable &variable) const override; |
|
42 | 65 | bool contains(const Variable &variable) const override; |
|
43 | 66 | QString name() const override; |
|
44 | 67 | |
|
68 | // VisualisationDragWidget | |
|
69 | QMimeData* mimeData() const override; | |
|
70 | bool isDragAllowed() const override; | |
|
71 | ||
|
45 | 72 | protected: |
|
46 | 73 | void closeEvent(QCloseEvent *event) override; |
|
47 | 74 | |
@@ -55,6 +82,8 private slots: | |||
|
55 | 82 | void onVariableAdded(std::shared_ptr<Variable> variable); |
|
56 | 83 | /// Slot called when a variable is about to be removed from a graph contained in the zone |
|
57 | 84 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); |
|
85 | ||
|
86 | void dropMimeData(int index, const QMimeData* mimeData); | |
|
58 | 87 | }; |
|
59 | 88 | |
|
60 | 89 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -3,12 +3,14 | |||
|
3 | 3 | #include "Visualization/VisualizationDefs.h" |
|
4 | 4 | #include "Visualization/VisualizationGraphHelper.h" |
|
5 | 5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
6 | #include "Visualization/VisualizationZoneWidget.h" | |
|
6 | 7 | #include "ui_VisualizationGraphWidget.h" |
|
7 | 8 | |
|
8 | 9 | #include <Data/ArrayData.h> |
|
9 | 10 | #include <Data/IDataSeries.h> |
|
10 | 11 | #include <Settings/SqpSettingsDefs.h> |
|
11 | 12 | #include <SqpApplication.h> |
|
13 | #include <DragDropHelper.h> | |
|
12 | 14 | #include <Variable/Variable.h> |
|
13 | 15 | #include <Variable/VariableController.h> |
|
14 | 16 | |
@@ -47,7 +49,7 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||
|
47 | 49 | }; |
|
48 | 50 | |
|
49 | 51 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
50 |
: |
|
|
52 | : VisualizationDragWidget{parent}, | |
|
51 | 53 | ui{new Ui::VisualizationGraphWidget}, |
|
52 | 54 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
53 | 55 | { |
@@ -92,6 +94,17 VisualizationGraphWidget::~VisualizationGraphWidget() | |||
|
92 | 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 | 108 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
96 | 109 | { |
|
97 | 110 | impl->m_DoAcquisition = enable; |
@@ -152,6 +165,17 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable | |||
|
152 | 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 | 179 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
156 | 180 | { |
|
157 | 181 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
@@ -206,6 +230,19 QString VisualizationGraphWidget::name() const | |||
|
206 | 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 | 246 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
210 | 247 | { |
|
211 | 248 | Q_UNUSED(event); |
@@ -284,6 +321,8 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||
|
284 | 321 | { |
|
285 | 322 | // Handles plot rendering when mouse is moving |
|
286 | 323 | impl->m_RenderingDelegate->onMouseMove(event); |
|
324 | ||
|
325 | VisualizationDragWidget::mouseMoveEvent(event); | |
|
287 | 326 | } |
|
288 | 327 | |
|
289 | 328 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
@@ -307,6 +346,10 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |||
|
307 | 346 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
308 | 347 | { |
|
309 | 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 | 355 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
@@ -3,6 +3,10 | |||
|
3 | 3 | #include "ui_VisualizationTabWidget.h" |
|
4 | 4 | |
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | #include "Visualization/VisualizationGraphWidget.h" | |
|
7 | ||
|
8 | #include "SqpApplication.h" | |
|
9 | #include "DragDropHelper.h" | |
|
6 | 10 | |
|
7 | 11 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") |
|
8 | 12 | |
@@ -55,6 +59,9 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par | |||
|
55 | 59 | { |
|
56 | 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 | 65 | // Widget is deleted when closed |
|
59 | 66 | setAttribute(Qt::WA_DeleteOnClose); |
|
60 | 67 | } |
@@ -66,16 +73,26 VisualizationTabWidget::~VisualizationTabWidget() | |||
|
66 | 73 | |
|
67 | 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 | 84 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
73 | 85 | { |
|
74 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this}; | |
|
75 | this->addZone(zoneWidget); | |
|
86 | return createZone({variable}, -1); | |
|
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 | 94 | // Creates a new graph into the zone |
|
78 | zoneWidget->createGraph(variable); | |
|
95 | zoneWidget->createGraph(variables, index); | |
|
79 | 96 | |
|
80 | 97 | return zoneWidget; |
|
81 | 98 | } |
@@ -125,5 +142,40 void VisualizationTabWidget::closeEvent(QCloseEvent *event) | |||
|
125 | 142 | |
|
126 | 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 | 12 | #include <QUuid> |
|
13 | 13 | #include <SqpApplication.h> |
|
14 | #include <DragDropHelper.h> | |
|
14 | 15 | #include <cmath> |
|
15 | 16 | |
|
17 | #include <QLayout> | |
|
18 | ||
|
16 | 19 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
17 | 20 | |
|
18 | 21 | namespace { |
@@ -66,7 +69,7 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |||
|
66 | 69 | }; |
|
67 | 70 | |
|
68 | 71 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
69 |
: |
|
|
72 | : VisualizationDragWidget{parent}, | |
|
70 | 73 | ui{new Ui::VisualizationZoneWidget}, |
|
71 | 74 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
72 | 75 | { |
@@ -74,6 +77,9 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p | |||
|
74 | 77 | |
|
75 | 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 | 83 | // 'Close' options : widget is deleted when closed |
|
78 | 84 | setAttribute(Qt::WA_DeleteOnClose); |
|
79 | 85 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
@@ -94,13 +100,26 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |||
|
94 | 100 | // Synchronize new graph with others in the zone |
|
95 | 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 | 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 | 121 | auto graphWidget = new VisualizationGraphWidget{ |
|
103 |
defaultGraphName(*ui-> |
|
|
122 | defaultGraphName(*ui->dragDropContainer->layout()), this}; | |
|
104 | 123 | |
|
105 | 124 | |
|
106 | 125 | // Set graph properties |
@@ -113,7 +132,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
113 | 132 | const SqpRange &oldGraphRange) { |
|
114 | 133 | |
|
115 | 134 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
116 |
auto frameLayout = ui-> |
|
|
135 | auto frameLayout = ui->dragDropContainer->layout(); | |
|
117 | 136 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
118 | 137 | auto graphChild |
|
119 | 138 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
@@ -203,7 +222,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
203 | 222 | auto range = SqpRange{}; |
|
204 | 223 | |
|
205 | 224 | // Apply visitor to graph children |
|
206 |
auto layout = ui-> |
|
|
225 | auto layout = ui->dragDropContainer->layout(); | |
|
207 | 226 | if (layout->count() > 0) { |
|
208 | 227 | // Case of a new graph in a existant zone |
|
209 | 228 | if (auto visualizationGraphWidget |
@@ -216,7 +235,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
216 | 235 | range = variable->range(); |
|
217 | 236 | } |
|
218 | 237 | |
|
219 |
this-> |
|
|
238 | this->insertGraph(index, graphWidget); | |
|
220 | 239 | |
|
221 | 240 | graphWidget->addVariable(variable, range); |
|
222 | 241 | |
@@ -240,6 +259,20 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
240 | 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 | 276 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
244 | 277 | { |
|
245 | 278 | if (visitor) { |
@@ -248,7 +281,7 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |||
|
248 | 281 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
249 | 282 | // action) |
|
250 | 283 | processGraphs( |
|
251 |
*ui-> |
|
|
284 | *ui->dragDropContainer->layout(), | |
|
252 | 285 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); |
|
253 | 286 | |
|
254 | 287 | visitor->visitLeave(this); |
@@ -276,10 +309,23 QString VisualizationZoneWidget::name() const | |||
|
276 | 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 | 325 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) |
|
280 | 326 | { |
|
281 | 327 | // Closes graphs in the zone |
|
282 |
processGraphs(*ui-> |
|
|
328 | processGraphs(*ui->dragDropContainer->layout(), | |
|
283 | 329 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); |
|
284 | 330 | |
|
285 | 331 | // Delete synchronization group from variable controller |
@@ -302,3 +348,47 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variabl | |||
|
302 | 348 | Q_ARG(std::shared_ptr<Variable>, variable), |
|
303 | 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 | 62 | <property name="bottomMargin"> |
|
63 | 63 | <number>0</number> |
|
64 | 64 | </property> |
|
65 | <item> | |
|
66 | <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/> | |
|
67 | </item> | |
|
65 | 68 | </layout> |
|
66 | 69 | </widget> |
|
67 | 70 | </widget> |
|
68 | 71 | </item> |
|
69 | 72 | </layout> |
|
70 | 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 | 82 | <resources/> |
|
72 | 83 | <connections/> |
|
73 | 84 | </ui> |
@@ -107,11 +107,22 | |||
|
107 | 107 | <property name="bottomMargin"> |
|
108 | 108 | <number>0</number> |
|
109 | 109 | </property> |
|
110 | <item> | |
|
111 | <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/> | |
|
112 | </item> | |
|
110 | 113 | </layout> |
|
111 | 114 | </widget> |
|
112 | 115 | </item> |
|
113 | 116 | </layout> |
|
114 | 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 | 126 | <resources/> |
|
116 | 127 | <connections/> |
|
117 | 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