Qml Outline: Support rearrangement of the items via drag&drop

This commit is contained in:
Kai Koehne
2010-07-19 14:28:53 +02:00
parent 2e949c7015
commit e708eb3d83
3 changed files with 316 additions and 16 deletions

View File

@@ -2,6 +2,7 @@
#define QMLOUTLINEMODEL_H
#include "qmljseditor.h"
#include <utils/changeset.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsicons.h>
#include <qmljs/qmljslookupcontext.h>
@@ -27,6 +28,16 @@ public:
//QStandardItem
QVariant data(int role = Qt::UserRole + 1) const;
int type() const;
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
@@ -34,8 +45,11 @@ private:
QString prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Context *context) const;
QmlOutlineModel *m_outlineModel;
QmlJS::AST::Node *m_node;
QmlJS::AST::UiQualifiedId *m_idNode;
};
class QmlOutlineModel : public QStandardItemModel
{
Q_OBJECT
@@ -44,8 +58,6 @@ public:
enum CustomRoles {
SourceLocationRole = Qt::UserRole + 1,
ItemTypeRole,
NodePointerRole,
IdPointerRole
};
enum ItemTypes {
@@ -55,6 +67,11 @@ public:
QmlOutlineModel(QObject *parent = 0);
// 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);
QmlJS::Document::Ptr document() const;
void update(const SemanticInfo &semanticInfo);
QmlJS::AST::Node *nodeForIndex(const QModelIndex &index);
@@ -76,6 +93,11 @@ private:
QModelIndex enterNode(const QmlOutlineItem &prototype);
void leaveNode();
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);
QStandardItem *parentItem();
static QString asString(QmlJS::AST::UiQualifiedId *id);
@@ -100,7 +122,5 @@ private:
} // namespace QmlJSEditor
Q_DECLARE_METATYPE(QmlJS::AST::SourceLocation);
Q_DECLARE_METATYPE(QmlJS::AST::Node*);
Q_DECLARE_METATYPE(QmlJS::AST::UiQualifiedId*);
#endif // QMLOUTLINEMODEL_H