forked from qt-creator/qt-creator
CppEditor: Check only pure virtual functions by default
Task-number: QTCREATORBUG-10154 Change-Id: Iec1b895e3f06d9d6ae36f19f6c8048c78faac514 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
07a1cddec2
commit
8da53e6587
@@ -3571,14 +3571,14 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3593,14 +3593,14 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << false << _(
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << false << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3615,38 +3615,38 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"protected:\n"
|
"protected:\n"
|
||||||
" virtual int b();\n"
|
" virtual int b() = 0;\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" virtual int c();\n"
|
" virtual int c() = 0;\n"
|
||||||
"public slots:\n"
|
"public slots:\n"
|
||||||
" virtual int d();\n"
|
" virtual int d() = 0;\n"
|
||||||
"protected slots:\n"
|
"protected slots:\n"
|
||||||
" virtual int e();\n"
|
" virtual int e() = 0;\n"
|
||||||
"private slots:\n"
|
"private slots:\n"
|
||||||
" virtual int f();\n"
|
" virtual int f() = 0;\n"
|
||||||
"signals:\n"
|
"signals:\n"
|
||||||
" virtual int g();\n"
|
" virtual int g() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Der@ived : public BaseA {\n"
|
"class Der@ived : public BaseA {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"protected:\n"
|
"protected:\n"
|
||||||
" virtual int b();\n"
|
" virtual int b() = 0;\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" virtual int c();\n"
|
" virtual int c() = 0;\n"
|
||||||
"public slots:\n"
|
"public slots:\n"
|
||||||
" virtual int d();\n"
|
" virtual int d() = 0;\n"
|
||||||
"protected slots:\n"
|
"protected slots:\n"
|
||||||
" virtual int e();\n"
|
" virtual int e() = 0;\n"
|
||||||
"private slots:\n"
|
"private slots:\n"
|
||||||
" virtual int f();\n"
|
" virtual int f() = 0;\n"
|
||||||
"signals:\n"
|
"signals:\n"
|
||||||
" virtual int g();\n"
|
" virtual int g() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3673,56 +3673,57 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class BaseB : public BaseA {\n"
|
"class BaseB : public BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int b();\n"
|
" virtual int b() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Der@ived : public BaseB {\n"
|
"class Der@ived : public BaseB {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class BaseB : public BaseA {\n"
|
"class BaseB : public BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int b();\n"
|
" virtual int b() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Der@ived : public BaseB {\n"
|
"class Der@ived : public BaseB {\n"
|
||||||
"\n"
|
"\n"
|
||||||
" // BaseB interface\n"
|
|
||||||
"public:\n"
|
|
||||||
" virtual int b();\n"
|
|
||||||
"\n"
|
|
||||||
" // BaseA interface\n"
|
" // BaseA interface\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a();\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseB interface\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int b();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Check: Do not insert reimplemented functions twice.
|
// Check: Do not insert reimplemented functions twice.
|
||||||
QTest::newRow("SuperclassOverride")
|
QTest::newRow("SuperclassOverride")
|
||||||
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class BaseB : public BaseA {\n"
|
"class BaseB : public BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Der@ived : public BaseB {\n"
|
"class Der@ived : public BaseB {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class BaseB : public BaseA {\n"
|
"class BaseB : public BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Der@ived : public BaseB {\n"
|
"class Der@ived : public BaseB {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3783,14 +3784,14 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeInsideClass << true << _(
|
<< InsertVirtualMethodsDialog::ModeInsideClass << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3807,14 +3808,14 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
<< InsertVirtualMethodsDialog::ModeOutsideClass << true << _(
|
<< InsertVirtualMethodsDialog::ModeOutsideClass << true << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -3836,7 +3837,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
"};"
|
"};"
|
||||||
) << _(
|
) << _(
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
@@ -3845,9 +3846,135 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_data()
|
|||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
|
"};\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check: One pure, one not
|
||||||
|
QTest::newRow("Some_Pure")
|
||||||
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
|
" virtual int virtualFuncB();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Derived : public Bas@eA {\n"
|
||||||
|
"};"
|
||||||
|
) << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int virtualFuncA() = 0;\n"
|
||||||
|
" virtual int virtualFuncB();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Derived : public BaseA {\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseA interface\n"
|
||||||
|
"public:\n"
|
||||||
" virtual int virtualFuncA();\n"
|
" virtual int virtualFuncA();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Check: Pure function in derived class
|
||||||
|
QTest::newRow("Pure_in_Derived")
|
||||||
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"};"
|
||||||
|
) << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseA interface\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a();\n"
|
||||||
|
"};\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check: One pure function in base class, one in derived
|
||||||
|
QTest::newRow("Pure_in_Base_And_Derived")
|
||||||
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int b() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"};"
|
||||||
|
) << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int b() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseA interface\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a();\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"};\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check: One pure function in base class, two in derived
|
||||||
|
QTest::newRow("Pure_in_Base_And_Derived_2")
|
||||||
|
<< InsertVirtualMethodsDialog::ModeOnlyDeclarations << true << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int b() = 0;\n"
|
||||||
|
" virtual int c() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"};"
|
||||||
|
) << _(
|
||||||
|
"class BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a() = 0;\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class BaseB : public BaseA {\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int b() = 0;\n"
|
||||||
|
" virtual int c() = 0;\n"
|
||||||
|
"};\n\n"
|
||||||
|
"class Der@ived : public BaseB {\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseA interface\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int a();\n"
|
||||||
|
" virtual int b();\n"
|
||||||
|
"\n"
|
||||||
|
" // BaseB interface\n"
|
||||||
|
"public:\n"
|
||||||
|
" virtual int c();\n"
|
||||||
|
"};\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::test_quickfix_InsertVirtualMethods()
|
void CppEditorPlugin::test_quickfix_InsertVirtualMethods()
|
||||||
@@ -3873,7 +4000,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
|
|||||||
original =
|
original =
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public Bas@eA {\n"
|
"class Derived : public Bas@eA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
@@ -3882,7 +4009,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
|
|||||||
expected =
|
expected =
|
||||||
"class BaseA {\n"
|
"class BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual int a();\n"
|
" virtual int a() = 0;\n"
|
||||||
"};\n\n"
|
"};\n\n"
|
||||||
"class Derived : public BaseA {\n"
|
"class Derived : public BaseA {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
@@ -3921,7 +4048,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
|
|||||||
"namespace BaseNS {\n"
|
"namespace BaseNS {\n"
|
||||||
"class Base {\n"
|
"class Base {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual BaseEnum a(BaseEnum e);\n"
|
" virtual BaseEnum a(BaseEnum e) = 0;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"class Deri@ved : public BaseNS::Base {\n"
|
"class Deri@ved : public BaseNS::Base {\n"
|
||||||
@@ -3933,7 +4060,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
|
|||||||
"namespace BaseNS {\n"
|
"namespace BaseNS {\n"
|
||||||
"class Base {\n"
|
"class Base {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" virtual BaseEnum a(BaseEnum e);\n"
|
" virtual BaseEnum a(BaseEnum e) = 0;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"class Deri@ved : public BaseNS::Base {\n"
|
"class Deri@ved : public BaseNS::Base {\n"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
#include "cppfunctiondecldeflink.h"
|
#include "cppfunctiondecldeflink.h"
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
|
#include "cppvirtualfunctionassistprovider.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
#include <cpptools/cpppointerdeclarationformatter.h>
|
#include <cpptools/cpppointerdeclarationformatter.h>
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
#include <cpptools/cpptoolsreuse.h>
|
#include <cpptools/cpptoolsreuse.h>
|
||||||
|
#include <cpptools/functionutils.h>
|
||||||
#include <cpptools/includeutils.h>
|
#include <cpptools/includeutils.h>
|
||||||
#include <cpptools/insertionpointlocator.h>
|
#include <cpptools/insertionpointlocator.h>
|
||||||
#include <cpptools/symbolfinder.h>
|
#include <cpptools/symbolfinder.h>
|
||||||
@@ -4690,7 +4692,6 @@ public:
|
|||||||
, m_insertPosDecl(0)
|
, m_insertPosDecl(0)
|
||||||
, m_insertPosOutside(0)
|
, m_insertPosOutside(0)
|
||||||
, m_functionCount(0)
|
, m_functionCount(0)
|
||||||
, m_implementedFunctionCount(0)
|
|
||||||
{
|
{
|
||||||
setDescription(QCoreApplication::translate(
|
setDescription(QCoreApplication::translate(
|
||||||
"CppEditor::QuickFix", "Insert Virtual Functions of Base Classes"));
|
"CppEditor::QuickFix", "Insert Virtual Functions of Base Classes"));
|
||||||
@@ -4742,7 +4743,7 @@ public:
|
|||||||
&& (clazz = interface->context().lookupType(symbol))
|
&& (clazz = interface->context().lookupType(symbol))
|
||||||
&& !visitedBaseClasses.contains(clazz)
|
&& !visitedBaseClasses.contains(clazz)
|
||||||
&& !baseClasses.contains(base)) {
|
&& !baseClasses.contains(base)) {
|
||||||
baseClasses << base;
|
baseClasses.prepend(base);
|
||||||
baseClassQueue.enqueue(clazz);
|
baseClassQueue.enqueue(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4755,36 +4756,36 @@ public:
|
|||||||
printer.showFunctionSignatures = true;
|
printer.showFunctionSignatures = true;
|
||||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::fontSettings();
|
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::fontSettings();
|
||||||
const Format formatReimpFunc = fs.formatFor(C_DISABLED_CODE);
|
const Format formatReimpFunc = fs.formatFor(C_DISABLED_CODE);
|
||||||
|
QHash<const Function *, QStandardItem *> virtualFunctions;
|
||||||
foreach (const Class *clazz, baseClasses) {
|
foreach (const Class *clazz, baseClasses) {
|
||||||
QStandardItem *itemBase = new QStandardItem(printer.prettyName(clazz->name()));
|
QStandardItem *itemBase = new QStandardItem(printer.prettyName(clazz->name()));
|
||||||
itemBase->setData(false, InsertVirtualMethodsDialog::Implemented);
|
itemBase->setData(false, InsertVirtualMethodsDialog::Reimplemented);
|
||||||
itemBase->setData(qVariantFromValue((void *) clazz),
|
itemBase->setData(qVariantFromValue((void *) clazz),
|
||||||
InsertVirtualMethodsDialog::ClassOrFunction);
|
InsertVirtualMethodsDialog::ClassOrFunction);
|
||||||
const QString baseClassName = printer.prettyName(clazz->name());
|
|
||||||
const Qt::CheckState funcItemsCheckState = (baseClassName != QLatin1String("QObject")
|
|
||||||
&& baseClassName != QLatin1String("QWidget")
|
|
||||||
&& baseClassName != QLatin1String("QPaintDevice"))
|
|
||||||
? Qt::Checked : Qt::Unchecked;
|
|
||||||
for (Scope::iterator it = clazz->firstMember(); it != clazz->lastMember(); ++it) {
|
for (Scope::iterator it = clazz->firstMember(); it != clazz->lastMember(); ++it) {
|
||||||
if (const Function *func = (*it)->type()->asFunctionType()) {
|
if (const Function *func = (*it)->type()->asFunctionType()) {
|
||||||
// Filter virtual destructors
|
// Filter virtual destructors
|
||||||
if (func->name()->asDestructorNameId())
|
if (func->name()->asDestructorNameId())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!func->isVirtual())
|
const Function *firstVirtual = 0;
|
||||||
|
const bool isVirtual = FunctionUtils::isVirtualFunction(
|
||||||
|
func, interface->context(), &firstVirtual);
|
||||||
|
if (!isVirtual)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Filter OQbject's
|
// Filter OQbject's
|
||||||
// - virtual const QMetaObject *metaObject() const;
|
// - virtual const QMetaObject *metaObject() const;
|
||||||
// - virtual void *qt_metacast(const char *);
|
// - virtual void *qt_metacast(const char *);
|
||||||
// - virtual int qt_metacall(QMetaObject::Call, int, void **);
|
// - virtual int qt_metacall(QMetaObject::Call, int, void **);
|
||||||
if (baseClassName == QLatin1String("QObject")) {
|
if (printer.prettyName(firstVirtual->enclosingClass()->name())
|
||||||
if (printer.prettyName(func->name()) == QLatin1String("metaObject"))
|
== QLatin1String("QObject")) {
|
||||||
continue;
|
const QString funcName = printer.prettyName(func->name());
|
||||||
if (printer.prettyName(func->name()) == QLatin1String("qt_metacast"))
|
if (funcName == QLatin1String("metaObject")
|
||||||
continue;
|
|| funcName == QLatin1String("qt_metacast")
|
||||||
if (printer.prettyName(func->name()) == QLatin1String("qt_metacall"))
|
|| funcName == QLatin1String("qt_metacall")) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not implement existing functions inside target class
|
// Do not implement existing functions inside target class
|
||||||
@@ -4802,76 +4803,83 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not show when reimplemented from an other class
|
|
||||||
bool funcReimplemented = false;
|
|
||||||
for (int i = baseClasses.count() - 1; i >= 0; --i) {
|
|
||||||
const Class *prevClass = baseClasses.at(i);
|
|
||||||
if (clazz == prevClass)
|
|
||||||
break; // reached current class
|
|
||||||
|
|
||||||
for (const Symbol *symbol = prevClass->find(funcName->identifier());
|
|
||||||
symbol; symbol = symbol->next()) {
|
|
||||||
if (!symbol->name()
|
|
||||||
|| !funcName->identifier()->isEqualTo(symbol->identifier())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (symbol->type().isEqualTo(func->type())) {
|
|
||||||
funcReimplemented = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (funcReimplemented)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Construct function item
|
// Construct function item
|
||||||
|
const bool isReimplemented = (func != firstVirtual);
|
||||||
const bool isPureVirtual = func->isPureVirtual();
|
const bool isPureVirtual = func->isPureVirtual();
|
||||||
QString itemName = printer.prettyType(func->type(), func->name());
|
QString itemName = printer.prettyType(func->type(), func->name());
|
||||||
if (isPureVirtual)
|
if (isPureVirtual)
|
||||||
itemName += QLatin1String(" = 0");
|
itemName += QLatin1String(" = 0");
|
||||||
const QString itemReturnTypeString = printer.prettyType(func->returnType());
|
const QString itemReturnTypeString = printer.prettyType(func->returnType());
|
||||||
QStandardItem *funcItem = new QStandardItem(
|
itemName += QLatin1String(" : ") + itemReturnTypeString;
|
||||||
itemName + QLatin1String(" : ") + itemReturnTypeString);
|
if (isReimplemented)
|
||||||
if (!funcExistsInClass) {
|
itemName += QLatin1String(" (redeclared)");
|
||||||
funcItem->setCheckable(true);
|
QStandardItem *funcItem = new QStandardItem(itemName);
|
||||||
funcItem->setCheckState(Qt::Checked);
|
funcItem->setCheckable(true);
|
||||||
} else {
|
if (isReimplemented) {
|
||||||
|
factory->setHasReimplementedFunctions(true);
|
||||||
funcItem->setEnabled(false);
|
funcItem->setEnabled(false);
|
||||||
funcItem->setData(formatReimpFunc.foreground(), Qt::ForegroundRole);
|
funcItem->setCheckState(Qt::Unchecked);
|
||||||
if (formatReimpFunc.background().isValid())
|
if (QStandardItem *first = virtualFunctions[firstVirtual]) {
|
||||||
funcItem->setData(formatReimpFunc.background(), Qt::BackgroundRole);
|
if (!first->data(InsertVirtualMethodsDialog::Reimplemented).toBool()) {
|
||||||
|
first->setCheckState(isPureVirtual ? Qt::Checked : Qt::Unchecked);
|
||||||
|
factory->updateCheckBoxes(first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!funcExistsInClass) {
|
||||||
|
funcItem->setCheckState(isPureVirtual ? Qt::Checked : Qt::Unchecked);
|
||||||
|
} else {
|
||||||
|
funcItem->setEnabled(false);
|
||||||
|
funcItem->setCheckState(Qt::Checked);
|
||||||
|
funcItem->setData(formatReimpFunc.foreground(), Qt::ForegroundRole);
|
||||||
|
if (formatReimpFunc.background().isValid())
|
||||||
|
funcItem->setData(formatReimpFunc.background(), Qt::BackgroundRole);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcItem->setData(qVariantFromValue((void *) func),
|
funcItem->setData(qVariantFromValue((void *) func),
|
||||||
InsertVirtualMethodsDialog::ClassOrFunction);
|
InsertVirtualMethodsDialog::ClassOrFunction);
|
||||||
funcItem->setData(isPureVirtual, InsertVirtualMethodsDialog::PureVirtual);
|
funcItem->setData(isPureVirtual, InsertVirtualMethodsDialog::PureVirtual);
|
||||||
funcItem->setData(acessSpec(*it), InsertVirtualMethodsDialog::AccessSpec);
|
funcItem->setData(acessSpec(*it), InsertVirtualMethodsDialog::AccessSpec);
|
||||||
funcItem->setData(funcExistsInClass, InsertVirtualMethodsDialog::Implemented);
|
funcItem->setData(funcExistsInClass || isReimplemented,
|
||||||
funcItem->setCheckState(funcItemsCheckState);
|
InsertVirtualMethodsDialog::Reimplemented);
|
||||||
|
|
||||||
itemBase->appendRow(funcItem);
|
itemBase->appendRow(funcItem);
|
||||||
|
virtualFunctions[func] = funcItem;
|
||||||
|
|
||||||
// update internal counters
|
// update internal counters
|
||||||
if (funcExistsInClass)
|
if (!funcExistsInClass)
|
||||||
++m_implementedFunctionCount;
|
|
||||||
else
|
|
||||||
++m_functionCount;
|
++m_functionCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (itemBase->hasChildren()) {
|
if (itemBase->hasChildren()) {
|
||||||
|
itemBase->setData(false, InsertVirtualMethodsDialog::Reimplemented);
|
||||||
|
bool enabledFound = false;
|
||||||
|
Qt::CheckState state = Qt::Unchecked;
|
||||||
for (int i = 0; i < itemBase->rowCount(); ++i) {
|
for (int i = 0; i < itemBase->rowCount(); ++i) {
|
||||||
if (itemBase->child(i, 0)->isCheckable()) {
|
QStandardItem *childItem = itemBase->child(i, 0);
|
||||||
|
if (!childItem->isEnabled())
|
||||||
|
continue;
|
||||||
|
if (!enabledFound) {
|
||||||
|
state = childItem->checkState();
|
||||||
|
enabledFound = true;
|
||||||
|
}
|
||||||
|
if (childItem->isCheckable()) {
|
||||||
if (!itemBase->isCheckable()) {
|
if (!itemBase->isCheckable()) {
|
||||||
itemBase->setCheckable(true);
|
itemBase->setCheckable(true);
|
||||||
itemBase->setTristate(true);
|
itemBase->setTristate(true);
|
||||||
itemBase->setData(false, InsertVirtualMethodsDialog::Implemented);
|
itemBase->setCheckState(state);
|
||||||
}
|
}
|
||||||
if (itemBase->child(i, 0)->checkState() == Qt::Checked) {
|
if (state != childItem->checkState()) {
|
||||||
itemBase->setCheckState(Qt::Checked);
|
itemBase->setCheckState(Qt::PartiallyChecked);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!enabledFound) {
|
||||||
|
itemBase->setCheckable(true);
|
||||||
|
itemBase->setEnabled(false);
|
||||||
|
}
|
||||||
m_factory->classFunctionModel->invisibleRootItem()->appendRow(itemBase);
|
m_factory->classFunctionModel->invisibleRootItem()->appendRow(itemBase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4883,7 +4891,6 @@ public:
|
|||||||
bool isHeaderFile = false;
|
bool isHeaderFile = false;
|
||||||
m_cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile);
|
m_cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile);
|
||||||
m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty());
|
m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty());
|
||||||
m_factory->setHasReimplementedFunctions(m_implementedFunctionCount != 0);
|
|
||||||
|
|
||||||
m_valid = true;
|
m_valid = true;
|
||||||
}
|
}
|
||||||
@@ -5087,7 +5094,6 @@ private:
|
|||||||
int m_insertPosDecl;
|
int m_insertPosDecl;
|
||||||
int m_insertPosOutside;
|
int m_insertPosOutside;
|
||||||
unsigned m_functionCount;
|
unsigned m_functionCount;
|
||||||
unsigned m_implementedFunctionCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class InsertVirtualMethodsFilterModel : public QSortFilterProxyModel
|
class InsertVirtualMethodsFilterModel : public QSortFilterProxyModel
|
||||||
@@ -5113,14 +5119,14 @@ public:
|
|||||||
|
|
||||||
for (int i = 0; i < sourceModel()->rowCount(index); ++i) {
|
for (int i = 0; i < sourceModel()->rowCount(index); ++i) {
|
||||||
const QModelIndex child = sourceModel()->index(i, 0, index);
|
const QModelIndex child = sourceModel()->index(i, 0, index);
|
||||||
if (!child.data(InsertVirtualMethodsDialog::Implemented).toBool())
|
if (!child.data(InsertVirtualMethodsDialog::Reimplemented).toBool())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_hideReimplemented)
|
if (m_hideReimplemented)
|
||||||
return !index.data(InsertVirtualMethodsDialog::Implemented).toBool();
|
return !index.data(InsertVirtualMethodsDialog::Reimplemented).toBool();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5174,7 +5180,7 @@ void InsertVirtualMethodsDialog::initGui()
|
|||||||
m_view->setHeaderHidden(true);
|
m_view->setHeaderHidden(true);
|
||||||
groupBoxViewLayout->addWidget(m_view);
|
groupBoxViewLayout->addWidget(m_view);
|
||||||
m_hideReimplementedFunctions =
|
m_hideReimplementedFunctions =
|
||||||
new QCheckBox(tr("&Hide already implemented functions of current class"), this);
|
new QCheckBox(tr("&Hide reimplemented functions"), this);
|
||||||
groupBoxViewLayout->addWidget(m_hideReimplementedFunctions);
|
groupBoxViewLayout->addWidget(m_hideReimplementedFunctions);
|
||||||
|
|
||||||
// Insertion options
|
// Insertion options
|
||||||
@@ -5223,7 +5229,7 @@ void InsertVirtualMethodsDialog::initData()
|
|||||||
m_view->setModel(classFunctionFilterModel);
|
m_view->setModel(classFunctionFilterModel);
|
||||||
m_expansionStateNormal.clear();
|
m_expansionStateNormal.clear();
|
||||||
m_expansionStateReimp.clear();
|
m_expansionStateReimp.clear();
|
||||||
m_hideReimplementedFunctions->setVisible(m_hasReimplementedFunctions);
|
m_hideReimplementedFunctions->setEnabled(m_hasReimplementedFunctions);
|
||||||
m_virtualKeyword->setChecked(m_insertKeywordVirtual);
|
m_virtualKeyword->setChecked(m_insertKeywordVirtual);
|
||||||
m_insertMode->setCurrentIndex(m_insertMode->findData(m_implementationMode));
|
m_insertMode->setCurrentIndex(m_insertMode->findData(m_implementationMode));
|
||||||
|
|
||||||
@@ -5304,8 +5310,9 @@ void InsertVirtualMethodsDialog::updateCheckBoxes(QStandardItem *item)
|
|||||||
if (!item->isCheckable() || state == Qt::PartiallyChecked)
|
if (!item->isCheckable() || state == Qt::PartiallyChecked)
|
||||||
return;
|
return;
|
||||||
for (int i = 0; i < item->rowCount(); ++i) {
|
for (int i = 0; i < item->rowCount(); ++i) {
|
||||||
if (item->child(i, 0)->isCheckable())
|
QStandardItem *childItem = item->child(i, 0);
|
||||||
item->child(i, 0)->setCheckState(state);
|
if (childItem->isCheckable() && childItem->isEnabled())
|
||||||
|
childItem->setCheckState(state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QStandardItem *parent = item->parent();
|
QStandardItem *parent = item->parent();
|
||||||
@@ -5313,7 +5320,8 @@ void InsertVirtualMethodsDialog::updateCheckBoxes(QStandardItem *item)
|
|||||||
return;
|
return;
|
||||||
const Qt::CheckState state = item->checkState();
|
const Qt::CheckState state = item->checkState();
|
||||||
for (int i = 0; i < parent->rowCount(); ++i) {
|
for (int i = 0; i < parent->rowCount(); ++i) {
|
||||||
if (state != parent->child(i, 0)->checkState()) {
|
QStandardItem *childItem = parent->child(i, 0);
|
||||||
|
if (childItem->isEnabled() && state != childItem->checkState()) {
|
||||||
parent->setCheckState(Qt::PartiallyChecked);
|
parent->setCheckState(Qt::PartiallyChecked);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,7 +532,7 @@ class InsertVirtualMethodsDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
enum CustomItemRoles {
|
enum CustomItemRoles {
|
||||||
ClassOrFunction = Qt::UserRole + 1,
|
ClassOrFunction = Qt::UserRole + 1,
|
||||||
Implemented = Qt::UserRole + 2,
|
Reimplemented = Qt::UserRole + 2,
|
||||||
PureVirtual = Qt::UserRole + 3,
|
PureVirtual = Qt::UserRole + 3,
|
||||||
AccessSpec = Qt::UserRole + 4
|
AccessSpec = Qt::UserRole + 4
|
||||||
};
|
};
|
||||||
@@ -556,8 +556,10 @@ public:
|
|||||||
bool hideReimplementedFunctions() const;
|
bool hideReimplementedFunctions() const;
|
||||||
virtual bool gather();
|
virtual bool gather();
|
||||||
|
|
||||||
private slots:
|
public slots:
|
||||||
void updateCheckBoxes(QStandardItem *item);
|
void updateCheckBoxes(QStandardItem *item);
|
||||||
|
|
||||||
|
private slots:
|
||||||
void setHideReimplementedFunctions(bool hide);
|
void setHideReimplementedFunctions(bool hide);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user