diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-07-08 11:32:45 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-07-08 14:02:51 +0200 |
commit | 02923cf2580ece7f1680059a3ed99f326b5dc724 (patch) | |
tree | dc0d5110396413fd690eb8bce20d4dce1fa863c6 /src/plugins/qmljseditor/qmljsoutline.h | |
parent | 1541dec6f34a6cbcec44391f87de2a7c2c00048b (diff) | |
download | qt-creator-02923cf2580ece7f1680059a3ed99f326b5dc724.tar.gz |
Support Outline sidebar for QML files
Diffstat (limited to 'src/plugins/qmljseditor/qmljsoutline.h')
-rw-r--r-- | src/plugins/qmljseditor/qmljsoutline.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/plugins/qmljseditor/qmljsoutline.h b/src/plugins/qmljseditor/qmljsoutline.h new file mode 100644 index 0000000000..d2cef659c4 --- /dev/null +++ b/src/plugins/qmljseditor/qmljsoutline.h @@ -0,0 +1,108 @@ +#ifndef QMLJSOUTLINE_H +#define QMLJSOUTLINE_H + +#include <qmljseditor.h> + +#include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/inavigationwidgetfactory.h> +#include <texteditor/ioutlinewidget.h> +#include <qmljs/parser/qmljsastvisitor_p.h> +#include <qmljs/qmljsdocument.h> +#include <qmljs/qmljsicons.h> + +#include <QtGui/QStandardItemModel> +#include <QtGui/QTreeView> +#include <QtGui/QWidget> + +namespace Core { +class IEditor; +} + +namespace QmlJS { +class Editor; +}; + +namespace QmlJSEditor { +namespace Internal { + +class QmlOutlineModel : public QStandardItemModel +{ + Q_OBJECT +public: + enum CustomRoles { + SourceLocationRole = Qt::UserRole + 1 + }; + + QmlOutlineModel(QObject *parent = 0); + + void startSync(); + + QModelIndex enterElement(const QString &typeName, const QmlJS::AST::SourceLocation &location); + void leaveElement(); + + QModelIndex enterProperty(const QString &name, const QmlJS::AST::SourceLocation &location); + void leaveProperty(); + +private: + QStandardItem *enterNode(const QmlJS::AST::SourceLocation &location); + void leaveNode(); + + QStandardItem *parentItem(); + + QList<int> m_treePos; + QStandardItem *m_currentItem; + QmlJS::Icons m_icons; +}; + +class QmlJSOutlineTreeView : public QTreeView +{ + Q_OBJECT +public: + QmlJSOutlineTreeView(QWidget *parent = 0); +}; + + +class QmlJSOutlineWidget : public TextEditor::IOutlineWidget +{ + Q_OBJECT +public: + QmlJSOutlineWidget(QWidget *parent = 0); + + void setEditor(QmlJSTextEditor *editor); + + // IOutlineWidget + virtual void setCursorSynchronization(bool syncWithCursor); + +private slots: + void updateOutline(const QmlJSEditor::Internal::SemanticInfo &semanticInfo); + void updateSelectionInTree(); + void updateSelectionInText(const QItemSelection &selection); + +private: + QModelIndex indexForPosition(const QModelIndex &rootIndex, int cursorPosition); + bool offsetInsideLocation(quint32 offset, const QmlJS::AST::SourceLocation &location); + bool syncCursor(); + +private: + QmlJSOutlineTreeView *m_treeView; + QAbstractItemModel *m_model; + QWeakPointer<QmlJSTextEditor> m_editor; + + bool m_enableCursorSync; + bool m_blockCursorSync; +}; + +class QmlJSOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory +{ + Q_OBJECT +public: + bool supportsEditor(Core::IEditor *editor) const; + TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor); +}; + +} // namespace Internal +} // namespace QmlJSEditor + +Q_DECLARE_METATYPE(QmlJS::AST::SourceLocation); + +#endif // QMLJSOUTLINE_H |