2016-01-15 14:55:33 +01:00
|
|
|
# Copyright (C) 2016 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
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2012-10-30 12:05:27 +01:00
|
|
|
source("../../shared/qtcreator.py")
|
|
|
|
|
|
|
|
qmlEditor = ":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget"
|
|
|
|
outline = ":Qt Creator_QmlJSEditor::Internal::QmlJSOutlineTreeView"
|
2016-07-13 16:37:00 +02:00
|
|
|
treebase = "keyinteraction.Resources.keyinteraction\\.qrc./keyinteraction.focus."
|
2012-10-30 12:05:27 +01:00
|
|
|
|
|
|
|
def main():
|
2023-02-22 13:49:54 +01:00
|
|
|
sourceExample = os.path.join(QtPath.examplesPath(Targets.DESKTOP_5_14_1_DEFAULT),
|
2016-07-13 16:37:00 +02:00
|
|
|
"quick", "keyinteraction")
|
|
|
|
proFile = "keyinteraction.pro"
|
2012-10-30 12:05:27 +01:00
|
|
|
if not neededFilePresent(os.path.join(sourceExample, proFile)):
|
|
|
|
return
|
|
|
|
templateDir = prepareTemplate(sourceExample)
|
2018-08-22 14:37:34 +02:00
|
|
|
startQC()
|
2013-02-22 14:31:39 +01:00
|
|
|
if not startedWithoutPluginError():
|
|
|
|
return
|
2020-02-06 21:05:01 +01:00
|
|
|
openQmakeProject(os.path.join(templateDir, proFile), [Targets.DESKTOP_5_14_1_DEFAULT])
|
2016-07-13 16:37:00 +02:00
|
|
|
qmlFiles = [treebase + "focus\\.qml", treebase + "Core.ListMenu\\.qml"]
|
2012-10-30 12:05:27 +01:00
|
|
|
checkOutlineFor(qmlFiles)
|
|
|
|
testModify()
|
2022-12-15 10:54:08 +01:00
|
|
|
saveAndExit()
|
2012-10-30 12:05:27 +01:00
|
|
|
|
|
|
|
def checkOutlineFor(qmlFiles):
|
|
|
|
for qmlFile in qmlFiles:
|
|
|
|
if not openDocument(qmlFile):
|
|
|
|
test.fatal("Failed to open file '%s'" % simpleFileName(qmlFile))
|
|
|
|
continue
|
|
|
|
selectFromCombo(":Qt Creator_Core::Internal::NavComboBox", "Outline")
|
|
|
|
pseudoTree = buildTreeFromOutline()
|
|
|
|
# __writeOutlineFile__(pseudoTree, simpleFileName(qmlFile)+"_outline.tsv")
|
|
|
|
verifyOutline(pseudoTree, simpleFileName(qmlFile) + "_outline.tsv")
|
|
|
|
|
|
|
|
def buildTreeFromOutline():
|
|
|
|
global outline
|
|
|
|
model = waitForObject(outline).model()
|
|
|
|
waitFor("model.rowCount() > 0")
|
2014-07-03 07:53:48 +02:00
|
|
|
snooze(1) # if model updates delayed processChildren() results in AUT crash
|
2012-10-30 12:05:27 +01:00
|
|
|
return processChildren(model, QModelIndex(), 0)
|
|
|
|
|
|
|
|
def processChildren(model, startIndex, level):
|
|
|
|
children = []
|
|
|
|
for index in dumpIndices(model, startIndex):
|
|
|
|
annotationData = str(index.data(Qt.UserRole + 3)) # HACK - taken from source
|
|
|
|
children.append((str(index.data()), level, annotationData))
|
|
|
|
if model.hasChildren(index):
|
|
|
|
children.extend(processChildren(model, index, level + 1))
|
|
|
|
return children
|
|
|
|
|
|
|
|
def testModify():
|
2014-01-07 14:30:39 +01:00
|
|
|
global qmlEditor
|
2016-07-13 16:37:00 +02:00
|
|
|
if not openDocument(treebase + "focus\\.qml"):
|
2012-10-30 12:05:27 +01:00
|
|
|
test.fatal("Failed to open file focus.qml")
|
|
|
|
return
|
|
|
|
test.log("Testing whether modifications show up inside outline.")
|
|
|
|
if not placeCursorToLine(qmlEditor, 'color: "#3E606F"'):
|
|
|
|
return
|
|
|
|
test.log("Modification: adding a QML element")
|
|
|
|
typeLines(qmlEditor, ['', '', 'Text {', 'id: addedText', 'text: "Squish QML outline test"',
|
|
|
|
'color: "darkcyan"', 'font.bold: true', 'anchors.centerIn: parent'])
|
|
|
|
selectFromCombo(":Qt Creator_Core::Internal::NavComboBox", "Outline")
|
|
|
|
snooze(1) # no way to wait for a private signal
|
|
|
|
pseudoTree = buildTreeFromOutline()
|
|
|
|
# __writeOutlineFile__(pseudoTree, "focus.qml_mod1_outline.tsv")
|
|
|
|
verifyOutline(pseudoTree, "focus.qml_mod1_outline.tsv")
|
|
|
|
test.log("Modification: change existing content")
|
|
|
|
performModification('color: "#3E606F"', "<Left>", 7, "Left", "white")
|
|
|
|
performModification('color: "black"', "<Left>", 5, "Left", "#cc00bb")
|
|
|
|
performModification('rotation: 90', None, 2, "Left", "180")
|
|
|
|
snooze(1) # no way to wait for a private signal
|
|
|
|
pseudoTree = buildTreeFromOutline()
|
|
|
|
# __writeOutlineFile__(pseudoTree, "focus.qml_mod2_outline.tsv")
|
|
|
|
verifyOutline(pseudoTree, "focus.qml_mod2_outline.tsv")
|
2013-01-18 15:37:32 +01:00
|
|
|
test.log("Modification: add special elements")
|
|
|
|
placeCursorToLine(qmlEditor, 'id: window')
|
|
|
|
typeLines(qmlEditor, ['', '', 'property string txtCnt: "Property"', 'signal clicked', '',
|
|
|
|
'function clicked() {','console.log("click")'])
|
|
|
|
performModification('onClicked: contextMenu.focus = true', None, 24, "Left", '{')
|
|
|
|
performModification('onClicked: {contextMenu.focus = true}', "<Left>", 0, None,
|
|
|
|
';window.clicked()')
|
|
|
|
snooze(1) # no way to wait for a private signal
|
|
|
|
pseudoTree = buildTreeFromOutline()
|
|
|
|
# __writeOutlineFile__(pseudoTree, "focus.qml_mod3_outline.tsv")
|
|
|
|
verifyOutline(pseudoTree, "focus.qml_mod3_outline.tsv")
|
2012-10-30 12:05:27 +01:00
|
|
|
|
|
|
|
def performModification(afterLine, typing, markCount, markDirection, newText):
|
|
|
|
global qmlEditor
|
|
|
|
if not placeCursorToLine(qmlEditor, afterLine):
|
|
|
|
return
|
|
|
|
if typing:
|
|
|
|
type(qmlEditor, typing)
|
2013-01-18 16:28:27 +01:00
|
|
|
markText(qmlEditor, markDirection, markCount)
|
2012-10-30 12:05:27 +01:00
|
|
|
type(qmlEditor, newText)
|
|
|
|
|
|
|
|
# used to create the tsv file(s)
|
|
|
|
def __writeOutlineFile__(outlinePseudoTree, filename):
|
|
|
|
f = open(filename, "w+")
|
|
|
|
f.write('"element"\t"nestinglevel"\t"value"\n')
|
|
|
|
for elem in outlinePseudoTree:
|
|
|
|
f.write('"%s"\t"%s"\t"%s"\n' % (elem[0], elem[1], elem[2].replace('"', '\"\"')))
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def retrieveData(record):
|
|
|
|
return (testData.field(record, "element"),
|
|
|
|
__builtin__.int(testData.field(record, "nestinglevel")),
|
|
|
|
testData.field(record, "value"))
|
|
|
|
|
|
|
|
def verifyOutline(outlinePseudoTree, datasetFileName):
|
|
|
|
fileName = datasetFileName[:datasetFileName.index("_")]
|
2023-03-21 10:10:03 +01:00
|
|
|
expected = list(map(retrieveData, testData.dataset(datasetFileName)))
|
2012-10-30 12:05:27 +01:00
|
|
|
if len(expected) != len(outlinePseudoTree):
|
|
|
|
test.fail("Mismatch in length of expected and found elements of outline. Skipping "
|
|
|
|
"verification of nodes.",
|
|
|
|
"Found %d elements, but expected %d" % (len(outlinePseudoTree), len(expected)))
|
|
|
|
return
|
|
|
|
for counter, (expectedItem, foundItem) in enumerate(zip(expected, outlinePseudoTree)):
|
2018-08-02 13:45:34 +02:00
|
|
|
if expectedItem != foundItem:
|
2020-05-28 10:40:54 +02:00
|
|
|
test.fail("Mismatch in element number %d for '%s'" % (counter + 1, fileName),
|
|
|
|
"%s != %s" % (str(expectedItem), str(foundItem)))
|
2018-08-02 13:45:34 +02:00
|
|
|
return
|
2012-10-30 12:05:27 +01:00
|
|
|
test.passes("All nodes (%d) inside outline match expected nodes for '%s'."
|
|
|
|
% (len(expected), fileName))
|