2016-01-15 14:55:33 +01:00
|
|
|
############################################################################
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
# Contact: https://www.qt.io/licensing/
|
|
|
|
|
#
|
|
|
|
|
# This file is part of Qt Creator.
|
|
|
|
|
#
|
|
|
|
|
# Commercial License Usage
|
|
|
|
|
# Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
# accordance with the commercial license agreement provided with the
|
|
|
|
|
# Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
# a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
# and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
# information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
#
|
|
|
|
|
# GNU General Public License Usage
|
|
|
|
|
# Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
# General Public License version 3 as published by the Free Software
|
|
|
|
|
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
# included in the packaging of this file. Please review the following
|
|
|
|
|
# information to ensure the GNU General Public License requirements will
|
|
|
|
|
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
#
|
|
|
|
|
############################################################################
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2012-05-10 10:53:06 +02:00
|
|
|
source("../shared/qmls.py")
|
2012-04-25 09:57:22 +02:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
projectDir = tempDir()
|
2017-10-13 10:08:08 +02:00
|
|
|
editorArea = startQtCreatorWithNewAppAtQMLEditor(projectDir, "SampleApp")
|
2012-05-10 10:53:06 +02:00
|
|
|
if not editorArea:
|
2012-04-25 09:57:22 +02:00
|
|
|
return
|
2017-10-13 10:08:08 +02:00
|
|
|
# add basic TextEdit item to check it afterwards
|
|
|
|
|
codelines = ['TextEdit {', 'id: textEdit', 'text: "Enter something"', 'anchors.top: parent.top',
|
|
|
|
|
'anchors.horizontalCenter: parent.horizontalCenter', 'anchors.topMargin: 20']
|
|
|
|
|
if not addTestableCodeAfterLine(editorArea, 'title: qsTr("Hello World")', codelines):
|
|
|
|
|
saveAndExit()
|
|
|
|
|
return
|
|
|
|
|
placeCursorToLine(editorArea, "TextEdit {")
|
2018-08-02 13:45:34 +02:00
|
|
|
for _ in range(5):
|
2012-05-25 11:52:01 +02:00
|
|
|
type(editorArea, "<Left>")
|
2012-04-25 09:57:22 +02:00
|
|
|
# invoke Refactoring - Move Component into separate file
|
2013-02-20 19:49:32 +01:00
|
|
|
invokeContextMenuItem(editorArea, "Refactoring", "Move Component into Separate File")
|
2012-04-25 09:57:22 +02:00
|
|
|
# give component name and proceed
|
|
|
|
|
replaceEditorContent(waitForObject(":Dialog.componentNameEdit_QLineEdit"), "MyComponent")
|
|
|
|
|
clickButton(waitForObject(":Dialog.OK_QPushButton"))
|
2012-05-16 18:13:55 +02:00
|
|
|
try:
|
|
|
|
|
waitForObject(":Add to Version Control_QMessageBox", 5000)
|
|
|
|
|
clickButton(waitForObject(":Add to Version Control.No_QPushButton"))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2012-04-25 09:57:22 +02:00
|
|
|
# verify if refactoring is done correctly
|
|
|
|
|
waitFor("'MyComponent' in str(editorArea.plainText)", 2000)
|
|
|
|
|
codeText = str(editorArea.plainText)
|
2016-08-11 16:54:18 +02:00
|
|
|
patternCodeToAdd = "MyComponent\s+\{\s*id: textEdit\s*\}"
|
|
|
|
|
patternCodeToMove = "TextEdit\s+\{.*\}"
|
|
|
|
|
# there should be empty MyComponent item instead of TextEdit item
|
2012-04-25 09:57:22 +02:00
|
|
|
if re.search(patternCodeToAdd, codeText, re.DOTALL) and not re.search(patternCodeToMove, codeText, re.DOTALL):
|
|
|
|
|
test.passes("Refactoring was properly applied in source file")
|
|
|
|
|
else:
|
|
|
|
|
test.fail("Refactoring of Text to MyComponent failed in source file. Content of editor:\n%s" % codeText)
|
2014-04-08 15:34:46 +02:00
|
|
|
myCompTE = "SampleApp.Resources.qml\\.qrc./.MyComponent\\.qml"
|
2012-04-25 09:57:22 +02:00
|
|
|
# there should be new QML file generated with name "MyComponent.qml"
|
|
|
|
|
try:
|
2015-12-01 14:14:02 +01:00
|
|
|
waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", myCompTE, 5000)
|
2012-04-25 09:57:22 +02:00
|
|
|
except:
|
2013-01-31 16:47:16 +01:00
|
|
|
try:
|
|
|
|
|
waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", addBranchWildcardToRoot(myCompTE), 1000)
|
|
|
|
|
except:
|
2014-04-03 08:58:19 +02:00
|
|
|
test.fail("Refactoring failed - file MyComponent.qml was not generated properly in project explorer")
|
|
|
|
|
#save and exit
|
|
|
|
|
invokeMenuItem("File", "Save All")
|
|
|
|
|
invokeMenuItem("File", "Exit")
|
|
|
|
|
return
|
|
|
|
|
test.passes("Refactoring - file MyComponent.qml was generated properly in project explorer")
|
|
|
|
|
# open MyComponent.qml file for verification
|
|
|
|
|
if not openDocument(myCompTE):
|
|
|
|
|
test.fatal("Could not open MyComponent.qml.")
|
|
|
|
|
invokeMenuItem("File", "Save All")
|
|
|
|
|
invokeMenuItem("File", "Exit")
|
|
|
|
|
return
|
2012-04-25 09:57:22 +02:00
|
|
|
editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget")
|
|
|
|
|
codeText = str(editorArea.plainText)
|
|
|
|
|
# there should be Text item in new file
|
|
|
|
|
if re.search(patternCodeToMove, codeText, re.DOTALL):
|
|
|
|
|
test.passes("Refactoring was properly applied to destination file")
|
|
|
|
|
else:
|
|
|
|
|
test.fail("Refactoring failed in destination file. Content of editor:\n%s" % codeText)
|
|
|
|
|
#save and exit
|
|
|
|
|
invokeMenuItem("File", "Save All")
|
|
|
|
|
# check if new file was created in file system
|
2014-04-08 15:34:46 +02:00
|
|
|
test.verify(os.path.exists(os.path.join(projectDir, "SampleApp", "MyComponent.qml")),
|
2012-04-25 09:57:22 +02:00
|
|
|
"Verifying if MyComponent.qml exists in file system after save")
|
|
|
|
|
invokeMenuItem("File", "Exit")
|