2010-07-12 09:44:42 +02:00
|
|
|
#include "qmloutlinemodel.h"
|
2010-07-19 11:39:41 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-19 14:28:53 +02:00
|
|
|
#include "qmljsrefactoringchanges.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-19 14:28:53 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
|
|
|
|
#include <qmljs/qmljsrewriter.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
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) :
|
2010-08-25 13:21:38 +02:00
|
|
|
m_outlineModel(model)
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
2010-07-19 14:28:53 +02:00
|
|
|
Qt::ItemFlags defaultFlags = flags();
|
|
|
|
|
setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags);
|
|
|
|
|
setEditable(false);
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant QmlOutlineItem::data(int role) const
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::ToolTipRole) {
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::SourceLocation location = m_outlineModel->sourceLocation(index());
|
|
|
|
|
AST::UiQualifiedId *uiQualifiedId = m_outlineModel->idNode(index());
|
|
|
|
|
if (!uiQualifiedId || !location.isValid())
|
2010-07-19 11:39:41 +02:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.astPath(location.begin());
|
2010-08-26 10:50:00 +02:00
|
|
|
LookupContext::Ptr lookupContext = m_outlineModel->m_semanticInfo.lookupContext(astPath);
|
2010-07-19 11:39:41 +02:00
|
|
|
const Interpreter::Value *value = lookupContext->evaluate(uiQualifiedId);
|
|
|
|
|
|
|
|
|
|
return prettyPrint(value, lookupContext->context());
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
if (role == Qt::DecorationRole) {
|
|
|
|
|
return m_outlineModel->icon(index());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
return QStandardItem::data(role);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
int QmlOutlineItem::type() const
|
|
|
|
|
{
|
|
|
|
|
return UserType;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
void QmlOutlineItem::setItemData(const QMap<int, QVariant> &roles)
|
|
|
|
|
{
|
|
|
|
|
QMap<int,QVariant>::const_iterator iter(roles.constBegin());
|
|
|
|
|
while (iter != roles.constEnd()) {
|
|
|
|
|
setData(iter.value(), iter.key());
|
|
|
|
|
iter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QString QmlOutlineItem::prettyPrint(const Interpreter::Value *value, const Interpreter::Context *context) const
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
|
|
|
|
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-19 14:28:53 +02:00
|
|
|
/**
|
|
|
|
|
Returns mapping of every UiObjectMember object to it's direct UiObjectMember parent object.
|
|
|
|
|
*/
|
|
|
|
|
class ObjectMemberParentVisitor : public AST::Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QHash<AST::UiObjectMember*,AST::UiObjectMember*> operator()(Document::Ptr doc) {
|
|
|
|
|
parent.clear();
|
|
|
|
|
if (doc && doc->ast())
|
|
|
|
|
doc->ast()->accept(this);
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QHash<AST::UiObjectMember*,AST::UiObjectMember*> parent;
|
|
|
|
|
QList<AST::UiObjectMember *> stack;
|
|
|
|
|
|
|
|
|
|
bool preVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (AST::UiObjectMember *objMember = node->uiObjectMemberCast())
|
|
|
|
|
stack.append(objMember);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void postVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (AST::UiObjectMember *objMember = node->uiObjectMemberCast()) {
|
|
|
|
|
stack.removeLast();
|
|
|
|
|
if (!stack.isEmpty()) {
|
|
|
|
|
parent.insert(objMember, stack.last());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
bool visit(AST::UiObjectBinding *objBinding)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_model->enterObjectBinding(objBinding);
|
|
|
|
|
m_nodeToIndex.insert(objBinding, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiObjectBinding * /*objBinding*/)
|
|
|
|
|
{
|
|
|
|
|
m_model->leaveObjectBinding();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool visit(AST::UiArrayBinding *arrayBinding)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_model->enterArrayBinding(arrayBinding);
|
|
|
|
|
m_nodeToIndex.insert(arrayBinding, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiArrayBinding * /*arrayBinding*/)
|
|
|
|
|
{
|
|
|
|
|
m_model->leaveArrayBinding();
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2010-08-25 13:21:38 +02:00
|
|
|
Icons::instance()->setIconFilesPath(resourcePath + "/qmlicons");
|
2010-07-19 14:28:53 +02:00
|
|
|
|
|
|
|
|
// TODO: Maybe add a Copy Action?
|
|
|
|
|
setSupportedDragActions(Qt::MoveAction);
|
|
|
|
|
setItemPrototype(new QmlOutlineItem(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList QmlOutlineModel::mimeTypes() const
|
|
|
|
|
{
|
|
|
|
|
QStringList types;
|
|
|
|
|
types << QLatin1String("application/x-qtcreator-qmloutlinemodel");
|
|
|
|
|
return types;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
|
|
|
|
|
{
|
|
|
|
|
if (indexes.count() <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
|
QMimeData *data = new QMimeData();
|
|
|
|
|
QString format = types.at(0);
|
|
|
|
|
QByteArray encoded;
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
|
stream << indexes.size();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < indexes.size(); ++i) {
|
2010-08-09 17:41:22 +02:00
|
|
|
QModelIndex index = indexes.at(i);
|
|
|
|
|
|
|
|
|
|
QList<int> rowPath;
|
|
|
|
|
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
|
|
|
|
|
rowPath.prepend(i.row());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream << rowPath;
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
data->setData(format, encoded);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex &parent)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << __FUNCTION__ << row << parent;
|
|
|
|
|
|
|
|
|
|
// check if the action is supported
|
|
|
|
|
if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// We cannot reparent outside of the root item
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// check if the format is supported
|
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
|
if (types.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
QString format = types.at(0);
|
|
|
|
|
if (!data->hasFormat(format))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// decode and insert
|
|
|
|
|
QByteArray encoded = data->data(format);
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
|
int indexSize;
|
|
|
|
|
stream >> indexSize;
|
|
|
|
|
QList<QmlOutlineItem*> itemsToMove;
|
|
|
|
|
for (int i = 0; i < indexSize; ++i) {
|
2010-08-09 17:41:22 +02:00
|
|
|
QList<int> rowPath;
|
|
|
|
|
stream >> rowPath;
|
|
|
|
|
|
|
|
|
|
QModelIndex index;
|
|
|
|
|
foreach (int row, rowPath) {
|
|
|
|
|
index = this->index(row, 0, index);
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemsToMove << static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlOutlineItem *targetItem = static_cast<QmlOutlineItem*>(itemFromIndex(parent));
|
|
|
|
|
reparentNodes(targetItem, row, itemsToMove);
|
2010-08-09 17:41:22 +02:00
|
|
|
|
|
|
|
|
// Prevent view from calling removeRow() on it's own
|
2010-07-19 14:28:53 +02:00
|
|
|
return false;
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
Document::Ptr QmlOutlineModel::document() const
|
2010-07-13 11:18:42 +02:00
|
|
|
{
|
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
|
|
|
|
|
//
|
2010-08-26 10:50:00 +02:00
|
|
|
// We're simplifying here by using the root context everywhere; should be
|
|
|
|
|
// ok since there is AFAIK no way to introduce new type names in a sub-context.
|
|
|
|
|
m_context = semanticInfo.lookupContext();
|
2010-07-19 11:39:41 +02:00
|
|
|
m_typeToIcon.clear();
|
2010-08-25 13:21:38 +02:00
|
|
|
m_itemToNode.clear();
|
|
|
|
|
m_itemToIdNode.clear();
|
|
|
|
|
m_itemToIcon.clear();
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-08-25 12:24:47 +02:00
|
|
|
|
2010-08-25 13:21:38 +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
|
|
|
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
2010-07-22 10:12:04 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> data;
|
2010-08-31 10:57:03 +02:00
|
|
|
AST::UiQualifiedId *idNode = 0;
|
|
|
|
|
QIcon icon;
|
2010-08-25 13:21:38 +02:00
|
|
|
|
|
|
|
|
if (typeName.at(0).isUpper()) {
|
|
|
|
|
data.insert(ItemTypeRole, ElementType);
|
2010-09-03 15:26:02 +02:00
|
|
|
data.insert(AnnotationRole, getAnnotation(objDef->initializer));
|
2010-08-31 10:57:03 +02:00
|
|
|
if (!m_typeToIcon.contains(typeName)) {
|
|
|
|
|
m_typeToIcon.insert(typeName, getIcon(objDef->qualifiedTypeNameId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
icon = m_typeToIcon.value(typeName);
|
|
|
|
|
idNode = objDef->qualifiedTypeNameId;
|
2010-08-25 13:21:38 +02:00
|
|
|
} else {
|
|
|
|
|
// it's a grouped propery like 'anchors'
|
|
|
|
|
data.insert(ItemTypeRole, NonElementBindingType);
|
2010-08-31 10:57:03 +02:00
|
|
|
|
|
|
|
|
icon = m_icons->scriptBindingIcon();
|
2010-08-25 13:21:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.insert(Qt::DisplayRole, typeName);
|
|
|
|
|
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(data, objDef, idNode, icon);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
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-08-10 16:33:23 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterObjectBinding(AST::UiObjectBinding *objBinding)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> bindingData;
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
bindingData.insert(Qt::DisplayRole, asString(objBinding->qualifiedId));
|
|
|
|
|
bindingData.insert(ItemTypeRole, ElementBindingType);
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *bindingItem = enterNode(bindingData, objBinding, objBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-08-10 16:33:23 +02:00
|
|
|
|
|
|
|
|
const QString typeName = asString(objBinding->qualifiedTypeNameId);
|
|
|
|
|
if (!m_typeToIcon.contains(typeName)) {
|
|
|
|
|
m_typeToIcon.insert(typeName, getIcon(objBinding->qualifiedTypeNameId));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
objectData.insert(Qt::DisplayRole, typeName);
|
|
|
|
|
objectData.insert(AnnotationRole, getAnnotation(objBinding->initializer));
|
|
|
|
|
objectData.insert(ItemTypeRole, ElementType);
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
enterNode(objectData, objBinding, objBinding->qualifiedTypeNameId, m_typeToIcon.value(typeName));
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return bindingItem->index();
|
2010-08-10 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveObjectBinding()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex QmlOutlineModel::enterArrayBinding(AST::UiArrayBinding *arrayBinding)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> bindingData;
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
bindingData.insert(Qt::DisplayRole, asString(arrayBinding->qualifiedId));
|
|
|
|
|
bindingData.insert(ItemTypeRole, ElementBindingType);
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(bindingData, arrayBinding, arrayBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
2010-08-10 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveArrayBinding()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterScriptBinding(AST::UiScriptBinding *scriptBinding)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
|
|
|
|
|
objectData.insert(Qt::DisplayRole, asString(scriptBinding->qualifiedId));
|
|
|
|
|
objectData.insert(AnnotationRole, getAnnotation(scriptBinding->statement));
|
|
|
|
|
objectData.insert(ItemTypeRole, NonElementBindingType);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(objectData, scriptBinding, scriptBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
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)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-08-02 15:57:42 +02:00
|
|
|
if (publicMember->name)
|
2010-08-25 13:21:38 +02:00
|
|
|
objectData.insert(Qt::DisplayRole, publicMember->name->asString());
|
|
|
|
|
objectData.insert(AnnotationRole, getAnnotation(publicMember->expression));
|
|
|
|
|
objectData.insert(ItemTypeRole, NonElementBindingType);
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(objectData, publicMember, 0, m_icons->publicMemberIcon());
|
2010-08-25 13:21:38 +02:00
|
|
|
|
|
|
|
|
return item->index();
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leavePublicMember()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index) const
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
|
2010-07-19 11:39:41 +02:00
|
|
|
if (index.isValid()) {
|
2010-07-19 14:28:53 +02:00
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
2010-08-25 13:21:38 +02:00
|
|
|
QTC_ASSERT(m_itemToNode.contains(item), return 0);
|
|
|
|
|
return m_itemToNode.value(item);
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
AST::SourceLocation location;
|
2010-08-26 18:35:30 +02:00
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return location);
|
2010-08-25 13:21:38 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *QmlOutlineModel::enterNode(QMap<int, QVariant> data, AST::Node *node, AST::UiQualifiedId *idNode, const QIcon &icon)
|
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
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
m_itemToNode.insert(newItem, node);
|
|
|
|
|
m_itemToIdNode.insert(newItem, idNode);
|
|
|
|
|
m_itemToIcon.insert(newItem, icon);
|
|
|
|
|
newItem->setItemData(data);
|
|
|
|
|
|
|
|
|
|
m_currentItem->appendRow(newItem);
|
2010-07-16 11:03:42 +02:00
|
|
|
m_currentItem = newItem;
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(0);
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(m_currentItem);
|
|
|
|
|
|
|
|
|
|
m_itemToNode.insert(item, node);
|
|
|
|
|
m_itemToIdNode.insert(item, idNode);
|
|
|
|
|
m_itemToIcon.insert(item, icon);
|
|
|
|
|
item->setItemData(data);
|
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-08-31 10:57:03 +02:00
|
|
|
|
|
|
|
|
m_itemToNode.insert(newItem, node);
|
|
|
|
|
m_itemToIdNode.insert(newItem, idNode);
|
|
|
|
|
m_itemToIcon.insert(newItem, icon);
|
|
|
|
|
newItem->setItemData(data);
|
|
|
|
|
|
2010-07-16 11:03:42 +02:00
|
|
|
m_currentItem->appendRow(newItem);
|
|
|
|
|
m_currentItem = newItem;
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(siblingIndex);
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(m_currentItem);
|
|
|
|
|
|
|
|
|
|
m_itemToNode.insert(item, node);
|
|
|
|
|
m_itemToIdNode.insert(item, idNode);
|
|
|
|
|
m_itemToIcon.insert(item, icon);
|
|
|
|
|
item->setItemData(data);
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
m_treePos.append(0);
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return static_cast<QmlOutlineItem*>(m_currentItem);
|
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()++;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<QmlOutlineItem*> itemsToMove)
|
|
|
|
|
{
|
|
|
|
|
Utils::ChangeSet changeSet;
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::UiObjectMember *targetObjectMember = m_itemToNode.value(targetItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
if (!targetObjectMember)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<Utils::ChangeSet::Range> changedRanges;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < itemsToMove.size(); ++i) {
|
|
|
|
|
QmlOutlineItem *outlineItem = itemsToMove.at(i);
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::UiObjectMember *sourceObjectMember = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
if (!sourceObjectMember)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool insertionOrderSpecified = true;
|
|
|
|
|
AST::UiObjectMember *memberToInsertAfter = 0;
|
|
|
|
|
{
|
|
|
|
|
if (row == -1) {
|
|
|
|
|
insertionOrderSpecified = false;
|
|
|
|
|
} else if (row > 0) {
|
|
|
|
|
QmlOutlineItem *outlineItem = static_cast<QmlOutlineItem*>(targetItem->child(row - 1));
|
2010-08-25 13:21:38 +02:00
|
|
|
memberToInsertAfter = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::ChangeSet::Range range;
|
|
|
|
|
if (sourceObjectMember)
|
|
|
|
|
moveObjectMember(sourceObjectMember, targetObjectMember, insertionOrderSpecified,
|
|
|
|
|
memberToInsertAfter, &changeSet, &range);
|
|
|
|
|
changedRanges << range;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), m_semanticInfo.snapshot);
|
2010-08-12 13:46:18 +02:00
|
|
|
TextEditor::RefactoringFile file = refactoring.file(m_semanticInfo.document->fileName());
|
|
|
|
|
file.change(changeSet);
|
2010-07-19 14:28:53 +02:00
|
|
|
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
|
2010-08-12 13:46:18 +02:00
|
|
|
file.indent(range);
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
|
|
|
|
|
AST::UiObjectMember *newParent,
|
|
|
|
|
bool insertionOrderSpecified,
|
|
|
|
|
AST::UiObjectMember *insertAfter,
|
|
|
|
|
Utils::ChangeSet *changeSet,
|
|
|
|
|
Utils::ChangeSet::Range *addedRange)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(toMove);
|
|
|
|
|
Q_ASSERT(newParent);
|
|
|
|
|
Q_ASSERT(changeSet);
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QHash<AST::UiObjectMember*, AST::UiObjectMember*> parentMembers;
|
2010-07-19 14:28:53 +02:00
|
|
|
{
|
|
|
|
|
ObjectMemberParentVisitor visitor;
|
|
|
|
|
parentMembers = visitor(m_semanticInfo.document);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::UiObjectMember *oldParent = parentMembers.value(toMove);
|
|
|
|
|
Q_ASSERT(oldParent);
|
|
|
|
|
|
|
|
|
|
// make sure that target parent is actually a direct ancestor of target sibling
|
|
|
|
|
if (insertAfter)
|
|
|
|
|
newParent = parentMembers.value(insertAfter);
|
|
|
|
|
|
|
|
|
|
const QString documentText = m_semanticInfo.document->source();
|
|
|
|
|
|
2010-08-12 18:05:50 +02:00
|
|
|
Rewriter rewriter(documentText, changeSet, QStringList());
|
2010-07-19 14:28:53 +02:00
|
|
|
|
2010-08-12 18:05:50 +02:00
|
|
|
if (AST::UiObjectDefinition *objDefinition = AST::cast<AST::UiObjectDefinition*>(newParent)) {
|
2010-07-19 14:28:53 +02:00
|
|
|
AST::UiObjectMemberList *listInsertAfter = 0;
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
if (insertAfter) {
|
|
|
|
|
listInsertAfter = objDefinition->initializer->members;
|
|
|
|
|
while (listInsertAfter && (listInsertAfter->member != insertAfter))
|
|
|
|
|
listInsertAfter = listInsertAfter->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 09:51:07 +02:00
|
|
|
if (AST::UiScriptBinding *moveScriptBinding = AST::cast<AST::UiScriptBinding*>(toMove)) {
|
2010-07-19 14:28:53 +02:00
|
|
|
const QString propertyName = asString(moveScriptBinding->qualifiedId);
|
|
|
|
|
QString propertyValue;
|
|
|
|
|
{
|
|
|
|
|
const int offset = moveScriptBinding->statement->firstSourceLocation().begin();
|
|
|
|
|
const int length = moveScriptBinding->statement->lastSourceLocation().end() - offset;
|
|
|
|
|
propertyValue = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
Rewriter::BindingType bindingType = Rewriter::ScriptBinding;
|
|
|
|
|
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType, listInsertAfter);
|
|
|
|
|
} else {
|
|
|
|
|
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QString strToMove;
|
|
|
|
|
{
|
|
|
|
|
const int offset = toMove->firstSourceLocation().begin();
|
|
|
|
|
const int length = toMove->lastSourceLocation().end() - offset;
|
|
|
|
|
strToMove = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove, listInsertAfter);
|
|
|
|
|
} else {
|
|
|
|
|
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-12 18:05:50 +02:00
|
|
|
} else if (AST::UiArrayBinding *arrayBinding = AST::cast<AST::UiArrayBinding*>(newParent)) {
|
|
|
|
|
AST::UiArrayMemberList *listInsertAfter = 0;
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
if (insertAfter) {
|
|
|
|
|
listInsertAfter = arrayBinding->members;
|
|
|
|
|
while (listInsertAfter && (listInsertAfter->member != insertAfter))
|
|
|
|
|
listInsertAfter = listInsertAfter->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QString strToMove;
|
|
|
|
|
{
|
|
|
|
|
const int offset = toMove->firstSourceLocation().begin();
|
|
|
|
|
const int length = toMove->lastSourceLocation().end() - offset;
|
|
|
|
|
strToMove = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
*addedRange = rewriter.addObject(arrayBinding, strToMove, listInsertAfter);
|
|
|
|
|
} else {
|
|
|
|
|
*addedRange = rewriter.addObject(arrayBinding, strToMove);
|
|
|
|
|
}
|
2010-09-07 14:34:38 +02:00
|
|
|
} else if (AST::cast<AST::UiObjectBinding*>(newParent)) {
|
2010-08-12 18:05:50 +02:00
|
|
|
qDebug() << "TODO: Reparent to UiObjectBinding";
|
|
|
|
|
return;
|
2010-07-19 14:28:53 +02:00
|
|
|
// target is a property
|
2010-08-12 18:05:50 +02:00
|
|
|
} else {
|
|
|
|
|
return;
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
2010-08-12 18:05:50 +02:00
|
|
|
|
|
|
|
|
rewriter.removeObjectMember(toMove, oldParent);
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QIcon QmlOutlineModel::getIcon(AST::UiQualifiedId *qualifiedId) {
|
2010-08-25 13:21:38 +02:00
|
|
|
const Interpreter::Value *value = m_context->evaluate(qualifiedId);
|
2010-07-19 11:39:41 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::UiObjectInitializer *objectInitializer) {
|
|
|
|
|
const QHash<QString,QString> bindings = getScriptBindings(objectInitializer);
|
2010-08-10 15:11:14 +02:00
|
|
|
|
|
|
|
|
if (bindings.contains("id"))
|
|
|
|
|
return bindings.value("id");
|
|
|
|
|
|
|
|
|
|
if (bindings.contains("name"))
|
|
|
|
|
return bindings.value("name");
|
|
|
|
|
|
|
|
|
|
if (bindings.contains("target"))
|
|
|
|
|
return bindings.value("target");
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::Statement *statement)
|
2010-08-12 15:10:19 +02:00
|
|
|
{
|
|
|
|
|
if (AST::ExpressionStatement *expr = AST::cast<AST::ExpressionStatement*>(statement))
|
|
|
|
|
return getAnnotation(expr->expression);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::ExpressionNode *expression)
|
2010-08-12 15:10:19 +02:00
|
|
|
{
|
|
|
|
|
if (!expression)
|
|
|
|
|
return QString();
|
|
|
|
|
QString source = m_semanticInfo.document->source();
|
|
|
|
|
return source.mid(expression->firstSourceLocation().begin(),
|
|
|
|
|
expression->lastSourceLocation().end() - expression->firstSourceLocation().begin());
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QHash<QString,QString> QmlOutlineModel::getScriptBindings(AST::UiObjectInitializer *objectInitializer) {
|
2010-08-10 15:11:14 +02:00
|
|
|
QHash <QString,QString> scriptBindings;
|
2010-08-10 16:33:23 +02:00
|
|
|
for (AST::UiObjectMemberList *it = objectInitializer->members; it; it = it->next) {
|
2010-07-22 09:51:07 +02:00
|
|
|
if (AST::UiScriptBinding *binding = AST::cast<AST::UiScriptBinding*>(it->member)) {
|
2010-08-10 15:11:14 +02:00
|
|
|
const QString bindingName = asString(binding->qualifiedId);
|
2010-08-12 15:10:19 +02:00
|
|
|
scriptBindings.insert(bindingName, getAnnotation(binding->statement));
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-10 15:11:14 +02:00
|
|
|
return scriptBindings;
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSEditor
|