2011-02-18 11:47:15 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-18 11:47:15 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-02-18 11:47:15 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
#ifndef QMLOUTLINEMODEL_H
|
|
|
|
|
#define QMLOUTLINEMODEL_H
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-19 14:28:53 +02:00
|
|
|
#include <utils/changeset.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <qmljs/qmljsdocument.h>
|
|
|
|
|
#include <qmljs/qmljsicons.h>
|
2010-07-19 11:39:41 +02:00
|
|
|
#include <qmljs/qmljslookupcontext.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2011-01-24 12:29:48 +01:00
|
|
|
#include <QtGui/QStandardItemModel>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
namespace QmlJS {
|
|
|
|
|
namespace Interpreter {
|
|
|
|
|
class Value;
|
|
|
|
|
class Context;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
class QmlOutlineModel;
|
|
|
|
|
|
2010-07-16 11:03:42 +02:00
|
|
|
class QmlOutlineItem : public QStandardItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem(QmlOutlineModel *model);
|
|
|
|
|
|
2010-08-12 14:37:52 +02:00
|
|
|
// QStandardItem
|
2010-07-19 11:39:41 +02:00
|
|
|
QVariant data(int role = Qt::UserRole + 1) const;
|
2010-07-19 14:28:53 +02:00
|
|
|
int type() const;
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
void setItemData(const QMap<int, QVariant> &roles);
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
private:
|
2010-08-25 11:51:34 +02:00
|
|
|
QString prettyPrint(const QmlJS::Interpreter::Value *value, const QmlJS::Interpreter::Context *context) const;
|
2010-07-19 11:39:41 +02:00
|
|
|
|
|
|
|
|
QmlOutlineModel *m_outlineModel;
|
2010-07-16 11:03:42 +02:00
|
|
|
};
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
class QmlOutlineModel : public QStandardItemModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
enum CustomRoles {
|
2010-08-25 13:21:38 +02:00
|
|
|
ItemTypeRole = Qt::UserRole + 1,
|
|
|
|
|
ElementTypeRole,
|
2010-08-10 14:33:13 +02:00
|
|
|
AnnotationRole
|
2010-07-14 16:46:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ItemTypes {
|
|
|
|
|
ElementType,
|
2010-10-30 21:54:23 +02:00
|
|
|
ElementBindingType, // might contain elements as children
|
2010-08-12 12:47:25 +02:00
|
|
|
NonElementBindingType // can be filtered out
|
2010-07-12 09:44:42 +02:00
|
|
|
};
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
QmlOutlineModel(QmlJSTextEditorWidget *editor);
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
// QStandardItemModel
|
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
|
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
|
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
2010-10-07 15:25:05 +02:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
2010-07-19 14:28:53 +02:00
|
|
|
|
2010-07-13 11:18:42 +02:00
|
|
|
QmlJS::Document::Ptr document() const;
|
2010-07-19 11:39:41 +02:00
|
|
|
void update(const SemanticInfo &semanticInfo);
|
2010-08-25 13:21:38 +02:00
|
|
|
|
|
|
|
|
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;
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-07-19 14:02:17 +02:00
|
|
|
signals:
|
|
|
|
|
void updated();
|
|
|
|
|
|
|
|
|
|
private:
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex enterObjectDefinition(QmlJS::AST::UiObjectDefinition *objectDefinition);
|
|
|
|
|
void leaveObjectDefiniton();
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QModelIndex enterObjectBinding(QmlJS::AST::UiObjectBinding *objectBinding);
|
|
|
|
|
void leaveObjectBinding();
|
|
|
|
|
|
|
|
|
|
QModelIndex enterArrayBinding(QmlJS::AST::UiArrayBinding *arrayBinding);
|
|
|
|
|
void leaveArrayBinding();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex enterScriptBinding(QmlJS::AST::UiScriptBinding *scriptBinding);
|
|
|
|
|
void leaveScriptBinding();
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex enterPublicMember(QmlJS::AST::UiPublicMember *publicMember);
|
|
|
|
|
void leavePublicMember();
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-09-27 15:36:50 +02:00
|
|
|
QModelIndex enterFunctionDeclaration(QmlJS::AST::FunctionDeclaration *functionDeclaration);
|
|
|
|
|
void leaveFunctionDeclaration();
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
private:
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *enterNode(QMap<int, QVariant> data, QmlJS::AST::Node *node, QmlJS::AST::UiQualifiedId *idNode, const QIcon &icon);
|
2010-07-12 09:44:42 +02:00
|
|
|
void leaveNode();
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
void reparentNodes(QmlOutlineItem *targetItem, int targetRow, QList<QmlOutlineItem*> itemsToMove);
|
|
|
|
|
void moveObjectMember(QmlJS::AST::UiObjectMember *toMove, QmlJS::AST::UiObjectMember *newParent,
|
|
|
|
|
bool insertionOrderSpecified, QmlJS::AST::UiObjectMember *insertAfter,
|
|
|
|
|
Utils::ChangeSet *changeSet, Utils::ChangeSet::Range *addedRange);
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QStandardItem *parentItem();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
static QString asString(QmlJS::AST::UiQualifiedId *id);
|
|
|
|
|
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::UiObjectMember *objMember);
|
2010-09-27 15:36:50 +02:00
|
|
|
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::ExpressionNode *exprNode);
|
2010-08-10 16:33:23 +02:00
|
|
|
QIcon getIcon(QmlJS::AST::UiQualifiedId *objDef);
|
2010-08-10 15:11:14 +02:00
|
|
|
|
2010-08-12 15:10:19 +02:00
|
|
|
QString getAnnotation(QmlJS::AST::UiObjectInitializer *objInitializer);
|
|
|
|
|
QString getAnnotation(QmlJS::AST::Statement *statement);
|
|
|
|
|
QString getAnnotation(QmlJS::AST::ExpressionNode *expression);
|
|
|
|
|
QHash<QString,QString> getScriptBindings(QmlJS::AST::UiObjectInitializer *objInitializer);
|
2010-07-19 11:39:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
SemanticInfo m_semanticInfo;
|
2010-07-12 09:44:42 +02:00
|
|
|
QList<int> m_treePos;
|
|
|
|
|
QStandardItem *m_currentItem;
|
2010-07-13 17:05:47 +02:00
|
|
|
QmlJS::Icons *m_icons;
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QHash<QString, QIcon> m_typeToIcon;
|
2010-08-25 13:21:38 +02:00
|
|
|
QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
|
|
|
|
|
QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;
|
|
|
|
|
QHash<QmlOutlineItem*,QmlJS::AST::UiQualifiedId*> m_itemToIdNode;
|
2011-02-21 16:02:26 +01:00
|
|
|
QmlJSTextEditorWidget *m_textEditor;
|
2010-08-25 13:21:38 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
friend class QmlOutlineModelSync;
|
2010-07-19 11:39:41 +02:00
|
|
|
friend class QmlOutlineItem;
|
2010-07-12 09:44:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSEditor
|
|
|
|
|
|
|
|
|
|
#endif // QMLOUTLINEMODEL_H
|