@@ -25,6 +25,8 signals: | |||
|
25 | 25 | public: |
|
26 | 26 | enum class DropBehavior { Inserted, Merged, InsertedAndMerged, Forbidden }; |
|
27 | 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 | 31 | VisualizationDragDropContainer(QWidget *parent = nullptr); |
|
30 | 32 | |
@@ -37,6 +39,8 public: | |||
|
37 | 39 | |
|
38 | 40 | void setAcceptMimeDataFunction(AcceptMimeDataFunction fun); |
|
39 | 41 | |
|
42 | void setAcceptDragWidgetFunction(AcceptDragWidgetFunction fun); | |
|
43 | ||
|
40 | 44 | void setPlaceHolderType(DragDropHelper::PlaceHolderType type, |
|
41 | 45 | const QString &placeHolderText = QString()); |
|
42 | 46 |
@@ -25,6 +25,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||
|
25 | 25 | |
|
26 | 26 | VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun |
|
27 | 27 | = [](auto mimeData) { return true; }; |
|
28 | VisualizationDragDropContainer::AcceptDragWidgetFunction m_AcceptDragWidgetFun | |
|
29 | = [](auto dragWidget, auto mimeData) { return true; }; | |
|
28 | 30 | |
|
29 | 31 | int m_MinContainerHeight = 0; |
|
30 | 32 | |
@@ -143,8 +145,8 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { | |||
|
143 | 145 | return nbGraph; |
|
144 | 146 | } |
|
145 | 147 | |
|
146 |
|
|
|
147 | const VisualizationDragDropContainer *container); | |
|
148 | bool findPlaceHolderPosition(const QPoint &pos, const QMimeData *mimeData, bool canInsert, | |
|
149 | bool canMerge, const VisualizationDragDropContainer *container); | |
|
148 | 150 | }; |
|
149 | 151 | |
|
150 | 152 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) |
@@ -188,6 +190,12 void VisualizationDragDropContainer::setAcceptMimeDataFunction( | |||
|
188 | 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 | 199 | void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type, |
|
192 | 200 | const QString &placeHolderText) |
|
193 | 201 | { |
@@ -263,7 +271,10 void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event) | |||
|
263 | 271 | |
|
264 | 272 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); |
|
265 | 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 | 279 | else { |
|
269 | 280 | // do nothing |
@@ -313,7 +324,7 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) | |||
|
313 | 324 | if (impl->acceptMimeData(event->mimeData())) { |
|
314 | 325 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); |
|
315 | 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 | 329 | else { |
|
319 | 330 | event->ignore(); |
@@ -387,8 +398,8 void VisualizationDragDropContainer::dropEvent(QDropEvent *event) | |||
|
387 | 398 | } |
|
388 | 399 | |
|
389 | 400 | |
|
390 |
|
|
|
391 | const QPoint &pos, bool canInsert, bool canMerge, | |
|
401 | bool VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::findPlaceHolderPosition( | |
|
402 | const QPoint &pos, const QMimeData *mimeData, bool canInsert, bool canMerge, | |
|
392 | 403 | const VisualizationDragDropContainer *container) |
|
393 | 404 | { |
|
394 | 405 | auto &helper = sqpApp->dragDropHelper(); |
@@ -451,7 +462,13 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find | |||
|
451 | 462 | helper.removePlaceHolder(); |
|
452 | 463 | } |
|
453 | 464 | |
|
454 |
|
|
|
465 | if (m_AcceptDragWidgetFun(dragWidgetHovered, mimeData)) { | |
|
466 | helper.setHightlightedDragWidget(dragWidgetHovered); | |
|
467 | return true; | |
|
468 | } | |
|
469 | else { | |
|
470 | return false; | |
|
471 | } | |
|
455 | 472 | } |
|
456 | 473 | else { |
|
457 | 474 | qCWarning(LOG_VisualizationDragDropContainer()) |
@@ -470,4 +487,6 void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::find | |||
|
470 | 487 | // the mouse is hover the placeHolder |
|
471 | 488 | // Do nothing |
|
472 | 489 | } |
|
490 | ||
|
491 | return true; | |
|
473 | 492 | } |
@@ -115,6 +115,29 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p | |||
|
115 | 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 | 141 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, |
|
119 | 142 | &VisualizationZoneWidget::dropMimeData); |
|
120 | 143 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, |
General Comments 0
You need to be logged in to leave comments.
Login now