forked from qt-creator/qt-creator
QmlDesigner: Select referenced node when clicking on reference node
Fixes: QDS-15301 Change-Id: I5e21e81b40b49c77e3d58973d688b1f78091e649 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -90,6 +90,7 @@ public:
|
|||||||
|
|
||||||
bool isReferenceNodesVisible() const override;
|
bool isReferenceNodesVisible() const override;
|
||||||
bool canBeReference(const ModelNode &modelNode) const override;
|
bool canBeReference(const ModelNode &modelNode) const override;
|
||||||
|
bool isReference(const QModelIndex &index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void toolTipPixmapUpdated(const QString &id, const QPixmap &pixmap);
|
void toolTipPixmapUpdated(const QString &id, const QPixmap &pixmap);
|
||||||
@@ -118,7 +119,6 @@ private:
|
|||||||
QList<ModelNode> referenceList(const QList<BindingProperty> &bindingProperties, const QList<ModelNode> &unwanted = {}) const;
|
QList<ModelNode> referenceList(const QList<BindingProperty> &bindingProperties, const QList<ModelNode> &unwanted = {}) const;
|
||||||
QModelIndex createReferenceIndex(int row, int column, const ReferenceData &referenceData) const;
|
QModelIndex createReferenceIndex(int row, int column, const ReferenceData &referenceData) const;
|
||||||
void resetReferences();
|
void resetReferences();
|
||||||
bool isReference(const QModelIndex &index) const;
|
|
||||||
ModelNode referenceExtractCurrent(const QModelIndex &index) const;
|
ModelNode referenceExtractCurrent(const QModelIndex &index) const;
|
||||||
ModelNode referenceExtractOwner(const QModelIndex &index) const;
|
ModelNode referenceExtractOwner(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
#include "modelnode.h"
|
||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
#include "navigatortreemodel.h"
|
#include "navigatortreemodel.h"
|
||||||
#include "qproxystyle.h"
|
#include "qproxystyle.h"
|
||||||
@@ -259,20 +260,43 @@ bool NavigatorTreeView::viewportEvent(QEvent *event)
|
|||||||
|
|
||||||
void NavigatorTreeView::mousePressEvent(QMouseEvent *event)
|
void NavigatorTreeView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
const QModelIndex modelIndex = indexAt(event->pos());
|
m_clickedIndex = indexAt(event->pos());
|
||||||
if (static_cast<qint32>(modelIndex.internalId()) < 0) {
|
if (auto navModel = qobject_cast<NavigatorTreeModel *>(model())) {
|
||||||
m_dragAllowed = false;
|
if (navModel->isReference(m_clickedIndex)) {
|
||||||
return; // Ignore mousePressEvent when item is reference node.
|
m_dragAllowed = false;
|
||||||
|
event->accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block drag from starting if press was on an item that is not draggable.
|
// 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
|
// 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.
|
// be a selected item, e.g. when pressing on locked item, leading to unexpected drags.
|
||||||
m_dragAllowed = model()->flags(modelIndex) & Qt::ItemIsDragEnabled;
|
m_dragAllowed = model()->flags(m_clickedIndex) & Qt::ItemIsDragEnabled;
|
||||||
|
|
||||||
QTreeView::mousePressEvent(event);
|
QTreeView::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
const QModelIndex modelIndex = indexAt(event->pos());
|
||||||
|
if (m_clickedIndex == modelIndex) {
|
||||||
|
if (auto navModel = qobject_cast<NavigatorTreeModel *>(model())) {
|
||||||
|
if (navModel->isReference(modelIndex)) {
|
||||||
|
ModelNode referencedNode = navModel->modelNodeForIndex(modelIndex);
|
||||||
|
if (referencedNode && !referencedNode.locked()) {
|
||||||
|
referencedNode.selectNode();
|
||||||
|
event->accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_clickedIndex = {};
|
||||||
|
|
||||||
|
QTreeView::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void NavigatorTreeView::startDrag(Qt::DropActions supportedActions)
|
void NavigatorTreeView::startDrag(Qt::DropActions supportedActions)
|
||||||
{
|
{
|
||||||
if (m_dragAllowed) {
|
if (m_dragAllowed) {
|
||||||
|
@@ -20,11 +20,13 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void startDrag(Qt::DropActions supportedActions) 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;
|
bool m_dragAllowed = true;
|
||||||
|
QModelIndex m_clickedIndex;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user