2022-03-14 19:21:24 +01:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-04-24 16:59:21 +02:00
|
|
|
|
|
|
|
|
source("../../shared/qtcreator.py")
|
|
|
|
|
|
2019-02-11 18:06:18 +01:00
|
|
|
def handleInsertVirtualFunctions(expected, toAdd):
|
|
|
|
|
def __checkVirtualFunction(treeView, classIndex, isCheckedF, child):
|
|
|
|
|
item = "%s.%s" % (str(classIndex.text), str(child.text))
|
|
|
|
|
test.log("Checking '%s'." % item)
|
2019-07-26 15:12:31 +02:00
|
|
|
# params required here
|
|
|
|
|
mouseClick(waitForObjectItem(treeView, item.replace("_", "\\_")), 5, 5, 0, Qt.LeftButton)
|
2019-02-11 18:06:18 +01:00
|
|
|
test.verify(waitFor("isCheckedF(child)", 1000), "Function must be checked after clicking")
|
|
|
|
|
|
2014-04-24 16:59:21 +02:00
|
|
|
treeView = waitForObject("{container={title='Functions to insert:' type='QGroupBox' unnamed='1'"
|
|
|
|
|
" visible='1'} type='QTreeView' unnamed='1' visible='1'}")
|
|
|
|
|
|
|
|
|
|
model = treeView.model()
|
|
|
|
|
classIndices = dumpIndices(model, treeView.rootIndex())
|
|
|
|
|
found = set()
|
|
|
|
|
isChecked = lambda ch: model.data(ch, Qt.CheckStateRole).toInt() == Qt.Checked
|
|
|
|
|
|
|
|
|
|
for classIndex in classIndices:
|
|
|
|
|
if model.hasChildren(classIndex):
|
|
|
|
|
for child in dumpIndices(model, classIndex):
|
|
|
|
|
for curr in expected:
|
|
|
|
|
if str(child.text).startswith(curr):
|
|
|
|
|
if test.verify(isChecked(child), "Verifying: '%s' is checked." % curr):
|
|
|
|
|
found.add(curr)
|
|
|
|
|
else:
|
2019-02-11 18:06:18 +01:00
|
|
|
__checkVirtualFunction(treeView, classIndex, isChecked, child)
|
|
|
|
|
for curr in toAdd:
|
|
|
|
|
if str(child.text).startswith(curr):
|
|
|
|
|
__checkVirtualFunction(treeView, classIndex, isChecked, child)
|
2014-04-24 16:59:21 +02:00
|
|
|
|
|
|
|
|
test.verify(len(set(expected).difference(found)) == 0,
|
|
|
|
|
"Verifying whether all expected functions have been found.")
|
|
|
|
|
|
|
|
|
|
selectFromCombo("{container={title='Insertion options:' type='QGroupBox' unnamed='1' "
|
2015-06-23 15:47:14 +02:00
|
|
|
" visible='1'} occurrence='2' type='QComboBox' unnamed='1' visible='1'}",
|
2014-04-24 16:59:21 +02:00
|
|
|
"Insert definitions in implementation file")
|
|
|
|
|
clickButton("{text='OK' type='QPushButton' unnamed='1' visible='1'}")
|
|
|
|
|
|
|
|
|
|
def checkSimpleCppLib(projectName, static):
|
2018-08-02 11:26:43 +02:00
|
|
|
projectName, className = createNewCPPLib(tempDir(), projectName, "MyClass",
|
2018-08-08 17:44:27 +02:00
|
|
|
Targets.desktopTargetClasses(),
|
2022-03-14 19:21:24 +01:00
|
|
|
static, buildSystem="qmake")
|
2018-08-02 11:26:43 +02:00
|
|
|
for kit, config in iterateBuildConfigs("Release"):
|
2022-03-15 15:34:22 +01:00
|
|
|
verifyBuildConfig(kit, config, False, True, buildSystem="qmake")
|
2014-04-24 16:59:21 +02:00
|
|
|
invokeMenuItem('Build', 'Build Project "%s"' % projectName)
|
|
|
|
|
waitForCompile(10000)
|
|
|
|
|
checkCompile()
|
|
|
|
|
|
|
|
|
|
def addReturn(editor, toFunction, returnValue):
|
|
|
|
|
placeCursorToLine(editor, toFunction, True)
|
|
|
|
|
type(editor, "<Down>")
|
|
|
|
|
type(editor, "<Return>")
|
|
|
|
|
type(editor, "return %s;" % returnValue)
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-08-22 14:37:34 +02:00
|
|
|
startQC()
|
2014-04-24 16:59:21 +02:00
|
|
|
if not startedWithoutPluginError():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
checkSimpleCppLib("SampleApp1", False)
|
|
|
|
|
checkSimpleCppLib("SampleApp2", True)
|
|
|
|
|
|
2020-02-06 21:05:01 +01:00
|
|
|
pluginTargets = (Targets.DESKTOP_5_10_1_DEFAULT, Targets.DESKTOP_5_14_1_DEFAULT)
|
2022-03-14 19:21:24 +01:00
|
|
|
projectName, className = createNewQtPlugin(tempDir(), "SampleApp3", "MyPlugin", pluginTargets,
|
|
|
|
|
buildSystem="qmake")
|
2014-04-24 16:59:21 +02:00
|
|
|
virtualFunctionsAdded = False
|
2018-08-02 11:26:43 +02:00
|
|
|
for kit, config in iterateBuildConfigs("Debug"):
|
2022-03-15 15:34:22 +01:00
|
|
|
verifyBuildConfig(kit, config, True, True, buildSystem="qmake")
|
2014-04-24 16:59:21 +02:00
|
|
|
invokeMenuItem('Build', 'Build Project "%s"' % projectName)
|
|
|
|
|
waitForCompile(10000)
|
|
|
|
|
if not virtualFunctionsAdded:
|
2023-05-26 00:46:45 +02:00
|
|
|
checkLastBuild(True)
|
2019-02-11 18:06:18 +01:00
|
|
|
if not openDocument("%s.Sources.%s\.cpp" % (projectName, className.lower())):
|
|
|
|
|
test.fatal("Could not open %s.cpp - continuing." % className.lower())
|
|
|
|
|
continue
|
|
|
|
|
editor = getEditorForFileSuffix("%s.cpp" % className.lower())
|
|
|
|
|
initialContent = str(editor.plainText)
|
2019-02-18 15:34:43 +01:00
|
|
|
test.verify("QObject *%s::create(" % className in initialContent,
|
2019-02-11 18:06:18 +01:00
|
|
|
"Verifying whether pure virtual function has been added to the source file.")
|
2014-04-24 16:59:21 +02:00
|
|
|
if not openDocument("%s.Headers.%s\.h" % (projectName, className.lower())):
|
2019-02-11 16:47:33 +01:00
|
|
|
test.fatal("Could not open %s.h - continuing." % className.lower())
|
2014-04-24 16:59:21 +02:00
|
|
|
continue
|
|
|
|
|
editor = getEditorForFileSuffix("%s.h" % className.lower())
|
2019-02-11 18:06:18 +01:00
|
|
|
initialContent = str(editor.plainText)
|
|
|
|
|
test.verify(re.search("QObject \*create.*;", initialContent, re.MULTILINE),
|
|
|
|
|
"Verifying whether create() declaration has been added to the header.")
|
2014-04-24 16:59:21 +02:00
|
|
|
placeCursorToLine(editor, "class %s.*" % className, True)
|
2018-07-06 16:58:38 +02:00
|
|
|
snooze(4) # avoid timing issue with the parser
|
2014-04-24 16:59:21 +02:00
|
|
|
invokeContextMenuItem(editor, "Refactor", "Insert Virtual Functions of Base Classes")
|
2019-02-11 18:06:18 +01:00
|
|
|
handleInsertVirtualFunctions(["create(const QString &, const QString &) = 0 : QObject *"],
|
|
|
|
|
["event(QEvent *) : bool"])
|
|
|
|
|
waitFor("'event' in str(editor.plainText)", 2000)
|
2014-04-24 16:59:21 +02:00
|
|
|
modifiedContent = str(editor.plainText)
|
2019-02-11 18:06:18 +01:00
|
|
|
test.verify(re.search("bool event\(QEvent \*event\);", modifiedContent, re.MULTILINE),
|
|
|
|
|
"Verifying whether event() declaration has been added to the header.")
|
2014-04-24 16:59:21 +02:00
|
|
|
|
|
|
|
|
if not openDocument("%s.Sources.%s\.cpp" % (projectName, className.lower())):
|
2019-02-11 16:47:33 +01:00
|
|
|
test.fatal("Could not open %s.cpp - continuing." % className.lower())
|
2014-04-24 16:59:21 +02:00
|
|
|
continue
|
|
|
|
|
editor = getEditorForFileSuffix("%s.cpp" % className.lower())
|
|
|
|
|
modifiedContent = str(editor.plainText)
|
2019-02-11 18:06:18 +01:00
|
|
|
test.verify("bool %s::event(QEvent *event)" % className in modifiedContent,
|
|
|
|
|
"Verifying whether event() definition has been added to the source file.")
|
2014-04-24 16:59:21 +02:00
|
|
|
# add return to not run into build issues of missing return values
|
2019-02-11 18:06:18 +01:00
|
|
|
addReturn(editor, "bool %s::event.*" % className, "true")
|
2019-02-18 15:34:43 +01:00
|
|
|
addReturn(editor, "QObject \*%s::create.*" % className, "0")
|
2019-02-11 18:06:18 +01:00
|
|
|
placeCursorToLine(editor, 'static_assert\(false, .*', True)
|
|
|
|
|
invokeContextMenuItem(editor, "Toggle Comment Selection")
|
2014-04-24 16:59:21 +02:00
|
|
|
virtualFunctionsAdded = True
|
|
|
|
|
invokeMenuItem('File', 'Save All')
|
2022-10-11 10:54:51 +02:00
|
|
|
selectFromLocator("t rebuild", "Rebuild Project")
|
2014-04-24 16:59:21 +02:00
|
|
|
waitForCompile(10000)
|
|
|
|
|
checkCompile()
|
|
|
|
|
|
|
|
|
|
invokeMenuItem("File", "Exit")
|