CppEditor: add more sections (protected, ...) for declaration (refactoring)

You can write definition of function, type Alt+Enter, as usual,
and select not only public but also other possible sections
like private, public slots and so on.

Change-Id: I2faefc3833c6f05c9e2e5a2a41328bcdbe17ba14
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Andrey M. Tokarev
2013-04-10 19:37:25 +04:00
committed by Nikolai Kosjar
parent f0f406bacb
commit 72e0ded3c4
7 changed files with 119 additions and 10 deletions

View File

@@ -2339,6 +2339,30 @@ private:
QString m_decl;
};
class DeclOperationFactory
{
public:
DeclOperationFactory(const CppQuickFixInterface &interface, const QString &fileName,
const Class *matchingClass, const QString &decl)
: m_interface(interface)
, m_fileName(fileName)
, m_matchingClass(matchingClass)
, m_decl(decl)
{}
TextEditor::QuickFixOperation::Ptr
operator()(InsertionPointLocator::AccessSpec xsSpec)
{
return TextEditor::QuickFixOperation::Ptr(
new InsertDeclOperation(m_interface, m_fileName, m_matchingClass, xsSpec, m_decl));
}
private:
const CppQuickFixInterface &m_interface;
const QString &m_fileName;
const Class *m_matchingClass;
const QString &m_decl;
};
} // anonymous namespace
void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
@@ -2387,8 +2411,16 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe
QString fileName = QString::fromUtf8(matchingClass->fileName(),
matchingClass->fileNameLength());
const QString decl = InsertDeclOperation::generateDeclaration(fun);
result.append(QuickFixOperation::Ptr(new InsertDeclOperation(interface, fileName, matchingClass,
InsertionPointLocator::Public, decl)));
// Add several possible insertion locations for declaration
DeclOperationFactory operation(interface, fileName, matchingClass, decl);
result.append(operation(InsertionPointLocator::Public));
result.append(operation(InsertionPointLocator::PublicSlot));
result.append(operation(InsertionPointLocator::Protected));
result.append(operation(InsertionPointLocator::ProtectedSlot));
result.append(operation(InsertionPointLocator::Private));
result.append(operation(InsertionPointLocator::PrivateSlot));
}
}