Skip to content

Commit

Permalink
feat: allow hiding adsb vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrikbjornland committed Oct 18, 2024
1 parent f474e17 commit 99563cb
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 1 deletion.
1 change: 1 addition & 0 deletions custom-example/qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<file alias="ROIIndicator.qml">../src/ui/toolbar/ROIIndicator.qml</file>
<file alias="TelemetryRSSIIndicator.qml">../src/ui/toolbar/TelemetryRSSIIndicator.qml</file>
<file alias="VTOLModeIndicator.qml">../src/ui/toolbar/VTOLModeIndicator.qml</file>
<file alias="ADSBVehicleIndicator.qml">../src/ui/toolbar/ADSBVehicleIndicator.qml</file>
</qresource>
<qresource prefix="/checklists">
<file alias="DefaultChecklist.qml">../src/FlightDisplay/DefaultChecklist.qml</file>
Expand Down
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<file alias="ROIIndicator.qml">src/ui/toolbar/ROIIndicator.qml</file>
<file alias="TelemetryRSSIIndicator.qml">src/ui/toolbar/TelemetryRSSIIndicator.qml</file>
<file alias="VTOLModeIndicator.qml">src/ui/toolbar/VTOLModeIndicator.qml</file>
<file alias="ADSBVehicleIndicator.qml">src/ui/toolbar/ADSBVehicleIndicator.qml</file>
</qresource>
<qresource prefix="/checklists">
<file alias="DefaultChecklist.qml">src/FlightDisplay/DefaultChecklist.qml</file>
Expand Down
33 changes: 33 additions & 0 deletions src/ADSB/ADSBVehicleManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,36 @@ void ADSBTCPLink::_parseLine(const QString& line)
}
}
}

void ADSBVehicleManager::hideADSBVehicle(quint32 icaoAddress)
{
qDebug() << "Hiding" << icaoAddress;
if (_adsbICAOMap.contains(icaoAddress)) {
ADSBVehicle* adsbVehicle = _adsbICAOMap.take(icaoAddress);
_adsbVehicles.removeOne(adsbVehicle);
_hiddenADSBICAOMap[icaoAddress] = adsbVehicle;
_hiddenADSBVehicles.append(adsbVehicle);
emit hiddenVehiclesChanged();
}
}

void ADSBVehicleManager::unhideADSBVehicle(uint32_t icaoAddress)
{
if (_hiddenADSBICAOMap.contains(icaoAddress)) {
ADSBVehicle* adsbVehicle = _hiddenADSBICAOMap.take(icaoAddress);
_hiddenADSBVehicles.removeOne(adsbVehicle);
_adsbICAOMap[icaoAddress] = adsbVehicle;
_adsbVehicles.append(adsbVehicle);
emit hiddenVehiclesChanged();
}
}

bool ADSBVehicleManager::isADSBVehicleHidden(uint32_t icaoAddress) const
{
return _hiddenADSBICAOMap.contains(icaoAddress);
}

