forked from qt-creator/qt-creator
QmlDesigner: Prepare for dropping items from item library to navigator
Change-Id: I7de6ffc61ae04e25df93e355f820205732867af6 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -48,6 +48,8 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
static PropertyNameList visibleProperties(const ModelNode &node)
|
static PropertyNameList visibleProperties(const ModelNode &node)
|
||||||
@@ -117,13 +119,16 @@ NavigatorTreeModel::~NavigatorTreeModel()
|
|||||||
|
|
||||||
Qt::DropActions NavigatorTreeModel::supportedDropActions() const
|
Qt::DropActions NavigatorTreeModel::supportedDropActions() const
|
||||||
{
|
{
|
||||||
return Qt::LinkAction;
|
return Qt::LinkAction | Qt::MoveAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList NavigatorTreeModel::mimeTypes() const
|
QStringList NavigatorTreeModel::mimeTypes() const
|
||||||
{
|
{
|
||||||
QStringList types;
|
QStringList types;
|
||||||
types.append("application/vnd.modelnode.list");
|
types.append("application/vnd.modelnode.list");
|
||||||
|
types.append("application/vnd.bauhaus.itemlibraryinfo");
|
||||||
|
types.append("application/vnd.bauhaus.libraryresource");
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,38 +218,25 @@ static bool computeTarget(const QModelIndex &rowModelIndex,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData,
|
bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData,
|
||||||
Qt::DropAction action,
|
Qt::DropAction action,
|
||||||
int rowNumber,
|
int rowNumber,
|
||||||
int columnNumber,
|
int columnNumber,
|
||||||
const QModelIndex &dropModelIndex)
|
const QModelIndex &dropModelIndex)
|
||||||
{
|
{
|
||||||
if (action == Qt::IgnoreAction)
|
if (action == Qt::IgnoreAction)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (action != Qt::LinkAction)
|
if (dropModelIndex.model() == this) {
|
||||||
return false;
|
if (mimeData->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
|
||||||
|
handleItemLibraryItemDrop(mimeData, rowNumber, dropModelIndex);
|
||||||
if (!mimeData->hasFormat("application/vnd.modelnode.list"))
|
} else if (mimeData->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
||||||
return false;
|
handleItemLibraryImageDrop(mimeData, rowNumber, dropModelIndex);
|
||||||
|
} else if (mimeData->hasFormat("application/vnd.modelnode.list")) {
|
||||||
if (columnNumber > 1)
|
handleInternalDrop(mimeData, rowNumber, dropModelIndex);
|
||||||
return false;
|
}
|
||||||
|
|
||||||
if (dropModelIndex.model() != this)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QModelIndex rowModelIndex = dropModelIndex.sibling(dropModelIndex.row(), 0);
|
|
||||||
int targetRowNumber = rowNumber;
|
|
||||||
NodeAbstractProperty targetProperty;
|
|
||||||
|
|
||||||
bool foundTarget = computeTarget(rowModelIndex, this, &targetProperty, &targetRowNumber);
|
|
||||||
|
|
||||||
if (foundTarget) {
|
|
||||||
QList<ModelNode> modelNodeList = modelNodesFromMimeData(mimeData, m_view);
|
|
||||||
|
|
||||||
if (fitsToTargetProperty(targetProperty, modelNodeList))
|
|
||||||
moveNodesInteractive(targetProperty, modelNodeList, targetRowNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // don't let the view do drag&drop on its own
|
return false; // don't let the view do drag&drop on its own
|
||||||
@@ -675,6 +667,44 @@ void NavigatorTreeModel::moveNodesInteractive(NodeAbstractProperty &parentProper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeModel::handleInternalDrop(const QMimeData *mimeData,
|
||||||
|
int rowNumber,
|
||||||
|
const QModelIndex &dropModelIndex)
|
||||||
|
{
|
||||||
|
QModelIndex rowModelIndex = dropModelIndex.sibling(dropModelIndex.row(), 0);
|
||||||
|
int targetRowNumber = rowNumber;
|
||||||
|
NodeAbstractProperty targetProperty;
|
||||||
|
|
||||||
|
bool foundTarget = computeTarget(rowModelIndex, this, &targetProperty, &targetRowNumber);
|
||||||
|
|
||||||
|
if (foundTarget) {
|
||||||
|
QList<ModelNode> modelNodeList = modelNodesFromMimeData(mimeData, m_view);
|
||||||
|
|
||||||
|
if (fitsToTargetProperty(targetProperty, modelNodeList))
|
||||||
|
moveNodesInteractive(targetProperty, modelNodeList, targetRowNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ItemLibraryEntry itemLibraryEntryFromData(const QByteArray &data)
|
||||||
|
{
|
||||||
|
QDataStream stream(data);
|
||||||
|
|
||||||
|
ItemLibraryEntry itemLibraryEntry;
|
||||||
|
stream >> itemLibraryEntry;
|
||||||
|
|
||||||
|
return itemLibraryEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeModel::handleItemLibraryItemDrop(const QMimeData *mimeData, int rowNumber, const QModelIndex &dropModelIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, int rowNumber, const QModelIndex &dropModelIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// along the lines of QObject::blockSignals
|
// along the lines of QObject::blockSignals
|
||||||
bool NavigatorTreeModel::blockItemChangedSignal(bool block)
|
bool NavigatorTreeModel::blockItemChangedSignal(bool block)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -133,7 +133,9 @@ private:
|
|||||||
void handleChangedVisibilityItem(QStandardItem *visibilityItem, ModelNode &modelNode);
|
void handleChangedVisibilityItem(QStandardItem *visibilityItem, ModelNode &modelNode);
|
||||||
|
|
||||||
void moveNodesInteractive(NodeAbstractProperty &parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
|
void moveNodesInteractive(NodeAbstractProperty &parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
|
||||||
|
void handleInternalDrop(const QMimeData *mimeData, int rowNumber, const QModelIndex &dropModelIndex);
|
||||||
|
void handleItemLibraryItemDrop(const QMimeData *mimeData, int rowNumber, const QModelIndex &dropModelIndex);
|
||||||
|
void handleItemLibraryImageDrop(const QMimeData *mimeData, int rowNumber, const QModelIndex &dropModelIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<ModelNode, ItemRow> m_nodeItemHash;
|
QHash<ModelNode, ItemRow> m_nodeItemHash;
|
||||||
|
|||||||
Reference in New Issue
Block a user