diff options
author | Roland Knall <rknall@gmail.com> | 2017-11-04 16:11:08 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2017-11-05 08:28:10 +0000 |
commit | 68ead1d025bd63079ea5eebbb5d767f8d0f98459 (patch) | |
tree | af2bd767512665f82528b30f61c9e6f6714cd8a5 /ui | |
parent | aed3e66672083940f94e0b33f5b2e9d25776a4d4 (diff) |
Qt: Fix drag-n-drop in toolbar
Fixing two crashes in the toolbar, first one only appeared on mac,
the second one happens every time the toolbar is removed or updated
Change-Id: Ic3075a5af1b4a566e09bbce9712c968c053cc727
Reviewed-on: https://code.wireshark.org/review/24244
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/widgets/drag_drop_toolbar.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/ui/qt/widgets/drag_drop_toolbar.cpp b/ui/qt/widgets/drag_drop_toolbar.cpp index 1b3cd47387..3ebfbcecc5 100644 --- a/ui/qt/widgets/drag_drop_toolbar.cpp +++ b/ui/qt/widgets/drag_drop_toolbar.cpp @@ -60,6 +60,10 @@ void DragDropToolBar::childEvent(QChildEvent * event) { if ( event->child()->isWidgetType() ) { + /* Reset if it has moved underneath lower limit */ + if ( childCounter < 0 ) + childCounter = 0; + ((QWidget *)event->child())->installEventFilter(this); event->child()->setProperty(drag_drop_toolbar_action_, qVariantFromValue(childCounter)); childCounter++; @@ -67,7 +71,16 @@ void DragDropToolBar::childEvent(QChildEvent * event) } else if ( event->type() == QEvent::ChildRemoved ) { - childCounter--; + childCounter--; + } + else if ( event->type() == QEvent::ChildPolished ) + { + /* Polish is called every time a child is added or removed. This is implemented by adding + * all childs again as hidden elements, and afterwards removing the existing ones. Therefore + * we have to reset child counter here, if a widget is being polished. If this is not being + * done, crashes will occur after an item has been removed and other items are moved afterwards */ + if ( event->child()->isWidgetType() ) + childCounter = 0; } } @@ -93,7 +106,7 @@ bool DragDropToolBar::eventFilter(QObject * obj, QEvent * event) if ( ( ev->buttons() & Qt::LeftButton ) && (ev->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance()) { - QDrag * drag = new QDrag(elem); + QDrag * drag = new QDrag(this); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-wireshark-toolbar-entry", elem->property(drag_drop_toolbar_action_).toByteArray()); @@ -109,10 +122,7 @@ bool DragDropToolBar::eventFilter(QObject * obj, QEvent * event) elem->render(&pixmap); drag->setPixmap(pixmap); - Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); - - if (dropAction == Qt::MoveAction) - elem->setVisible(false); + drag->exec(Qt::CopyAction | Qt::MoveAction); return true; } |