diff options
| author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-08-17 11:35:57 +0200 |
|---|---|---|
| committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-08-19 11:12:09 +0200 |
| commit | 8a6d767a8f2f98ea4e04847f92cff40d661b806f (patch) | |
| tree | 586e5c539adfbb18623246d00dec5e894288c8e1 /src/plugins/cpptools/cpprefactoringchanges.h | |
| parent | a07acad516b5fa1ac503493b4ec28d595f6e1ea0 (diff) | |
| download | qt-creator-8a6d767a8f2f98ea4e04847f92cff40d661b806f.tar.gz | |
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>
Diffstat (limited to 'src/plugins/cpptools/cpprefactoringchanges.h')
| -rw-r--r-- | src/plugins/cpptools/cpprefactoringchanges.h | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/plugins/cpptools/cpprefactoringchanges.h b/src/plugins/cpptools/cpprefactoringchanges.h index c32e4e5c99..610d4cb66e 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.h +++ b/src/plugins/cpptools/cpprefactoringchanges.h @@ -45,14 +45,14 @@ namespace CppTools { class CppRefactoringChanges; +class CppRefactoringFile; +class CppRefactoringChangesData; +typedef QSharedPointer<CppRefactoringFile> CppRefactoringFilePtr; +typedef QSharedPointer<const CppRefactoringFile> CppRefactoringFileConstPtr; class CPPTOOLS_EXPORT CppRefactoringFile: public TextEditor::RefactoringFile { public: - CppRefactoringFile(); - CppRefactoringFile(QTextDocument *document, const QString &fileName = QString()); - CppRefactoringFile(TextEditor::BaseTextEditorWidget *editor); - CPlusPlus::Document::Ptr cppDocument() const; void setCppDocument(CPlusPlus::Document::Ptr document); @@ -78,10 +78,12 @@ public: QString textOf(const CPlusPlus::AST *ast) const; protected: - CppRefactoringFile(const QString &fileName, CppRefactoringChanges *refactoringChanges); + CppRefactoringFile(const QString &fileName, const QSharedPointer<TextEditor::RefactoringChangesData> &data); + CppRefactoringFile(QTextDocument *document, const QString &fileName); + CppRefactoringFile(TextEditor::BaseTextEditorWidget *editor); -private: - CppRefactoringChanges *refactoringChanges() const; + CppRefactoringChangesData *data() const; + virtual void fileChanged(); mutable CPlusPlus::Document::Ptr m_cppDocument; @@ -93,21 +95,16 @@ class CPPTOOLS_EXPORT CppRefactoringChanges: public TextEditor::RefactoringChang public: CppRefactoringChanges(const CPlusPlus::Snapshot &snapshot); - const CPlusPlus::Snapshot &snapshot() const; - CppRefactoringFile file(const QString &fileName); + static CppRefactoringFilePtr file(TextEditor::BaseTextEditorWidget *editor, + const CPlusPlus::Document::Ptr &document); + CppRefactoringFilePtr file(const QString &fileName) const; + // safe to use from non-gui threads + CppRefactoringFileConstPtr fileNoEditor(const QString &fileName) const; -private: - virtual void indentSelection(const QTextCursor &selection, - const QString &fileName, - const TextEditor::BaseTextEditorWidget *textEditor) const; - virtual void fileChanged(const QString &fileName); + const CPlusPlus::Snapshot &snapshot() const; private: - CPlusPlus::Document::Ptr m_thisDocument; - CPlusPlus::Snapshot m_snapshot; - CPlusPlus::LookupContext m_context; - CPlusPlus::CppModelManagerInterface *m_modelManager; - CPlusPlus::CppModelManagerInterface::WorkingCopy m_workingCopy; + CppRefactoringChangesData *data() const; }; } // namespace CppTools |
