mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-05-09 07:59:37 +00:00
added tests for import scaner of qt6 qml
This commit is contained in:
parent
3a7e407627
commit
f6570014fd
@ -14,15 +14,6 @@
|
||||
#include "deployconfig.h"
|
||||
|
||||
QStringList QML::extractImportsFromFile(const QString &filepath) {
|
||||
|
||||
if (DeployCore::_config && DeployCore::_config->qtDir.getQtVersion() == QtMajorVersion::Qt6) {
|
||||
return extractImportsFromFileQt6(filepath);
|
||||
}
|
||||
|
||||
return extractImportsFromFileQt5(filepath);
|
||||
}
|
||||
|
||||
QStringList QML::extractImportsFromFileQt5(const QString &filepath) {
|
||||
QStringList imports;
|
||||
QFile F(filepath);
|
||||
if (!F.open(QIODevice::ReadOnly)) return QStringList();
|
||||
@ -39,27 +30,24 @@ QStringList QML::extractImportsFromFileQt5(const QString &filepath) {
|
||||
if (!word.startsWith("import")) continue;
|
||||
|
||||
QStringList list = word.split(" ", QString::SkipEmptyParts);
|
||||
if (list.count() != 3)
|
||||
{
|
||||
if (list.count() == 5)
|
||||
{
|
||||
if (list[3] != "as") continue;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
imports << (list[2][0] + "#" + list[1].replace(".", "/"));
|
||||
if (list.count() == 3 || (list.count() == 5 && list[3] == "as")) {
|
||||
if (list[2] == "auto") {
|
||||
// qt6
|
||||
imports << (list[1].replace(".", "/"));
|
||||
continue;
|
||||
}
|
||||
// qt5
|
||||
imports << (list[2][0] + "#" + list[1].replace(".", "/"));
|
||||
} else if (list.count() == 2 || (list.count() == 4 && list[2] == "as")) {
|
||||
// qt6
|
||||
imports << (list[1].replace(".", "/"));
|
||||
}
|
||||
}
|
||||
|
||||
return imports;
|
||||
}
|
||||
|
||||
QStringList QML::extractImportsFromFileQt6(const QString &filepath) {
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool QML::extractImportsFromDir(const QString &path, bool recursive) {
|
||||
QDir dir(path);
|
||||
|
||||
@ -90,14 +78,12 @@ bool QML::extractImportsFromDir(const QString &path, bool recursive) {
|
||||
}
|
||||
|
||||
QString QML::getPathFromImport(const QString &import, bool checkVersions) {
|
||||
if (DeployCore::_config && DeployCore::_config->qtDir.getQtVersion() == QtMajorVersion::Qt6) {
|
||||
return getPathFromImportQt6(import, checkVersions);
|
||||
if (!import.contains("#")) {
|
||||
// qt 6
|
||||
auto info = QFileInfo(_qmlRoot + "/" + import);
|
||||
return info.absoluteFilePath();
|
||||
}
|
||||
|
||||
return getPathFromImportQt5(import, checkVersions);
|
||||
}
|
||||
|
||||
QString QML::getPathFromImportQt5(const QString &import, bool checkVersions) {
|
||||
auto importData = import.split("#");
|
||||
|
||||
int index;
|
||||
@ -133,12 +119,6 @@ QString QML::getPathFromImportQt5(const QString &import, bool checkVersions) {
|
||||
return info.absoluteFilePath();
|
||||
}
|
||||
|
||||
|
||||
QString QML::getPathFromImportQt6(const QString &import, bool checkVersions) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
bool QML::deployPath(const QString &path, QStringList &res) {
|
||||
QDir dir(path);
|
||||
auto infoList = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
|
||||
|
@ -16,14 +16,10 @@ class DEPLOYSHARED_EXPORT QML {
|
||||
private:
|
||||
|
||||
QStringList extractImportsFromFile(const QString &filepath);
|
||||
QStringList extractImportsFromFileQt5(const QString &filepath);
|
||||
QStringList extractImportsFromFileQt6(const QString &filepath);
|
||||
|
||||
bool extractImportsFromDir(const QString &path, bool recursive = false);
|
||||
|
||||
QString getPathFromImport(const QString& import, bool checkVersions = true);
|
||||
QString getPathFromImportQt5(const QString& import, bool checkVersions = true);
|
||||
QString getPathFromImportQt6(const QString& import, bool checkVersions = true);
|
||||
|
||||
bool deployPath( const QString& path, QStringList& res);
|
||||
bool scanQmlTree(const QString& qmlTree);
|
||||
|
@ -12,6 +12,7 @@
|
||||
<file alias="win64msvc.exe">testRes/win64/msvc/exe.exe</file>
|
||||
<file alias="win64msvc.dll">testRes/win64/msvc/lib.dll</file>
|
||||
<file alias="qmlFile.qml">testRes/qml/Scene</file>
|
||||
<file alias="qmlFileQt6.qml">testRes/qml/SceneQt6</file>
|
||||
</qresource>
|
||||
<qresource prefix="/testResurces">
|
||||
<file>testRes/TestQMLWidgets.sh</file>
|
||||
|
271
UnitTests/testRes/qml/SceneQt6
Normal file
271
UnitTests/testRes/qml/SceneQt6
Normal file
@ -0,0 +1,271 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls.Material auto
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Item {
|
||||
id: scene;
|
||||
z: -2
|
||||
|
||||
Rectangle {
|
||||
id: background;
|
||||
color: "#ffffff"
|
||||
anchors.fill: parent;
|
||||
|
||||
Behavior on color {
|
||||
|
||||
ColorAnimation {
|
||||
duration: 5000
|
||||
}
|
||||
}
|
||||
|
||||
z: -3
|
||||
|
||||
}
|
||||
|
||||
property var model: (contr)? contr: null;
|
||||
property var arrayObjects: []
|
||||
property bool showMenu: false
|
||||
property bool isPause: false
|
||||
|
||||
function add (cppObjId) {
|
||||
if (!model) {
|
||||
console.log("create object fail")
|
||||
return;
|
||||
}
|
||||
var objModel = model.getGameObject(cppObjId);
|
||||
|
||||
if (!objModel) {
|
||||
console.log("object model not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var viewTemplate = objModel.viewTemplate;
|
||||
|
||||
var temp = Qt.createComponent( viewTemplate + ".qml")
|
||||
if (temp.status === Component.Ready) {
|
||||
var obj = temp.createObject(parent) // parent - это обьект на который будет помещен соззданный элемент
|
||||
obj.model = model.getGameObject(cppObjId);
|
||||
obj.z = -2;
|
||||
arrayObjects.push(obj)
|
||||
} else {
|
||||
console.log("wrong viewTemplate in model");
|
||||
}
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
if (typeof id !== "number" || id < 0) {
|
||||
console.log("id not found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < arrayObjects.length; ++i) {
|
||||
if (id === arrayObjects[i].guiId) {
|
||||
arrayObjects.splice(i,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setAuto (auto) {
|
||||
if (auto && model) {
|
||||
model.newGame();
|
||||
|
||||
}
|
||||
showMenu = (auto && model)
|
||||
autoTimer.running = auto && model;
|
||||
}
|
||||
|
||||
function updateBackgroundColor(lvl) {
|
||||
switch(lvl % 7) {
|
||||
case 0: background.color = "#d6eaf8"; break;
|
||||
case 1: background.color = "#d0ece7"; break;
|
||||
case 2: background.color = "#d4efdf"; break;
|
||||
case 3: background.color = "#fcf3cf"; break;
|
||||
case 4: background.color = "#f6ddcc"; break;
|
||||
case 5: background.color = "#f2d7d5"; break;
|
||||
case 6: background.color = "#ebdef0"; break;
|
||||
case 7: background.color = "#fbfcfc"; break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Timer {
|
||||
id :autoTimer;
|
||||
repeat: true;
|
||||
running: false;
|
||||
interval: 1000
|
||||
onTriggered: {
|
||||
interval = Math.random() * 600
|
||||
scene.model.buttonPress();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: model;
|
||||
onGameObjectsChanged: {
|
||||
if (!dif) {
|
||||
console.log("dif not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var tempDifRem = [];
|
||||
tempDifRem = dif.getRemoveIds();
|
||||
var tempDifAdd = [];
|
||||
tempDifAdd = dif.getAddedIds();
|
||||
|
||||
for (var i = 0; i < tempDifAdd.length; ++i) {
|
||||
add(tempDifAdd[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < tempDifRem.length; ++i) {
|
||||
remove(tempDifRem[i]);
|
||||
}
|
||||
}
|
||||
|
||||
onFinished: {
|
||||
|
||||
var isVictory = victory;
|
||||
var gameLvl = lvl + 1;
|
||||
var dist = distance;
|
||||
updateBackgroundColor(gameLvl);
|
||||
|
||||
if (isVictory ) {
|
||||
|
||||
if (!autoTimer.running)
|
||||
notification.show(qsTr(" Next Lvl!!!"),
|
||||
qsTr(" You anblock next lvl (" + gameLvl + ")" ),
|
||||
"qrc:/texture/up");
|
||||
|
||||
model.nextLvl();
|
||||
} else if (autoTimer.running) {
|
||||
model.newGame();
|
||||
} else {
|
||||
showMenu = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
updateBackgroundColor(0);
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent;
|
||||
|
||||
onClicked: {
|
||||
if (!model) {
|
||||
console.log("model not found");
|
||||
return;
|
||||
}
|
||||
|
||||
model.buttonPress();
|
||||
}
|
||||
}
|
||||
|
||||
NotificationForm {
|
||||
z: -1
|
||||
id: notification;
|
||||
margin: mainWindow.point;
|
||||
|
||||
x: parent.width - width - margin;
|
||||
y: margin;
|
||||
|
||||
width: 40 * mainWindow.point;
|
||||
height: width * 0.5
|
||||
|
||||
}
|
||||
|
||||
Button {
|
||||
id: returnToMenu;
|
||||
|
||||
text: "<<"
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: point
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: point
|
||||
z: 1
|
||||
|
||||
onClicked: {
|
||||
showMenu = true;
|
||||
}
|
||||
|
||||
visible: !showMenu
|
||||
}
|
||||
|
||||
Button {
|
||||
id: pause
|
||||
|
||||
text: (isPause)? "▶" :"||"
|
||||
|
||||
anchors.left: returnToMenu.right
|
||||
anchors.leftMargin: point
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: point
|
||||
z: returnToMenu.z
|
||||
|
||||
onClicked: {
|
||||
isPause = !isPause;
|
||||
if (model) model.setPause(isPause);
|
||||
}
|
||||
|
||||
visible: !showMenu
|
||||
|
||||
}
|
||||
|
||||
Button {
|
||||
id: long_
|
||||
Label {
|
||||
anchors.fill: parent;
|
||||
|
||||
textFormat: Text.AutoText
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.WordWrap
|
||||
|
||||
text: qsTr("lvl long: ") + ((model)? model.long_: "0")
|
||||
}
|
||||
|
||||
width: 35 * point;
|
||||
height: pause.height;
|
||||
|
||||
anchors.left: pause.right
|
||||
anchors.leftMargin: point
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: point
|
||||
z: returnToMenu.z
|
||||
|
||||
visible: !showMenu
|
||||
|
||||
}
|
||||
|
||||
Button {
|
||||
Label {
|
||||
anchors.fill: parent;
|
||||
|
||||
textFormat: Text.AutoText
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.WordWrap
|
||||
|
||||
text: qsTr("general long: ") + ((model)? model.generalLong: "0")
|
||||
}
|
||||
|
||||
width: 35 * point;
|
||||
height: long_.height;
|
||||
|
||||
anchors.left: long_.right
|
||||
anchors.leftMargin: point
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: point
|
||||
z: returnToMenu.z
|
||||
|
||||
visible: !showMenu
|
||||
|
||||
}
|
||||
}
|
@ -143,6 +143,8 @@ private slots:
|
||||
void testInit();
|
||||
|
||||
void testDependencyMap();
|
||||
|
||||
void testQmlScaner();
|
||||
};
|
||||
|
||||
bool deploytest::runProcess(const QString &DistroPath,
|
||||
@ -680,6 +682,50 @@ void deploytest::testDependencyMap() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testQmlScaner() {
|
||||
|
||||
// qt5
|
||||
auto qmlRoot = QFileInfo(TestQtDir + "/qml").absoluteFilePath();
|
||||
QML *scaner = new QML(qmlRoot);
|
||||
auto imports = scaner->extractImportsFromFile(":/qmlFile.qml");
|
||||
|
||||
scaner->scanQmlTree(qmlRoot);
|
||||
|
||||
QSet<QString> results = {
|
||||
{qmlRoot + "/QtQuick.2/"},
|
||||
{qmlRoot + "/QtQuick/Controls.2/"},
|
||||
{qmlRoot + "/QtQuick/Controls.2/Material/"},
|
||||
{qmlRoot + "/QtQuick/Layouts/"},
|
||||
};
|
||||
|
||||
QVERIFY(results.size() == imports.size());
|
||||
|
||||
for (auto import: imports) {
|
||||
auto path = scaner->getPathFromImport(import);
|
||||
QVERIFY(results.contains(path));
|
||||
}
|
||||
|
||||
|
||||
// qt6
|
||||
|
||||
results = {
|
||||
{qmlRoot + "/QtQuick"},
|
||||
{qmlRoot + "/QtQuick/Controls"},
|
||||
{qmlRoot + "/QtQuick/Controls/Material"},
|
||||
{qmlRoot + "/QtQuick/Layouts"},
|
||||
};
|
||||
|
||||
imports = scaner->extractImportsFromFile(":/qmlFileQt6.qml");
|
||||
|
||||
QVERIFY(results.size() == imports.size());
|
||||
|
||||
for (auto import: imports) {
|
||||
auto path = scaner->getPathFromImport(import);
|
||||
QVERIFY(results.contains(path));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testQmlExtrct() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user