summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2010-08-25 13:21:38 +0200
committerKai Koehne <kai.koehne@nokia.com>2010-08-25 13:28:04 +0200
commit6cf563bb25b3bc8f48cd45e22d648bfdb16bca99 (patch)
treee275f20a5bed22b91159c7de8543e1ab610a588a /src
parent22fe4f584d26ac3f877722e3fc5457dc0f0b9b89 (diff)
downloadqt-creator-6cf563bb25b3bc8f48cd45e22d648bfdb16bca99.tar.gz
QmlOutline: Cut down update times considerably
Cut down update times of Outline by a magnitude by only emitting itemChanged signal if absolutely needed. This doesn't include the change of the icon, because QIcon is missing a comparison operator ...
Diffstat (limited to 'src')
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp7
-rw-r--r--src/plugins/qmljseditor/qmljsoutline.cpp7
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.cpp265
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.h36
4 files changed, 146 insertions, 169 deletions
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 1405779bd7..605b459e62 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -882,7 +882,10 @@ void QmlJSTextEditor::modificationChanged(bool changed)
void QmlJSTextEditor::jumpToOutlineElement(int /*index*/)
{
QModelIndex index = m_outlineCombo->view()->currentIndex();
- AST::SourceLocation location = index.data(QmlOutlineModel::SourceLocationRole).value<AST::SourceLocation>();
+ AST::SourceLocation location = m_outlineModel->sourceLocation(index);
+
+ if (!location.isValid())
+ return;
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
@@ -1753,7 +1756,7 @@ QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QMo
const int rowCount = m_outlineModel->rowCount(rootIndex);
for (int i = 0; i < rowCount; ++i) {
QModelIndex childIndex = m_outlineModel->index(i, 0, rootIndex);
- AST::SourceLocation location = childIndex.data(QmlOutlineModel::SourceLocationRole).value<AST::SourceLocation>();
+ AST::SourceLocation location = m_outlineModel->sourceLocation(childIndex);
if ((cursorPosition >= location.offset)
&& (cursorPosition <= location.offset + location.length)) {
diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp
index ae2438942a..db9da7dfd6 100644
--- a/src/plugins/qmljseditor/qmljsoutline.cpp
+++ b/src/plugins/qmljseditor/qmljsoutline.cpp
@@ -158,7 +158,12 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!selection.indexes().isEmpty()) {
QModelIndex index = selection.indexes().first();
- AST::SourceLocation location = index.data(QmlOutlineModel::SourceLocationRole).value<AST::SourceLocation>();
+ QModelIndex sourceIndex = m_filterModel->mapToSource(index);
+
+ AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex);
+
+ if (!location.isValid())
+ return;
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index cdcb34c72a..7b2d9bf7e5 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -8,6 +8,8 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsrewriter.h>
+#include <utils/qtcassert.h>
+
#include <coreplugin/icore.h>
#include <QtCore/QDebug>
#include <QtCore/QTime>
@@ -24,9 +26,7 @@ namespace QmlJSEditor {
namespace Internal {
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
- m_outlineModel(model),
- m_node(0),
- m_idNode(0)
+ m_outlineModel(model)
{
Qt::ItemFlags defaultFlags = flags();
setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags);
@@ -36,21 +36,25 @@ QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
QVariant QmlOutlineItem::data(int role) const
{
if (role == Qt::ToolTipRole) {
- AST::SourceLocation location = sourceLocation();
- AST::UiQualifiedId *uiQualifiedId = m_idNode;
- if (!uiQualifiedId)
+ AST::SourceLocation location = m_outlineModel->sourceLocation(index());
+ AST::UiQualifiedId *uiQualifiedId = m_outlineModel->idNode(index());
+ if (!uiQualifiedId || !location.isValid())
return QVariant();
QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.astPath(location.begin());
- QmlJS::Document::Ptr document = m_outlineModel->m_semanticInfo.document;
- QmlJS::Snapshot snapshot = m_outlineModel->m_semanticInfo.snapshot;
+ Document::Ptr document = m_outlineModel->m_semanticInfo.document;
+ Snapshot snapshot = m_outlineModel->m_semanticInfo.snapshot;
LookupContext::Ptr lookupContext = LookupContext::create(document, snapshot, astPath);
const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId);
return prettyPrint(value, lookupContext->context());
}
+ if (role == Qt::DecorationRole) {
+ return m_outlineModel->icon(index());
+ }
+
return QStandardItem::data(role);
}
@@ -59,56 +63,7 @@ int QmlOutlineItem::type() const
return UserType;
}
-QString QmlOutlineItem::annotation() const
-{
- return data(QmlOutlineModel::AnnotationRole).value<QString>();
-}
-
-void QmlOutlineItem::setAnnotation(const QString &id)
-{
- setData(QVariant::fromValue(id), QmlOutlineModel::AnnotationRole);
-}
-
-QmlJS::AST::SourceLocation QmlOutlineItem::sourceLocation() const
-{
- return data(QmlOutlineModel::SourceLocationRole).value<QmlJS::AST::SourceLocation>();
-}
-
-void QmlOutlineItem::setSourceLocation(const QmlJS::AST::SourceLocation &location)
-{
- setData(QVariant::fromValue(location), QmlOutlineModel::SourceLocationRole);
-}
-
-QmlJS::AST::Node *QmlOutlineItem::node() const
-{
- return m_node;
-}
-
-void QmlOutlineItem::setNode(QmlJS::AST::Node *node)
-{
- m_node = node;
-}
-
-QmlJS::AST::UiQualifiedId *QmlOutlineItem::idNode() const
-{
- return m_idNode;
-}
-
-void QmlOutlineItem::setIdNode(QmlJS::AST::UiQualifiedId *idNode)
-{
- m_idNode = idNode;
-}
-
-QmlOutlineItem &QmlOutlineItem::copyValues(const QmlOutlineItem &other)
-{
- *this = other;
- m_node = other.m_node;
- m_idNode = other.m_idNode;
- emitDataChanged();
- return *this;
-}
-
-QString QmlOutlineItem::prettyPrint(const QmlJS::Interpreter::Value *value, const QmlJS::Interpreter::Context *context) const
+QString QmlOutlineItem::prettyPrint(const Interpreter::Value *value, const Interpreter::Context *context) const
{
if (! value)
return QString();
@@ -273,7 +228,7 @@ QmlOutlineModel::QmlOutlineModel(QObject *parent) :
{
m_icons = Icons::instance();
const QString resourcePath = Core::ICore::instance()->resourcePath();
- QmlJS::Icons::instance()->setIconFilesPath(resourcePath + "/qmlicons");
+ Icons::instance()->setIconFilesPath(resourcePath + "/qmlicons");
// TODO: Maybe add a Copy Action?
setSupportedDragActions(Qt::MoveAction);
@@ -361,7 +316,7 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
return false;
}
-QmlJS::Document::Ptr QmlOutlineModel::document() const
+Document::Ptr QmlOutlineModel::document() const
{
return m_semanticInfo.document;
}
@@ -381,12 +336,13 @@ void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
// and there is AFAIK no way to introduce new type names in a sub-context.
m_context = LookupContext::create(semanticInfo.document, semanticInfo.snapshot, QList<AST::Node*>());
m_typeToIcon.clear();
+ m_itemToNode.clear();
+ m_itemToIdNode.clear();
+ m_itemToIcon.clear();
- QmlOutlineModelSync syncModel(this);
- beginResetModel();
+ QmlOutlineModelSync syncModel(this);
syncModel(m_semanticInfo.document);
- endResetModel();
m_context.clear();
@@ -395,29 +351,34 @@ void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
QModelIndex QmlOutlineModel::enterObjectDefinition(AST::UiObjectDefinition *objDef)
{
- QmlOutlineItem prototype(this);
-
const QString typeName = asString(objDef->qualifiedTypeNameId);
+ QMap<int, QVariant> data;
+
+ if (typeName.at(0).isUpper()) {
+ data.insert(ItemTypeRole, ElementType);
+ } else {
+ // it's a grouped propery like 'anchors'
+ data.insert(ItemTypeRole, NonElementBindingType);
+ }
+
+ data.insert(Qt::DisplayRole, typeName);
+
+ QmlOutlineItem *item = enterNode(data);
+
+ m_itemToNode.insert(item, objDef);
if (typeName.at(0).isUpper()) {
- prototype.setText(typeName);
- prototype.setAnnotation(getAnnotation(objDef->initializer));
if (!m_typeToIcon.contains(typeName)) {
m_typeToIcon.insert(typeName, getIcon(objDef->qualifiedTypeNameId));
}
- prototype.setIcon(m_typeToIcon.value(typeName));
- prototype.setData(ElementType, ItemTypeRole);
- prototype.setIdNode(objDef->qualifiedTypeNameId);
+
+ m_itemToIdNode.insert(item, objDef->qualifiedTypeNameId);
+ m_itemToIcon.insert(item, m_typeToIcon.value(typeName));
} else {
- // it's a grouped propery like 'anchors'
- prototype.setText(typeName);
- prototype.setIcon(m_icons->scriptBindingIcon());
- prototype.setData(NonElementBindingType, ItemTypeRole);
+ m_itemToIcon.insert(item, m_icons->scriptBindingIcon());
}
- prototype.setSourceLocation(getLocation(objDef));
- prototype.setNode(objDef);
- return enterNode(prototype);
+ return item->index();
}
void QmlOutlineModel::leaveObjectDefiniton()
@@ -427,34 +388,32 @@ void QmlOutlineModel::leaveObjectDefiniton()
QModelIndex QmlOutlineModel::enterObjectBinding(AST::UiObjectBinding *objBinding)
{
- QmlOutlineItem bindingPrototype(this);
+ QMap<int, QVariant> bindingData;
- bindingPrototype.setText(asString(objBinding->qualifiedId));
- bindingPrototype.setIcon(m_icons->scriptBindingIcon());
- bindingPrototype.setData(ElementBindingType, ItemTypeRole);
- bindingPrototype.setNode(objBinding);
- bindingPrototype.setSourceLocation(getLocation(objBinding));
- bindingPrototype.setIdNode(objBinding->qualifiedId);
+ bindingData.insert(Qt::DisplayRole, asString(objBinding->qualifiedId));
+ bindingData.insert(ItemTypeRole, ElementBindingType);
- enterNode(bindingPrototype);
-
- QmlOutlineItem objectPrototype(this);
+ QmlOutlineItem *bindingItem = enterNode(bindingData);
+ m_itemToNode.insert(bindingItem, objBinding);
+ m_itemToIdNode.insert(bindingItem, objBinding->qualifiedId);
+ m_itemToIcon.insert(bindingItem, m_icons->scriptBindingIcon());
const QString typeName = asString(objBinding->qualifiedTypeNameId);
- objectPrototype.setText(typeName);
- objectPrototype.setAnnotation(getAnnotation(objBinding->initializer));
if (!m_typeToIcon.contains(typeName)) {
m_typeToIcon.insert(typeName, getIcon(objBinding->qualifiedTypeNameId));
}
- objectPrototype.setIcon(m_typeToIcon.value(typeName));
- objectPrototype.setData(ElementType, ItemTypeRole);
- objectPrototype.setIdNode(objBinding->qualifiedTypeNameId);
- objectPrototype.setNode(objBinding);
- objectPrototype.setSourceLocation(getLocation(objBinding));
- enterNode(objectPrototype);
+ QMap<int, QVariant> objectData;
+ objectData.insert(Qt::DisplayRole, typeName);
+ objectData.insert(AnnotationRole, getAnnotation(objBinding->initializer));
+ objectData.insert(ItemTypeRole, ElementType);
+
+ QmlOutlineItem *objectItem = enterNode(objectData);
+ m_itemToNode.insert(objectItem, objBinding);
+ m_itemToIdNode.insert(objectItem, objBinding->qualifiedTypeNameId);
+ m_itemToIcon.insert(objectItem, m_typeToIcon.value(typeName));
- return bindingPrototype.index();
+ return bindingItem->index();
}
void QmlOutlineModel::leaveObjectBinding()
@@ -465,18 +424,17 @@ void QmlOutlineModel::leaveObjectBinding()
QModelIndex QmlOutlineModel::enterArrayBinding(AST::UiArrayBinding *arrayBinding)
{
- QmlOutlineItem bindingPrototype(this);
+ QMap<int, QVariant> bindingData;
- bindingPrototype.setText(asString(arrayBinding->qualifiedId));
- bindingPrototype.setIcon(m_icons->scriptBindingIcon());
- bindingPrototype.setData(ElementBindingType, ItemTypeRole);
- bindingPrototype.setNode(arrayBinding);
- bindingPrototype.setSourceLocation(getLocation(arrayBinding));
- bindingPrototype.setIdNode(arrayBinding->qualifiedId);
+ bindingData.insert(Qt::DisplayRole, asString(arrayBinding->qualifiedId));
+ bindingData.insert(ItemTypeRole, ElementBindingType);
- enterNode(bindingPrototype);
+ QmlOutlineItem *item = enterNode(bindingData);
+ m_itemToNode.insert(item, arrayBinding);
+ m_itemToIdNode.insert(item, arrayBinding->qualifiedId);
+ m_itemToIcon.insert(item, m_icons->scriptBindingIcon());
- return bindingPrototype.index();
+ return item->index();
}
void QmlOutlineModel::leaveArrayBinding()
@@ -486,17 +444,18 @@ void QmlOutlineModel::leaveArrayBinding()
QModelIndex QmlOutlineModel::enterScriptBinding(AST::UiScriptBinding *scriptBinding)
{
- QmlOutlineItem prototype(this);
+ QMap<int, QVariant> objectData;
+
+ objectData.insert(Qt::DisplayRole, asString(scriptBinding->qualifiedId));
+ objectData.insert(AnnotationRole, getAnnotation(scriptBinding->statement));
+ objectData.insert(ItemTypeRole, NonElementBindingType);
- prototype.setText(asString(scriptBinding->qualifiedId));
- prototype.setIcon(m_icons->scriptBindingIcon());
- prototype.setAnnotation(getAnnotation(scriptBinding->statement));
- prototype.setData(NonElementBindingType, ItemTypeRole);
- prototype.setSourceLocation(getLocation(scriptBinding));
- prototype.setNode(scriptBinding);
- prototype.setIdNode(scriptBinding->qualifiedId);
+ QmlOutlineItem *item = enterNode(objectData);
+ m_itemToNode.insert(item, scriptBinding);
+ m_itemToIdNode.insert(item, scriptBinding->qualifiedId);
+ m_itemToIcon.insert(item, m_icons->scriptBindingIcon());
- return enterNode(prototype);
+ return item->index();
}
void QmlOutlineModel::leaveScriptBinding()
@@ -506,17 +465,18 @@ void QmlOutlineModel::leaveScriptBinding()
QModelIndex QmlOutlineModel::enterPublicMember(AST::UiPublicMember *publicMember)
{
- QmlOutlineItem prototype(this);
+ QMap<int, QVariant> objectData;
if (publicMember->name)
- prototype.setText(publicMember->name->asString());
- prototype.setIcon(m_icons->publicMemberIcon());
- prototype.setAnnotation(getAnnotation(publicMember->expression));
- prototype.setData(NonElementBindingType, ItemTypeRole);
- prototype.setSourceLocation(getLocation(publicMember));
- prototype.setNode(publicMember);
+ objectData.insert(Qt::DisplayRole, publicMember->name->asString());
+ objectData.insert(AnnotationRole, getAnnotation(publicMember->expression));
+ objectData.insert(ItemTypeRole, NonElementBindingType);
- return enterNode(prototype);
+ QmlOutlineItem *item = enterNode(objectData);
+ m_itemToNode.insert(item, publicMember);
+ m_itemToIcon.insert(item, m_icons->publicMemberIcon());
+
+ return item->index();
}
void QmlOutlineModel::leavePublicMember()
@@ -524,16 +484,44 @@ void QmlOutlineModel::leavePublicMember()
leaveNode();
}
-QmlJS::AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index)
+AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index) const
{
+ QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
if (index.isValid()) {
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
- return item->node();
+ QTC_ASSERT(m_itemToNode.contains(item), return 0);
+ return m_itemToNode.value(item);
}
return 0;
}
-QModelIndex QmlOutlineModel::enterNode(const QmlOutlineItem &prototype)
+AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) const
+{
+ QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
+ AST::SourceLocation location;
+ AST::Node *node = nodeForIndex(index);
+ if (node) {
+ if (AST::UiObjectMember *member = node->uiObjectMemberCast())
+ location = getLocation(member);
+ }
+ return location;
+}
+
+AST::UiQualifiedId *QmlOutlineModel::idNode(const QModelIndex &index) const
+{
+ QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
+ QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
+ return m_itemToIdNode.value(item);
+}
+
+QIcon QmlOutlineModel::icon(const QModelIndex &index) const
+{
+ QTC_ASSERT(index.isValid() && (index.model() == this), return QIcon());
+ QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
+ return m_itemToIcon.value(item);
+}
+
+QmlOutlineItem *QmlOutlineModel::enterNode(QMap<int, QVariant> data)
{
int siblingIndex = m_treePos.last();
if (siblingIndex == 0) {
@@ -543,16 +531,12 @@ QModelIndex QmlOutlineModel::enterNode(const QmlOutlineItem &prototype)
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
QmlOutlineItem *newItem = new QmlOutlineItem(this);
- newItem->copyValues(prototype);
newItem->setEditable(false);
m_currentItem->appendRow(newItem);
m_currentItem = newItem;
} else {
m_currentItem = m_currentItem->child(0);
-
- QmlOutlineItem *existingItem = static_cast<QmlOutlineItem*>(m_currentItem);
- existingItem->copyValues(prototype);
}
} else {
// sibling
@@ -561,21 +545,18 @@ QModelIndex QmlOutlineModel::enterNode(const QmlOutlineItem &prototype)
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
QmlOutlineItem *newItem = new QmlOutlineItem(this);
- newItem->copyValues(prototype);
newItem->setEditable(false);
m_currentItem->appendRow(newItem);
m_currentItem = newItem;
} else {
m_currentItem = m_currentItem->child(siblingIndex);
-
- QmlOutlineItem *existingItem = static_cast<QmlOutlineItem*>(m_currentItem);
- existingItem->copyValues(prototype);
}
}
+ setItemData(m_currentItem->index(), data);
m_treePos.append(0);
- return m_currentItem->index();
+ return static_cast<QmlOutlineItem*>(m_currentItem);
}
void QmlOutlineModel::leaveNode()
@@ -608,7 +589,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
{
Utils::ChangeSet changeSet;
- AST::UiObjectMember *targetObjectMember = targetItem->node()->uiObjectMemberCast();
+ AST::UiObjectMember *targetObjectMember = m_itemToNode.value(targetItem)->uiObjectMemberCast();
if (!targetObjectMember)
return;
@@ -616,7 +597,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
for (int i = 0; i < itemsToMove.size(); ++i) {
QmlOutlineItem *outlineItem = itemsToMove.at(i);
- AST::UiObjectMember *sourceObjectMember = outlineItem->node()->uiObjectMemberCast();
+ AST::UiObjectMember *sourceObjectMember = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
if (!sourceObjectMember)
return;
@@ -627,7 +608,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
insertionOrderSpecified = false;
} else if (row > 0) {
QmlOutlineItem *outlineItem = static_cast<QmlOutlineItem*>(targetItem->child(row - 1));
- memberToInsertAfter = outlineItem->node()->uiObjectMemberCast();
+ memberToInsertAfter = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
}
}
@@ -638,7 +619,7 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
changedRanges << range;
}
- QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(), m_semanticInfo.snapshot);
+ QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), m_semanticInfo.snapshot);
TextEditor::RefactoringFile file = refactoring.file(m_semanticInfo.document->fileName());
file.change(changeSet);
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
@@ -657,7 +638,7 @@ void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
Q_ASSERT(newParent);
Q_ASSERT(changeSet);
- QHash<QmlJS::AST::UiObjectMember*, QmlJS::AST::UiObjectMember*> parentMembers;
+ QHash<AST::UiObjectMember*, AST::UiObjectMember*> parentMembers;
{
ObjectMemberParentVisitor visitor;
parentMembers = visitor(m_semanticInfo.document);
@@ -780,7 +761,7 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember)
}
QIcon QmlOutlineModel::getIcon(AST::UiQualifiedId *qualifiedId) {
- const QmlJS::Interpreter::Value *value = m_context->evaluate(qualifiedId);
+ const Interpreter::Value *value = m_context->evaluate(qualifiedId);
if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
do {
@@ -818,14 +799,14 @@ QString QmlOutlineModel::getAnnotation(AST::UiObjectInitializer *objectInitializ
return QString();
}
-QString QmlOutlineModel::getAnnotation(QmlJS::AST::Statement *statement)
+QString QmlOutlineModel::getAnnotation(AST::Statement *statement)
{
if (AST::ExpressionStatement *expr = AST::cast<AST::ExpressionStatement*>(statement))
return getAnnotation(expr->expression);
return QString();
}
-QString QmlOutlineModel::getAnnotation(QmlJS::AST::ExpressionNode *expression)
+QString QmlOutlineModel::getAnnotation(AST::ExpressionNode *expression)
{
if (!expression)
return QString();
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.h b/src/plugins/qmljseditor/qmloutlinemodel.h
index 34fe23015b..8a918c35a5 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.h
+++ b/src/plugins/qmljseditor/qmloutlinemodel.h
@@ -30,38 +30,20 @@ public:
QVariant data(int role = Qt::UserRole + 1) const;
int type() const;
- QString annotation() const;
- void setAnnotation(const QString &id);
-
- QmlJS::AST::SourceLocation sourceLocation() const;
- void setSourceLocation(const QmlJS::AST::SourceLocation &location);
-
-
- QmlJS::AST::Node *node() const;
- void setNode(QmlJS::AST::Node *node);
-
- QmlJS::AST::UiQualifiedId *idNode() const;
- void setIdNode(QmlJS::AST::UiQualifiedId *idNode);
-
- QmlOutlineItem &copyValues(const QmlOutlineItem &other); // so that we can assign all values at onc
-
private:
QString prettyPrint(const QmlJS::Interpreter::Value *value, const QmlJS::Interpreter::Context *context) const;
QmlOutlineModel *m_outlineModel;
- QmlJS::AST::Node *m_node;
- QmlJS::AST::UiQualifiedId *m_idNode;
};
-
class QmlOutlineModel : public QStandardItemModel
{
Q_OBJECT
public:
enum CustomRoles {
- SourceLocationRole = Qt::UserRole + 1,
- ItemTypeRole,
+ ItemTypeRole = Qt::UserRole + 1,
+ ElementTypeRole,
AnnotationRole
};
@@ -80,7 +62,11 @@ public:
QmlJS::Document::Ptr document() const;
void update(const SemanticInfo &semanticInfo);
- QmlJS::AST::Node *nodeForIndex(const QModelIndex &index);
+
+ QmlJS::AST::Node *nodeForIndex(const QModelIndex &index) const;
+ QmlJS::AST::SourceLocation sourceLocation(const QModelIndex &index) const;
+ QmlJS::AST::UiQualifiedId *idNode(const QModelIndex &index) const;
+ QIcon icon(const QModelIndex &index) const;
signals:
void updated();
@@ -102,7 +88,7 @@ private:
void leavePublicMember();
private:
- QModelIndex enterNode(const QmlOutlineItem &prototype);
+ QmlOutlineItem *enterNode(QMap<int, QVariant> data);
void leaveNode();
void reparentNodes(QmlOutlineItem *targetItem, int targetRow, QList<QmlOutlineItem*> itemsToMove);
@@ -129,6 +115,10 @@ private:
QmlJS::LookupContext::Ptr m_context;
QHash<QString, QIcon> m_typeToIcon;
+ QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
+ QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;
+ QHash<QmlOutlineItem*,QmlJS::AST::UiQualifiedId*> m_itemToIdNode;
+
friend class QmlOutlineModelSync;
friend class QmlOutlineItem;
@@ -137,6 +127,4 @@ private:
} // namespace Internal
} // namespace QmlJSEditor
-Q_DECLARE_METATYPE(QmlJS::AST::SourceLocation);
-
#endif // QMLOUTLINEMODEL_H