bool ADSBVehicleManager::hasHiddenADSBVehicle() const
{
return _hiddenADSBVehicles.count() > 0;
}
13 changes: 13 additions & 0 deletions src/ADSB/ADSBVehicleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,22 @@ class ADSBVehicleManager : public QGCTool {
ADSBVehicleManager(QGCApplication* app, QGCToolbox* toolbox);

Q_PROPERTY(QmlObjectListModel* adsbVehicles READ adsbVehicles CONSTANT)
Q_PROPERTY(QmlObjectListModel* hiddenADSBVehicles READ hiddenADSBVehicles NOTIFY hiddenVehiclesChanged)

QmlObjectListModel* adsbVehicles(void) { return &_adsbVehicles; }
QmlObjectListModel* hiddenADSBVehicles(void) { return &_hiddenADSBVehicles; }

// QGCTool overrides
void setToolbox(QGCToolbox* toolbox) final;

Q_INVOKABLE void hideADSBVehicle(quint32 icaoAddress);
Q_INVOKABLE void unhideADSBVehicle(uint32_t icaoAddress);
Q_INVOKABLE bool isADSBVehicleHidden(uint32_t icaoAddress) const;
Q_INVOKABLE bool hasHiddenADSBVehicle() const;

signals:
void hiddenVehiclesChanged(void);

public slots:
void adsbVehicleUpdate (const ADSBVehicle::VehicleInfo_t vehicleInfo);
void _tcpError (const QString errorMsg);
Expand All @@ -72,4 +82,7 @@ private slots:
QMap<uint32_t, ADSBVehicle*> _adsbICAOMap;
QTimer _adsbVehicleCleanupTimer;
ADSBTCPLink* _tcpLink = nullptr;

QmlObjectListModel _hiddenADSBVehicles;
QMap<uint32_t, ADSBVehicle*> _hiddenADSBICAOMap;
};
1 change: 1 addition & 0 deletions src/FirmwarePlugin/FirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const QVariantList& FirmwarePlugin::toolIndicators(const Vehicle*)
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/GPSIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/TelemetryRSSIIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/RCRSSIIndicator.qml")),
QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ADSBVehicleIndicator.qml")),
});
AviantSettings* aviantSettings = qgcApp()->toolbox()->settingsManager()->aviantSettings();
if (!aviantSettings->showBatteryWidget()->rawValue().toBool()) {
Expand Down
1 change: 1 addition & 0 deletions src/FlightDisplay/FlyViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ FlightMap {
heading: object.heading
alert: object.alert
emitterType: object.emitterType
icaoAddress: object.icaoAddress
map: _root
z: QGroundControl.zOrderVehicles
}
Expand Down
50 changes: 49 additions & 1 deletion src/FlightMap/MapItems/VehicleMapItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
****************************************************************************/

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
import QtLocation 5.3
import QtPositioning 5.3
import QtGraphicalEffects 1.0
Expand All @@ -28,6 +31,7 @@ MapQuickItem {
property real size: _adsbVehicle ? _adsbSize : _uavSize /// Size for icon
property bool alert: false /// Collision alert
property var emitterType: ADSBVehicle.EMITTER_TYPE_NO_INFO
property int icaoAddress /// ICAO address for ADSB vehicle

anchorPoint.x: vehicleItem.width / 2
anchorPoint.y: vehicleItem.height / 2
Expand All @@ -39,13 +43,37 @@ MapQuickItem {
property real _adsbSize: ScreenTools.defaultFontPixelHeight * 2.5
property var _map: map
property bool _multiVehicle: QGroundControl.multiVehicleManager.vehicles.count > 1

sourceItem: Item {
id: vehicleItem
width: vehicleIcon.width
height: vehicleIcon.height
opacity: _adsbVehicle || vehicle === _activeVehicle ? 1.0 : 0.5

MouseArea {
anchors.fill: parent
z: 2
hoverEnabled: true
enabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
console.log("Clicked on vehicle")
console.log(_adsbVehicle)
if (_adsbVehicle) {
console.log("Showing dialog")
console.log(mainWindow)
mainWindow.showComponentDialog(hideAdsbVehicle, qsTr("Hide Vehicle"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
}
}
acceptedButtons: Qt.AllButtons // Ensure the MouseArea responds to all mouse buttons
onEntered: {
console.log("Hover entered");
}
onExited: {
console.log("Hover exited");
}
}

Rectangle {
id: vehicleShadow
anchors.fill: vehicleIcon
Expand Down Expand Up @@ -109,6 +137,26 @@ MapQuickItem {
}
}

Component {
id: hideAdsbVehicle
QGCViewMessage {
property var manager: QGroundControl.adsbVehicleManager

message: "The selected adsb vehicle " + callsign + " will be hidden. Do you want to continue? You can show it again in the vehicle list."
function accept() {
console.log("Hiding adsb vehicle")
if (manager && icaoAddress) {
console.log(icaoAddress)
manager.hideADSBVehicle(Number(icaoAddress))
} else {
mainWindow.showMessageDialog(qsTr("Error"), qsTr("ADSB vehicle manager or icao address not found"))
console.log("ADSB vehicle manager or icao address not found")
}
hideDialog()
}
}
}

QGCMapLabel {
id: vehicleLabel
anchors.top: parent.bottom
Expand Down
102 changes: 102 additions & 0 deletions src/ui/toolbar/ADSBVehicleIndicator.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

import QtQuick 2.11
import QtQuick.Layouts 1.11

import QGroundControl 1.0
import QGroundControl.Controls 1.0
import QGroundControl.MultiVehicleManager 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0

//-------------------------------------------------------------------------
//-- ADSB Vehicle
Item {
id: _root
anchors.top: parent.top
anchors.bottom: parent.bottom
width: adsbIcon.width * 1.1

property var adsbManager: QGroundControl.adsbVehicleManager

// Add a button or icon to display the list of hidden vehicles
QGCColoredImage {
id: adsbIcon
anchors.top: parent.top
anchors.bottom: parent.bottom
width: height
sourceSize.height: height
source: "/qmlimages/AwarenessDrone.svg"
fillMode: Image.PreserveAspectFit
visible: adsbManager && adsbManager.hasHiddenVehicles
}

MouseArea {
anchors.fill: adsbIcon
onClicked: {
mainWindow.showIndicatorPopup(_root, hiddenVehiclesPopup)
}
}

Component {
id: hiddenVehiclesPopup

Rectangle {
width: adsbCol.width + ScreenTools.defaultFontPixelWidth * 3
height: adsbCol.height + ScreenTools.defaultFontPixelHeight * 2
radius: ScreenTools.defaultFontPixelHeight * 0.5
color: qgcPal.window
border.color: qgcPal.text

Column {
id: adsbCol
spacing: ScreenTools.defaultFontPixelHeight * 0.5
width: Math.max(hiddenVehiclesList.width, adsbLabel.width)
anchors.margins: ScreenTools.defaultFontPixelHeight
anchors.centerIn: parent

QGCLabel {
id: adsbLabel
text: qsTr("Hidden ADS-B Vehicles")
font.family: ScreenTools.demiboldFontFamily
anchors.horizontalCenter: parent.horizontalCenter
}

ListView {
id: hiddenVehiclesList
anchors.left: parent.left
anchors.right: parent.right
anchors.top: titleLabel.bottom
anchors.bottom: parent.bottom
model: adsbManager.hiddenVehicles
delegate: Item {
width: parent.width
height: ScreenTools.defaultFontPixelHeight * 2

MouseArea {
anchors.fill: parent
onClicked: {
adsbManager.unhideADSBVehicle(modelData["icaoAddress"])
mainWindow.hidePopup()
}
}

Text {
text: modelData["callsign"] !== "" ? modelData["callsign"] : qsTr("Unknown Vehicle")
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 10
}
}
}
}
}
}
}

0 comments on commit 99563cb

Please sign in to comment.