2010-07-12 09:44:42 +02:00
|
|
|
#include "qmloutlinemodel.h"
|
2010-07-19 11:39:41 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <qmljs/parser/qmljsastvisitor_p.h>
|
2010-07-13 17:05:47 +02:00
|
|
|
#include <qmljs/qmljsinterpreter.h>
|
|
|
|
|
#include <qmljs/qmljslookupcontext.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-07-13 17:05:47 +02:00
|
|
|
#include <QtCore/QTime>
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <typeinfo>
|
|
|
|
|
|
|
|
|
|
using namespace QmlJS;
|
|
|
|
|
using namespace QmlJSEditor::Internal;
|
|
|
|
|
|
|
|
|
|
enum {
|
2010-07-14 13:36:18 +02:00
|
|
|
debug = false
|
2010-07-12 09:44:42 +02:00
|
|
|
};
|
|
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
namespace Internal {
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
|
|
|
|
|
m_outlineModel(model)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant QmlOutlineItem::data(int role) const
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::ToolTipRole) {
|
|
|
|
|
AST::SourceLocation location = data(QmlOutlineModel::SourceLocationRole).value<AST::SourceLocation>();
|
|
|
|
|
AST::UiQualifiedId *uiQualifiedId = data(QmlOutlineModel::IdPointerRole).value<AST::UiQualifiedId*>();
|
|
|
|
|
if (!uiQualifiedId)
|
|
|
|
|
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;
|
|
|
|
|
LookupContext::Ptr lookupContext = LookupContext::create(document, snapshot, astPath);
|
|
|
|
|
const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId);
|
|
|
|
|
|
|
|
|
|
return prettyPrint(value, lookupContext->context());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QStandardItem::data(role);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:03:42 +02:00
|
|
|
QmlOutlineItem &QmlOutlineItem::copyValues(const QmlOutlineItem &other)
|
|
|
|
|
{
|
|
|
|
|
*this = other;
|
|
|
|
|
emitDataChanged();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QString QmlOutlineItem::prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Context *context) const
|
|
|
|
|
{
|
|
|
|
|
if (! value)
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
|
|
|
|
|
const QString className = objectValue->className();
|
|
|
|
|
if (!className.isEmpty()) {
|
|
|
|
|
return className;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString typeId = context->engine()->typeId(value);
|
|
|
|
|
if (typeId == QLatin1String("undefined")) {
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return typeId;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
class QmlOutlineModelSync : protected AST::Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QmlOutlineModelSync(QmlOutlineModel *model) :
|
|
|
|
|
m_model(model),
|
|
|
|
|
indent(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void operator()(Document::Ptr doc)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
m_nodeToIndex.clear();
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel ------";
|
|
|
|
|
if (doc && doc->ast())
|
|
|
|
|
doc->ast()->accept(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool preVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (!node)
|
|
|
|
|
return false;
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel -" << QByteArray(indent++, '-').constData() << node << typeid(*node).name();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void postVisit(AST::Node *)
|
|
|
|
|
{
|
|
|
|
|
indent--;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
typedef QPair<QString,QString> ElementType;
|
2010-07-12 09:44:42 +02:00
|
|
|
bool visit(AST::UiObjectDefinition *objDef)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterObjectDefinition(objDef);
|
2010-07-12 09:44:42 +02:00
|
|
|
m_nodeToIndex.insert(objDef, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 13:34:49 +02:00
|
|
|
void endVisit(AST::UiObjectDefinition * /*objDef*/)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leaveObjectDefiniton();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool visit(AST::UiScriptBinding *scriptBinding)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterScriptBinding(scriptBinding);
|
2010-07-12 09:44:42 +02:00
|
|
|
m_nodeToIndex.insert(scriptBinding, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiScriptBinding * /*scriptBinding*/)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leaveScriptBinding();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 13:32:42 +02:00
|
|
|
bool visit(AST::UiPublicMember *publicMember)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterPublicMember(publicMember);
|
2010-07-14 13:32:42 +02:00
|
|
|
m_nodeToIndex.insert(publicMember, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiPublicMember * /*publicMember*/)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leavePublicMember();
|
2010-07-14 13:32:42 +02:00
|
|
|
}
|
2010-07-12 15:51:26 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QmlOutlineModel *m_model;
|
2010-07-13 17:05:47 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QHash<AST::Node*, QModelIndex> m_nodeToIndex;
|
|
|
|
|
int indent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QmlOutlineModel::QmlOutlineModel(QObject *parent) :
|
|
|
|
|
QStandardItemModel(parent)
|
|
|
|
|
{
|
2010-07-13 17:05:47 +02:00
|
|
|
m_icons = Icons::instance();
|
|
|
|
|
const QString resourcePath = Core::ICore::instance()->resourcePath();
|
|
|
|
|
QmlJS::Icons::instance()->setIconFilesPath(resourcePath + "/qmlicons");
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-13 11:18:42 +02:00
|
|
|
QmlJS::Document::Ptr QmlOutlineModel::document() const
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
return m_semanticInfo.document;
|
2010-07-13 11:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_semanticInfo = semanticInfo;
|
2010-07-13 11:18:42 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
m_treePos.clear();
|
|
|
|
|
m_treePos.append(0);
|
|
|
|
|
m_currentItem = invisibleRootItem();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
// Set up lookup context once to do the element type lookup
|
|
|
|
|
//
|
|
|
|
|
// We're simplifying here by using the root context everywhere
|
|
|
|
|
// (empty node list). However, creating the LookupContext is quite expensive (about 3ms),
|
|
|
|
|
// 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();
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QmlOutlineModelSync syncModel(this);
|
2010-07-19 11:39:41 +02:00
|
|
|
syncModel(m_semanticInfo.document);
|
|
|
|
|
|
|
|
|
|
m_context.clear();
|
2010-07-12 14:45:22 +02:00
|
|
|
|
|
|
|
|
emit updated();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterObjectDefinition(AST::UiObjectDefinition *objDef)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem prototype(this);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
|
|
|
|
const QString id = getId(objDef);
|
2010-07-12 15:51:26 +02:00
|
|
|
if (!id.isEmpty()) {
|
2010-07-16 11:03:42 +02:00
|
|
|
prototype.setText(id);
|
2010-07-12 15:51:26 +02:00
|
|
|
} else {
|
2010-07-19 11:39:41 +02:00
|
|
|
prototype.setText(typeName);
|
2010-07-12 15:51:26 +02:00
|
|
|
}
|
2010-07-19 11:39:41 +02:00
|
|
|
if (!m_typeToIcon.contains(typeName)) {
|
|
|
|
|
m_typeToIcon.insert(typeName, getIcon(objDef));
|
|
|
|
|
}
|
|
|
|
|
prototype.setIcon(m_typeToIcon.value(typeName));
|
2010-07-16 11:03:42 +02:00
|
|
|
prototype.setData(ElementType, ItemTypeRole);
|
2010-07-19 11:39:41 +02:00
|
|
|
prototype.setData(QVariant::fromValue(getLocation(objDef)), SourceLocationRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(static_cast<AST::Node*>(objDef)), NodePointerRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(static_cast<AST::UiQualifiedId*>(objDef->qualifiedTypeNameId)), IdPointerRole);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
|
|
|
|
return enterNode(prototype);
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::leaveObjectDefiniton()
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterScriptBinding(AST::UiScriptBinding *scriptBinding)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem prototype(this);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
prototype.setText(asString(scriptBinding->qualifiedId));
|
|
|
|
|
prototype.setIcon(m_icons->scriptBindingIcon());
|
2010-07-16 11:03:42 +02:00
|
|
|
prototype.setData(PropertyType, ItemTypeRole);
|
2010-07-19 11:39:41 +02:00
|
|
|
prototype.setData(QVariant::fromValue(getLocation(scriptBinding)), SourceLocationRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(static_cast<AST::Node*>(scriptBinding)), NodePointerRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(static_cast<AST::UiQualifiedId*>(scriptBinding->qualifiedId)), IdPointerRole);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
|
|
|
|
return enterNode(prototype);
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::leaveScriptBinding()
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterPublicMember(AST::UiPublicMember *publicMember)
|
|
|
|
|
{
|
|
|
|
|
QmlOutlineItem prototype(this);
|
|
|
|
|
|
|
|
|
|
prototype.setText(publicMember->name->asString());
|
|
|
|
|
prototype.setIcon(m_icons->publicMemberIcon());
|
|
|
|
|
prototype.setData(PropertyType, ItemTypeRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(getLocation(publicMember)), SourceLocationRole);
|
|
|
|
|
prototype.setData(QVariant::fromValue(static_cast<AST::Node*>(publicMember)), NodePointerRole);
|
|
|
|
|
|
|
|
|
|
return enterNode(prototype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leavePublicMember()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlJS::AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
return index.data(NodePointerRole).value<QmlJS::AST::Node*>();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:03:42 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterNode(const QmlOutlineItem &prototype)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
int siblingIndex = m_treePos.last();
|
|
|
|
|
if (siblingIndex == 0) {
|
|
|
|
|
// first child
|
|
|
|
|
if (!m_currentItem->hasChildren()) {
|
|
|
|
|
if (debug)
|
2010-07-16 11:03:42 +02:00
|
|
|
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem *newItem = new QmlOutlineItem(this);
|
2010-07-16 11:03:42 +02:00
|
|
|
newItem->copyValues(prototype);
|
|
|
|
|
newItem->setEditable(false);
|
|
|
|
|
m_currentItem->appendRow(newItem);
|
|
|
|
|
|
|
|
|
|
m_currentItem = newItem;
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(0);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
|
|
|
|
QmlOutlineItem *existingItem = static_cast<QmlOutlineItem*>(m_currentItem);
|
|
|
|
|
existingItem->copyValues(prototype);
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// sibling
|
|
|
|
|
if (m_currentItem->rowCount() <= siblingIndex) {
|
|
|
|
|
if (debug)
|
2010-07-16 11:03:42 +02:00
|
|
|
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem *newItem = new QmlOutlineItem(this);
|
2010-07-16 11:03:42 +02:00
|
|
|
newItem->copyValues(prototype);
|
|
|
|
|
newItem->setEditable(false);
|
|
|
|
|
m_currentItem->appendRow(newItem);
|
|
|
|
|
m_currentItem = newItem;
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(siblingIndex);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
|
|
|
|
QmlOutlineItem *existingItem = static_cast<QmlOutlineItem*>(m_currentItem);
|
|
|
|
|
existingItem->copyValues(prototype);
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_treePos.append(0);
|
|
|
|
|
|
2010-07-16 11:03:42 +02:00
|
|
|
return m_currentItem->index();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveNode()
|
|
|
|
|
{
|
|
|
|
|
int lastIndex = m_treePos.takeLast();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastIndex > 0) {
|
|
|
|
|
// element has children
|
|
|
|
|
if (lastIndex < m_currentItem->rowCount()) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel - removeRows from " << m_currentItem->text() << lastIndex << m_currentItem->rowCount() - lastIndex;
|
|
|
|
|
m_currentItem->removeRows(lastIndex, m_currentItem->rowCount() - lastIndex);
|
|
|
|
|
}
|
|
|
|
|
m_currentItem = parentItem();
|
|
|
|
|
} else {
|
|
|
|
|
if (m_currentItem->hasChildren()) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel - removeRows from " << m_currentItem->text() << 0 << m_currentItem->rowCount();
|
|
|
|
|
m_currentItem->removeRows(0, m_currentItem->rowCount());
|
|
|
|
|
}
|
|
|
|
|
m_currentItem = parentItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_treePos.last()++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItem *QmlOutlineModel::parentItem()
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *parent = m_currentItem->parent();
|
|
|
|
|
if (!parent)
|
|
|
|
|
parent = invisibleRootItem();
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
|
|
|
|
|
QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
|
|
|
|
|
{
|
|
|
|
|
QString text;
|
|
|
|
|
for (; id; id = id->next) {
|
|
|
|
|
if (id->name)
|
|
|
|
|
text += id->name->asString();
|
|
|
|
|
else
|
|
|
|
|
text += QLatin1Char('?');
|
|
|
|
|
|
|
|
|
|
if (id->next)
|
|
|
|
|
text += QLatin1Char('.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember) {
|
|
|
|
|
AST::SourceLocation location;
|
|
|
|
|
location.offset = objMember->firstSourceLocation().offset;
|
|
|
|
|
location.length = objMember->lastSourceLocation().offset
|
|
|
|
|
- objMember->firstSourceLocation().offset
|
|
|
|
|
+ objMember->lastSourceLocation().length;
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon QmlOutlineModel::getIcon(AST::UiObjectDefinition *objDef) {
|
|
|
|
|
const QmlJS::Interpreter::Value *value = m_context->evaluate(objDef->qualifiedTypeNameId);
|
|
|
|
|
|
|
|
|
|
if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
|
|
|
|
|
do {
|
|
|
|
|
QString module;
|
|
|
|
|
QString typeName;
|
|
|
|
|
if (const Interpreter::QmlObjectValue *qmlObjectValue =
|
|
|
|
|
dynamic_cast<const Interpreter::QmlObjectValue*>(objectValue)) {
|
|
|
|
|
module = qmlObjectValue->packageName();
|
|
|
|
|
}
|
|
|
|
|
typeName = objectValue->className();
|
|
|
|
|
|
|
|
|
|
QIcon icon = m_icons->icon(module, typeName);
|
|
|
|
|
if (! icon.isNull())
|
|
|
|
|
return icon;
|
|
|
|
|
|
|
|
|
|
objectValue = objectValue->prototype(m_context->context());
|
|
|
|
|
} while (objectValue);
|
|
|
|
|
}
|
|
|
|
|
return QIcon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString QmlOutlineModel::getId(AST::UiObjectDefinition *objDef) {
|
|
|
|
|
QString id;
|
|
|
|
|
for (AST::UiObjectMemberList *it = objDef->initializer->members; it; it = it->next) {
|
|
|
|
|
if (AST::UiScriptBinding *binding = dynamic_cast<AST::UiScriptBinding*>(it->member)) {
|
|
|
|
|
if (binding->qualifiedId->name->asString() == "id") {
|
|
|
|
|
AST::ExpressionStatement *expr = dynamic_cast<AST::ExpressionStatement*>(binding->statement);
|
|
|
|
|
if (!expr)
|
|
|
|
|
continue;
|
|
|
|
|
AST::IdentifierExpression *idExpr = dynamic_cast<AST::IdentifierExpression*>(expr->expression);
|
|
|
|
|
if (!idExpr)
|
|
|
|
|
continue;
|
|
|
|
|
id = idExpr->name->asString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSEditor
|