Commit 95af1cd4 authored by Robert Loehning's avatar Robert Loehning
Browse files

Squish: Added helper functions for views and models



Change-Id: Ic5dc4a5fe11ec5f693ef9f5ddf3abbefd689fd99
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent e94642e8
......@@ -142,7 +142,7 @@ def iterateBuildConfigs(targetCount, currentTarget, filter = ""):
model = waitForObject(":scrollArea.Edit build configuration:_QComboBox", 20000).model()
prog = re.compile(filter)
# for each row in the model, write its data to a list
configNames = [str(model.index(row, 0).data()) for row in range(model.rowCount())]
configNames = dumpItems(model)
# pick only those configuration names which pass the filter
configs = [config for config in configNames if prog.match(config)]
switchViewTo(ViewConstants.EDIT)
......
......@@ -89,8 +89,7 @@ def removeOldBreakpoints():
test.log("No breakpoints found...")
else:
test.log("Found %d breakpoints - removing them" % model.rowCount())
for row in range(model.rowCount()):
currentIndex = model.index(row,0)
for currentIndex in dumpIndices(model):
rect = breakPointTreeView.visualRect(currentIndex)
mouseClick(breakPointTreeView, rect.x+5, rect.y+5, 0, Qt.LeftButton)
type(breakPointTreeView, "<Delete>")
......
......@@ -261,13 +261,11 @@ def validateSearchResult(expectedCount):
matches = cast((str(counterLabel.text)).split(" ", 1)[0], "int")
test.compare(matches, expectedCount, "Verified match count.")
model = resultTreeView.model()
for row in range(model.rowCount()):
index = model.index(row, 0)
for index in dumpIndices(model):
itemText = str(model.data(index).toString())
doubleClickItem(resultTreeView, maskSpecialCharsForSearchResult(itemText), 5, 5, 0, Qt.LeftButton)
test.log("%d occurrences in %s" % (model.rowCount(index), itemText))
for chRow in range(model.rowCount(index)):
chIndex = model.index(chRow, 0, index)
for chIndex in dumpIndices(model, index):
resultTreeView.scrollTo(chIndex)
text = str(chIndex.data()).rstrip('\r')
rect = resultTreeView.visualRect(chIndex)
......
......@@ -25,9 +25,8 @@ def modifyRunSettingsForHookInto(projectName, port):
envVarsTableView = waitForObject("{type='QTableView' visible='1' unnamed='1'}")
model = envVarsTableView.model()
changingVars = []
for row in range(model.rowCount()):
for index in dumpIndices(model):
# get var name
index = model.index(row, 0)
envVarsTableView.scrollTo(index)
varName = str(model.data(index).toString())
# if its a special SQUISH var simply unset it, SQUISH_LIBQTDIR and PATH will be replaced with Qt paths
......@@ -172,9 +171,7 @@ def getQMakeFromQtVersion(qtVersion):
mouseClick(qtVersionTab, 5, 5, 0, Qt.LeftButton)
qtVersionsTree = waitForObject("{name='qtdirList' type='QTreeWidget' visible='1'}")
rootIndex = qtVersionsTree.invisibleRootItem()
rows = rootIndex.childCount()
for currentRow in range(rows):
current = rootIndex.child(currentRow)
for current in dumpChildren(rootIndex):
child = getTreeWidgetChildByText(current, qtVersion)
if child != None:
break
......@@ -191,9 +188,7 @@ def getQMakeFromQtVersion(qtVersion):
return qmake
def getTreeWidgetChildByText(parent, text, column=0):
childCount = parent.childCount()
for row in range(childCount):
child = parent.child(row)
for child in dumpChildren(parent):
if child.text(column)==text:
return child
return None
......
......@@ -468,7 +468,7 @@ def __sortFilenamesOSDependent__(filenames):
def __iterateChildren__(model, parent, nestingLevel=0):
children = []
for currentIndex in [model.index(row, 0, parent) for row in range(model.rowCount(parent))]:
for currentIndex in dumpIndices(model, parent):
children.append([str(currentIndex.text), nestingLevel])
if model.hasChildren(currentIndex):
children.extend(__iterateChildren__(model, currentIndex, nestingLevel + 1))
......
......@@ -188,12 +188,12 @@ def __selectTreeItemOnBuildAndRun__(treeViewOrWidget, itemText, isRegex=False):
pattern = re.compile(itemText)
found = False
for section in [autoDetected, manual]:
for index in [section.child(i, 0) for i in range(model.rowCount(section))]:
if (isRegex and pattern.match(str(index.data().toString()))
or itemText == (str(index.data().toString()))):
for dumpedItem in dumpItems(model, section):
if (isRegex and pattern.match(dumpedItem)
or itemText == dumpedItem):
found = True
item = ".".join([str(section.data().toString()),
str(index.data().toString()).replace(".", "\\.")])
dumpedItem.replace(".", "\\.")])
clickItem(treeViewOrWidget, item, 5, 5, 0, Qt.LeftButton)
break
if found:
......
......@@ -19,11 +19,9 @@ def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True):
if(warnIfMoreIssues and issuesModel.rowCount() > 1):
test.warning("More than one expected issues reported")
# iterate issues and check if there exists "Unexpected token" message
for row in range(issuesModel.rowCount()):
for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole + 3),
dumpItems(issuesModel, role=Qt.UserRole + 5)):
# enum Roles { File = Qt::UserRole, Line, MovedLine, Description, FileNotFound, Type, Category, Icon, Task_t };
index = issuesModel.index(row, 0)
description = str(index.data(Qt.UserRole + 3).toString())
type = str(index.data(Qt.UserRole + 5).toString())
# check if at least one of expected texts found in issue text
for expectedText in expectedTextsArray:
if expectedText in description:
......
......@@ -434,11 +434,9 @@ def iterateQtVersions(keepOptionsOpen=False, alreadyOnOptionsDialog=False,
pattern = re.compile("Qt version (?P<version>.*?) for (?P<target>.*)")
treeWidget = waitForObject(":QtSupport__Internal__QtVersionManager.qtdirList_QTreeWidget")
root = treeWidget.invisibleRootItem()
for childRow in range(root.childCount()):
rootChild = root.child(childRow)
for rootChild in dumpChildren(root):
rootChildText = str(rootChild.text(0)).replace(".", "\\.")
for row in range(rootChild.childCount()):
subChild = rootChild.child(row)
for subChild in dumpChildren(rootChild):
subChildText = str(subChild.text(0)).replace(".", "\\.")
clickItem(treeWidget, ".".join([rootChildText,subChildText]), 5, 5, 0, Qt.LeftButton)
currentText = str(waitForObject(":QtSupport__Internal__QtVersionManager.QLabel").text)
......@@ -503,13 +501,13 @@ def iterateKits(keepOptionsOpen=False, alreadyOnOptionsDialog=False,
manual = model.index(1, 0)
test.compare(manual.data().toString(), "Manual", "Verifying label for target section")
for section in [autoDetected, manual]:
for index in [section.child(i, 0) for i in range(model.rowCount(section))]:
kitName = str(index.data().toString())
for currentItem in dumpItems(model, section):
kitName = currentItem
if (kitName.endswith(" (default)")):
kitName = kitName.rsplit(" (default)", 1)[0]
result.append(kitName)
item = ".".join([str(section.data().toString()),
str(index.data().toString()).replace(".", "\\.")])
currentItem.replace(".", "\\.")])
if additionalFunction:
try:
if isinstance(additionalFunction, (str, unicode)):
......@@ -547,3 +545,19 @@ def removePackagingDirectory(projectPath):
deleteDirIfExists(qtcPackaging)
else:
test.log("Couldn't remove packaging directory '%s' - did not exist." % qtcPackaging)
# returns the indices from a QAbstractItemModel
def dumpIndices(model, parent=None, column=0):
if parent:
return [model.index(row, column, parent) for row in range(model.rowCount(parent))]
else:
return [model.index(row, column) for row in range(model.rowCount())]
DisplayRole = 0
# returns the data from a QAbstractItemModel as strings
def dumpItems(model, parent=None, role=DisplayRole, column=0):
return [str(index.data(role)) for index in dumpIndices(model, parent, column)]
# returns the children of a QTreeWidgetItem
def dumpChildren(item):
return [item.child(index) for index in range(item.childCount())]
......@@ -16,9 +16,7 @@ def __beginTestSuggestions__(editorArea, lineText, textToType):
def verifySuggestions(textToType):
popup = findObject(":popupFrame_Proposal_QListView")
model = popup.model()
for row in range(model.rowCount()):
index = model.index(row, 0)
text = str(model.data(index).toString())
for text in dumpItems(model):
test.verify(textToType.lower() in text.lower(),
"Checking whether suggestion '%s' makes sense for typed '%s'"
% (text, textToType))
......
......@@ -13,14 +13,12 @@ def checkUsages(resultsView, expectedResults):
resultsModel = resultsView.model()
waitFor("resultsModel.rowCount() > 0", 5000)
expectedResultIndex = 0
for row in range(resultsModel.rowCount()):
for index in dumpIndices(resultsModel):
# enum Roles { ResultItemRole = Qt::UserRole, ResultLineRole, ResultLineNumberRole, ResultIconRole,
# SearchTermStartRole, SearchTermLengthRole, IsGeneratedRole };
index = resultsModel.index(row, 0)
# get only filename not full path
resultFile = str(index.data(Qt.UserRole + 1).toString()).replace("\\", "/").split('/')[-1]
for chRow in range(resultsModel.rowCount(index)):
chIndex = resultsModel.index(chRow, 0, index)
for chIndex in dumpIndices(resultsModel, index):
resultLine = str(chIndex.data(Qt.UserRole + 1).toString()).strip()
resultLineNumber = chIndex.data(Qt.UserRole + 2).toInt()
# verify if we don't get more results
......
......@@ -24,20 +24,15 @@ def main():
comboBox = waitForObject("{name='comboBox' type='QComboBox' visible='1' "
"window=':New_Core::Internal::NewDialog'}")
test.compare(comboBox.currentText, "All Templates")
for row in range(catModel.rowCount(projects)):
index = catModel.index(row, 0, projects)
category = str(index.data()).replace(".", "\\.")
for category in [item.replace(".", "\\.") for item in dumpItems(catModel, projects)]:
# skip non-configurable
if "Import" in category or "Non-Qt" in category:
continue
clickItem(categoriesView, "Projects." + category, 5, 5, 0, Qt.LeftButton)
templatesView = waitForObject("{name='templatesView' type='QListView' visible='1'}", 20000)
# needed because categoriesView and templatesView using same model
tempRootIndex = templatesView.rootIndex()
tempModel = templatesView.model()
for tRow in range(tempModel.rowCount(tempRootIndex)):
tIndex = tempModel.index(tRow, 0, tempRootIndex)
template = str(tempModel.data(tIndex)).replace(".", "\\.")
for template in dumpItems(templatesView.model(), templatesView.rootIndex()):
template = template.replace(".", "\\.")
# skip non-configurable
if "Qt Quick UI" in template or "Plain C" in template:
continue
......
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