Skip to content
Snippets Groups Projects
Commit 20733343 authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

QDS-11912 Project list and run project button are enabled/disabled properly

parent 16db45fc
No related branches found
No related tags found
1 merge request!36QDS-11912 Project list and run project button are enabled/disabled properly
Pipeline #67155 passed
...@@ -150,7 +150,7 @@ void Backend::setAutoScaleProject(const bool &enabled) ...@@ -150,7 +150,7 @@ void Backend::setAutoScaleProject(const bool &enabled)
void Backend::setUserHash(const QString &userHash) void Backend::setUserHash(const QString &userHash)
{ {
QSettings().setValue("user/hash", userHash); QSettings().setValue("user/hash", userHash);
updateUserProjectList(); emit userRegistered();
} }
bool Backend::updateInBackground() bool Backend::updateInBackground()
...@@ -494,8 +494,6 @@ void Backend::runOnlineProject(const QString &url) ...@@ -494,8 +494,6 @@ void Backend::runOnlineProject(const QString &url)
void Backend::updateUserProjectList() void Backend::updateUserProjectList()
{ {
emit userRegistered();
const QString userHash = Backend::userHash(); const QString userHash = Backend::userHash();
if (userHash.isEmpty()) { if (userHash.isEmpty()) {
...@@ -511,17 +509,16 @@ void Backend::updateUserProjectList() ...@@ -511,17 +509,16 @@ void Backend::updateUserProjectList()
return; return;
} }
if (projectList == m_projectListArray) { if (projectList == m_projectList) {
qDebug("No new projects available"); qDebug("No new projects available");
return; return;
} }
m_projectListArray = projectList;
m_projectList.clear(); m_projectList = projectList;
qDebug("List of available projects fetched:"); qDebug("List of available projects fetched:");
for (const auto &project : projectList) { for (const auto &project : projectList) {
const QString projectName{project.toObject().value("appName").toString()}; const QString projectName{project.toObject().value("appName").toString()};
qDebug() << "--" << projectName; qDebug() << "--" << projectName;
m_projectList << projectName;
} }
emit projectListChanged(); emit projectListChanged();
...@@ -534,7 +531,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url) ...@@ -534,7 +531,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url)
// If it is a user hash, we register the user and fetch the project list // If it is a user hash, we register the user and fetch the project list
// If it is a project url, we submit the url to the text field // If it is a project url, we submit the url to the text field
// sample url: https://<url>/<project_name>.qmlrc // sample url: https://<url>/<project_name>.qmlrc
// sample user hash: qtdesignviewer://17e8907b3b84029384hs8djshdu38476 // sample user hash: qtdesignviewer://19f8907b6t84029384hs8djshdu38476
if (urlData.isEmpty()) if (urlData.isEmpty())
return; return;
else if (urlData.startsWith("https//")) { else if (urlData.startsWith("https//")) {
...@@ -545,6 +542,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url) ...@@ -545,6 +542,7 @@ void Backend::parseDesignViewerUrl(const QUrl &url)
} else if (urlData.startsWith("qtdesignviewer://")) { } else if (urlData.startsWith("qtdesignviewer://")) {
qDebug() << "Registering user from QR code"; qDebug() << "Registering user from QR code";
setUserHash(url.toString().remove("qtdesignviewer://")); setUserHash(url.toString().remove("qtdesignviewer://"));
updateUserProjectList();
} else { } else {
qWarning() << "Unknown QR code data: " << urlData; qWarning() << "Unknown QR code data: " << urlData;
} }
......
...@@ -58,7 +58,7 @@ signals: ...@@ -58,7 +58,7 @@ signals:
class Backend : public QObject class Backend : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QStringList projectList READ projectList NOTIFY projectListChanged FINAL) Q_PROPERTY(QJsonArray projectList READ projectList NOTIFY projectListChanged)
public: public:
explicit Backend(QObject *parent = nullptr); explicit Backend(QObject *parent = nullptr);
...@@ -69,13 +69,12 @@ public: ...@@ -69,13 +69,12 @@ public:
emit logsChanged(m_logs); emit logsChanged(m_logs);
} }
QStringList projectList() const { return m_projectList; } QJsonArray projectList() const { return m_projectList; }
private: private:
// UI data // UI data
QString m_logs; QString m_logs;
QStringList m_projectList; QJsonArray m_projectList;
QJsonArray m_projectListArray;
// Other members // Other members
ServiceConnector m_serviceConnector; ServiceConnector m_serviceConnector;
......
...@@ -62,33 +62,42 @@ Item { ...@@ -62,33 +62,42 @@ Item {
ColumnLayout { ColumnLayout {
id: column2 id: column2
Layout.fillWidth: true Layout.fillWidth: true
ComboBox { ComboBox {
id: projectList id: projectList
Layout.fillWidth: true Layout.fillWidth: true
enabled: backend.userHash() !== '' enabled: true
onCurrentIndexChanged: { onCurrentIndexChanged: {
displayText = textAt(currentIndex) displayText = textAt(currentIndex)
} }
textRole: "appName"
model: backend.projectList model: backend.projectList
displayText: "Scan QR code to access your projects"; displayText: "Scan QR code to access your projects";
currentIndex: -1 currentIndex: -1
Layout.preferredHeight: 50 Layout.preferredHeight: 50
Connections {
target: backend
function onUserRegistered(){
projectList.enabled = true;
}
}
} }
Button { Button {
id: downloadUserProject id: downloadUserProject
text: qsTr("Run Project") text: qsTr("Run Project")
onClicked: backend.runUserProject(projectList.currentText) onClicked: backend.runUserProject(projectList.currentText)
enabled: backend.userHash() !== '' enabled: false
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
} }
Connections {
target: backend
function onUserRegistered(){
projectList.displayText = "No projects available for the user";
projectList.enabled = false;
downloadUserProject.enabled = false;
}
function onProjectListChanged(){
projectList.enabled = true;
downloadUserProject.enabled = true;
}
}
} }
Item { Item {
......
...@@ -45,8 +45,9 @@ Item { ...@@ -45,8 +45,9 @@ Item {
Text{ Text{
leftPadding: 45 leftPadding: 45
text: qsTr("Scales the project to fit it to the current display and orientation") text: qsTr("Scales the project to fit it to the current\ndisplay and orientation")
font.pointSize: 12 font.pointSize: 12
wrapMode: Text.WordWrap
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment