QmlDesigner: Block starting drag when clicking on non-draggable node

Fixes: QDS-6415
Change-Id: I328e7715d2837d1126506a6fbbf4d1bf52cc250f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Miikka Heikkinen
2022-03-08 15:57:19 +02:00
parent 59a721c0ea
commit 6c9ded9461
2 changed files with 21 additions and 0 deletions

View File

@@ -281,4 +281,20 @@ bool NavigatorTreeView::viewportEvent(QEvent *event)
return QTreeView::viewportEvent(event); return QTreeView::viewportEvent(event);
} }
void NavigatorTreeView::mousePressEvent(QMouseEvent *event)
{
// Block drag from starting if press was on an item that is not draggable.
// This is necessary as it is the selected items that are dragged and the pressed item may not
// be a selected item, e.g. when pressing on locked item, leading to unexpected drags.
m_dragAllowed = model()->flags(indexAt(event->pos())) & Qt::ItemIsDragEnabled;
QTreeView::mousePressEvent(event);
}
void NavigatorTreeView::startDrag(Qt::DropActions supportedActions)
{
if (m_dragAllowed)
QTreeView::startDrag(supportedActions);
}
} }

View File

@@ -40,8 +40,13 @@ public:
static void drawSelectionBackground(QPainter *painter, const QStyleOption &option); static void drawSelectionBackground(QPainter *painter, const QStyleOption &option);
bool viewportEvent(QEvent *event) override; bool viewportEvent(QEvent *event) override;
protected:
void mousePressEvent(QMouseEvent *event) override;
void startDrag(Qt::DropActions supportedActions) override;
private: private:
PreviewToolTip *m_previewToolTip = nullptr; PreviewToolTip *m_previewToolTip = nullptr;
qint32 m_previewToolTipNodeId = -1; qint32 m_previewToolTipNodeId = -1;
bool m_dragAllowed = true;
}; };
} }