2010-01-07 12:14:35 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "navigatorview.h"
|
|
|
|
|
#include "navigatortreemodel.h"
|
|
|
|
|
#include "navigatorwidget.h"
|
|
|
|
|
|
2011-02-02 14:02:17 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <nodeproperty.h>
|
2010-04-21 17:02:54 +02:00
|
|
|
#include <nodelistproperty.h>
|
2010-02-15 16:24:49 +01:00
|
|
|
#include <QHeaderView>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
NavigatorView::NavigatorView(QObject* parent) :
|
2010-04-21 17:02:54 +02:00
|
|
|
AbstractView(parent),
|
2010-01-07 12:14:35 +01:00
|
|
|
m_blockSelectionChangedSignal(false),
|
|
|
|
|
m_widget(new NavigatorWidget),
|
|
|
|
|
m_treeModel(new NavigatorTreeModel(this))
|
|
|
|
|
{
|
|
|
|
|
m_widget->setTreeModel(m_treeModel.data());
|
|
|
|
|
|
|
|
|
|
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
2011-02-02 14:02:17 +01:00
|
|
|
connect(treeWidget(), SIGNAL(doubleClicked(QModelIndex)), this, SLOT(changeToComponent(QModelIndex)));
|
2010-01-07 12:14:35 +01:00
|
|
|
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
|
2010-01-29 12:10:08 +01:00
|
|
|
|
2010-09-07 16:30:57 +02:00
|
|
|
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
|
2010-01-29 12:10:08 +01:00
|
|
|
IconCheckboxItemDelegate *showDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/eye_open.png",
|
2010-02-02 17:20:49 +01:00
|
|
|
":/qmldesigner/images/placeholder.png",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
|
|
|
|
|
treeWidget()->setItemDelegateForColumn(1,showDelegate);
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigatorView::~NavigatorView()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget && !m_widget->parent())
|
|
|
|
|
delete m_widget.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *NavigatorView::widget()
|
|
|
|
|
{
|
|
|
|
|
return m_widget.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::modelAttached(Model *model)
|
|
|
|
|
{
|
2010-04-21 17:02:54 +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
|
|
|
|
2010-02-17 10:47:33 +01:00
|
|
|
treeView->header()->setResizeMode(0, QHeaderView::Stretch);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
m_treeModel->clearView();
|
2010-04-21 17:02:54 +02:00
|
|
|
AbstractView::modelAboutToBeDetached(model);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-15 17:12:01 +01:00
|
|
|
void NavigatorView::importAdded(const Import &)
|
|
|
|
|
{
|
|
|
|
|
treeWidget()->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::importRemoved(const Import &)
|
|
|
|
|
{
|
|
|
|
|
treeWidget()->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::nodeCreated(const ModelNode & /*createdNode*/)
|
2010-04-21 17:02:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::nodeRemoved(const ModelNode & /*removedNode*/, const NodeAbstractProperty & /*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
|
2010-04-21 17:02:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::propertiesRemoved(const QList<AbstractProperty> & /*propertyList*/)
|
2010-04-21 17:02:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::variantPropertiesChanged(const QList<VariantProperty> & /*propertyList*/, PropertyChangeFlags /*propertyChange*/)
|
2010-04-21 17:02:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::bindingPropertiesChanged(const QList<BindingProperty> & /*propertyList*/, PropertyChangeFlags /*propertyChange*/)
|
2010-04-21 17:02:54 +02:00
|
|
|
{
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
|
|
|
|
{
|
|
|
|
|
if (m_treeModel->isInTree(removedNode))
|
|
|
|
|
m_treeModel->removeSubTree(removedNode);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 16:46:25 +01:00
|
|
|
void NavigatorView::nodeAboutToBeReparented(const ModelNode &/*node*/, const NodeAbstractProperty &/*newPropertyParent*/, const NodeAbstractProperty &/*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void NavigatorView::nodeReparented(const ModelNode &node, const NodeAbstractProperty & /*newPropertyParent*/, const NodeAbstractProperty & /*oldPropertyParent*/, AbstractView::PropertyChangeFlags /*propertyChange*/)
|
|
|
|
|
{
|
|
|
|
|
bool blocked = blockSelectionChangedSignal(true);
|
|
|
|
|
|
|
|
|
|
if (m_treeModel->isInTree(node))
|
|
|
|
|
m_treeModel->removeSubTree(node);
|
|
|
|
|
if (node.isInHierarchy())
|
|
|
|
|
m_treeModel->addSubTree(node);
|
|
|
|
|
|
|
|
|
|
// make sure selection is in sync again
|
|
|
|
|
updateItemSelection();
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
if (property.isNodeProperty()) {
|
|
|
|
|
NodeProperty nodeProperty(property.toNodeProperty());
|
|
|
|
|
m_treeModel->removeSubTree(nodeProperty.modelNode());
|
|
|
|
|
} else if (property.isNodeListProperty()) {
|
|
|
|
|
NodeListProperty nodeListProperty(property.toNodeListProperty());
|
|
|
|
|
foreach (const ModelNode &node, nodeListProperty.toModelNodeList()) {
|
|
|
|
|
m_treeModel->removeSubTree(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2010-04-23 10:49:36 +02:00
|
|
|
void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString & /*name*/, const QVariant & /*data*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
if (m_treeModel->isInTree(node))
|
2010-02-02 17:20:49 +01:00
|
|
|
{
|
|
|
|
|
// update model
|
2010-01-07 12:14:35 +01:00
|
|
|
m_treeModel->updateItemRow(node);
|
2010-02-02 17:20:49 +01:00
|
|
|
|
|
|
|
|
// repaint row (id and icon)
|
|
|
|
|
QModelIndex index = m_treeModel->indexForNode(node);
|
|
|
|
|
treeWidget()->update( index );
|
|
|
|
|
treeWidget()->update( index.sibling(index.row(),index.column()+1) );
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-10 17:36:14 +02:00
|
|
|
void NavigatorView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 15:26:58 +02:00
|
|
|
void NavigatorView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-06-10 17:36:14 +02:00
|
|
|
|
2010-12-09 16:09:37 +01:00
|
|
|
void NavigatorView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 15:54:52 +01:00
|
|
|
void NavigatorView::instanceInformationsChange(const QVector<ModelNode> &/*nodeList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::rewriterBeginTransaction()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigatorView::rewriterEndTransaction()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 16:30:57 +02:00
|
|
|
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
if (m_treeModel->isInTree(node))
|
2010-09-07 16:30:57 +02:00
|
|
|
m_treeModel->updateItemRowOrder(listProperty, node, oldIndex);
|
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);
|
|
|
|
|
if (doubleClickNode.metaInfo().isComponent())
|
|
|
|
|
Core::EditorManager::instance()->openEditor(doubleClickNode.metaInfo().componentFileName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// make sure selected nodes a visible
|
|
|
|
|
foreach(const QModelIndex &selectedIndex, itemSelection.indexes()) {
|
|
|
|
|
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
|