Skip to content

Commit

Permalink
✨ added remove sighting to app
Browse files Browse the repository at this point in the history
  • Loading branch information
chriamue committed Mar 4, 2022
1 parent e8941f9 commit 0ed56ea
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 19 deletions.
10 changes: 5 additions & 5 deletions ornithology/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -46,4 +46,4 @@ set_target_properties(appornithology PROPERTIES
target_compile_definitions(appornithology
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(appornithology
PRIVATE Qt6::Bluetooth Qt6::Quick Qt6::Gui)
PRIVATE Qt6::Bluetooth Qt6::Quick Qt6::QuickControls2 Qt6::Gui)
35 changes: 26 additions & 9 deletions ornithology/Client.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,7 +75,7 @@ Rectangle {
}
}

Dialog {
InfoDialog {
id: info
anchors.centerIn: parent
visible: true
Expand Down Expand Up @@ -132,27 +130,46 @@ 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
anchors.top: sightingsSpecies.bottom
anchors.topMargin: 5
}

Label {
CustomLabel {
id: sightingsUuid
font.pointSize: sightingsSpecies.font.pointSize * 0.5
textContent: modelData.sightingUuid
Expand Down Expand Up @@ -187,7 +204,7 @@ Rectangle {
}
}

Menu {
SearchMenu {
id: menu
anchors.bottom: parent.bottom
menuWidth: parent.width
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions ornithology/Devices.qml
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -33,7 +35,7 @@ Rectangle {
}
}

Dialog {
InfoDialog {
id: info
anchors.centerIn: parent
visible: false
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions ornithology/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ornithology/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions ornithology/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
8 changes: 8 additions & 0 deletions ornithology/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ornithology/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 0ed56ea

Please sign in to comment.