@@ -1,319 +1,320 | |||||
1 | #include "Visualization/VisualizationTabWidget.h" |
|
1 | #include "Visualization/VisualizationTabWidget.h" | |
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/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | #include "Visualization/VisualizationZoneWidget.h" | |
7 |
|
7 | |||
8 | #include "Visualization/MacScrollBarStyle.h" |
|
8 | #include "Visualization/MacScrollBarStyle.h" | |
9 |
|
9 | |||
10 | #include "Variable/VariableController.h" |
|
10 | #include "Variable/VariableController.h" | |
11 |
|
11 | |||
12 | #include "Common/MimeTypesDef.h" |
|
12 | #include "Common/MimeTypesDef.h" | |
13 |
|
13 | |||
14 | #include "DragAndDrop/DragDropHelper.h" |
|
14 | #include "DragAndDrop/DragDropHelper.h" | |
15 | #include "SqpApplication.h" |
|
15 | #include "SqpApplication.h" | |
16 |
|
16 | |||
17 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") |
|
17 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") | |
18 |
|
18 | |||
19 | namespace { |
|
19 | namespace { | |
20 |
|
20 | |||
21 | /// Generates a default name for a new zone, according to the number of zones already displayed in |
|
21 | /// Generates a default name for a new zone, according to the number of zones already displayed in | |
22 | /// the tab |
|
22 | /// the tab | |
23 | QString defaultZoneName(const QLayout &layout) |
|
23 | QString defaultZoneName(const QLayout &layout) | |
24 | { |
|
24 | { | |
25 | auto count = 0; |
|
25 | auto count = 0; | |
26 | for (auto i = 0; i < layout.count(); ++i) { |
|
26 | for (auto i = 0; i < layout.count(); ++i) { | |
27 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { |
|
27 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { | |
28 | count++; |
|
28 | count++; | |
29 | } |
|
29 | } | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | return QObject::tr("Zone %1").arg(count + 1); |
|
32 | return QObject::tr("Zone %1").arg(count + 1); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | /** |
|
35 | /** | |
36 | * Applies a function to all zones of the tab represented by its layout |
|
36 | * Applies a function to all zones of the tab represented by its layout | |
37 | * @param layout the layout that contains zones |
|
37 | * @param layout the layout that contains zones | |
38 | * @param fun the function to apply to each zone |
|
38 | * @param fun the function to apply to each zone | |
39 | */ |
|
39 | */ | |
40 | template <typename Fun> |
|
40 | template <typename Fun> | |
41 | void processZones(QLayout &layout, Fun fun) |
|
41 | void processZones(QLayout &layout, Fun fun) | |
42 | { |
|
42 | { | |
43 | for (auto i = 0; i < layout.count(); ++i) { |
|
43 | for (auto i = 0; i < layout.count(); ++i) { | |
44 | if (auto item = layout.itemAt(i)) { |
|
44 | if (auto item = layout.itemAt(i)) { | |
45 | if (auto visualizationZoneWidget |
|
45 | if (auto visualizationZoneWidget | |
46 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { |
|
46 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
47 | fun(*visualizationZoneWidget); |
|
47 | fun(*visualizationZoneWidget); | |
48 | } |
|
48 | } | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | } // namespace |
|
53 | } // namespace | |
54 |
|
54 | |||
55 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { |
|
55 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { | |
56 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} |
|
56 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} | |
57 |
|
57 | |||
58 | QString m_Name; |
|
58 | QString m_Name; | |
59 |
|
59 | |||
60 | #ifdef Q_OS_MAC |
|
60 | #ifdef Q_OS_MAC | |
61 | std::unique_ptr<MacScrollBarStyle> m_MacScrollBarStyle = std::make_unique<MacScrollBarStyle>(); |
|
61 | std::unique_ptr<MacScrollBarStyle> m_MacScrollBarStyle = std::make_unique<MacScrollBarStyle>(); | |
62 | #endif |
|
62 | #endif | |
63 |
|
63 | |||
64 | void dropGraph(int index, VisualizationTabWidget *tabWidget); |
|
64 | void dropGraph(int index, VisualizationTabWidget *tabWidget); | |
65 | void dropZone(int index, VisualizationTabWidget *tabWidget); |
|
65 | void dropZone(int index, VisualizationTabWidget *tabWidget); | |
66 | void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index, |
|
66 | void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index, | |
67 | VisualizationTabWidget *tabWidget); |
|
67 | VisualizationTabWidget *tabWidget); | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) |
|
70 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) | |
71 | : QWidget{parent}, |
|
71 | : QWidget{parent}, | |
72 | ui{new Ui::VisualizationTabWidget}, |
|
72 | ui{new Ui::VisualizationTabWidget}, | |
73 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} |
|
73 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} | |
74 | { |
|
74 | { | |
75 | ui->setupUi(this); |
|
75 | ui->setupUi(this); | |
76 |
|
76 | |||
77 | #ifdef Q_OS_MAC |
|
77 | #ifdef Q_OS_MAC | |
78 | impl->m_MacScrollBarStyle->selfInstallOn(ui->scrollArea, true); |
|
78 | impl->m_MacScrollBarStyle->selfInstallOn(ui->scrollArea, true); | |
79 | #endif |
|
79 | #endif | |
80 |
|
80 | |||
81 | ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone"); |
|
81 | ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone"); | |
82 |
ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, |
|
82 | ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 12); | |
|
83 | ui->dragDropContainer->layout()->setSpacing(0); | |||
83 | ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH, |
|
84 | ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH, | |
84 | VisualizationDragDropContainer::DropBehavior::Inserted); |
|
85 | VisualizationDragDropContainer::DropBehavior::Inserted); | |
85 | ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE, |
|
86 | ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE, | |
86 | VisualizationDragDropContainer::DropBehavior::Inserted); |
|
87 | VisualizationDragDropContainer::DropBehavior::Inserted); | |
87 | ui->dragDropContainer->setMimeType(MIME_TYPE_VARIABLE_LIST, |
|
88 | ui->dragDropContainer->setMimeType(MIME_TYPE_VARIABLE_LIST, | |
88 | VisualizationDragDropContainer::DropBehavior::Inserted); |
|
89 | VisualizationDragDropContainer::DropBehavior::Inserted); | |
89 |
|
90 | |||
90 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { |
|
91 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { | |
91 | return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData, |
|
92 | return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData, | |
92 | ui->dragDropContainer); |
|
93 | ui->dragDropContainer); | |
93 | }); |
|
94 | }); | |
94 |
|
95 | |||
95 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, |
|
96 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
96 | &VisualizationTabWidget::dropMimeData); |
|
97 | &VisualizationTabWidget::dropMimeData); | |
97 |
|
98 | |||
98 | sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea); |
|
99 | sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea); | |
99 |
|
100 | |||
100 | // Widget is deleted when closed |
|
101 | // Widget is deleted when closed | |
101 | setAttribute(Qt::WA_DeleteOnClose); |
|
102 | setAttribute(Qt::WA_DeleteOnClose); | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | VisualizationTabWidget::~VisualizationTabWidget() |
|
105 | VisualizationTabWidget::~VisualizationTabWidget() | |
105 | { |
|
106 | { | |
106 | sqpApp->dragDropHelper().removeDragDropScrollArea(ui->scrollArea); |
|
107 | sqpApp->dragDropHelper().removeDragDropScrollArea(ui->scrollArea); | |
107 | delete ui; |
|
108 | delete ui; | |
108 | } |
|
109 | } | |
109 |
|
110 | |||
110 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
111 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | |
111 | { |
|
112 | { | |
112 | ui->dragDropContainer->addDragWidget(zoneWidget); |
|
113 | ui->dragDropContainer->addDragWidget(zoneWidget); | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) |
|
116 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) | |
116 | { |
|
117 | { | |
117 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); |
|
118 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
121 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | |
121 | { |
|
122 | { | |
122 | return createZone({variable}, -1); |
|
123 | return createZone({variable}, -1); | |
123 | } |
|
124 | } | |
124 |
|
125 | |||
125 | VisualizationZoneWidget * |
|
126 | VisualizationZoneWidget * | |
126 | VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) |
|
127 | VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) | |
127 | { |
|
128 | { | |
128 | auto zoneWidget = createEmptyZone(index); |
|
129 | auto zoneWidget = createEmptyZone(index); | |
129 |
|
130 | |||
130 | // Creates a new graph into the zone |
|
131 | // Creates a new graph into the zone | |
131 | zoneWidget->createGraph(variables, index); |
|
132 | zoneWidget->createGraph(variables, index); | |
132 |
|
133 | |||
133 | return zoneWidget; |
|
134 | return zoneWidget; | |
134 | } |
|
135 | } | |
135 |
|
136 | |||
136 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) |
|
137 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) | |
137 | { |
|
138 | { | |
138 | auto zoneWidget |
|
139 | auto zoneWidget | |
139 | = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; |
|
140 | = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; | |
140 | this->insertZone(index, zoneWidget); |
|
141 | this->insertZone(index, zoneWidget); | |
141 |
|
142 | |||
142 | return zoneWidget; |
|
143 | return zoneWidget; | |
143 | } |
|
144 | } | |
144 |
|
145 | |||
145 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
146 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | |
146 | { |
|
147 | { | |
147 | if (visitor) { |
|
148 | if (visitor) { | |
148 | visitor->visitEnter(this); |
|
149 | visitor->visitEnter(this); | |
149 |
|
150 | |||
150 | // Apply visitor to zone children: widgets different from zones are not visited (no action) |
|
151 | // Apply visitor to zone children: widgets different from zones are not visited (no action) | |
151 | processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) { |
|
152 | processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) { | |
152 | zoneWidget.accept(visitor); |
|
153 | zoneWidget.accept(visitor); | |
153 | }); |
|
154 | }); | |
154 |
|
155 | |||
155 | visitor->visitLeave(this); |
|
156 | visitor->visitLeave(this); | |
156 | } |
|
157 | } | |
157 | else { |
|
158 | else { | |
158 | qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); |
|
159 | qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); | |
159 | } |
|
160 | } | |
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 | bool VisualizationTabWidget::canDrop(const Variable &variable) const |
|
163 | bool VisualizationTabWidget::canDrop(const Variable &variable) const | |
163 | { |
|
164 | { | |
164 | // A tab can always accomodate a variable |
|
165 | // A tab can always accomodate a variable | |
165 | Q_UNUSED(variable); |
|
166 | Q_UNUSED(variable); | |
166 | return true; |
|
167 | return true; | |
167 | } |
|
168 | } | |
168 |
|
169 | |||
169 | bool VisualizationTabWidget::contains(const Variable &variable) const |
|
170 | bool VisualizationTabWidget::contains(const Variable &variable) const | |
170 | { |
|
171 | { | |
171 | Q_UNUSED(variable); |
|
172 | Q_UNUSED(variable); | |
172 | return false; |
|
173 | return false; | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | QString VisualizationTabWidget::name() const |
|
176 | QString VisualizationTabWidget::name() const | |
176 | { |
|
177 | { | |
177 | return impl->m_Name; |
|
178 | return impl->m_Name; | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | void VisualizationTabWidget::closeEvent(QCloseEvent *event) |
|
181 | void VisualizationTabWidget::closeEvent(QCloseEvent *event) | |
181 | { |
|
182 | { | |
182 | // Closes zones in the tab |
|
183 | // Closes zones in the tab | |
183 | processZones(tabLayout(), [](VisualizationZoneWidget &zoneWidget) { zoneWidget.close(); }); |
|
184 | processZones(tabLayout(), [](VisualizationZoneWidget &zoneWidget) { zoneWidget.close(); }); | |
184 |
|
185 | |||
185 | QWidget::closeEvent(event); |
|
186 | QWidget::closeEvent(event); | |
186 | } |
|
187 | } | |
187 |
|
188 | |||
188 | QLayout &VisualizationTabWidget::tabLayout() const noexcept |
|
189 | QLayout &VisualizationTabWidget::tabLayout() const noexcept | |
189 | { |
|
190 | { | |
190 | return *ui->dragDropContainer->layout(); |
|
191 | return *ui->dragDropContainer->layout(); | |
191 | } |
|
192 | } | |
192 |
|
193 | |||
193 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
194 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) | |
194 | { |
|
195 | { | |
195 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { |
|
196 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { | |
196 | impl->dropGraph(index, this); |
|
197 | impl->dropGraph(index, this); | |
197 | } |
|
198 | } | |
198 | else if (mimeData->hasFormat(MIME_TYPE_ZONE)) { |
|
199 | else if (mimeData->hasFormat(MIME_TYPE_ZONE)) { | |
199 | impl->dropZone(index, this); |
|
200 | impl->dropZone(index, this); | |
200 | } |
|
201 | } | |
201 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
202 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
202 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
203 | auto variables = sqpApp->variableController().variablesForMimeData( | |
203 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
204 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
204 | impl->dropVariables(variables, index, this); |
|
205 | impl->dropVariables(variables, index, this); | |
205 | } |
|
206 | } | |
206 | else { |
|
207 | else { | |
207 | qCWarning(LOG_VisualizationZoneWidget()) |
|
208 | qCWarning(LOG_VisualizationZoneWidget()) | |
208 | << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received."); |
|
209 | << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received."); | |
209 | } |
|
210 | } | |
210 | } |
|
211 | } | |
211 |
|
212 | |||
212 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph( |
|
213 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph( | |
213 | int index, VisualizationTabWidget *tabWidget) |
|
214 | int index, VisualizationTabWidget *tabWidget) | |
214 | { |
|
215 | { | |
215 | auto &helper = sqpApp->dragDropHelper(); |
|
216 | auto &helper = sqpApp->dragDropHelper(); | |
216 |
|
217 | |||
217 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); |
|
218 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); | |
218 | if (!graphWidget) { |
|
219 | if (!graphWidget) { | |
219 | qCWarning(LOG_VisualizationZoneWidget()) |
|
220 | qCWarning(LOG_VisualizationZoneWidget()) | |
220 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the dropped graph is not " |
|
221 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the dropped graph is not " | |
221 | "found or invalid."); |
|
222 | "found or invalid."); | |
222 | Q_ASSERT(false); |
|
223 | Q_ASSERT(false); | |
223 | return; |
|
224 | return; | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | auto parentDragDropContainer |
|
227 | auto parentDragDropContainer | |
227 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); |
|
228 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); | |
228 | if (!parentDragDropContainer) { |
|
229 | if (!parentDragDropContainer) { | |
229 | qCWarning(LOG_VisualizationZoneWidget()) |
|
230 | qCWarning(LOG_VisualizationZoneWidget()) | |
230 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the parent container of " |
|
231 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the parent container of " | |
231 | "the dropped graph is not found."); |
|
232 | "the dropped graph is not found."); | |
232 | Q_ASSERT(false); |
|
233 | Q_ASSERT(false); | |
233 | return; |
|
234 | return; | |
234 | } |
|
235 | } | |
235 |
|
236 | |||
236 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
237 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
237 |
|
238 | |||
238 | const auto &variables = graphWidget->variables(); |
|
239 | const auto &variables = graphWidget->variables(); | |
239 |
|
240 | |||
240 | if (!variables.isEmpty()) { |
|
241 | if (!variables.isEmpty()) { | |
241 | // Abort the requests for the variables (if any) |
|
242 | // Abort the requests for the variables (if any) | |
242 | // Commented, because it's not sure if it's needed or not |
|
243 | // Commented, because it's not sure if it's needed or not | |
243 | // for (const auto& var : variables) |
|
244 | // for (const auto& var : variables) | |
244 | //{ |
|
245 | //{ | |
245 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
246 | // sqpApp->variableController().onAbortProgressRequested(var); | |
246 | //} |
|
247 | //} | |
247 |
|
248 | |||
248 | if (nbGraph == 1) { |
|
249 | if (nbGraph == 1) { | |
249 | // This is the only graph in the previous zone, close the zone |
|
250 | // This is the only graph in the previous zone, close the zone | |
250 | helper.delayedCloseWidget(graphWidget->parentZoneWidget()); |
|
251 | helper.delayedCloseWidget(graphWidget->parentZoneWidget()); | |
251 | } |
|
252 | } | |
252 | else { |
|
253 | else { | |
253 | // Close the graph |
|
254 | // Close the graph | |
254 | helper.delayedCloseWidget(graphWidget); |
|
255 | helper.delayedCloseWidget(graphWidget); | |
255 | } |
|
256 | } | |
256 |
|
257 | |||
257 | tabWidget->createZone(variables, index); |
|
258 | tabWidget->createZone(variables, index); | |
258 | } |
|
259 | } | |
259 | else { |
|
260 | else { | |
260 | // The graph is empty, create an empty zone and move the graph inside |
|
261 | // The graph is empty, create an empty zone and move the graph inside | |
261 |
|
262 | |||
262 | auto parentZoneWidget = graphWidget->parentZoneWidget(); |
|
263 | auto parentZoneWidget = graphWidget->parentZoneWidget(); | |
263 |
|
264 | |||
264 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
265 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |
265 |
|
266 | |||
266 | auto zoneWidget = tabWidget->createEmptyZone(index); |
|
267 | auto zoneWidget = tabWidget->createEmptyZone(index); | |
267 | zoneWidget->addGraph(graphWidget); |
|
268 | zoneWidget->addGraph(graphWidget); | |
268 |
|
269 | |||
269 | // Close the old zone if it was the only graph inside |
|
270 | // Close the old zone if it was the only graph inside | |
270 | if (nbGraph == 1) { |
|
271 | if (nbGraph == 1) { | |
271 | helper.delayedCloseWidget(parentZoneWidget); |
|
272 | helper.delayedCloseWidget(parentZoneWidget); | |
272 | } |
|
273 | } | |
273 | } |
|
274 | } | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropZone( |
|
277 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropZone( | |
277 | int index, VisualizationTabWidget *tabWidget) |
|
278 | int index, VisualizationTabWidget *tabWidget) | |
278 | { |
|
279 | { | |
279 | auto &helper = sqpApp->dragDropHelper(); |
|
280 | auto &helper = sqpApp->dragDropHelper(); | |
280 |
|
281 | |||
281 | auto zoneWidget = qobject_cast<VisualizationZoneWidget *>(helper.getCurrentDragWidget()); |
|
282 | auto zoneWidget = qobject_cast<VisualizationZoneWidget *>(helper.getCurrentDragWidget()); | |
282 | if (!zoneWidget) { |
|
283 | if (!zoneWidget) { | |
283 | qCWarning(LOG_VisualizationZoneWidget()) |
|
284 | qCWarning(LOG_VisualizationZoneWidget()) | |
284 | << tr("VisualizationTabWidget::dropZone, drop aborted, the dropped zone is not " |
|
285 | << tr("VisualizationTabWidget::dropZone, drop aborted, the dropped zone is not " | |
285 | "found or invalid."); |
|
286 | "found or invalid."); | |
286 | Q_ASSERT(false); |
|
287 | Q_ASSERT(false); | |
287 | return; |
|
288 | return; | |
288 | } |
|
289 | } | |
289 |
|
290 | |||
290 | auto parentDragDropContainer |
|
291 | auto parentDragDropContainer | |
291 | = qobject_cast<VisualizationDragDropContainer *>(zoneWidget->parentWidget()); |
|
292 | = qobject_cast<VisualizationDragDropContainer *>(zoneWidget->parentWidget()); | |
292 | if (!parentDragDropContainer) { |
|
293 | if (!parentDragDropContainer) { | |
293 | qCWarning(LOG_VisualizationZoneWidget()) |
|
294 | qCWarning(LOG_VisualizationZoneWidget()) | |
294 | << tr("VisualizationTabWidget::dropZone, drop aborted, the parent container of " |
|
295 | << tr("VisualizationTabWidget::dropZone, drop aborted, the parent container of " | |
295 | "the dropped zone is not found."); |
|
296 | "the dropped zone is not found."); | |
296 | Q_ASSERT(false); |
|
297 | Q_ASSERT(false); | |
297 | return; |
|
298 | return; | |
298 | } |
|
299 | } | |
299 |
|
300 | |||
300 | // Simple move of the zone, no variable operation associated |
|
301 | // Simple move of the zone, no variable operation associated | |
301 | parentDragDropContainer->layout()->removeWidget(zoneWidget); |
|
302 | parentDragDropContainer->layout()->removeWidget(zoneWidget); | |
302 | tabWidget->ui->dragDropContainer->insertDragWidget(index, zoneWidget); |
|
303 | tabWidget->ui->dragDropContainer->insertDragWidget(index, zoneWidget); | |
303 | } |
|
304 | } | |
304 |
|
305 | |||
305 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables( |
|
306 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables( | |
306 | const QList<std::shared_ptr<Variable> > &variables, int index, |
|
307 | const QList<std::shared_ptr<Variable> > &variables, int index, | |
307 | VisualizationTabWidget *tabWidget) |
|
308 | VisualizationTabWidget *tabWidget) | |
308 | { |
|
309 | { | |
309 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
310 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and | |
310 | // compatible variable here |
|
311 | // compatible variable here | |
311 | if (variables.count() > 1) { |
|
312 | if (variables.count() > 1) { | |
312 | qCWarning(LOG_VisualizationZoneWidget()) |
|
313 | qCWarning(LOG_VisualizationZoneWidget()) | |
313 | << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation " |
|
314 | << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation " | |
314 | "aborted."); |
|
315 | "aborted."); | |
315 | return; |
|
316 | return; | |
316 | } |
|
317 | } | |
317 |
|
318 | |||
318 | tabWidget->createZone(variables, index); |
|
319 | tabWidget->createZone(variables, index); | |
319 | } |
|
320 | } |
@@ -1,125 +1,125 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>VisualizationZoneWidget</class> |
|
3 | <class>VisualizationZoneWidget</class> | |
4 | <widget class="QWidget" name="VisualizationZoneWidget"> |
|
4 | <widget class="QWidget" name="VisualizationZoneWidget"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>400</width> |
|
9 | <width>400</width> | |
10 | <height>300</height> |
|
10 | <height>300</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |
17 | <property name="spacing"> |
|
17 | <property name="spacing"> | |
18 | <number>0</number> |
|
18 | <number>0</number> | |
19 | </property> |
|
19 | </property> | |
20 | <property name="leftMargin"> |
|
20 | <property name="leftMargin"> | |
21 | <number>0</number> |
|
21 | <number>0</number> | |
22 | </property> |
|
22 | </property> | |
23 | <property name="topMargin"> |
|
23 | <property name="topMargin"> | |
24 | <number>0</number> |
|
24 | <number>0</number> | |
25 | </property> |
|
25 | </property> | |
26 | <property name="rightMargin"> |
|
26 | <property name="rightMargin"> | |
27 | <number>0</number> |
|
27 | <number>0</number> | |
28 | </property> |
|
28 | </property> | |
29 | <property name="bottomMargin"> |
|
29 | <property name="bottomMargin"> | |
30 |
<number> |
|
30 | <number>6</number> | |
31 | </property> |
|
31 | </property> | |
32 | <item> |
|
32 | <item> | |
33 | <widget class="QWidget" name="infobar" native="true"> |
|
33 | <widget class="QWidget" name="infobar" native="true"> | |
34 | <property name="sizePolicy"> |
|
34 | <property name="sizePolicy"> | |
35 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> |
|
35 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> | |
36 | <horstretch>0</horstretch> |
|
36 | <horstretch>0</horstretch> | |
37 | <verstretch>0</verstretch> |
|
37 | <verstretch>0</verstretch> | |
38 | </sizepolicy> |
|
38 | </sizepolicy> | |
39 | </property> |
|
39 | </property> | |
40 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
40 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
41 | <property name="spacing"> |
|
41 | <property name="spacing"> | |
42 | <number>0</number> |
|
42 | <number>0</number> | |
43 | </property> |
|
43 | </property> | |
44 | <property name="leftMargin"> |
|
44 | <property name="leftMargin"> | |
45 | <number>0</number> |
|
45 | <number>0</number> | |
46 | </property> |
|
46 | </property> | |
47 | <property name="topMargin"> |
|
47 | <property name="topMargin"> | |
48 | <number>0</number> |
|
48 | <number>0</number> | |
49 | </property> |
|
49 | </property> | |
50 | <property name="rightMargin"> |
|
50 | <property name="rightMargin"> | |
51 | <number>0</number> |
|
51 | <number>0</number> | |
52 | </property> |
|
52 | </property> | |
53 | <property name="bottomMargin"> |
|
53 | <property name="bottomMargin"> | |
54 | <number>0</number> |
|
54 | <number>0</number> | |
55 | </property> |
|
55 | </property> | |
56 | <item> |
|
56 | <item> | |
57 | <widget class="QLabel" name="zoneNameLabel"> |
|
57 | <widget class="QLabel" name="zoneNameLabel"> | |
58 | <property name="styleSheet"> |
|
58 | <property name="styleSheet"> | |
59 | <string notr="true">color: rgb(127, 127, 127); |
|
59 | <string notr="true">color: rgb(127, 127, 127); | |
60 | </string> |
|
60 | </string> | |
61 | </property> |
|
61 | </property> | |
62 | <property name="text"> |
|
62 | <property name="text"> | |
63 | <string>TextLabel</string> |
|
63 | <string>TextLabel</string> | |
64 | </property> |
|
64 | </property> | |
65 | </widget> |
|
65 | </widget> | |
66 | </item> |
|
66 | </item> | |
67 | <item> |
|
67 | <item> | |
68 | <widget class="QToolButton" name="closeButton"> |
|
68 | <widget class="QToolButton" name="closeButton"> | |
69 | <property name="styleSheet"> |
|
69 | <property name="styleSheet"> | |
70 | <string notr="true">background-color: transparent;</string> |
|
70 | <string notr="true">background-color: transparent;</string> | |
71 | </property> |
|
71 | </property> | |
72 | <property name="text"> |
|
72 | <property name="text"> | |
73 | <string>Close</string> |
|
73 | <string>Close</string> | |
74 | </property> |
|
74 | </property> | |
75 | </widget> |
|
75 | </widget> | |
76 | </item> |
|
76 | </item> | |
77 | </layout> |
|
77 | </layout> | |
78 | </widget> |
|
78 | </widget> | |
79 | </item> |
|
79 | </item> | |
80 | <item> |
|
80 | <item> | |
81 | <widget class="VisualizationDragDropContainer" name="dragDropContainer"> |
|
81 | <widget class="VisualizationDragDropContainer" name="dragDropContainer"> | |
82 | <property name="sizePolicy"> |
|
82 | <property name="sizePolicy"> | |
83 | <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> |
|
83 | <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> | |
84 | <horstretch>0</horstretch> |
|
84 | <horstretch>0</horstretch> | |
85 | <verstretch>0</verstretch> |
|
85 | <verstretch>0</verstretch> | |
86 | </sizepolicy> |
|
86 | </sizepolicy> | |
87 | </property> |
|
87 | </property> | |
88 | <property name="frameShape"> |
|
88 | <property name="frameShape"> | |
89 | <enum>QFrame::Box</enum> |
|
89 | <enum>QFrame::Box</enum> | |
90 | </property> |
|
90 | </property> | |
91 | <property name="frameShadow"> |
|
91 | <property name="frameShadow"> | |
92 | <enum>QFrame::Raised</enum> |
|
92 | <enum>QFrame::Raised</enum> | |
93 | </property> |
|
93 | </property> | |
94 | <property name="lineWidth"> |
|
94 | <property name="lineWidth"> | |
95 | <number>1</number> |
|
95 | <number>1</number> | |
96 | </property> |
|
96 | </property> | |
97 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
97 | <layout class="QVBoxLayout" name="verticalLayout"> | |
98 | <property name="leftMargin"> |
|
98 | <property name="leftMargin"> | |
99 | <number>0</number> |
|
99 | <number>0</number> | |
100 | </property> |
|
100 | </property> | |
101 | <property name="topMargin"> |
|
101 | <property name="topMargin"> | |
102 | <number>0</number> |
|
102 | <number>0</number> | |
103 | </property> |
|
103 | </property> | |
104 | <property name="rightMargin"> |
|
104 | <property name="rightMargin"> | |
105 | <number>0</number> |
|
105 | <number>0</number> | |
106 | </property> |
|
106 | </property> | |
107 | <property name="bottomMargin"> |
|
107 | <property name="bottomMargin"> | |
108 | <number>0</number> |
|
108 | <number>0</number> | |
109 | </property> |
|
109 | </property> | |
110 | </layout> |
|
110 | </layout> | |
111 | </widget> |
|
111 | </widget> | |
112 | </item> |
|
112 | </item> | |
113 | </layout> |
|
113 | </layout> | |
114 | </widget> |
|
114 | </widget> | |
115 | <customwidgets> |
|
115 | <customwidgets> | |
116 | <customwidget> |
|
116 | <customwidget> | |
117 | <class>VisualizationDragDropContainer</class> |
|
117 | <class>VisualizationDragDropContainer</class> | |
118 | <extends>QFrame</extends> |
|
118 | <extends>QFrame</extends> | |
119 | <header>Visualization/VisualizationDragDropContainer.h</header> |
|
119 | <header>Visualization/VisualizationDragDropContainer.h</header> | |
120 | <container>1</container> |
|
120 | <container>1</container> | |
121 | </customwidget> |
|
121 | </customwidget> | |
122 | </customwidgets> |
|
122 | </customwidgets> | |
123 | <resources/> |
|
123 | <resources/> | |
124 | <connections/> |
|
124 | <connections/> | |
125 | </ui> |
|
125 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now