Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
03b443b8
Commit
03b443b8
authored
Aug 12, 2010
by
Christian Kamm
Browse files
QuickFix: Simplify getting a Document for a C++ refactoring.
parent
538f6115
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppdeclfromdef.cpp
View file @
03b443b8
...
...
@@ -84,12 +84,12 @@ public:
void
performChanges
(
TextEditor
::
RefactoringFile
*
,
CppRefactoringChanges
*
refactoring
)
{
Document
::
Ptr
targetDoc
=
refactoring
->
document
(
m_targetFileName
);
TextEditor
::
RefactoringFile
targetFile
=
refactoring
->
file
(
m_targetFileName
);
Document
::
Ptr
targetDoc
=
refactoring
->
document
(
targetFile
);
InsertionPointLocator
locator
(
targetDoc
);
const
InsertionLocation
loc
=
locator
.
methodDeclarationInClass
(
m_targetSymbol
,
m_xsSpec
);
Q_ASSERT
(
loc
.
isValid
());
TextEditor
::
RefactoringFile
targetFile
=
refactoring
->
file
(
m_targetFileName
);
int
targetPosition1
=
targetFile
.
position
(
loc
.
line
(),
loc
.
column
());
int
targetPosition2
=
qMax
(
0
,
targetFile
.
position
(
loc
.
line
(),
1
)
-
1
);
...
...
src/plugins/cppeditor/cpprefactoringchanges.cpp
View file @
03b443b8
...
...
@@ -63,33 +63,13 @@ const LookupContext &CppRefactoringChanges::context() const
return
m_context
;
}
Document
::
Ptr
CppRefactoringChanges
::
document
(
const
QString
&
file
Name
)
const
Document
::
Ptr
CppRefactoringChanges
::
document
(
const
TextEditor
::
RefactoringFile
&
file
)
const
{
QString
source
;
unsigned
editorRevision
=
0
;
QDateTime
lastModified
;
if
(
m_workingCopy
.
contains
(
fileName
))
{
const
QPair
<
QString
,
unsigned
>
workingCopy
=
m_workingCopy
.
get
(
fileName
);
source
=
workingCopy
.
first
;
editorRevision
=
workingCopy
.
second
;
}
else
{
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QFile
::
ReadOnly
))
return
Document
::
Ptr
();
lastModified
=
QFileInfo
(
file
).
lastModified
();
source
=
QTextStream
(
&
file
).
readAll
();
// ### FIXME read bytes, and remove the convert below
file
.
close
();
}
QString
source
=
file
.
document
()
->
toPlainText
();
QString
fileName
=
file
.
fileName
();
const
QByteArray
contents
=
m_snapshot
.
preprocessedCode
(
source
,
fileName
);
Document
::
Ptr
doc
=
m_snapshot
.
documentFromSource
(
contents
,
fileName
);
if
(
lastModified
.
isValid
())
doc
->
setLastModified
(
lastModified
);
else
doc
->
setEditorRevision
(
editorRevision
);
doc
->
check
();
return
doc
;
...
...
src/plugins/cppeditor/cpprefactoringchanges.h
View file @
03b443b8
...
...
@@ -48,9 +48,10 @@ public:
CPlusPlus
::
Document
::
Ptr
thisDocument
()
const
;
const
CPlusPlus
::
Snapshot
&
snapshot
()
const
;
CPlusPlus
::
Document
::
Ptr
document
(
const
QString
&
fileName
)
const
;
const
CPlusPlus
::
LookupContext
&
context
()
const
;
CPlusPlus
::
Document
::
Ptr
document
(
const
TextEditor
::
RefactoringFile
&
file
)
const
;
private:
virtual
void
indentSelection
(
const
QTextCursor
&
selection
)
const
;
virtual
void
fileChanged
(
const
QString
&
fileName
);
...
...
src/plugins/texteditor/refactoringchanges.cpp
View file @
03b443b8
...
...
@@ -270,6 +270,11 @@ const QTextCursor RefactoringFile::cursor() const
return
QTextCursor
();
}
QString
RefactoringFile
::
fileName
()
const
{
return
m_fileName
;
}
int
RefactoringFile
::
position
(
unsigned
line
,
unsigned
column
)
const
{
Q_ASSERT
(
line
!=
0
);
...
...
src/plugins/texteditor/refactoringchanges.h
View file @
03b443b8
...
...
@@ -57,6 +57,7 @@ public:
const
QTextDocument
*
document
()
const
;
const
QTextCursor
cursor
()
const
;
QString
fileName
()
const
;
// converts 1-based line and column into 0-based offset
int
position
(
unsigned
line
,
unsigned
column
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment