diff --git a/ornithology/CMakeLists.txt b/ornithology/CMakeLists.txt index 47ad6ac..38041d6 100644 --- a/ornithology/CMakeLists.txt +++ b/ornithology/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 6.2 COMPONENTS Bluetooth Quick Gui REQUIRED) +find_package(Qt6 6.2 COMPONENTS Bluetooth Quick QuickControls2 Gui REQUIRED) qt_add_executable(appornithology main.cpp @@ -24,11 +24,11 @@ qt_add_qml_module(appornithology QML_FILES main.qml Client.qml + CustomLabel.qml Devices.qml - Dialog.qml + InfoDialog.qml Header.qml - Label.qml - Menu.qml + SearchMenu.qml ZoomImage.qml RESOURCES resources/bluetooth.png @@ -46,4 +46,4 @@ set_target_properties(appornithology PROPERTIES target_compile_definitions(appornithology PRIVATE $<$,$>:QT_QML_DEBUG>) target_link_libraries(appornithology - PRIVATE Qt6::Bluetooth Qt6::Quick Qt6::Gui) + PRIVATE Qt6::Bluetooth Qt6::Quick Qt6::QuickControls2 Qt6::Gui) diff --git a/ornithology/Client.qml b/ornithology/Client.qml index 5ac0756..35a1533 100644 --- a/ornithology/Client.qml +++ b/ornithology/Client.qml @@ -49,16 +49,14 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick 2.15 +import QtQuick.Controls 2.15 Rectangle { width: 300 height: 600 Component.onCompleted: { - // Loading this page may take longer than QLEController - // stopping with an error, go back and readjust this view - // based on controller errors if (client.controllerError) { info.visible = false; menu.menuText = client.update @@ -77,7 +75,7 @@ Rectangle { } } - Dialog { + InfoDialog { id: info anchors.centerIn: parent visible: true @@ -132,19 +130,38 @@ Rectangle { MouseArea { anchors.fill: parent + propagateComposedEvents: true onClicked: { client.loadImage(modelData.sightingUuid); } + onPressAndHold: { + deleteDialog.open(); + mouse.accepted = false; + } + } + + Dialog { + id: deleteDialog + title: "Delete" + standardButtons: Dialog.Ok | Dialog.Cancel + modal: true + focus: true + + onAccepted: { + client.removeSighting(modelData.sightingUuid); + console.log("Ok clicked") + } } - Label { + + CustomLabel { id: sightingsSpecies textContent: modelData.sightingSpecies anchors.top: parent.top anchors.topMargin: 5 } - Label { + CustomLabel { id: sightingsDatetime font.pointSize: sightingsSpecies.font.pointSize * 0.5 textContent: modelData.sightingDatetime @@ -152,7 +169,7 @@ Rectangle { anchors.topMargin: 5 } - Label { + CustomLabel { id: sightingsUuid font.pointSize: sightingsSpecies.font.pointSize * 0.5 textContent: modelData.sightingUuid @@ -187,7 +204,7 @@ Rectangle { } } - Menu { + SearchMenu { id: menu anchors.bottom: parent.bottom menuWidth: parent.width diff --git a/ornithology/Label.qml b/ornithology/CustomLabel.qml similarity index 100% rename from ornithology/Label.qml rename to ornithology/CustomLabel.qml diff --git a/ornithology/Devices.qml b/ornithology/Devices.qml index 270600b..0b43fe2 100644 --- a/ornithology/Devices.qml +++ b/ornithology/Devices.qml @@ -1,15 +1,17 @@ -import QtQuick 2 +import QtQuick +import QtQuick.Controls 2 Rectangle { width: 300 height: 600 - Menu { + SearchMenu { id: menu anchors.top: parent.top menuWidth: parent.width menuHeight: (parent.height/6) menuText: device.update + onButtonClick: { if (device.state) { device.deviceScanFinished(); @@ -33,7 +35,7 @@ Rectangle { } } - Dialog { + InfoDialog { id: info anchors.centerIn: parent visible: false @@ -69,14 +71,14 @@ Rectangle { } } - Label { + CustomLabel { id: deviceName textContent: modelData.deviceName anchors.top: parent.top anchors.topMargin: 5 } - Label { + CustomLabel { id: deviceAddress textContent: modelData.deviceAddress font.pointSize: deviceName.font.pointSize*0.7 diff --git a/ornithology/Dialog.qml b/ornithology/InfoDialog.qml similarity index 100% rename from ornithology/Dialog.qml rename to ornithology/InfoDialog.qml diff --git a/ornithology/Menu.qml b/ornithology/SearchMenu.qml similarity index 100% rename from ornithology/Menu.qml rename to ornithology/SearchMenu.qml diff --git a/ornithology/client.cpp b/ornithology/client.cpp index 4c71d91..3ea7f6f 100644 --- a/ornithology/client.cpp +++ b/ornithology/client.cpp @@ -66,6 +66,14 @@ void Client::requestSightingIds() socket->write(text); } +void Client::removeSighting(const QString &uuid) +{ + if (!socket) + return; + QByteArray text = Message::RemoveSightingRequest(uuid).toJson(QJsonDocument::Compact); + socket->write(text); +} + void Client::loadImage(const QString &uuid) { if (!socket) @@ -143,6 +151,8 @@ void Client::on_dataReady() } } else if(message.type == Message::MessageType::SightingIdsResponse) { + m_sightings.clear(); + emit sightingsUpdated(); for(auto id: message.ids) { QByteArray text = Message::SightingRequest(id).toJson(QJsonDocument::Compact); qDebug() << text; diff --git a/ornithology/client.h b/ornithology/client.h index f21c8ea..2aa835e 100644 --- a/ornithology/client.h +++ b/ornithology/client.h @@ -26,6 +26,7 @@ public slots: void connect(const QString &address); void disconnect(); void requestSightingIds(); + void removeSighting(const QString &uuid); void loadImage(const QString &uuid); private slots: diff --git a/ornithology/main.cpp b/ornithology/main.cpp index 92a235f..1bf4b26 100644 --- a/ornithology/main.cpp +++ b/ornithology/main.cpp @@ -9,6 +9,8 @@ int main(int argc, char *argv[]) { + QGuiApplication::setApplicationName("Ornithology"); + QGuiApplication::setOrganizationName("chriamue"); QGuiApplication app(argc, argv); app.setWindowIcon(QIcon(":/favicon.ico")); diff --git a/ornithology/message.cpp b/ornithology/message.cpp index da3431c..a2b2795 100644 --- a/ornithology/message.cpp +++ b/ornithology/message.cpp @@ -74,6 +74,14 @@ QJsonDocument Message::SightingRequest(QString uuid) return QJsonDocument( payload ); } +QJsonDocument Message::RemoveSightingRequest(QString uuid) +{ + QJsonObject payload; + payload["op"] = "remove_sighting_request"; + payload["uuid"] = uuid; + return QJsonDocument( payload ); +} + QJsonDocument Message::ImageRequest(QString uuid) { QJsonObject payload; diff --git a/ornithology/message.h b/ornithology/message.h index 486b788..d7b8b1c 100644 --- a/ornithology/message.h +++ b/ornithology/message.h @@ -27,6 +27,7 @@ class Message static QJsonDocument LastRequest(); static QJsonDocument SightingIdsRequest(); static QJsonDocument SightingRequest(QString uuid); + static QJsonDocument RemoveSightingRequest(QString uuid); static QJsonDocument ImageRequest(QString uuid); };