2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:57:40 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include "navigatorview.h"
|
|
|
|
|
#include "navigatortreemodel.h"
|
|
|
|
|
#include "navigatorwidget.h"
|
2014-05-05 14:31:54 +02:00
|
|
|
#include "nameitemdelegate.h"
|
2014-05-05 14:31:17 +02:00
|
|
|
#include "iconcheckboxitemdelegate.h"
|
2015-11-23 16:41:54 +01:00
|
|
|
#include "qmldesignerconstants.h"
|
|
|
|
|
#include "qmldesignericons.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-02-02 14:02:17 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-03-07 17:04:11 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-02-02 14:02:17 +01:00
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <utils/icon.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2015-11-19 13:42:00 +01:00
|
|
|
|
2015-07-15 17:38:27 +02:00
|
|
|
#include <bindingproperty.h>
|
2013-03-07 17:04:11 +01:00
|
|
|
#include <designmodecontext.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <nodeproperty.h>
|
2010-04-21 17:02:54 +02:00
|
|
|
#include <nodelistproperty.h>
|
2011-07-26 11:22:52 +02:00
|
|
|
#include <variantproperty.h>
|
2010-02-15 16:24:49 +01:00
|
|
|
#include <QHeaderView>
|
2013-07-31 15:45:09 +02:00
|
|
|
#include <qmlitemnode.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-07-26 11:22:52 +02:00
|
|
|
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
|
|
|
|
|
{
|
2013-07-24 15:58:51 +02:00
|
|
|
if (modelNode.hasParentProperty() && QmlDesigner::QmlItemNode::isValidQmlItemNode(modelNode.parentProperty().parentModelNode())) {
|
|
|
|
|
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
|
2014-08-07 17:22:53 +02:00
|
|
|
|
|
|
|
|
if (!parentNode.modelNode().metaInfo().isLayoutable()) {
|
|
|
|
|
QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
|
|
|
|
|
modelNode.variantProperty("x").setValue(localPos.toPoint().x());
|
|
|
|
|
modelNode.variantProperty("y").setValue(localPos.toPoint().y());
|
|
|
|
|
} else { //Items in Layouts do not have a position
|
|
|
|
|
modelNode.removeProperty("x");
|
|
|
|
|
modelNode.removeProperty("y");
|
|
|
|
|
}
|
2011-07-26 11:22:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
NavigatorView::NavigatorView(QObject* parent) :
|
2013-07-31 15:45:09 +02:00
|
|
|
AbstractView(parent),
|
2010-01-07 12:14:35 +01:00
|
|
|
m_blockSelectionChangedSignal(false),
|
2011-04-28 17:12:45 +02:00
|
|
|
m_widget(new NavigatorWidget(this)),
|
2010-01-07 12:14:35 +01:00
|
|
|
m_treeModel(new NavigatorTreeModel(this))
|
|
|
|
|
{
|
2013-03-07 17:04:11 +01:00
|
|
|
Internal::NavigatorContext *navigatorContext = new Internal::NavigatorContext(m_widget.data());
|
|
|
|
|
Core::ICore::addContextObject(navigatorContext);
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
m_widget->setTreeModel(m_treeModel.data());
|
|
|
|
|
|
|
|
|
|
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
2011-04-28 17:12:45 +02:00
|
|
|
|
|
|
|
|
connect(m_widget.data(), SIGNAL(leftButtonClicked()), this, SLOT(leftButtonClicked()));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(rightButtonClicked()), this, SLOT(rightButtonClicked()));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(downButtonClicked()), this, SLOT(downButtonClicked()));
|
|
|
|
|
connect(m_widget.data(), SIGNAL(upButtonClicked()), this, SLOT(upButtonClicked()));
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
|
2010-01-29 12:10:08 +01:00
|
|
|
|
2014-05-05 14:31:17 +02:00
|
|
|
NameItemDelegate *idDelegate = new NameItemDelegate(this,
|
|
|
|
|
m_treeModel.data());
|
2015-11-19 13:42:00 +01:00
|
|
|
IconCheckboxItemDelegate *showDelegate =
|
|
|
|
|
new IconCheckboxItemDelegate(this,
|
2016-08-03 17:55:54 +02:00
|
|
|
Utils::Icons::EYE_OPEN_TOOLBAR.pixmap(),
|
|
|
|
|
Utils::Icons::EYE_CLOSED_TOOLBAR.pixmap(),
|
2015-11-19 13:42:00 +01:00
|
|
|
m_treeModel.data());
|
|
|
|
|
|
|
|
|
|
IconCheckboxItemDelegate *exportDelegate =
|
|
|
|
|
new IconCheckboxItemDelegate(this,
|
2015-11-23 16:41:54 +01:00
|
|
|
Icons::EXPORT_CHECKED.pixmap(),
|
|
|
|
|
Icons::EXPORT_UNCHECKED.pixmap(),
|
2015-11-19 13:42:00 +01:00
|
|
|
m_treeModel.data());
|
2010-01-29 12:10:08 +01:00
|
|
|
|
|
|
|
|
#ifdef _LOCK_ITEMS_
|
|
|
|
|
IconCheckboxItemDelegate *lockDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/lock.png",
|
|
|
|
|
":/qmldesigner/images/hole.png",m_treeModel.data());
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treeWidget()->setItemDelegateForColumn(0,idDelegate);
|
|
|
|
|
#ifdef _LOCK_ITEMS_
|
|
|
|
|
treeWidget()->setItemDelegateForColumn(1,lockDelegate);
|
|
|
|
|
treeWidget()->setItemDelegateForColumn(2,showDelegate);
|
|
|
|
|
#else
|
2015-07-15 17:38:27 +02:00
|
|
|
treeWidget()->setItemDelegateForColumn(1,exportDelegate);
|
|
|
|
|
treeWidget()->setItemDelegateForColumn(2,showDelegate);
|
2010-01-29 12:10:08 +01:00
|
|
|
#endif
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigatorView::~NavigatorView()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget && !m_widget->parent())
|
|
|
|
|
delete m_widget.data();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
bool NavigatorView::hasWidget() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WidgetInfo NavigatorView::widgetInfo()
|
|
|
|
|
{
|
2013-03-21 12:51:39 +01:00
|
|
|
return createWidgetInfo(m_widget.data(),
|
|
|
|
|
new WidgetInfo::ToolBarWidgetDefaultFactory<NavigatorWidget>(m_widget.data()),
|
2014-05-12 14:09:02 +02:00
|
|
|
QStringLiteral("Navigator"),
|
2013-03-21 12:51:39 +01:00
|
|
|
WidgetInfo::LeftPane,
|
|
|
|
|
0);
|
2013-03-07 17:04:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void NavigatorView::modelAttached(Model *model)
|
|
|
|
|
{
|
2013-07-31 15:45:09 +02:00
|
|
|
AbstractView::modelAttached(model);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
m_treeModel->setView(this);
|
|
|
|
|
|
2010-02-17 10:47:33 +01:00
|
|
|
QTreeView *treeView = treeWidget();
|
|
|
|
|
treeView->expandAll();
|
2010-02-15 16:24:49 +01:00
|
|
|
|
2014-08-28 17:33:47 +02:00
|
|
|
treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
2010-02-17 10:47:33 +01:00
|
|
|
treeView->header()->resizeSection(1,26);
|
|
|
|
|
treeView->setRootIsDecorated(false);
|
|
|
|
|
treeView->setIndentation(20);
|
2010-02-15 16:24:49 +01:00
|
|
|
#ifdef _LOCK_ITEMS_
|
2010-02-17 10:47:33 +01:00
|
|
|
treeView->header()->resizeSection(2,20);
|
2010-02-15 16:24:49 +01:00
|
|
|
#endif
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::modelAboutToBeDetached(Model *model)
|
|
|
|
|
{
|
2014-03-05 13:22:47 +01:00
|
|
|
m_treeModel->removeSubTree(rootModelNode());
|
2010-01-07 12:14:35 +01:00
|
|
|
m_treeModel->clearView();
|
2013-07-31 15:45:09 +02:00
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
2010-04-21 17:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-10 15:44:40 +01:00
|
|
|
void NavigatorView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
|
2010-12-15 17:12:01 +01:00
|
|
|
{
|
|
|
|
|
treeWidget()->update();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:38:27 +02:00
|
|
|
void NavigatorView::bindingPropertiesChanged(const QList<BindingProperty> & propertyList, PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
foreach (const BindingProperty &bindingProperty, propertyList) {
|
|
|
|
|
/* If a binding property that exports an item using an alias property has
|
|
|
|
|
* changed, we have to update the affected item.
|
|
|
|
|
*/
|
|
|
|
|
if (bindingProperty.isAliasExport())
|
|
|
|
|
m_treeModel->updateItemRow(modelNodeForId(bindingProperty.expression()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void NavigatorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
2014-04-24 18:15:49 +02:00
|
|
|
m_treeModel->removeSubTree(removedNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:28:18 +02:00
|
|
|
void NavigatorView::nodeReparented(const ModelNode &node, const NodeAbstractProperty & newPropertyParent, const NodeAbstractProperty & /*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
|
2014-04-24 18:15:49 +02:00
|
|
|
m_treeModel->removeSubTree(node);
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (node.isInHierarchy())
|
|
|
|
|
m_treeModel->addSubTree(node);
|
|
|
|
|
|
|
|
|
|
// make sure selection is in sync again
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
|
2015-07-15 17:28:18 +02:00
|
|
|
if (newPropertyParent.parentModelNode().isValid()) {
|
|
|
|
|
QModelIndex index = m_treeModel->indexForNode(newPropertyParent.parentModelNode());
|
|
|
|
|
treeWidget()->expand(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::nodeIdChanged(const ModelNode& node, const QString & /*newId*/, const QString & /*oldId*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
if (m_treeModel->isInTree(node))
|
|
|
|
|
m_treeModel->updateItemRow(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
|
|
|
|
|
{
|
|
|
|
|
foreach (const AbstractProperty &property, propertyList) {
|
2014-04-24 16:15:09 +02:00
|
|
|
if (property.isNodeAbstractProperty()) {
|
|
|
|
|
NodeAbstractProperty nodeAbstractProperty(property.toNodeListProperty());
|
|
|
|
|
foreach (const ModelNode &childNode, nodeAbstractProperty.directSubNodes()) {
|
|
|
|
|
m_treeModel->removeSubTree(childNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-19 16:39:46 +02:00
|
|
|
void NavigatorView::propertiesRemoved(const QList<AbstractProperty> &propertyList)
|
|
|
|
|
{
|
|
|
|
|
for (const AbstractProperty &property : propertyList) {
|
|
|
|
|
ModelNode node = property.parentModelNode();
|
|
|
|
|
/* Update export alias state if property from root note was removed and the root node was not selected. */
|
|
|
|
|
/* The check for the selection is an optimization to reduce updates. */
|
|
|
|
|
if (node.isRootNode() && !selectedModelNodes().isEmpty() && !selectedModelNodes().first().isRootNode()) {
|
|
|
|
|
|
|
|
|
|
foreach (const ModelNode &modelNode, node.allSubModelNodes())
|
|
|
|
|
m_treeModel->updateItemRow(modelNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::rootNodeTypeChanged(const QString & /*type*/, int /*majorVersion*/, int /*minorVersion*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-10 13:02:49 +01:00
|
|
|
if (m_treeModel->isInTree(rootModelNode()))
|
|
|
|
|
m_treeModel->updateItemRow(rootModelNode());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-23 12:57:26 +02:00
|
|
|
void NavigatorView::auxiliaryDataChanged(const ModelNode &modelNode, const PropertyName & name, const QVariant & /*data*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-04-23 12:57:26 +02:00
|
|
|
if (name == "invisible" && m_treeModel->isInTree(modelNode))
|
2010-02-02 17:20:49 +01:00
|
|
|
{
|
|
|
|
|
// update model
|
2014-04-23 12:57:26 +02:00
|
|
|
m_treeModel->updateItemRow(modelNode);
|
2010-02-02 17:20:49 +01:00
|
|
|
|
|
|
|
|
// repaint row (id and icon)
|
2014-04-23 12:57:26 +02:00
|
|
|
foreach (const ModelNode ¤tModelNode, modelNode.allSubModelNodesAndThisNode()) {
|
|
|
|
|
QModelIndex index = m_treeModel->indexForNode(currentModelNode);
|
|
|
|
|
treeWidget()->update(index);
|
|
|
|
|
treeWidget()->update(index.sibling(index.row(),index.column()+1));
|
|
|
|
|
}
|
2010-02-02 17:20:49 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 17:38:27 +02:00
|
|
|
void NavigatorView::instanceErrorChange(const QVector<ModelNode> &errorNodeList)
|
|
|
|
|
{
|
|
|
|
|
foreach (const ModelNode ¤tModelNode, errorNodeList)
|
|
|
|
|
m_treeModel->updateItemRow(currentModelNode);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-16 18:55:32 +03:00
|
|
|
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int /*oldIndex*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-09-08 10:37:22 +02:00
|
|
|
if (m_treeModel->isInTree(node)) {
|
|
|
|
|
m_treeModel->removeSubTree(listProperty.parentModelNode());
|
|
|
|
|
|
|
|
|
|
if (node.isInHierarchy())
|
|
|
|
|
m_treeModel->addSubTree(listProperty.parentModelNode());
|
|
|
|
|
|
2015-07-15 17:28:18 +02:00
|
|
|
if (listProperty.parentModelNode().isValid()) {
|
|
|
|
|
QModelIndex index = m_treeModel->indexForNode(listProperty.parentModelNode());
|
|
|
|
|
treeWidget()->expand(index);
|
|
|
|
|
}
|
2014-09-08 10:37:22 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-02 14:02:17 +01:00
|
|
|
void NavigatorView::changeToComponent(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid() && m_treeModel->data(index, Qt::UserRole).isValid()) {
|
|
|
|
|
ModelNode doubleClickNode = m_treeModel->nodeForIndex(index);
|
2013-01-23 12:31:22 +01:00
|
|
|
if (doubleClickNode.metaInfo().isFileComponent())
|
2013-05-31 12:52:53 +02:00
|
|
|
Core::EditorManager::openEditor(doubleClickNode.metaInfo().componentFileName(),
|
|
|
|
|
Core::Id(), Core::EditorManager::DoNotMakeVisible);
|
2011-02-02 14:02:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-28 17:12:45 +02:00
|
|
|
void NavigatorView::leftButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
if (selectedModelNodes().count() > 1)
|
|
|
|
|
return; //Semantics are unclear for multi selection.
|
|
|
|
|
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
|
|
|
|
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
2011-07-26 11:22:52 +02:00
|
|
|
if (!node.isRootNode() && !node.parentProperty().parentModelNode().isRootNode()) {
|
2013-07-24 15:58:51 +02:00
|
|
|
if (QmlItemNode::isValidQmlItemNode(node)) {
|
2011-07-26 11:22:52 +02:00
|
|
|
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
|
2014-05-06 13:46:47 +02:00
|
|
|
node.parentProperty().parentProperty().reparentHere(node);
|
2011-07-26 11:22:52 +02:00
|
|
|
if (!scenePos.isNull())
|
|
|
|
|
setScenePos(node, scenePos);
|
|
|
|
|
} else {
|
2014-05-06 13:46:47 +02:00
|
|
|
node.parentProperty().parentProperty().reparentHere(node);
|
2011-07-26 11:22:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
2011-04-28 17:12:45 +02:00
|
|
|
}
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::rightButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
if (selectedModelNodes().count() > 1)
|
|
|
|
|
return; //Semantics are unclear for multi selection.
|
|
|
|
|
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
2014-05-06 13:46:47 +02:00
|
|
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty() && node.parentProperty().count() > 1) {
|
|
|
|
|
int index = node.parentProperty().indexOf(node);
|
2011-04-28 17:12:45 +02:00
|
|
|
index--;
|
|
|
|
|
if (index >= 0) { //for the first node the semantics are not clear enough. Wrapping would be irritating.
|
|
|
|
|
ModelNode newParent = node.parentProperty().toNodeListProperty().at(index);
|
2011-07-26 11:22:52 +02:00
|
|
|
|
2013-09-16 16:05:17 +02:00
|
|
|
if (QmlItemNode::isValidQmlItemNode(node)
|
|
|
|
|
&& QmlItemNode::isValidQmlItemNode(newParent)
|
|
|
|
|
&& !newParent.metaInfo().defaultPropertyIsComponent()) {
|
2011-07-26 11:22:52 +02:00
|
|
|
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
|
|
|
|
|
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
|
|
|
|
|
if (!scenePos.isNull())
|
|
|
|
|
setScenePos(node, scenePos);
|
|
|
|
|
} else {
|
2013-09-16 16:05:17 +02:00
|
|
|
if (newParent.metaInfo().isValid() && !newParent.metaInfo().defaultPropertyIsComponent())
|
|
|
|
|
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
|
2011-07-26 11:22:52 +02:00
|
|
|
}
|
2011-04-28 17:12:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::upButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
|
|
|
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty()) {
|
2014-05-06 13:46:47 +02:00
|
|
|
int oldIndex = node.parentProperty().indexOf(node);
|
2011-04-28 17:12:45 +02:00
|
|
|
int index = oldIndex;
|
|
|
|
|
index--;
|
|
|
|
|
if (index < 0)
|
2014-05-06 13:46:47 +02:00
|
|
|
index = node.parentProperty().count() - 1; //wrap around
|
2011-04-28 17:12:45 +02:00
|
|
|
node.parentProperty().toNodeListProperty().slide(oldIndex, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::downButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
|
|
|
|
if (!node.isRootNode() && node.parentProperty().isNodeListProperty()) {
|
2014-05-06 13:46:47 +02:00
|
|
|
int oldIndex = node.parentProperty().indexOf(node);
|
2011-04-28 17:12:45 +02:00
|
|
|
int index = oldIndex;
|
|
|
|
|
index++;
|
2014-05-06 13:46:47 +02:00
|
|
|
if (index >= node.parentProperty().count())
|
2011-04-28 17:12:45 +02:00
|
|
|
index = 0; //wrap around
|
|
|
|
|
node.parentProperty().toNodeListProperty().slide(oldIndex, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
|
|
|
|
|
{
|
|
|
|
|
if (m_blockSelectionChangedSignal)
|
|
|
|
|
return;
|
|
|
|
|
QSet<ModelNode> nodeSet;
|
|
|
|
|
foreach (const QModelIndex &index, treeWidget()->selectionModel()->selectedIndexes()) {
|
2010-09-07 16:30:57 +02:00
|
|
|
if (m_treeModel->data(index, Qt::UserRole).isValid())
|
|
|
|
|
nodeSet.insert(m_treeModel->nodeForIndex(index));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
setSelectedModelNodes(nodeSet.toList());
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/, const QList<ModelNode> &/*lastSelectedNodeList*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::updateItemSelection()
|
|
|
|
|
{
|
|
|
|
|
QItemSelection itemSelection;
|
|
|
|
|
foreach (const ModelNode &node, selectedModelNodes()) {
|
|
|
|
|
const QModelIndex index = m_treeModel->indexForNode(node);
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
const QModelIndex beginIndex(m_treeModel->index(index.row(), 0, index.parent()));
|
|
|
|
|
const QModelIndex endIndex(m_treeModel->index(index.row(), m_treeModel->columnCount(index.parent()) - 1, index.parent()));
|
|
|
|
|
if (beginIndex.isValid() && endIndex.isValid())
|
|
|
|
|
itemSelection.select(beginIndex, endIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
treeWidget()->selectionModel()->select(itemSelection, QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
blockSelectionChangedSignal(blocked);
|
|
|
|
|
|
2011-04-07 16:38:44 +02:00
|
|
|
if (!selectedModelNodes().isEmpty())
|
|
|
|
|
treeWidget()->scrollTo(m_treeModel->indexForNode(selectedModelNodes().first()));
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
// make sure selected nodes a visible
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QModelIndex &selectedIndex, itemSelection.indexes()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
if (selectedIndex.column() == 0)
|
|
|
|
|
expandRecursively(selectedIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTreeView *NavigatorView::treeWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
return m_widget->treeView();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigatorTreeModel *NavigatorView::treeModel()
|
|
|
|
|
{
|
|
|
|
|
return m_treeModel.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// along the lines of QObject::blockSignals
|
|
|
|
|
bool NavigatorView::blockSelectionChangedSignal(bool block)
|
|
|
|
|
{
|
|
|
|
|
bool oldValue = m_blockSelectionChangedSignal;
|
|
|
|
|
m_blockSelectionChangedSignal = block;
|
|
|
|
|
return oldValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::expandRecursively(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex currentIndex = index;
|
|
|
|
|
while (currentIndex.isValid()) {
|
|
|
|
|
if (!treeWidget()->isExpanded(currentIndex))
|
|
|
|
|
treeWidget()->expand(currentIndex);
|
|
|
|
|
currentIndex = currentIndex.parent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|