Commit 3a1f6f9a authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: generate quick-exit style setters for Q_PROPERTY.

Change-Id: Ie278c2901a49075500526eb17a84ab2baf80cd01
Task-number: QTCREATORBUG-12519
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 33a80e56
......@@ -1194,6 +1194,39 @@ void CppEditorPlugin::test_quickfix_data()
<< CppQuickFixFactoryPtr(new OptimizeForLoop)
<< _("void foo() {fo@r (int i = 0; i < -3; ++i) {}}\n")
<< _();
QTest::newRow("InsertQtPropertyMembers")
<< CppQuickFixFactoryPtr(new InsertQtPropertyMembers)
<< _("struct XmarksTheSpot {\n"
" @Q_PROPERTY(int it READ getIt WRITE setIt NOTIFY itChanged)\n"
"};\n"
)
<< _("struct XmarksTheSpot {\n"
" Q_PROPERTY(int it READ getIt WRITE setIt NOTIFY itChanged)\n"
"\n"
"public:\n"
" int getIt() const\n"
" {\n"
" return m_it;\n"
" }\n"
"\n"
"public slots:\n"
" void setIt(int arg)\n"
" {\n"
" if (m_it == arg)\n"
" return;\n"
"\n"
" m_it = arg;\n"
" emit itChanged(arg);\n"
" }\n"
"\n"
"signals:\n"
" void itChanged(int arg);\n"
"\n"
"private:\n"
" int m_it;\n"
"};\n"
);
}
void CppEditorPlugin::test_quickfix()
......
......@@ -3953,8 +3953,8 @@ public:
if (m_signalName.isEmpty()) {
setter << m_storageName << " = arg;\n}\n";
} else {
setter << "if (" << m_storageName << " != arg) {\n" << m_storageName
<< " = arg;\nemit " << m_signalName << "(arg);\n}\n}\n";
setter << "if (" << m_storageName << " == arg)\nreturn;\n\n"
<< m_storageName << " = arg;\nemit " << m_signalName << "(arg);\n}\n";
}
InsertionLocation setterLoc = locator.methodDeclarationInClass(file->fileName(), m_class, InsertionPointLocator::PublicSlot);
QTC_ASSERT(setterLoc.isValid(), return);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment