Skip to content
GitLab
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
0555837c
Commit
0555837c
authored
Oct 06, 2010
by
Erik Verbruggen
Browse files
C++ Editor: prevent insertion of method definitions in header files.
parent
9deccd31
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppinsertdecldef.cpp
View file @
0555837c
...
...
@@ -146,7 +146,7 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(const CppQuickFixState &stat
foreach
(
Symbol
*
s
,
targetBinding
->
symbols
())
{
if
(
Class
*
clazz
=
s
->
asClass
())
{
QList
<
CppQuickFixOperation
::
Ptr
>
results
;
const
Q
Latin1String
fn
(
clazz
->
fileName
());
const
Q
String
fn
=
QString
::
fromUtf8
(
clazz
->
fileName
(),
clazz
->
fileName
Length
());
const
QString
decl
=
generateDeclaration
(
state
,
method
,
targetBinding
);
...
...
src/plugins/cpptools/cpptoolsplugin.cpp
View file @
0555837c
...
...
@@ -264,7 +264,6 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
const
QString
privateHeaderSuffix
=
QLatin1String
(
"_p"
);
const
QChar
dot
=
QLatin1Char
(
'.'
);
QStringList
candidates
;
// Check base matches 'source.h'-> 'source.cpp' and vice versa
const
QStringList
::
const_iterator
scend
=
suffixes
.
constEnd
();
for
(
QStringList
::
const_iterator
it
=
suffixes
.
constBegin
();
it
!=
scend
;
++
it
)
{
...
...
src/plugins/cpptools/insertionpointlocator.cpp
View file @
0555837c
...
...
@@ -35,6 +35,9 @@
#include
<ASTVisitor.h>
#include
<TranslationUnit.h>
#include
<coreplugin/icore.h>
#include
<coreplugin/mimedatabase.h>
using
namespace
CPlusPlus
;
using
namespace
CppTools
;
...
...
@@ -298,6 +301,19 @@ InsertionLocation InsertionPointLocator::methodDeclarationInClass(
}
}
static
bool
isSourceFile
(
const
QString
&
fileName
)
{
const
Core
::
MimeDatabase
*
mimeDb
=
Core
::
ICore
::
instance
()
->
mimeDatabase
();
Core
::
MimeType
cSourceTy
=
mimeDb
->
findByType
(
QLatin1String
(
"text/x-csrc"
));
Core
::
MimeType
cppSourceTy
=
mimeDb
->
findByType
(
QLatin1String
(
"text/x-c++src"
));
Core
::
MimeType
mSourceTy
=
mimeDb
->
findByType
(
QLatin1String
(
"text/x-objcsrc"
));
QStringList
suffixes
=
cSourceTy
.
suffixes
();
suffixes
+=
cppSourceTy
.
suffixes
();
suffixes
+=
mSourceTy
.
suffixes
();
QFileInfo
fileInfo
(
fileName
);
return
suffixes
.
contains
(
fileInfo
.
suffix
());
}
/// Currently, we return the end of fileName.cpp
QList
<
InsertionLocation
>
InsertionPointLocator
::
methodDefinition
(
Declaration
*
declaration
)
const
...
...
@@ -306,10 +322,14 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(
if
(
!
declaration
)
return
result
;
Internal
::
CppToolsPlugin
*
cpptools
=
Internal
::
CppToolsPlugin
::
instance
();
const
QString
declFileName
=
QString
::
fromUtf8
(
declaration
->
fileName
(),
declaration
->
fileNameLength
());
QString
target
=
declFileName
;
if
(
!
isSourceFile
(
declFileName
))
{
Internal
::
CppToolsPlugin
*
cpptools
=
Internal
::
CppToolsPlugin
::
instance
();
target
=
cpptools
->
correspondingHeaderOrSource
(
declFileName
);
}
const
QString
declFileName
=
QLatin1String
(
declaration
->
fileName
());
QString
target
=
cpptools
->
correspondingHeaderOrSource
(
declFileName
);
Document
::
Ptr
doc
=
m_refactoringChanges
->
file
(
target
).
cppDocument
();
if
(
doc
.
isNull
())
return
result
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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