Refactoring changes: Cleanup and improvements.

Previously RefactoringFiles were usually passed around by value.
However, since a RefactoringFile may sometimes own a QTextDocument
(when it was read from a file), that's not great and caused the
file to be reread after every copy.

With this change RefactoringFile becomes noncopyable and is always
owned by a shared pointer.

This change also allowed having const RefactoringFiles which is
useful because they can be safely used from other threads. See
CppRefactoringChanges::fileNoEditor.

Change-Id: I9045921d6d0f6349f9558ff2a3d8317ea172193b
Reviewed-on: http://codereview.qt.nokia.com/3084
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
Christian Kamm
2011-08-17 11:35:57 +02:00
parent a07acad516
commit 8a6d767a8f
30 changed files with 609 additions and 500 deletions

View File

@@ -46,14 +46,13 @@ class ModelManagerInterface;
namespace QmlJSTools {
class QmlJSRefactoringChanges;
class QmlJSRefactoringFile;
class QmlJSRefactoringChangesData;
typedef QSharedPointer<QmlJSRefactoringFile> QmlJSRefactoringFilePtr;
class QMLJSTOOLS_EXPORT QmlJSRefactoringFile: public TextEditor::RefactoringFile
{
public:
QmlJSRefactoringFile();
QmlJSRefactoringFile(const QString &fileName, QmlJSRefactoringChanges *refactoringChanges);
QmlJSRefactoringFile(TextEditor::BaseTextEditorWidget *editor, QmlJS::Document::Ptr document);
QmlJS::Document::Ptr qmljsDocument() const;
/*!
@@ -65,10 +64,16 @@ public:
bool isCursorOn(QmlJS::AST::UiObjectMember *ast) const;
bool isCursorOn(QmlJS::AST::UiQualifiedId *ast) const;
private:
QmlJSRefactoringChanges *refactoringChanges() const;
protected:
QmlJSRefactoringFile(const QString &fileName, const QSharedPointer<TextEditor::RefactoringChangesData> &data);
QmlJSRefactoringFile(TextEditor::BaseTextEditorWidget *editor, QmlJS::Document::Ptr document);
QmlJSRefactoringChangesData *data() const;
virtual void fileChanged();
mutable QmlJS::Document::Ptr m_qmljsDocument;
friend class QmlJSRefactoringChanges;
};
@@ -78,19 +83,14 @@ public:
QmlJSRefactoringChanges(QmlJS::ModelManagerInterface *modelManager,
const QmlJS::Snapshot &snapshot);
static QmlJSRefactoringFilePtr file(TextEditor::BaseTextEditorWidget *editor,
const QmlJS::Document::Ptr &document);
QmlJSRefactoringFilePtr file(const QString &fileName) const;
const QmlJS::Snapshot &snapshot() const;
QmlJSRefactoringFile file(const QString &fileName);
private:
virtual void indentSelection(const QTextCursor &selection,
const QString &fileName,
const TextEditor::BaseTextEditorWidget *textEditor) const;
virtual void fileChanged(const QString &fileName);
private:
QmlJS::ModelManagerInterface *m_modelManager;
QmlJS::Snapshot m_snapshot;
QmlJSRefactoringChangesData *data() const;
};
} // namespace QmlJSTools