Commit 5823de4e authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Move handleChangedExport to NavigatorView

This allows to share functionality with an alternative tree model.

Change-Id: I2737ce2e7d93cc92695a6b888afda9da411c9fa4
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 64ec6955
......@@ -24,6 +24,7 @@
****************************************************************************/
#include "navigatortreemodel.h"
#include "navigatorview.h"
#include <bindingproperty.h>
#include <nodeabstractproperty.h>
......@@ -392,7 +393,7 @@ bool NavigatorTreeModel::hasModelNodeForIndex(const QModelIndex &index) const
return m_view->modelNodeForInternalId(index.internalId()).isValid();
}
void NavigatorTreeModel::setView(AbstractView *view)
void NavigatorTreeModel::setView(NavigatorView *view)
{
m_view = view;
}
......@@ -639,32 +640,12 @@ Qt::DropActions NavigatorTreeModel::supportedDragActions() const
return Qt::LinkAction;
}
void NavigatorTreeModel::handleChangedExport(const ModelNode &modelNode, bool exported)
{
QTC_ASSERT(m_view, return);
const ModelNode rootModelNode = m_view->rootModelNode();
Q_ASSERT(rootModelNode.isValid());
const PropertyName modelNodeId = modelNode.id().toUtf8();
if (rootModelNode.hasProperty(modelNodeId))
rootModelNode.removeProperty(modelNodeId);
if (exported) {
try {
RewriterTransaction transaction =
m_view->beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem"));
QmlObjectNode qmlObjectNode(modelNode);
qmlObjectNode.ensureAliasExport();
} catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail
exception.showException();
}
}
}
bool NavigatorTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
ModelNode modelNode = modelNodeForIndex(index);
if (index.column() == 1 && role == Qt::CheckStateRole) {
handleChangedExport(modelNode, value.toInt() != 0);
QTC_ASSERT(m_view, return false);
m_view->handleChangedExport(modelNode, value.toInt() != 0);
} else if (index.column() == 2 && role == Qt::CheckStateRole) {
if (value.toInt() == 0)
modelNode.setAuxiliaryData("invisible", true);
......
......@@ -35,7 +35,7 @@
namespace QmlDesigner {
class Model;
class AbstractView;
class NavigatorView;
class ModelNode;
class NavigatorTreeModel : public QAbstractItemModel
......@@ -60,7 +60,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
void setView(AbstractView *view);
void setView(NavigatorView *view);
ModelNode modelNodeForIndex(const QModelIndex &index) const;
bool hasModelNodeForIndex(const QModelIndex &index) const;
......@@ -94,14 +94,13 @@ public:
bool hasError(const QModelIndex &index) const;
private:
void handleChangedExport(const ModelNode &modelNode, bool exportItem);
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);
QList<QPersistentModelIndex> nodesToPersistentIndex(const QList<ModelNode> &modelNodes);
QPointer<AbstractView> m_view;
QPointer<NavigatorView> m_view;
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
};
......
......@@ -38,6 +38,7 @@
#include <nodelistproperty.h>
#include <variantproperty.h>
#include <qmlitemnode.h>
#include <rewritingexception.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
......@@ -176,6 +177,27 @@ void NavigatorView::bindingPropertiesChanged(const QList<BindingProperty> & prop
}
}
void NavigatorView::handleChangedExport(const ModelNode &modelNode, bool exported)
{
const ModelNode rootNode = rootModelNode();
Q_ASSERT(rootNode.isValid());
const PropertyName modelNodeId = modelNode.id().toUtf8();
if (rootNode.hasProperty(modelNodeId))
rootNode.removeProperty(modelNodeId);
if (exported) {
try {
RewriterTransaction transaction =
beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem"));
QmlObjectNode qmlObjectNode(modelNode);
qmlObjectNode.ensureAliasExport();
transaction.commit();
} catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail
exception.showException();
}
}
}
void NavigatorView::nodeAboutToBeRemoved(const ModelNode & /*removedNode*/)
{
}
......
......@@ -75,6 +75,8 @@ public:
void bindingPropertiesChanged(const QList<BindingProperty> &propertyList, PropertyChangeFlags) override;
void handleChangedExport(const ModelNode &modelNode, bool exported);
private:
void changeSelection(const QItemSelection &selected, const QItemSelection &deselected);
void updateItemSelection();
......
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