Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+12
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
ADD_SUBDIRECTORY(Gui)
|
||||
|
||||
#
|
||||
# Gui Pairing Plugin Interface
|
||||
#
|
||||
ADD_INTERFACE_LIBRARY(NmeGuiNotificationPluginInterface
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/nme_notification_gui_plugin_interface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||
GuiPluginInterface
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
SET (nme_info_gui_SRCS
|
||||
nme_notification_gui_plugin.h
|
||||
nme_notification_gui_plugin.cpp
|
||||
nme_battery_info_dialog.h
|
||||
nme_battery_info_dialog.cpp
|
||||
nme_shutdown_dialog.h
|
||||
nme_shutdown_dialog.cpp
|
||||
)
|
||||
|
||||
QT5_WRAP_UI(nme_info_gui_SRCS
|
||||
nme_battery_info_dialog.ui
|
||||
nme_shutdown_dialog.ui
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY(WS NmeNotificationGuiPlugin MODULE ${nme_info_gui_SRCS})
|
||||
NGL_TARGET_LINK_LIBRARIES(NmeNotificationGuiPlugin
|
||||
Qt5::Widgets
|
||||
LtsSession
|
||||
LtsWidgets
|
||||
LtsNotification
|
||||
LtsUtilsGuiDds
|
||||
NGLLogger
|
||||
NmeGuiNotificationPluginInterface
|
||||
svcTabCommon
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(NmeNotificationGuiPlugin)
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
|
||||
#include "nme_battery_info_dialog.h"
|
||||
#include "nme_shutdown_dialog.h"
|
||||
#include "ui_nme_battery_info_dialog.h"
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <LtsWidgets/lts_global_wait_dialog.h>
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
|
||||
namespace NmeaManagement
|
||||
{
|
||||
/*!
|
||||
* \brief NmeBatteryInfoDialog::NmeBatteryInfoDialog
|
||||
* \author Niklas Schmidt
|
||||
* \param currentBatteryStateForId
|
||||
* \param ftc
|
||||
* \param dtc
|
||||
* \param parent
|
||||
* \details Shows detailed battery states for 2 batteries and shows the shutdown Button
|
||||
*/
|
||||
NmeBatteryInfoDialog::NmeBatteryInfoDialog(QMap<int,
|
||||
TrainingAreaBase::BatteryState> currentBatteryStateForId,
|
||||
const std::shared_ptr<TrainingAreaBase::Interface::Dtc> &tabDtc,
|
||||
const std::shared_ptr<TrainingAreaBase::Interface::Ftc> &tabFtc,
|
||||
QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_tabDtc(tabDtc)
|
||||
, m_tabFtc(tabFtc)
|
||||
, m_currentBatteryStateForId(currentBatteryStateForId)
|
||||
, m_ui(new Ui::NmeBatteryInfoDialog)
|
||||
{
|
||||
|
||||
m_oudatedFirstBatteryTimer = new QTimer(this);
|
||||
m_oudatedSecondBatteryTimer = new QTimer(this);
|
||||
connect(m_oudatedFirstBatteryTimer, &QTimer::timeout,this, &NmeBatteryInfoDialog::onOutdatedFirstBatteryTimerTimeout );
|
||||
connect(m_oudatedSecondBatteryTimer, &QTimer::timeout,this, &NmeBatteryInfoDialog::onOutdatedSecondBatteryTimerTimeout );
|
||||
|
||||
m_ui->setupUi(this);
|
||||
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::batteryInfoChanged, this, &NmeBatteryInfoDialog::fillStates);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::batteryAlarmChanged, this, &NmeBatteryInfoDialog::fillWarnings);
|
||||
|
||||
// Create Yes-Button for Shutdown
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Yes, this, &NmeBatteryInfoDialog::onShutdownClicked);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Yes, true);
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Yes, tr("Shutdown Radio Master"));
|
||||
|
||||
//FIXME: Uncomment if needed
|
||||
m_ui->lblBat1CurrentCap->hide();
|
||||
m_ui->lblBat1Current->hide();
|
||||
m_ui->lblBat1FreqCap->hide();
|
||||
m_ui->lblBat1Freq->hide();
|
||||
m_ui->lblBat1TempCap->hide();
|
||||
m_ui->lblBat1Temp->hide();
|
||||
m_ui->lblBat2CurrentCap->hide();
|
||||
m_ui->lblBat2Current->hide();
|
||||
m_ui->lblBat2FreqCap->hide();
|
||||
m_ui->lblBat2Freq->hide();
|
||||
m_ui->lblBat2TempCap->hide();
|
||||
m_ui->lblBat2Temp->hide();
|
||||
|
||||
updateDialog();
|
||||
}
|
||||
|
||||
|
||||
NmeBatteryInfoDialog::~NmeBatteryInfoDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief NmeBatteryInfoDialog::resetDialog
|
||||
* \param batteryOne
|
||||
* \param batteryTwo
|
||||
* \details Resets Dialog to Unknown state
|
||||
*/
|
||||
void NmeBatteryInfoDialog::resetDialog(bool batteryOne, bool batteryTwo)
|
||||
{
|
||||
if(batteryOne)
|
||||
{
|
||||
m_ui->lblBat1Level->setStyleSheet(QStringLiteral(""));
|
||||
m_ui->lblBat1LevelCap->setStyleSheet(QStringLiteral(""));
|
||||
m_ui->lblCaptionBatteryOne->setText(tr("Battery 1"));
|
||||
m_ui->lblBat1Current->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Voltage->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Freq->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Generic->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Level->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Temp->setText(tr("Unknown"));
|
||||
m_ui->lblBat1Warn->setText(tr("No Warnings"));
|
||||
}
|
||||
if(batteryTwo)
|
||||
{
|
||||
m_ui->lblBat2Level->setStyleSheet(QStringLiteral(""));
|
||||
m_ui->lblBat2LevelCap->setStyleSheet(QStringLiteral(""));
|
||||
m_ui->lblCaptionBatteryTwo->setText(tr("Battery 2"));
|
||||
m_ui->lblBat2Current->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Voltage->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Freq->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Generic->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Level->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Temp->setText(tr("Unknown"));
|
||||
m_ui->lblBat2Warn->setText(tr("No Warnings"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NmeBatteryInfoDialog::onShutdownClicked()
|
||||
{
|
||||
NmeShutdownDialog *shutdownDialog = new NmeShutdownDialog(m_tabFtc);
|
||||
shutdownDialog->show();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief NmeBatteryInfoDialog::updateDialog
|
||||
* \details
|
||||
* Set all values in dialog
|
||||
* If battery state is empty -> colorize battery state red
|
||||
*/
|
||||
void NmeBatteryInfoDialog::updateDialog()
|
||||
{
|
||||
resetDialog(true, true);
|
||||
|
||||
|
||||
|
||||
// if(m_currentBatteryWarnForId.contains(0))
|
||||
// m_ui->lblBat1Warn->setText(QString::fromStdString(m_currentBatteryWarnForId.value(0).description()));
|
||||
|
||||
// if(m_currentBatteryWarnForId.contains(1))
|
||||
// m_ui->lblBat2Warn->setText(QString::fromStdString(m_currentBatteryWarnForId.value(1).description()));
|
||||
|
||||
|
||||
if(m_currentBatteryStateForId.isEmpty())
|
||||
return;
|
||||
if(m_currentBatteryStateForId.values().length() > 2)
|
||||
return;
|
||||
|
||||
if(m_currentBatteryStateForId.contains(0))
|
||||
{
|
||||
m_ui->lblCaptionBatteryOne->setText(QStringLiteral("Battery 1 (") + QString::fromStdString(m_currentBatteryStateForId.value(0).serialNumber()) + QStringLiteral(")"));
|
||||
|
||||
m_ui->lblBat1Current->setText(QString::number(m_currentBatteryStateForId.value(0).current()) + QStringLiteral("mA"));
|
||||
m_ui->lblBat1Freq->setText(QString::number(m_currentBatteryStateForId.value(0).frequency()));
|
||||
m_ui->lblBat1Generic->setText(QString::number(m_currentBatteryStateForId.value(0).generic()));
|
||||
m_ui->lblBat1Voltage->setText(QString::number(m_currentBatteryStateForId.value(0).voltage()) + QStringLiteral(" mV"));
|
||||
m_ui->lblBat1Level->setText(QString::number(m_currentBatteryStateForId.value(0).batteryPercent()) + QStringLiteral("%"));
|
||||
m_ui->lblBat1Temp->setText(QString::number(m_currentBatteryStateForId.value(0).temperature()));
|
||||
|
||||
if(m_currentBatteryStateForId.value(0).batteryPercent() / 20 == 0)
|
||||
{
|
||||
m_ui->lblBat1Level->setStyleSheet(QStringLiteral("QLabel { color : red; }"));
|
||||
}
|
||||
}
|
||||
|
||||
if(m_currentBatteryStateForId.contains(1))
|
||||
{
|
||||
m_ui->lblCaptionBatteryTwo->setText(QStringLiteral("Battery 2 (") + QString::fromStdString(m_currentBatteryStateForId.value(1).serialNumber()) + QStringLiteral(")"));
|
||||
|
||||
m_ui->lblBat2Current->setText(QString::number(m_currentBatteryStateForId.value(1).current()) + QStringLiteral("mA"));
|
||||
m_ui->lblBat2Freq->setText(QString::number(m_currentBatteryStateForId.value(1).frequency()));
|
||||
m_ui->lblBat2Generic->setText(QString::number(m_currentBatteryStateForId.value(1).generic()));
|
||||
m_ui->lblBat2Voltage->setText(QString::number(m_currentBatteryStateForId.value(1).voltage()) + QStringLiteral(" mV"));
|
||||
m_ui->lblBat2Level->setText(QString::number(m_currentBatteryStateForId.value(1).batteryPercent()) + QStringLiteral("%"));
|
||||
m_ui->lblBat2Temp->setText(QString::number(m_currentBatteryStateForId.value(1).temperature()));
|
||||
|
||||
if(m_currentBatteryStateForId.value(1).batteryPercent() / 20 == 0)
|
||||
{
|
||||
m_ui->lblBat2Level->setStyleSheet(QStringLiteral("QLabel { color : red; }"));
|
||||
}
|
||||
}
|
||||
}
|
||||
void NmeBatteryInfoDialog::fillWarnings(const TrainingAreaBase::BatteryAlarm &data, DataModification modType)
|
||||
{
|
||||
if(data.equipmentNumber() != 1)
|
||||
return;
|
||||
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
m_currentBatteryWarnForId.insert(data.batteryPort(),data);
|
||||
updateDialog();
|
||||
break;
|
||||
}
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
m_currentBatteryWarnForId.remove(data.batteryPort());
|
||||
updateDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NmeBatteryInfoDialog::fillStates(const TrainingAreaBase::BatteryInfo &dataArr, DataModification modType)
|
||||
{
|
||||
if(dataArr.equipmentNumber() != 1)
|
||||
return;
|
||||
|
||||
auto data = dataArr.batteryStates().at(0);
|
||||
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
m_currentBatteryStateForId.insert(data.batteryPort(),data);
|
||||
updateDialog();
|
||||
if(data.batteryPort() == 0)
|
||||
m_oudatedFirstBatteryTimer->start(30000);
|
||||
else if(data.batteryPort() == 1)
|
||||
m_oudatedSecondBatteryTimer->start(30000);
|
||||
break;
|
||||
}
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
if(!m_currentBatteryStateForId.isEmpty())
|
||||
m_currentBatteryStateForId.remove(data.batteryPort());
|
||||
updateDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NmeBatteryInfoDialog::onOutdatedFirstBatteryTimerTimeout()
|
||||
{
|
||||
if(m_currentBatteryStateForId.size() < 2)
|
||||
{
|
||||
m_currentBatteryStateForId.clear();
|
||||
resetDialog(true, true);
|
||||
return;
|
||||
}
|
||||
m_currentBatteryStateForId.remove(0);
|
||||
resetDialog(true, false);
|
||||
}
|
||||
|
||||
void NmeBatteryInfoDialog::onOutdatedSecondBatteryTimerTimeout()
|
||||
{
|
||||
if(m_currentBatteryStateForId.size() < 2)
|
||||
{
|
||||
m_currentBatteryStateForId.clear();
|
||||
resetDialog(true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentBatteryStateForId.remove(1);
|
||||
resetDialog(false, true);
|
||||
}
|
||||
|
||||
|
||||
void NmeBatteryInfoDialog::retranslate()
|
||||
{
|
||||
translate(m_ui, QStringLiteral("Radio Master Shutdown"));
|
||||
}
|
||||
|
||||
|
||||
} // namespace NmeaManagement
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <PluginInterfaces/data_plugin_interface.h>
|
||||
#include <QDialog>
|
||||
#include <QListWidgetItem>
|
||||
#include <QTimer>
|
||||
#include <Proxies/TrainingAreaBase/tab_dtc.h>
|
||||
#include <Proxies/TrainingAreaBase/tab_ftc.h>
|
||||
//#include <NmeaManagement/logger.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
|
||||
|
||||
namespace Ui { class NmeBatteryInfoDialog; }
|
||||
|
||||
|
||||
namespace NmeaManagement
|
||||
{
|
||||
|
||||
class NmeBatteryInfoDialog : public LtsWidgets::LtsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NmeBatteryInfoDialog(QMap<int,
|
||||
TrainingAreaBase::BatteryState> currentBatteryStateForId,
|
||||
const std::shared_ptr<TrainingAreaBase::Interface::Dtc> &tabDtc,
|
||||
const std::shared_ptr<TrainingAreaBase::Interface::Ftc> &tabFtc,
|
||||
QWidget *parent = nullptr);
|
||||
~NmeBatteryInfoDialog();
|
||||
private:
|
||||
void resetDialog(bool batteryOne, bool batteryTwo);
|
||||
|
||||
private slots:
|
||||
void onShutdownClicked();
|
||||
void fillWarnings(const TrainingAreaBase::BatteryAlarm &data, DataModification modType);
|
||||
void fillStates(const TrainingAreaBase::BatteryInfo &dataArr, DataModification modType);
|
||||
void onOutdatedFirstBatteryTimerTimeout();
|
||||
void onOutdatedSecondBatteryTimerTimeout();
|
||||
|
||||
signals:
|
||||
void signalQuit();
|
||||
void signalSelectScript(int scriptId);
|
||||
void signalEditQuit();
|
||||
|
||||
private:
|
||||
bool m_selected;
|
||||
bool m_close { false };
|
||||
void updateDialog();
|
||||
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dtc> m_tabDtc {nullptr};
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Ftc> m_tabFtc {nullptr};
|
||||
QMap<int, TrainingAreaBase::BatteryState> m_currentBatteryStateForId;
|
||||
QMap<int, TrainingAreaBase::BatteryAlarm> m_currentBatteryWarnForId;
|
||||
Ui::NmeBatteryInfoDialog *m_ui { nullptr };
|
||||
QTimer *m_oudatedFirstBatteryTimer;
|
||||
QTimer *m_oudatedSecondBatteryTimer;
|
||||
// LtsDialog interface
|
||||
public:
|
||||
void retranslate() override;
|
||||
};
|
||||
|
||||
} // namespace NmeaManagement
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NmeBatteryInfoDialog</class>
|
||||
<widget class="QWidget" name="NmeBatteryInfoDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>561</width>
|
||||
<height>383</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Battery Information</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="glBatteryOne">
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="lblBat1Generic">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="lblBat1WarnCap">
|
||||
<property name="text">
|
||||
<string>Warnings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="lblBat1CurrentCap">
|
||||
<property name="text">
|
||||
<string>Current</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="lblCaptionBatteryOne">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Battery 1</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="lblBat1Current">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblBat1LevelCap">
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="lblBat1Temp">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="lblBat1GenericCap">
|
||||
<property name="text">
|
||||
<string>Generic</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="lblBat1Level">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLabel" name="lblBat1Warn">
|
||||
<property name="text">
|
||||
<string notr="true">No Warnings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lblBat1FreqCap">
|
||||
<property name="text">
|
||||
<string>Frequency</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="lblBat1Freq">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="lblBat1TempCap">
|
||||
<property name="text">
|
||||
<string>Temperature</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblBat1VoltageCap">
|
||||
<property name="text">
|
||||
<string>Voltage</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="lblBat1Voltage">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="glBatteryTwo">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lblBat2TempCap">
|
||||
<property name="text">
|
||||
<string>Temperature</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="lblBat2Warn">
|
||||
<property name="text">
|
||||
<string notr="true">NoWarnings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="lblCaptionBatteryTwo">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Battery 2</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="lblBat2GenericCap">
|
||||
<property name="text">
|
||||
<string>Generic</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblBat2FreqCap">
|
||||
<property name="text">
|
||||
<string>Frequency</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblBat2LevelCap">
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="lblBat2Level">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="lblBat2Generic">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="lblBat2CurrentCap">
|
||||
<property name="text">
|
||||
<string>Current</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="lblBat2Freq">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="lblBat2Temp">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="lblBat2Current">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="lblBat2WarnCap">
|
||||
<property name="text">
|
||||
<string>Warnings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblBat2VoltageCap">
|
||||
<property name="text">
|
||||
<string>Voltage</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="lblBat2Voltage">
|
||||
<property name="text">
|
||||
<string notr="true">Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+441
@@ -0,0 +1,441 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Notifcation plugin for TAB connection states
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-09-19
|
||||
*/
|
||||
|
||||
|
||||
#include "nme_battery_info_dialog.h"
|
||||
#include "nme_notification_gui_plugin.h"
|
||||
#include "nme_shutdown_dialog.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsNotification/lts_notification.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
|
||||
|
||||
namespace NmeaManagement
|
||||
{
|
||||
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
||||
{
|
||||
return std::make_shared<InterfaceImpl>(session);
|
||||
}
|
||||
|
||||
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
||||
: GuiPluginBase::Interface(session, NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("NmeaGuiPlugin"))
|
||||
, m_tabDtc(nullptr)
|
||||
, m_tabFtc(nullptr)
|
||||
, m_notiBattery(nullptr)
|
||||
, m_notiOwnPosition(nullptr)
|
||||
{
|
||||
m_oudatedFirstBatteryTimer = new QTimer(this);
|
||||
m_oudatedSecondBatteryTimer = new QTimer(this);
|
||||
connect(m_oudatedFirstBatteryTimer, &QTimer::timeout, this,&InterfaceImpl::onOutdatedFirstBatteryTimerTimeout);
|
||||
connect(m_oudatedSecondBatteryTimer, &QTimer::timeout, this,&InterfaceImpl::onOutdatedSecondBatteryTimerTimeout);
|
||||
}
|
||||
|
||||
InterfaceImpl::~InterfaceImpl()
|
||||
{
|
||||
delete m_notiBattery;
|
||||
delete m_notiOwnPosition;
|
||||
}
|
||||
|
||||
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
||||
{
|
||||
QVector<LtsWidgets::PluginData> ret;
|
||||
|
||||
LtsWidgets::PluginData plData;
|
||||
plData.menuGroup = menuGroup();
|
||||
plData.menuText = tr("Shutdown Radio Master");
|
||||
plData.identifier = QLatin1String("ShutdownRadioMaster");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:application-exit.svg"));
|
||||
plData.exercisePart = LtsWidgets::ExercisePart::eSpecial;
|
||||
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
||||
{
|
||||
NmeBatteryInfoDialog *batteryDialog = new NmeBatteryInfoDialog(m_currentBatteryStateForId, m_tabDtc, m_tabFtc);
|
||||
m_session->addWidget(batteryDialog, menuGroup(), QStringLiteral("batteryInfo"), LtsWidgets::LayoutArea::eDialogTab);
|
||||
};
|
||||
|
||||
if (m_notiBattery != nullptr /*|| m_notiOwnPosition != nullptr*/)
|
||||
return QVector<LtsWidgets::PluginData>();
|
||||
|
||||
//TODO: Uncomment if necessary
|
||||
// m_notiOwnPosition = m_session->createNotification(QStringLiteral("Show own position"));
|
||||
// m_notiOwnPosition->setToolTip(tr("Show own position"));
|
||||
// m_notiOwnPosition->setIcon(QIcon(QStringLiteral("icon:/position.svg")));
|
||||
// m_notiOwnPosition->setAction([this](){
|
||||
|
||||
// //TODO: What to do if something like that happend
|
||||
// });
|
||||
|
||||
m_notiBattery = m_session->createNotification(QStringLiteral("Radio Master Battery State"));
|
||||
updateBatteryLevel();
|
||||
m_notiBattery->setAction([this](){
|
||||
NmeBatteryInfoDialog *batteryDialog = new NmeBatteryInfoDialog(m_currentBatteryStateForId, m_tabDtc, m_tabFtc);
|
||||
m_session->addWidget(batteryDialog, menuGroup(), QStringLiteral("batteryInfo"), LtsWidgets::LayoutArea::eDialogTab);
|
||||
|
||||
});
|
||||
//setToolTip();
|
||||
|
||||
// ret.append(plData);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool InterfaceImpl::fetchInterfaces()
|
||||
{
|
||||
//Dual Use while migrating from NmeaService to Nmea Tab Plugin
|
||||
|
||||
if (!m_session->getDtc<TrainingAreaBase::DataInterface>(m_tabDtc))
|
||||
return false;
|
||||
|
||||
if (!m_session->getFtc<TrainingAreaBase::DataInterface>(m_tabFtc))
|
||||
return false;
|
||||
|
||||
if(!m_tabDtc->enableBatteryInfo())
|
||||
return false;
|
||||
|
||||
if(!m_tabDtc->enableBatteryAlarm())
|
||||
return false;
|
||||
|
||||
if(!m_tabDtc->enableServiceControl())
|
||||
return false;
|
||||
|
||||
if(!m_tabFtc->enableSetDevicePower())
|
||||
return false;
|
||||
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::batteryInfoChanged, this, &InterfaceImpl::onBatteryChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::serviceControlChanged, this, &InterfaceImpl::onShutdownStateChanged);
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterfaceImpl::clearInterfaces()
|
||||
{
|
||||
|
||||
disconnect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::batteryInfoChanged, this, &InterfaceImpl::onBatteryChanged);
|
||||
disconnect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::serviceControlChanged, this, &InterfaceImpl::onShutdownStateChanged);
|
||||
m_tabDtc = nullptr;
|
||||
m_tabFtc = nullptr;
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::onBatteryChanged
|
||||
* \param data
|
||||
* \param modType
|
||||
* \details
|
||||
* Receives Battery State and save them if changed
|
||||
* Paints new Icon and set new tooltip
|
||||
* If incoming BatteryState is under 2 (40%) and lower than last received state -> Show Warning
|
||||
*/
|
||||
void InterfaceImpl::onBatteryChanged(const TrainingAreaBase::BatteryInfo &dataArr, DataModification modType)
|
||||
{
|
||||
if(dataArr.equipmentNumber() != 1)
|
||||
return;
|
||||
auto data = dataArr.batteryStates().at(0);
|
||||
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
|
||||
if(m_hasConnection == false)
|
||||
{
|
||||
m_hasConnection = true;
|
||||
if (m_session->baseLayout() != nullptr)
|
||||
m_session->baseLayout()->showMessage(tr("The radio master is connected"), tr("Connection was successfully reestablished"), LtsWidgets::LtsNotificationBox::MessageType::Success);
|
||||
}
|
||||
if((data.batteryPercent() / 20) < m_currentBatteryStateForId.value(data.batteryPort()).batteryPercent() / 20 && data.batteryPercent() / 20 < 2)
|
||||
{
|
||||
QMessageBox batteryWarnBox;
|
||||
batteryWarnBox.setWindowTitle(tr("Battery Warning"));
|
||||
batteryWarnBox.setText(tr("The battery (%1) has only %2 \% left").arg(QString::fromStdString(data.serialNumber())).arg(data.batteryPercent())); //*20 = Real percentage
|
||||
batteryWarnBox.exec();
|
||||
}
|
||||
m_currentBatteryStateForId.insert(data.batteryPort(), data);
|
||||
|
||||
updateBatteryLevel();
|
||||
|
||||
if(data.batteryPort() == 0)
|
||||
m_oudatedFirstBatteryTimer->start(30000);
|
||||
else if(data.batteryPort() == 1)
|
||||
m_oudatedSecondBatteryTimer->start(30000);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
m_currentBatteryStateForId.remove(data.batteryPort());
|
||||
updateBatteryLevel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::onShutdownStateChanged
|
||||
* \author Niklas Schmidt
|
||||
* \param data
|
||||
* \param modType
|
||||
* \details
|
||||
* Receives notification for the sthutdown state of RadioMaster
|
||||
* Than show QMessageBox with shutdown state
|
||||
*/
|
||||
void InterfaceImpl::onShutdownStateChanged(const TrainingAreaBase::ServiceControl &data, DataModification modType)
|
||||
{
|
||||
if(data.equipmentNumber() != 1)
|
||||
return;
|
||||
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
|
||||
if(data.serviceControlState().underlying() == TrainingAreaBase::ServiceControlEnum::STOP)
|
||||
{
|
||||
m_hasConnection = false;
|
||||
if (m_session->baseLayout() != nullptr)
|
||||
m_session->baseLayout()->showMessage(tr("The radio master is shut down"), tr("The batteries can be disconnected."), LtsWidgets::LtsNotificationBox::MessageType::Error);
|
||||
|
||||
|
||||
}
|
||||
//shutdownInfoBox.exec();
|
||||
break;
|
||||
}
|
||||
case DataModification::eRemoved:
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::onOutdatedFirstBatteryTimerTimeout
|
||||
* \details
|
||||
* Timeouted if no new incoming data is available
|
||||
* Updates battery icon to unknown state
|
||||
*/
|
||||
void InterfaceImpl::onOutdatedFirstBatteryTimerTimeout()
|
||||
{
|
||||
//Default values for undefined state
|
||||
if(m_currentBatteryStateForId.size() < 2)
|
||||
{
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage()));
|
||||
setToolTip();
|
||||
m_currentBatteryStateForId.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage(99, m_currentBatteryStateForId.value(1).batteryPercent() / 20)));
|
||||
setToolTip(99, m_currentBatteryStateForId.value(1).batteryPercent() / 20);
|
||||
m_currentBatteryStateForId.remove(0);
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief InterfaceImpl::onOutdatedSecondBatteryTimerTimeout
|
||||
* \details
|
||||
* Timeouted if no new incoming data is available
|
||||
* Updates battery icon to unknown state
|
||||
*/
|
||||
void InterfaceImpl::onOutdatedSecondBatteryTimerTimeout()
|
||||
{
|
||||
|
||||
if(m_currentBatteryStateForId.size() < 2)
|
||||
{
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage()));
|
||||
setToolTip();
|
||||
m_currentBatteryStateForId.clear();
|
||||
return;
|
||||
}
|
||||
//Default values for undefined state
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage(m_currentBatteryStateForId.value(0).batteryPercent() / 20, 99)));
|
||||
setToolTip(m_currentBatteryStateForId.value(0).batteryPercent() / 20, 99);
|
||||
m_currentBatteryStateForId.remove(1);
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::setToolTip
|
||||
* \param firstBattery
|
||||
* \author Niklas Schmidt
|
||||
* \param secondBattery
|
||||
* \details Changes Tooltip for BatteryState Notification
|
||||
*/
|
||||
void InterfaceImpl::setToolTip(int firstBattery, int secondBattery)
|
||||
{
|
||||
QString tooltip;
|
||||
if(firstBattery == 99)
|
||||
tooltip = tr("First Battery Level: Unknown %1").arg(QStringLiteral("\n"));
|
||||
else
|
||||
tooltip = tr("First Battery Level: ") + QString::number(firstBattery * 20) + QStringLiteral("% \n");
|
||||
|
||||
if(secondBattery == 99)
|
||||
tooltip += tr("Second Battery Level: Unknown");
|
||||
else
|
||||
tooltip += tr("Second Battery Level: ") + QString::number(secondBattery * 20) + QStringLiteral("%");
|
||||
|
||||
m_notiBattery->setToolTip(tooltip);
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::renderBatteryImage
|
||||
* \author Niklas Schmidt
|
||||
* \param firstBatteryState
|
||||
* \param secondBatteryState
|
||||
* \details
|
||||
* This method paints the icon for battery state
|
||||
*
|
||||
* Battery Unknown = Only Outline and Questionmark in middle
|
||||
* Battery 0% = 5 Red Bars
|
||||
* Battery 20% = 1 Red Bar
|
||||
* Battery 40% = 2 Yellow Bar
|
||||
* Battery 60% = 3 Green Bars
|
||||
* Battery 80% = 4 Green Bras
|
||||
* Battery 100% = 5 Green Bars
|
||||
*
|
||||
* BatteryState Int -> 0 = Empty ... 5 = Full | 99 = Unknown
|
||||
* \return
|
||||
*/
|
||||
QImage InterfaceImpl::renderBatteryImage(int firstBatteryState, int secondBatteryState)
|
||||
{
|
||||
|
||||
int firstBattery = firstBatteryState;
|
||||
int secondBattery = secondBatteryState;
|
||||
|
||||
int size = 100;
|
||||
QImage image(size, size, QImage::Format_ARGB32);
|
||||
image.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&image);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
|
||||
if(firstBattery != 99)
|
||||
{
|
||||
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
|
||||
if(firstBattery < 3)
|
||||
painter.setBrush(QBrush(Qt::yellow, Qt::SolidPattern));
|
||||
if(firstBattery < 2)
|
||||
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
|
||||
|
||||
if(firstBattery == 0)
|
||||
{
|
||||
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
|
||||
firstBattery = 5; // To paint all 5 bars red
|
||||
}
|
||||
//For first battery (upper bar)
|
||||
if (firstBattery > 0)
|
||||
painter.drawRect(00, 00, 18, 40);
|
||||
if (firstBattery > 1)
|
||||
painter.drawRect(20, 00, 18, 40);
|
||||
if (firstBattery > 2)
|
||||
painter.drawRect(40, 00, 18, 40);
|
||||
if (firstBattery > 3)
|
||||
painter.drawRect(60, 00, 18, 40);
|
||||
if (firstBattery > 4)
|
||||
painter.drawRect(80, 00, 18, 40);
|
||||
}
|
||||
|
||||
if(secondBattery != 99)
|
||||
{
|
||||
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
|
||||
if(secondBattery < 3)
|
||||
painter.setBrush(QBrush(Qt::yellow, Qt::SolidPattern));
|
||||
if(secondBattery < 2)
|
||||
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
|
||||
|
||||
if(secondBattery == 0)
|
||||
{
|
||||
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
|
||||
secondBattery = 5; // To paint all 5 bars red
|
||||
}
|
||||
|
||||
//For second battery (lower bar)
|
||||
if (secondBattery > 0)
|
||||
painter.drawRect(00, 60, 18, 40);
|
||||
if (secondBattery > 1)
|
||||
painter.drawRect(20, 60, 18, 40);
|
||||
if (secondBattery > 2)
|
||||
painter.drawRect(40, 60, 18, 40);
|
||||
if (secondBattery > 3)
|
||||
painter.drawRect(60, 60, 18, 40);
|
||||
if (secondBattery > 4)
|
||||
painter.drawRect(80, 60, 18, 40);
|
||||
}
|
||||
|
||||
QFont font = painter.font() ;
|
||||
font.setPointSize(30);
|
||||
painter.setFont(font);
|
||||
|
||||
painter.setBrush(QBrush(Qt::black, Qt::NoBrush));
|
||||
if(firstBattery == 99) //If Unknown BatteryState
|
||||
{
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(45,35, QStringLiteral("?"));
|
||||
}
|
||||
|
||||
// Draw Outline for whole Battery
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawRect(00,00,100,40);
|
||||
|
||||
painter.setBrush(QBrush(Qt::black, Qt::NoBrush));
|
||||
if(secondBattery == 99) //If Unknown BatteryState
|
||||
{
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(45,92, QStringLiteral("?"));
|
||||
}
|
||||
|
||||
// Draw Outline for whole Battery
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawRect(00,60,100,40);
|
||||
|
||||
|
||||
// 'marking':
|
||||
// painter.setPen(QPen(Qt::NoPen)); // rect with no outter line
|
||||
|
||||
painter.end();
|
||||
|
||||
return image;
|
||||
}
|
||||
/*!
|
||||
* \brief InterfaceImpl::updateBatteryLevel
|
||||
* \details Changes the icon of battery state and change Tooltip
|
||||
*/
|
||||
void InterfaceImpl::updateBatteryLevel()
|
||||
{
|
||||
if(!m_notiBattery)
|
||||
return;
|
||||
|
||||
if(m_currentBatteryStateForId.isEmpty())
|
||||
{
|
||||
setToolTip();
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage()));
|
||||
return;
|
||||
}
|
||||
int firstBatteryState = m_currentBatteryStateForId.value(0).batteryPercent() / 20;
|
||||
int secondBatteryState = m_currentBatteryStateForId.value(1).batteryPercent() / 20;
|
||||
|
||||
if(m_currentBatteryStateForId.values().length() == 2)
|
||||
{
|
||||
setToolTip(firstBatteryState, secondBatteryState);
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage(firstBatteryState, secondBatteryState)));
|
||||
}
|
||||
else if(m_currentBatteryStateForId.values().length() == 1)
|
||||
{
|
||||
if(m_currentBatteryStateForId.first().batteryPort() == 0)
|
||||
{
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage(firstBatteryState, 99)));
|
||||
setToolTip(firstBatteryState, 99);
|
||||
}
|
||||
else if(m_currentBatteryStateForId.first().batteryPort() == 1)
|
||||
{
|
||||
m_notiBattery->setIcon(QPixmap::fromImage(renderBatteryImage(99,secondBatteryState)));
|
||||
setToolTip(99,secondBatteryState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NmeaManagement
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Notifcation plugin for TAB connection states
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-09-19
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <Plugins/NmeaManagement/nme_notification_gui_plugin_interface.h>
|
||||
#include <Plugins/TrainingAreaBase/tab_data_plugin_interface.h>
|
||||
#include <Proxies/TrainingAreaBase/tab_dtc.h>
|
||||
#include <Proxies/TrainingAreaBase/tab_ftc.h>
|
||||
//#include <NmeaManagement/logger.h>
|
||||
#include <QTimer>
|
||||
|
||||
namespace LtsNotification
|
||||
{
|
||||
class LtsNotification;
|
||||
}
|
||||
|
||||
namespace NmeaManagement
|
||||
{
|
||||
|
||||
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
|
||||
{
|
||||
Q_PLUGIN_METADATA(IID "gui:3:nme.notification")
|
||||
Q_INTERFACES(GuiPluginBase::Plugin)
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GuiPlugin() = default;
|
||||
~GuiPlugin() = default;
|
||||
|
||||
QString pluginName() override { return ForeignGuiInterface::pluginName(); }
|
||||
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
|
||||
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Global;
|
||||
}
|
||||
};
|
||||
|
||||
class InterfaceImpl final : public QObject, public NmeaManagement::ForeignGuiInterface, public GuiPluginBase::Interface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InterfaceImpl(LtsSession::LtsSession *session);
|
||||
~InterfaceImpl();
|
||||
|
||||
QString pluginName() { return ForeignGuiInterface::pluginName(); }
|
||||
QVector<LtsWidgets::PluginData> getActions() override;
|
||||
QString menuGroup() const override { return tr("RadioMaster"); }
|
||||
|
||||
bool fetchInterfaces() override;
|
||||
void clearInterfaces() override;
|
||||
|
||||
private slots:
|
||||
void onBatteryChanged(const TrainingAreaBase::BatteryInfo &dataArr, DataModification modType);
|
||||
void onShutdownStateChanged(const TrainingAreaBase::ServiceControl &data, DataModification modType);
|
||||
void onOutdatedFirstBatteryTimerTimeout();
|
||||
void onOutdatedSecondBatteryTimerTimeout();
|
||||
private:
|
||||
enum class State { //TODO:Better names, There are only five akku states
|
||||
Empty = 0,
|
||||
Twenty = 1,
|
||||
Fourty = 2,
|
||||
Sixty = 3,
|
||||
Eighty = 4,
|
||||
Full = 5,
|
||||
Unknown = 6
|
||||
};
|
||||
|
||||
void setToolTip(int firstBattery = 99, int secondBattery = 99);
|
||||
QImage renderBatteryImage(int firstBatteryState = 99, int secondBatteryState = 99);
|
||||
void updateBatteryLevel();
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dtc> m_tabDtc;
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Ftc> m_tabFtc;
|
||||
LtsNotification::LtsNotification *m_notiBattery;
|
||||
LtsNotification::LtsNotification *m_notiOwnPosition;
|
||||
QMap<int, TrainingAreaBase::BatteryState> m_currentBatteryStateForId;
|
||||
bool m_hasConnection = true;
|
||||
QTimer *m_oudatedFirstBatteryTimer;
|
||||
QTimer *m_oudatedSecondBatteryTimer;
|
||||
|
||||
};
|
||||
|
||||
} // namespace NmeaManagement
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* SimChooser Payload UI
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Mike Wille, SLSE, 2017-03-21
|
||||
*/
|
||||
|
||||
#include "nme_shutdown_dialog.h"
|
||||
#include "ui_nme_shutdown_dialog.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <LtsWidgets/lts_global_wait_dialog.h>
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
NmeShutdownDialog::NmeShutdownDialog(const std::shared_ptr<TrainingAreaBase::Interface::Ftc> &tabFtc,
|
||||
QWidget *parent)
|
||||
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
||||
, m_selected(false)
|
||||
, m_ui(new Ui::NmeShutdownDialog)
|
||||
, m_tabFtc(tabFtc)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setWindowFlags( Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint ); // hints..
|
||||
|
||||
connect(m_ui->pbQuit, &QPushButton::clicked, this, [this]()
|
||||
{
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
||||
m_close = true;
|
||||
close();
|
||||
});
|
||||
|
||||
connect(m_ui->pbShutdownAccept, &QPushButton::clicked,
|
||||
this, &NmeShutdownDialog::onShutdownClicked);
|
||||
|
||||
}
|
||||
|
||||
NmeShutdownDialog::~NmeShutdownDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void NmeShutdownDialog::reject()
|
||||
{
|
||||
if (!m_selected /* do not quit session if this dialog is misused as import dialog for a running app */)
|
||||
emit signalQuit();
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
|
||||
void NmeShutdownDialog::onShutdownClicked()
|
||||
{
|
||||
|
||||
if(!m_tabFtc)
|
||||
return;
|
||||
TrainingAreaBase::SetDevicePowerRequest request;
|
||||
|
||||
request.equipmentNumber(1);// Only the EqNumber 1 will be consumed from NmeaTabPlugin
|
||||
request.powerType(TrainingAreaBase::PowerMethod::PowerOff); //Need to be PowerOff
|
||||
request.subdeviceId(0); // Not used in TAB
|
||||
|
||||
auto cb = [request, this]()
|
||||
{
|
||||
return m_tabFtc->setDevicePowerRequest(request, this);
|
||||
};
|
||||
m_requestHelper->startSingleRequest(cb);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void NmeShutdownDialog::onEnaDisa()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NmeShutdownDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!m_close)
|
||||
{
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void NmeShutdownDialog::onSetDevicePowerReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_requestHelper->requestReply(reply);
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <PluginInterfaces/data_plugin_interface.h>
|
||||
#include <Proxies/TrainingAreaBase/tab_ftc.h>
|
||||
//#include <NmeaManagement/logger.h>
|
||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||
#include <QDialog>
|
||||
#include <QListWidgetItem>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
|
||||
|
||||
namespace Ui { class NmeShutdownDialog; }
|
||||
|
||||
|
||||
|
||||
class NmeShutdownDialog : public LtsWidgets::LtsFramelessDialog
|
||||
, protected TrainingAreaBase::Interface::Ftc::SetDevicePowerReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NmeShutdownDialog(const std::shared_ptr<TrainingAreaBase::Interface::Ftc> &tabFtc,
|
||||
QWidget *parent = nullptr);
|
||||
~NmeShutdownDialog();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void reject() override;
|
||||
void onShutdownClicked();
|
||||
void onEnaDisa();
|
||||
|
||||
signals:
|
||||
void signalQuit();
|
||||
void signalSelectScript(int scriptId);
|
||||
void signalEditQuit();
|
||||
|
||||
private:
|
||||
bool m_selected;
|
||||
bool m_close { false };
|
||||
|
||||
Ui::NmeShutdownDialog *m_ui { nullptr };
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Ftc> m_tabFtc;
|
||||
LtsUtils::RequestHelper *m_requestHelper;
|
||||
// SetPowerDeviceReplyHandler interface
|
||||
public:
|
||||
void onSetDevicePowerReply(const Core::FunctionReplyObject &reply) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NmeShutdownDialog</class>
|
||||
<widget class="QDialog" name="NmeShutdownDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>353</width>
|
||||
<height>99</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Shutdown Radio Master</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblShutdown">
|
||||
<property name="text">
|
||||
<string>Do you really want to shut down the Radio Master?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbShutdownAccept">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Yes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbQuit">
|
||||
<property name="text">
|
||||
<string>No</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
ADD_SUBDIRECTORY(BatteryNotification)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
# NmeaManagement Plugin ReadMe
|
||||
|
||||
*Author = Niklas Schmidt*
|
||||
|
||||
This plugin creates:
|
||||
- Notification to show the battery states of RadioMaster
|
||||
- Notification for center yourself(RadioMaster user) on the map
|
||||
- Dialog which show detailed information about the batteries and there values
|
||||
- MessageBox for "Low Battery" warnings
|
||||
- Ability(Button in accordion menu and in BatteryDialog) to shutdown the RadioMaster
|
||||
- MessageBox to get the current shutdown state of the RadioMaster
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace NmeaManagement
|
||||
{
|
||||
class ForeignGuiInterface
|
||||
{
|
||||
public:
|
||||
ForeignGuiInterface() = default;
|
||||
virtual ~ForeignGuiInterface() = default;
|
||||
|
||||
static QString pluginName() { return QStringLiteral("NmeNotificationGuiPlugin"); }
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user