forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
||||
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;
|
||||
|
||||
const CPlusPlus::Snapshot &snapshot() const;
|
||||
CppRefactoringFile 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:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user