Commit 071722fb authored by Marco Bubke's avatar Marco Bubke Committed by Kai Koehne

Use AbstractView as base class NavigatorView

This is fixing a crash

Task-Number: BAUHAUS-622
Reviewed-by: Marco Bubke
parent 3096b2a0
......@@ -32,7 +32,6 @@
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
#include <abstractview.h>
#include <qmlitemnode.h>
#include <invalididexception.h>
#include <QMimeData>
......@@ -142,7 +141,7 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
QByteArray encodedData = data->data("application/vnd.modelnode.list");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QmlItemNode parentItemNode(nodeForIndex(parentIdIndex));
ModelNode parentNode(nodeForIndex(parentIdIndex));
QList<ModelNode> nodeList;
......@@ -150,7 +149,7 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
uint nodeHash;
stream >> nodeHash;
ModelNode node(nodeForHash(nodeHash));
if (!node.isValid() || (parentItemNode == node) || node.isAncestorOf(parentItemNode))
if (!node.isValid() || (parentNode == node) || node.isAncestorOf(parentNode))
continue;
nodeList.append(node);
}
......@@ -158,10 +157,9 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
RewriterTransaction transaction = m_view->beginRewriterTransaction();
foreach (const ModelNode &node, nodeList) {
if (!isAnchestorInList(node, nodeList)) {
if (node.parentProperty().parentModelNode() != parentItemNode) {
QmlItemNode itemNode(node);
if (node != parentItemNode) {
itemNode.setParent(parentItemNode);
if (node.parentProperty().parentModelNode() != parentNode) {
if (node != parentNode) {
reparentModelNode(parentNode, node);
}
}
......@@ -177,7 +175,7 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
}
}
propagateInvisible(parentItemNode, isNodeInvisible(parentItemNode));
propagateInvisible(parentNode, isNodeInvisible(parentNode));
return false; // don't let the view do drag&drop on its own
}
......@@ -436,12 +434,23 @@ void NavigatorTreeModel::removeSubTree(const ModelNode &node)
m_nodeItemHash.remove(node);
}
void NavigatorTreeModel::reparentModelNode(const ModelNode &parentNode, const ModelNode &node)
{
parentNode.nodeListProperty("data").reparentHere(node);
}
QList<ModelNode> NavigatorTreeModel::modelNodeChildren(const ModelNode &parentNode)
{
QList<ModelNode> children;
if (QmlItemNode(parentNode).isValid())
foreach (const QmlItemNode &childNode, QmlItemNode(parentNode).children())
children << childNode.modelNode();
if (parentNode.hasProperty("children")) {
children.append(parentNode.nodeListProperty("children").toModelNodeList());
}
if (parentNode.hasProperty("data")) {
children.append(parentNode.nodeListProperty("data").toModelNodeList());
}
return children;
}
......@@ -467,6 +476,4 @@ void NavigatorTreeModel::setVisible(const QModelIndex &index, bool visible)
itemRow.visibilityItem->setCheckState(visible ? Qt::Checked : Qt::Unchecked);
}
}
} // QmlDesigner
......@@ -123,6 +123,7 @@ private:
ItemRow createItemRow(const ModelNode &node);
void updateItemRow(const ModelNode &node, ItemRow row);
void reparentModelNode(const ModelNode &parentNode, const ModelNode &node);
QList<ModelNode> modelNodeChildren(const ModelNode &parentNode);
bool blockItemChangedSignal(bool block);
......
......@@ -32,13 +32,14 @@
#include "navigatorwidget.h"
#include <nodeproperty.h>
#include <nodelistproperty.h>
#include <QHeaderView>
namespace QmlDesigner {
NavigatorView::NavigatorView(QObject* parent) :
QmlModelView(parent),
AbstractView(parent),
m_blockSelectionChangedSignal(false),
m_widget(new NavigatorWidget),
m_treeModel(new NavigatorTreeModel(this))
......@@ -81,7 +82,7 @@ QWidget *NavigatorView::widget()
void NavigatorView::modelAttached(Model *model)
{
QmlModelView::modelAttached(model);
AbstractView::modelAttached(model);
m_treeModel->setView(this);
......@@ -100,14 +101,33 @@ void NavigatorView::modelAttached(Model *model)
void NavigatorView::modelAboutToBeDetached(Model *model)
{
m_treeModel->clearView();
QmlModelView::modelAboutToBeDetached(model);
AbstractView::modelAboutToBeDetached(model);
}
void NavigatorView::nodeCreated(const ModelNode &createdNode)
{
}
void NavigatorView::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
{
}
void NavigatorView::propertiesRemoved(const QList<AbstractProperty> &propertyList)
{
}
void NavigatorView::variantPropertiesChanged(const QList<VariantProperty> &propertyList, PropertyChangeFlags propertyChange)
{
}
void NavigatorView::bindingPropertiesChanged(const QList<BindingProperty> &propertyList, PropertyChangeFlags propertyChange)
{
}
void NavigatorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
{
if (m_treeModel->isInTree(removedNode))
m_treeModel->removeSubTree(removedNode);
QmlModelView::nodeAboutToBeRemoved(removedNode);
}
void NavigatorView::nodeReparented(const ModelNode &node, const NodeAbstractProperty & /*newPropertyParent*/, const NodeAbstractProperty & /*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
......@@ -127,14 +147,12 @@ void NavigatorView::nodeReparented(const ModelNode &node, const NodeAbstractProp
void NavigatorView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
{
QmlModelView::nodeIdChanged(node, newId, oldId);
if (m_treeModel->isInTree(node))
m_treeModel->updateItemRow(node);
}
void NavigatorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
{
QmlModelView::propertiesAboutToBeRemoved(propertyList);
foreach (const AbstractProperty &property, propertyList) {
if (property.isNodeProperty()) {
NodeProperty nodeProperty(property.toNodeProperty());
......@@ -150,14 +168,12 @@ void NavigatorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& pr
void NavigatorView::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
{
QmlModelView::rootNodeTypeChanged(type, majorVersion, minorVersion);
if (m_treeModel->isInTree(rootModelNode()))
m_treeModel->updateItemRow(rootModelNode());
}
void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
{
QmlModelView::auxiliaryDataChanged(node, name, data);
if (m_treeModel->isInTree(node))
{
// update model
......@@ -172,16 +188,10 @@ void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString &n
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{
QmlModelView::nodeOrderChanged(listProperty, node, oldIndex);
if (m_treeModel->isInTree(node))
m_treeModel->updateItemRowOrder(node);
}
void NavigatorView::stateChanged(const QmlModelState &/*newQmlModelState*/, const QmlModelState &/*oldQmlModelState*/)
{
}
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
{
if (m_blockSelectionChangedSignal)
......@@ -198,8 +208,6 @@ void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, con
void NavigatorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList)
{
QmlModelView::selectedNodesChanged(selectedNodeList, lastSelectedNodeList);
updateItemSelection();
}
......
......@@ -30,7 +30,7 @@
#ifndef NAVIGATORVIEW_H
#define NAVIGATORVIEW_H
#include <qmlmodelview.h>
#include <abstractview.h>
#include <QWeakPointer>
......@@ -48,7 +48,7 @@ class NavigatorTreeModel;
class IconCheckboxItemDelegate;
class IdItemDelegate;
class NavigatorView : public QmlModelView
class NavigatorView : public AbstractView
{
Q_OBJECT
......@@ -62,6 +62,12 @@ public:
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
void propertiesRemoved(const QList<AbstractProperty> &propertyList);
void variantPropertiesChanged(const QList<VariantProperty> &propertyList, PropertyChangeFlags propertyChange);
void bindingPropertiesChanged(const QList<BindingProperty> &propertyList, PropertyChangeFlags propertyChange);
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);
......@@ -75,7 +81,6 @@ public:
const QList<ModelNode> &lastSelectedNodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
private slots:
// void handleChangedItem(QStandardItem * item);
......
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