designdocument.h 4.96 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

Marco Bubke's avatar
Marco Bubke committed
30 31
#ifndef DesignDocument_h
#define DesignDocument_h
32 33 34

#include "rewriterview.h"

35 36 37 38 39 40 41 42 43 44 45 46
#include <model.h>
#include <rewriterview.h>
#include <itemlibraryview.h>
#include <navigatorview.h>
#include <stateseditorview.h>
#include <formeditorview.h>
#include <propertyeditor.h>
#include <componentview.h>
#include <basetexteditmodifier.h>
#include <componenttextmodifier.h>
#include <subcomponentmanager.h>
#include <model/viewlogger.h>
Marco Bubke's avatar
Marco Bubke committed
47
#include <viewmanager.h>
48

49 50
#include <QObject>
#include <QString>
51

52 53
#include <QStackedWidget>

54
QT_BEGIN_NAMESPACE
55 56 57 58 59
class QUndoStack;
class QWidget;
class QIODevice;
class QProcess;
class QPlainTextEdit;
60
class QDeclarativeError;
61
QT_END_NAMESPACE
62 63 64 65 66 67

namespace QmlDesigner {

class ModelNode;
class TextModifier;
class QmlObjectNode;
68
class CrumbleBarInfo;
69

Marco Bubke's avatar
Marco Bubke committed
70
class DesignDocument: public QObject
71 72 73
{
    Q_OBJECT
public:
Marco Bubke's avatar
Marco Bubke committed
74 75
    DesignDocument(QObject *parent = 0);
    ~DesignDocument();
76 77

    QString displayName() const;
78 79
    QString simplfiedDisplayName() const;

80
    void loadDocument(QPlainTextEdit *edit);
Marco Bubke's avatar
Marco Bubke committed
81 82
    void activateCurrentModel(TextModifier *textModifier);
    void activateDocumentModel();
83
    void close();
Thomas Hartmann's avatar
Thomas Hartmann committed
84
    void updateSubcomponentManager();
85 86 87 88

    bool isUndoAvailable() const;
    bool isRedoAvailable() const;

Marco Bubke's avatar
Marco Bubke committed
89 90 91 92 93 94
    Model *currentModel() const;
    Model *documentModel() const;

    QString contextHelpId() const;
    QList<RewriterView::Error> qmlSyntaxErrors() const;
    bool hasQmlSyntaxErrors() const;
95

Kai Koehne's avatar
Kai Koehne committed
96
    RewriterView *rewriterView() const;
97

Marco Bubke's avatar
Marco Bubke committed
98 99
    void setEditor(Core::IEditor *editor);
    Core::IEditor *editor() const;
100

Marco Bubke's avatar
Marco Bubke committed
101 102 103 104 105
    TextEditor::ITextEditor *textEditor() const;
    QPlainTextEdit *plainTextEdit() const;
    QString fileName() const;
    int qtVersionId() const; // maybe that is not working, because the id should be not cached!!!
    bool isDocumentLoaded() const;
106

Marco Bubke's avatar
Marco Bubke committed
107
    void resetToDocumentModel();
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
signals:
    void displayNameChanged(const QString &newFileName);
    void dirtyStateChanged(bool newState);

    void undoAvailable(bool isAvailable);
    void redoAvailable(bool isAvailable);
    void designDocumentClosed();
    void qmlErrorsChanged(const QList<RewriterView::Error> &errors);

    void fileToOpen(const QString &path);

public slots:
    void deleteSelected();
    void copySelected();
    void cutSelected();
    void paste();
125
    void selectAll();
126 127
    void undo();
    void redo();
Marco Bubke's avatar
Marco Bubke committed
128
    void updateActiveQtVersion();
129
    void changeCurrentModelTo(const ModelNode &node);
130
    void changeToSubComponent(const ModelNode &node);
Marco Bubke's avatar
Marco Bubke committed
131
    void changeToExternalSubComponent(const QString &m_oldFileName);
132
    void goIntoComponent();
133 134

private slots:
Marco Bubke's avatar
Marco Bubke committed
135
    void updateFileName(const QString &oldFileName, const QString &newFileName);
136

137
private: // functions
Marco Bubke's avatar
Marco Bubke committed
138 139
    void changeToDocumentModel();
    void changeToInFileComponentModel();
140

141
    QWidget *centralWidget() const;
142 143
    QString pathToQt() const;

Marco Bubke's avatar
Marco Bubke committed
144 145
    const ViewManager &viewManager() const;
    ViewManager &viewManager();
146

Marco Bubke's avatar
Marco Bubke committed
147 148 149 150 151
    ModelNode rootModelNode() const;

    bool loadSubComponent(const ModelNode &componentNode);

private: // variables
152
    QWeakPointer<QStackedWidget> m_stackedWidget;
Marco Bubke's avatar
Marco Bubke committed
153 154 155 156 157 158 159
    QWeakPointer<Model> m_documentModel;
    QWeakPointer<Model> m_inFileComponentModel;
    QWeakPointer<Model> m_currentModel;
    QWeakPointer<Core::IEditor> m_textEditor;
    QWeakPointer<BaseTextEditModifier> m_documentTextModifier;
    QWeakPointer<ComponentTextModifier> m_inFileComponentTextModifier;
    QWeakPointer<SubComponentManager> m_subComponentManager;
160 161 162 163

    QWeakPointer<RewriterView> m_rewriterView;

    bool m_documentLoaded;
Marco Bubke's avatar
Marco Bubke committed
164
    int m_qtVersionId;
165 166 167 168
};

} // namespace QmlDesigner

Christian Kandeler's avatar
Christian Kandeler committed
169

Marco Bubke's avatar
Marco Bubke committed
170
#endif // DesignDocument_h