2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-18 11:47:15 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2014-01-30 16:10:23 +01:00
|
|
|
#include "qmljseditordocument.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>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStandardItemModel>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
namespace QmlJS {
|
|
|
|
|
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:
|
2011-08-08 12:47:49 +02:00
|
|
|
QString prettyPrint(const QmlJS::Value *value, const QmlJS::ContextPtr &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
|
|
|
};
|
|
|
|
|
|
2014-06-29 17:34:09 +03:00
|
|
|
QmlOutlineModel(QmlJSEditorDocument *document);
|
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;
|
2014-08-28 17:33:47 +02:00
|
|
|
Qt::DropActions supportedDragActions() const;
|
2017-12-04 11:54:07 +01:00
|
|
|
Qt::DropActions supportedDropActions() const;
|
2010-07-19 14:28:53 +02:00
|
|
|
|
2010-07-13 11:18:42 +02:00
|
|
|
QmlJS::Document::Ptr document() const;
|
2012-04-12 15:51:56 +02:00
|
|
|
void update(const QmlJSTools::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();
|
|
|
|
|
|
2014-12-14 21:13:35 -05:00
|
|
|
QModelIndex enterFieldMemberExpression(QmlJS::AST::FieldMemberExpression *expression,
|
|
|
|
|
QmlJS::AST::FunctionExpression *functionExpression);
|
|
|
|
|
void leaveFieldMemberExpression();
|
|
|
|
|
|
2018-10-16 15:32:58 +02:00
|
|
|
QModelIndex enterTestCase(QmlJS::AST::ObjectPattern *objectLiteral);
|
2011-07-27 18:10:00 +10:00
|
|
|
void leaveTestCase();
|
|
|
|
|
|
2018-10-16 15:32:58 +02:00
|
|
|
QModelIndex enterTestCaseProperties(QmlJS::AST::PatternPropertyList *propertyAssignmentList);
|
2011-07-27 18:10:00 +10:00
|
|
|
void leaveTestCaseProperties();
|
|
|
|
|
|
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);
|
2018-10-16 15:32:58 +02:00
|
|
|
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternProperty *propertyNode);
|
|
|
|
|
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::PatternPropertyList *propertyNode);
|
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
|
|
|
|
|
|
|
|
|
2012-04-12 15:51:56 +02:00
|
|
|
QmlJSTools::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;
|
2014-01-30 16:10:23 +01:00
|
|
|
QmlJSEditorDocument *m_editorDocument;
|
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
|