Update QsoTab.qml

Fixed Log Entry Serial and Added Share Button

Signed-off-by: rohithzmoi <166651631+rohithzmoi@users.noreply.github.com>
This commit is contained in:
rohithzmoi 2024-09-06 16:23:17 +05:30 committed by GitHub
parent 5c1994daf6
commit 9152655956
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 84 additions and 48 deletions

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2024 Rohith Namboothiri Copyright (C) 2024 Rohith Namboothiri
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -30,8 +30,8 @@ Item {
property int tgid: -1 property int tgid: -1
property string logFileName: "logs.json" property string logFileName: "logs.json"
property string savedFilePath: "" property string savedFilePath: ""
//property int latestSerialNumber: 0 property int latestSerialNumber: 0
property int latestSerialNumber: 1 property bool isLoading: true
signal firstRowDataChanged(string serialNumber, string callsign, string handle, string country) signal firstRowDataChanged(string serialNumber, string callsign, string handle, string country)
@ -63,7 +63,6 @@ Item {
target: logModel target: logModel
onCountChanged: { onCountChanged: {
updateRowData(); updateRowData();
saveSettings(); // Save logs when the model changes
} }
} }
@ -92,6 +91,7 @@ Item {
logModel.append(savedData[i]); logModel.append(savedData[i]);
latestSerialNumber = Math.max(latestSerialNumber, savedData[i].serialNumber + 1); latestSerialNumber = Math.max(latestSerialNumber, savedData[i].serialNumber + 1);
} }
isLoading = false;
} }
function clearSettings() { function clearSettings() {
@ -273,37 +273,77 @@ Item {
} }
} }
// Error Dialog to show if file name is empty
Dialog {
id: errorDialog
title: "Error"
standardButtons: Dialog.Ok
modal: true
width: 300
contentItem: Text {
text: "Empty/Invalid File Name."
wrapMode: Text.WordWrap
color: "red"
width: parent.width * 0.9
}
}
// Dialog to show that the file was saved // Dialog to show that the file was saved
Dialog { Dialog {
id: fileSavedDialog id: fileSavedDialog
title: "File Saved" title: "File Saved"
standardButtons: Dialog.Ok standardButtons: Dialog.Ok
width: 300 // Set a fixed width for the dialog to avoid binding loops width: 300
onAccepted: { onAccepted: {
console.log("File saved successfully!"); console.log("File saved successfully!");
} }
background: Rectangle { background: Rectangle {
color: "#80c342" color: "#80c342"
radius: 8 // Optional: Add rounded corners radius: 8
} }
contentItem: Text { contentItem: Column {
spacing: 10
// Text to display the success message
Text {
text: "File saved successfully to " + savedFilePath text: "File saved successfully to " + savedFilePath
font.pointSize: 14 font.pointSize: 14
color: "black" color: "black"
wrapMode: Text.WordWrap // Enable text wrapping wrapMode: Text.WordWrap
width: parent.width * 0.9 // Ensure some padding from the edges width: parent.width * 0.9
}
// Row for the buttons
Row {
spacing: 10
anchors.horizontalCenter: parent.horizontalCenter
Button {
text: "Cancel"
onClicked: fileSavedDialog.accept()
}
Button {
text: "Share"
onClicked: {
logHandler.shareFile();
}
}
} }
} }
}
Row { Row {
id: tableHeader id: tableHeader
width: parent.width width: parent.width
height: 25 // Make the rectangles slightly smaller in height height: 25
y: clearButton.y + clearButton.height + 10 y: clearButton.y + clearButton.height + 10
spacing: 4 // Reduce spacing slightly spacing: 4
Rectangle { Rectangle {
width: parent.width / 8 width: parent.width / 8
@ -313,7 +353,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "Sr.No" text: "Sr.No"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
Rectangle { Rectangle {
@ -324,7 +364,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "Callsign" text: "Callsign"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
Rectangle { Rectangle {
@ -335,7 +375,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "DMR ID" text: "DMR ID"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
Rectangle { Rectangle {
@ -346,7 +386,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "TGID" text: "TGID"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
Rectangle { Rectangle {
@ -357,7 +397,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "Handle" text: "Handle"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
Rectangle { Rectangle {
@ -368,12 +408,12 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: "Country" text: "Country"
font.bold: true font.bold: true
font.pixelSize: 12 // Smaller font size font.pixelSize: 12
} }
} }
} }
// The TableView for the rows
TableView { TableView {
id: tableView id: tableView
x: 0 x: 0
@ -385,13 +425,13 @@ TableView {
delegate: Rectangle { delegate: Rectangle {
width: tableView.width width: tableView.width
implicitWidth: tableView.width implicitWidth: tableView.width
implicitHeight: 100 // Adjust the height to accommodate the checkbox and time text implicitHeight: 100
height: implicitHeight height: implicitHeight
color: checkBox.checked ? "#b9fbd7" : (index % 2 === 0 ? "lightgrey" : "white") // Changes color when checked color: checkBox.checked ? "#b9fbd7" : (index % 2 === 0 ? "lightgrey" : "white")
Row { Row {
width: parent.width width: parent.width
height: 40 // Set a fixed height for the row height: 40
Rectangle { Rectangle {
width: parent.width / 8 width: parent.width / 8
@ -399,7 +439,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: serialNumber // Using direct access to model properties text: serialNumber
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -409,7 +449,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: callsign // Using direct access to model properties text: callsign
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -419,7 +459,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: dmrID // Using direct access to model properties text: dmrID
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -429,7 +469,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: tgid // Using direct access to model properties text: tgid
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -439,7 +479,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: fname // Using direct access to model properties text: fname
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -449,7 +489,7 @@ TableView {
color: "transparent" color: "transparent"
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
text: country // Using direct access to model properties text: country
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@ -482,7 +522,7 @@ TableView {
Text { Text {
id: menuIcon id: menuIcon
text: "\uf0c9" // FontAwesome icon for bars (hamburger menu) text: "\uf0c9"
font.family: "FontAwesome" font.family: "FontAwesome"
font.pixelSize: 20 font.pixelSize: 20
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -526,8 +566,8 @@ TableView {
function onDataUpdated(receivedDmrID, receivedTGID) { function onDataUpdated(receivedDmrID, receivedTGID) {
console.log("Received dmrID:", receivedDmrID, "and TGID:", receivedTGID); console.log("Received dmrID:", receivedDmrID, "and TGID:", receivedTGID);
qsoTab.dmrID = receivedDmrID; // Correctly scope the dmrID assignment qsoTab.dmrID = receivedDmrID;
qsoTab.tgid = receivedTGID; // Set the TGID in qsoTab qsoTab.tgid = receivedTGID;
fetchData(receivedDmrID, receivedTGID); fetchData(receivedDmrID, receivedTGID);
} }
@ -565,9 +605,8 @@ TableView {
console.error("Invalid data received:", data); console.error("Invalid data received:", data);
return; return;
} }
isLoading = false;
// Increment the latest serial number
latestSerialNumber += 1;
// Check and update the country field // Check and update the country field
if (data.country === "United States") { if (data.country === "United States") {
@ -576,10 +615,7 @@ TableView {
data.country = "UK"; data.country = "UK";
} }
logModel.insert(0, {
logModel.insert(0, {
serialNumber: latestSerialNumber, serialNumber: latestSerialNumber,
callsign: data.callsign, callsign: data.callsign,
dmrID: data.dmrID, dmrID: data.dmrID,
@ -590,14 +626,14 @@ TableView {
checked: false checked: false
}); });
// Save the updated log latestSerialNumber += 1;
saveSettings(); saveSettings();
// Ensure that the log doesn't exceed the maximum number of entries // Ensure that the log doesn't exceed the maximum number of entries
const maxEntries = 250; const maxEntries = 250;
while (logModel.count > maxEntries) { while (logModel.count > maxEntries) {
logModel.remove(logModel.count - 1); // Remove the oldest entry logModel.remove(logModel.count - 1);
} }
} }
} }