mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-09-12 16:13:13 +02:00
On mac we can get a drop event even if dragMoveEvent() says the drop is
invalid. So we validate the drop the same we validate in dragMove to make sure we don't crash on an invalid drop. Fixes #2540.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2011-06-29 theron <theron@netcitadel.com>
|
||||
* Fixed #2540. On mac we can get a drop event even if
|
||||
dragMoveEvent() says the drop is invalid. So in ObjectTreeView we
|
||||
validate the drop the same we we validate in dragMove to make sure
|
||||
the drop is valid.
|
||||
|
||||
2011-06-27 theron <theron@netcitadel.com>
|
||||
|
||||
* Fixed #2530, where adding a subfolder opens the parent folder in
|
||||
|
||||
@@ -464,23 +464,11 @@ void ObjectTreeView::dragEnterEvent( QDragEnterEvent *ev)
|
||||
ev->setDropAction(Qt::MoveAction);
|
||||
}
|
||||
|
||||
void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
|
||||
|
||||
static bool isValidDropTarget(QTreeWidgetItem *item, list<FWObject *> &objs)
|
||||
{
|
||||
QWidget *fromWidget = ev->source();
|
||||
|
||||
// The source of DnD object must be the same instance of fwbuilder
|
||||
if (!fromWidget || fromWidget != this) {
|
||||
notWanted:
|
||||
ev->setAccepted(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectTreeViewItem *dest =
|
||||
dynamic_cast<ObjectTreeViewItem *>(itemAt(ev->pos()));
|
||||
if (dest == 0) goto notWanted;
|
||||
|
||||
list<FWObject*> objs;
|
||||
if (!FWObjectDrag::decode(ev, objs)) goto notWanted;
|
||||
ObjectTreeViewItem *dest = dynamic_cast<ObjectTreeViewItem *>(item);
|
||||
if (dest == 0) return false;
|
||||
|
||||
bool dragIsNoop = true;
|
||||
list<FWObject *>::const_iterator iter;
|
||||
@@ -492,13 +480,13 @@ void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
|
||||
Interface::cast(dragobj->getParent()) != 0 ||
|
||||
Policy::cast(dragobj) != 0 ||
|
||||
NAT::cast(dragobj) != 0 ||
|
||||
Routing::cast(dragobj) != 0) goto notWanted;
|
||||
Routing::cast(dragobj) != 0) return false;
|
||||
|
||||
/* See if destination is a user folder */
|
||||
if (dest->getUserFolderParent() != 0) {
|
||||
/* Dragged object has to match parent of user folder */
|
||||
if (dest->getUserFolderParent() != dragobj->getParent()) {
|
||||
goto notWanted;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Are we dragging within the same user folder? */
|
||||
@@ -510,7 +498,7 @@ void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
|
||||
/* OK to drag onto parent itself, or object that shares parent */
|
||||
if (dragobj->getParent() != dest->getFWObject() &&
|
||||
dragobj->getParent() != dest->getFWObject()->getParent()) {
|
||||
goto notWanted;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Are we dragging to a new place? */
|
||||
@@ -523,7 +511,18 @@ void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
|
||||
}
|
||||
}
|
||||
|
||||
if (dragIsNoop) goto notWanted;
|
||||
return !dragIsNoop;
|
||||
}
|
||||
|
||||
|
||||
void ObjectTreeView::dragMoveEvent(QDragMoveEvent *ev)
|
||||
{
|
||||
list<FWObject*> objs;
|
||||
if (ev->source() != this || !FWObjectDrag::decode(ev, objs) ||
|
||||
!isValidDropTarget(itemAt(ev->pos()), objs)) {
|
||||
ev->setAccepted(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ev->setDropAction(Qt::MoveAction);
|
||||
ev->setAccepted(true);
|
||||
@@ -543,6 +542,9 @@ void ObjectTreeView::dropEvent(QDropEvent *ev)
|
||||
list<FWObject*> objs;
|
||||
if (!FWObjectDrag::decode(ev, objs)) goto notWanted;
|
||||
|
||||
/* Make sure the drop event is on an object that can handle it */
|
||||
if (ev->source() != this || !isValidDropTarget(dest, objs)) goto notWanted;
|
||||
|
||||
emit moveItems_sign(dest, objs);
|
||||
ev->setAccepted(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user