@@ -25,6 +25,8 signals: | |||||
25 | public: |
|
25 | public: | |
26 | enum class DropBehavior { Inserted, Merged, InsertedAndMerged, Forbidden }; |
|
26 | enum class DropBehavior { Inserted, Merged, InsertedAndMerged, Forbidden }; | |
27 | using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>; |
|
27 | using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>; | |
|
28 | using AcceptDragWidgetFunction | |||
|
29 | = std::function<bool(const VisualizationDragWidget *dragWidget, const QMimeData *mimeData)>; | |||
28 |
|
30 | |||
29 | VisualizationDragDropContainer(QWidget *parent = nullptr); |
|
31 | VisualizationDragDropContainer(QWidget *parent = nullptr); | |
30 |
|
32 | |||
@@ -37,6 +39,8 public: | |||||
37 |
|
39 | |||
38 | void setAcceptMimeDataFunction(AcceptMimeDataFunction fun); |
|
40 | void setAcceptMimeDataFunction(AcceptMimeDataFunction fun); | |
39 |
|
41 | |||
|
42 | void setAcceptDragWidgetFunction(AcceptDragWidgetFunction fun); | |||
|
43 | ||||
40 | void setPlaceHolderType(DragDropHelper::PlaceHolderType type, |
|
44 | void setPlaceHolderType(DragDropHelper::PlaceHolderType type, | |
41 | const QString &placeHolderText = QString()); |
|
45 | const QString &placeHolderText = QString()); | |
42 |
|
46 |
@@ -25,6 +25,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||||
25 |
|
25 | |||
26 | VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun |
|
26 | VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun | |
27 | = [](auto mimeData) { return true; }; |
|
27 | = [](auto mimeData) { return true; }; | |
|
28 | VisualizationDragDropContainer::AcceptDragWidgetFunction m_AcceptDragWidgetFun | |||
|
29 | = [](auto dragWidget, auto mimeData) { return true; }; | |||
28 |
|
30 | |||
29 | int m_MinContainerHeight = 0; |
|
31 | int m_MinContainerHeight = 0; | |
30 |
|
32 | |||
@@ -143,8 +145,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||||
143 | return nbGraph; |
|
145 | return nbGraph; | |
144 | } |
|
146 | } | |
145 |
|
147 | |||
146 |
|
|
148 | bool findPlaceHolderPosition(const QPoint &pos, const QMimeData *mimeData, bool canInsert, | |
147 | const VisualizationDragDropContainer *container); |
|
149 | bool canMerge, const VisualizationDragDropContainer *container); | |
148 | }; |
|
150 | }; | |
149 |
|
151 | |||
150 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) |
|
152 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) | |
@@ -188,6 +190,12 void VisualizationDragDropContainer::setAcceptMimeDataFunction( | |||||
188 | impl->m_AcceptMimeDataFun = fun; |
|
190 | impl->m_AcceptMimeDataFun = fun; | |
189 | } |
|
191 | } | |
190 |
|
192 | |||
|
193 | void VisualizationDragDropContainer::setAcceptDragWidgetFunction( | |||
|
194 | VisualizationDragDropContainer::AcceptDragWidgetFunction fun) | |||
|
195 | { | |||
|
196 | impl->m_AcceptDragWidgetFun = fun; | |||
|
197 | } | |||
|
198 | ||||
191 | void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type, |
|
199 | void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type, | |
192 | const QString &placeHolderText) |
|
200 | const QString &placeHolderText) | |
193 | { |
|
201 | { | |
@@ -263,7 +271,10 void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event) | |||||
263 |
|
271 | |||
264 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); |
|
272 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); | |
265 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); |
|
273 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); | |
266 |
impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, |
|
274 | if (!impl->findPlaceHolderPosition(event->pos(), event->mimeData(), canInsert, canMerge, | |
|
275 | this)) { | |||
|
276 | event->ignore(); | |||
|
277 | } | |||
267 | } |
|
278 | } | |
268 | else { |
|
279 | else { | |
269 | // do nothing |
|
280 | // do nothing | |
@@ -313,7 +324,7 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) | |||||
313 | if (impl->acceptMimeData(event->mimeData())) { |
|
324 | if (impl->acceptMimeData(event->mimeData())) { | |
314 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); |
|
325 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); | |
315 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); |
|
326 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); | |
316 | impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, this); |
|
327 | impl->findPlaceHolderPosition(event->pos(), event->mimeData(), canInsert, canMerge, this); | |
317 | } |
|
328 | } | |
318 | else { |
|
329 | else { | |
319 | event->ignore(); |
|
330 | event->ignore(); | |
@@ -387,8 +398,8 void VisualizationDragDropContainer::dropEvent(QDropEvent *event) | |||||
387 | } |
|
398 | } | |
388 |
|
399 | |||
389 |
|
400 | |||
390 |
|
|
401 | bool VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::findPlaceHolderPosition( | |
391 | const QPoint &pos, bool canInsert, bool canMerge, |
|
402 | const QPoint &pos, const QMimeData *mimeData, bool canInsert, bool canMerge, | |
392 | const VisualizationDragDropContainer *container) |
|
403 | const VisualizationDragDropContainer *container) | |
393 | { |
|
404 | { | |
394 | auto &helper = sqpApp->dragDropHelper(); |
|
405 | auto &helper = sqpApp->dragDropHelper(); | |
@@ -451,7 +462,13 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find | |||||
451 | helper.removePlaceHolder(); |
|
462 | helper.removePlaceHolder(); | |
452 | } |
|
463 | } | |
453 |
|
464 | |||
|
465 | if (m_AcceptDragWidgetFun(dragWidgetHovered, mimeData)) { | |||
454 | helper.setHightlightedDragWidget(dragWidgetHovered); |
|
466 | helper.setHightlightedDragWidget(dragWidgetHovered); | |
|
467 | return true; | |||
|
468 | } | |||
|
469 | else { | |||
|
470 | return false; | |||
|
471 | } | |||
455 | } |
|
472 | } | |
456 | else { |
|
473 | else { | |
457 | qCWarning(LOG_VisualizationDragDropContainer()) |
|
474 | qCWarning(LOG_VisualizationDragDropContainer()) | |
@@ -470,4 +487,6 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find | |||||
470 | // the mouse is hover the placeHolder |
|
487 | // the mouse is hover the placeHolder | |
471 | // Do nothing |
|
488 | // Do nothing | |
472 | } |
|
489 | } | |
|
490 | ||||
|
491 | return true; | |||
473 | } |
|
492 | } |
@@ -115,6 +115,29 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p | |||||
115 | ui->dragDropContainer); |
|
115 | ui->dragDropContainer); | |
116 | }); |
|
116 | }); | |
117 |
|
117 | |||
|
118 | auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) { | |||
|
119 | if (!mimeData) { | |||
|
120 | return false; | |||
|
121 | } | |||
|
122 | ||||
|
123 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |||
|
124 | auto variables = sqpApp->variableController().variablesForMimeData( | |||
|
125 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |||
|
126 | ||||
|
127 | if (variables.count() != 1) { | |||
|
128 | return false; | |||
|
129 | } | |||
|
130 | auto variable = variables.first(); | |||
|
131 | ||||
|
132 | if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget *>(dragWidget)) { | |||
|
133 | return graphWidget->canDrop(*variable); | |||
|
134 | } | |||
|
135 | } | |||
|
136 | ||||
|
137 | return true; | |||
|
138 | }; | |||
|
139 | ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun); | |||
|
140 | ||||
118 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, |
|
141 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
119 | &VisualizationZoneWidget::dropMimeData); |
|
142 | &VisualizationZoneWidget::dropMimeData); | |
120 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, |
|
143 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, |
General Comments 0
You need to be logged in to leave comments.
Login now