Commit 45f8895e authored by Kai Koehne's avatar Kai Koehne
Browse files

Change signature of AbstractView::nodeSlidedToIndex in QmlDesigner

The usage of 'int newIndex' was ambiguous in the case of
oldIndex < newIndex. Solved by directly passing the ModelNode that was
moved around.

'nodeSlidedToIndex' was also renamed to 'nodeOrderChanged', since
'Slided' is no proper English.
parent 2e36b9a3
......@@ -167,7 +167,7 @@ void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeL
void ComponentView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/) {}
void ComponentView::nodeSlidedToIndex(const NodeListProperty &/*listProperty*/, int /*newIndex*/, int /*oldIndex*/) {}
void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {}
void ComponentView::importsChanged() {}
......
......@@ -72,7 +72,7 @@ public:
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged();
......
......@@ -52,7 +52,7 @@ void DesignDocumentControllerView::nodeTypeChanged(const ModelNode & /*node*/,co
void DesignDocumentControllerView::selectedNodesChanged(const QList<ModelNode> & /*selectedNodeList*/,
const QList<ModelNode> & /*lastSelectedNodeList*/) {};
void DesignDocumentControllerView::nodeSlidedToIndex(const NodeListProperty & /*listProperty*/, int /*newIndex*/, int /*oldIndex*/) {};
void DesignDocumentControllerView::nodeOrderChanged(const NodeListProperty & /*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {};
static QStringList arrayToStringList(const QByteArray &byteArray)
{
......
......@@ -56,7 +56,7 @@ public:
virtual void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
virtual void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); }
......
......@@ -122,20 +122,18 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
if (parentIndex.model() != this)
return false;
int beginRow = 0;
QModelIndex parentIdIndex = parentIndex;
parentIdIndex = parentIdIndex.sibling(parentIdIndex.row(), 0);
Q_ASSERT(parentIdIndex.isValid());
if (row > -1)
beginRow = row;
else if (parentIdIndex.isValid())
beginRow = rowCount(parentIdIndex);
else
beginRow = rowCount(QModelIndex());
int targetIndex = 0;
if (row > -1) {
targetIndex = row;
} else {
targetIndex = rowCount(parentIdIndex);
}
QByteArray encodedData = data->data("application/vnd.modelnode.list");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
......@@ -159,13 +157,19 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
if (!isAnchestorInList(node, nodeList)) {
if (node.parentProperty().parentModelNode() != parentItemNode) {
QmlItemNode itemNode(node);
if (node != parentItemNode)
if (node != parentItemNode) {
itemNode.setParent(parentItemNode);
}
}
if (node.parentProperty().isNodeListProperty()) {
int index = node.parentProperty().toNodeListProperty().toModelNodeList().indexOf(node);
node.parentProperty().toNodeListProperty().slide(index, beginRow);
if (index < targetIndex) { // item is first removed from oldIndex, then inserted at new index
--targetIndex;
}
if (index != targetIndex) {
node.parentProperty().toNodeListProperty().slide(index, targetIndex);
}
}
}
}
......
......@@ -133,14 +133,10 @@ void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString &n
m_treeModel->updateItemRow(node);
}
void NavigatorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex)
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{
QmlModelView::nodeSlidedToIndex(listProperty, newIndex, oldIndex);
QmlModelView::nodeOrderChanged(listProperty, node, oldIndex);
int nodeIndex = newIndex;
if (oldIndex < newIndex)
--nodeIndex;
ModelNode node = listProperty.toModelNodeList().at(nodeIndex);
if (m_treeModel->isInTree(node))
m_treeModel->updateItemRowOrder(node);
}
......
......@@ -60,8 +60,8 @@ public:
void nodeAboutToBeRemoved(const ModelNode &removedNode);
void nodeReparented(const ModelNode &node, const ModelNode &oldParent, const ModelNode &newParent);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void nodeSlidedToIndex(const ModelNode &node, int newIndex, int oldIndex);
void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
void nodeTypeChanged(const ModelNode &node,const QString &type, int majorVersion, int minorVersion);
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
......@@ -70,7 +70,6 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
......
......@@ -274,15 +274,16 @@ void StatesEditorView::nodeReparented(const ModelNode &node, const NodeAbstractP
}
}
void StatesEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex)
void StatesEditorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
{
QmlModelView::nodeSlidedToIndex(listProperty, newIndex, oldIndex);
QmlModelView::nodeOrderChanged(listProperty, movedNode, oldIndex);
if (listProperty.parentModelNode() == m_stateRootNode
&& listProperty.name() == "states") {
int index = newIndex;
if (oldIndex < newIndex)
--index;
QmlModelState state = listProperty.toModelNodeList().at(index);
int newIndex = listProperty.toModelNodeList().indexOf(movedNode);
Q_ASSERT(newIndex >= 0);
QmlModelState state = QmlModelState(movedNode);
if (state.isValid()) {
Q_ASSERT(oldIndex == modelStateIndex(state));
removeModelState(state);
......
......@@ -64,7 +64,7 @@ public:
void nodeAboutToBeRemoved(const ModelNode &removedNode);
void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
// QmlModelView
void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
......
......@@ -118,7 +118,7 @@ public:
virtual void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
virtual void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex) = 0;
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex) = 0;
virtual void importsChanged();
......
......@@ -69,7 +69,7 @@ public:
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged();
......@@ -210,10 +210,11 @@ void ForwardView<ViewType>::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUr
}
template <class ViewType>
void ForwardView<ViewType>::nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex)
void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
{
foreach (const ViewTypePointer &view, m_targetViewList)
view->nodeSlidedToIndex(NodeListProperty(listProperty, view.data()), newIndex, oldIndex);
view->nodeOrderChanged(NodeListProperty(listProperty, view.data()),
ModelNode(movedNode, view.data()), oldIndex);
}
template <class ViewType>
......
......@@ -85,7 +85,7 @@ public:
void nodeStatesAboutToBeRemoved(const QList<ModelNode> &nodeStateList);
void nodeStatesAdded(const QList<ModelNode> &nodeStateList);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
NodeInstance rootNodeInstance() const;
NodeInstance viewNodeInstance() const;
......
......@@ -121,7 +121,7 @@ public:
void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int /*oldIndex*/);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void nodeTypeChanged(const ModelNode &node,const QString &type, int majorVersion, int minorVersion);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
......
......@@ -293,10 +293,10 @@ void NodeInstanceView::nodeIdChanged(const ModelNode& node, const QString& newId
}
}
void NodeInstanceView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/)
void NodeInstanceView::nodeOrderChanged(const NodeListProperty & listProperty,
const ModelNode & /*movedNode*/, int /*oldIndex*/)
{
QList<ModelNode> newOrderModelNodeList = listProperty.toModelNodeList();
foreach(const ModelNode &node, newOrderModelNodeList) {
foreach(const ModelNode &node, listProperty.toModelNodeList()) {
NodeInstance instance = instanceForNode(node);
instance.reparent(instance.parent(), listProperty.name(), instance.parent(), listProperty.name());
}
......
......@@ -438,12 +438,15 @@ void ModelPrivate::notifyNodeReparent(const InternalNode::Pointer &internalNodeP
}
}
void ModelPrivate::notifyNodeSlidedToIndex(const InternalNodeListProperty::Pointer &internalNodeListproperty, int newIndex, int oldIndex)
void ModelPrivate::notifyNodeOrderChanged(const InternalNodeListPropertyPointer &internalListPropertyPointer,
const InternalNode::Pointer &internalNodePointer,
int oldIndex)
{
foreach (const QWeakPointer<AbstractView> &view, m_viewList) {
Q_ASSERT(view != 0);
NodeListProperty nodeListproperty(internalNodeListproperty, model(), view.data());
view->nodeSlidedToIndex(nodeListproperty, newIndex, oldIndex);
Q_ASSERT(!view.isNull());
view->nodeOrderChanged(NodeListProperty(internalListPropertyPointer, model(), view.data()),
ModelNode(internalNodePointer, model(), view.data()),
oldIndex);
}
}
......@@ -678,14 +681,15 @@ void ModelPrivate::changeType(const InternalNodePointer &internalNode, const QSt
notifyNodeTypeChanged(internalNode, type, majorVersion, minorVersion);
}
void ModelPrivate::slideNodeList(const InternalNode::Pointer &internalNode, const QString &name, int from, int to)
void ModelPrivate::changeNodeOrder(const InternalNode::Pointer &internalParentNode, const QString &listPropertyName, int from, int to)
{
InternalNodeListProperty::Pointer nodeList(internalNode->nodeListProperty(name));
InternalNodeListProperty::Pointer nodeList(internalParentNode->nodeListProperty(listPropertyName));
Q_ASSERT(!nodeList.isNull());
nodeList->slide(from, to);
notifyNodeSlidedToIndex(nodeList, to, from);
}
const InternalNodePointer internalNode = nodeList->nodeList().at(to);
notifyNodeOrderChanged(nodeList, internalNode, from);
}
void ModelPrivate::setRootNode(const InternalNode::Pointer& newRootNode)
{
......
......@@ -118,7 +118,7 @@ public:
void notifyBindingPropertiesChanged(const QList<InternalBindingPropertyPointer> &propertyList, AbstractView::PropertyChangeFlags propertyChange);
void notifyVariantPropertiesChanged(const InternalNodePointer &internalNodePointer, const QStringList& propertyNameList, AbstractView::PropertyChangeFlags propertyChange);
void notifyNodeSlidedToIndex(const InternalNodeListPropertyPointer &internalNode, int newIndex, int oldIndex);
void notifyNodeOrderChanged(const InternalNodeListPropertyPointer &internalListPropertyPointer, const InternalNodePointer &internalNodePointer, int oldIndex);
void notifyAuxiliaryDataChanged(const InternalNodePointer &internalNode, const QString &name, const QVariant &data);
void notifyNodeTypeChanged(const InternalNodePointer &internalNode, const QString &type, int majorVersion, int minorVersion);
......@@ -156,7 +156,7 @@ public:
void setDynamicVariantProperty(const InternalNodePointer &internalNode, const QString &name, const QString &propertyType, const QVariant &value);
void setDynamicBindingProperty(const InternalNodePointer &internalNode, const QString &name, const QString &dynamicPropertyType, const QString &expression);
void reparentNode(const InternalNodePointer &internalNode, const QString &name, const InternalNodePointer &internalNodeToBeAppended, bool list = true);
void slideNodeList(const InternalNodePointer &internalNode, const QString &name, int from, int to);
void changeNodeOrder(const InternalNodePointer &internalParentNode, const QString &listPropertyName, int from, int to);
void checkPropertyName(const QString &propertyName);
void clearParent(const InternalNodePointer &internalNode);
void changeType(const InternalNodePointer & internalNode, const QString &type, int majorVersion, int minorVersion);
......
......@@ -103,10 +103,10 @@ void NodeListProperty::slide(int from, int to) const
{
if (!isValid())
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list property>");
if (to > toModelNodeList().count())
if (to > toModelNodeList().count() - 1)
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<invalid node list sliding>");
model()->m_d->slideNodeList(internalNode(), name(), from, to);
model()->m_d->changeNodeOrder(internalNode(), name(), from, to);
}
void NodeListProperty::reparentHere(const ModelNode &modelNode)
......
......@@ -258,18 +258,19 @@ void RewriterView::nodeIdChanged(const ModelNode& node, const QString& newId, co
modelToTextMerger()->applyChanges();
}
void RewriterView::nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int /*oldIndex*/)
{ // FIXME: "slided" ain't no English, probably "slid" or "sliding" is meant...
void RewriterView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int /*oldIndex*/)
{
Q_ASSERT(textModifier());
if (textToModelMerger()->isActive())
return;
const QList<ModelNode> nodes = listProperty.toModelNodeList();
const ModelNode movingNode = nodes.at(newIndex);
ModelNode trailingNode;
int newIndex = nodes.indexOf(movedNode);
if (newIndex + 1 < nodes.size())
trailingNode = nodes.at(newIndex + 1);
modelToTextMerger()->nodeSlidAround(movingNode, trailingNode);
modelToTextMerger()->nodeSlidAround(movedNode, trailingNode);
if (!isModificationGroupActive())
modelToTextMerger()->applyChanges();
......
......@@ -171,9 +171,9 @@ void ViewLogger::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
m_output << time() << indent("fileUrlChanged:") << oldUrl.toString() << "\t" << newUrl.toString() << endl;
}
void ViewLogger::nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex)
void ViewLogger::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
{
m_output << time() << indent("nodeSlidedToIndex:") << listProperty << newIndex << oldIndex << endl;
m_output << time() << indent("nodeOrderChanged:") << listProperty << movedNode << oldIndex << endl;
}
void ViewLogger::importsChanged()
......
......@@ -63,7 +63,7 @@ public:
void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment