8 #include <QStringBuilder>
9 #include <QStringListModel>
11 #include "ui_aircraftpartshistory.h"
21 using namespace swift::misc::aviation;
22 using namespace swift::misc::network;
24 using namespace swift::core::context;
28 CAircraftPartsHistory::CAircraftPartsHistory(QWidget *parent) : QFrame(parent), ui(new Ui::
CAircraftPartsHistory)
33 m_timerUpdateHistory.setInterval(2 * 1000);
35 m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
37 &CAircraftPartsHistory::callsignEntered);
38 connect(ui->cb_PartsHistoryEnabled, &QCheckBox::toggled,
this, &CAircraftPartsHistory::toggleHistoryEnabled);
40 if (this->hasContexts())
43 &CAircraftPartsHistory::valuesChanged);
45 &CAircraftPartsHistory::connectionStatusChanged);
47 connect(&m_timerUpdateHistory, &QTimer::timeout,
this, &CAircraftPartsHistory::updatePartsHistory);
52 void CAircraftPartsHistory::initGui()
55 const bool needCallsigns = this->partsHistoryEnabled();
56 if (needCallsigns && !m_timerUpdateHistory.isActive()) { m_timerUpdateHistory.start(); }
57 else if (!needCallsigns) { m_timerUpdateHistory.stop(); }
61 ui->cb_PartsHistoryEnabled->setChecked(c);
64 bool CAircraftPartsHistory::hasContexts()
const
69 bool CAircraftPartsHistory::partsHistoryEnabled()
const {
return this->hasContexts(); }
71 void CAircraftPartsHistory::updatePartsHistory()
73 if (!this->hasContexts()) {
return; }
74 if (!this->isVisible()) {
return; }
75 const CCallsign cs(ui->comp_CallsignCompleter->getCallsign());
76 if (cs.isEmpty()) {
return; }
81 if (currentAircraftParts ==
CAircraftParts() && aircraftPartsHistory.isEmpty())
83 html = cs.
toQString() % u
" does not support aircraft parts or nothing received yet.";
87 const QString s = u
"lights on:"
89 u
" " %
90 currentAircraftParts.getLights().toQString() %
96 QString::number(currentAircraftParts.getFlapsPercent()) %
103 u
" " %
104 currentAircraftParts.getEngines().toQString() %
109 if (ui->cb_PartsHistoryEnabled->isChecked())
111 html += u
"<hr>" % aircraftPartsHistory.toHtml(CStatusMessageList::timestampHtmlOutput());
115 const size_t hash =
qHash(html);
116 if (hash == m_htmlHash) {
return; }
118 m_text.setHtml(html);
119 ui->te_Messages->setDocument(&m_text);
121 if (ui->cb_AutoScrollEnabled->isChecked())
123 QTextCursor c = ui->te_Messages->textCursor();
124 c.movePosition(QTextCursor::End);
125 ui->te_Messages->setTextCursor(c);
129 void CAircraftPartsHistory::callsignEntered()
131 this->updatePartsHistory();
132 m_timerUpdateHistory.start();
135 void CAircraftPartsHistory::valuesChanged() { this->initGui(); }
137 void CAircraftPartsHistory::toggleHistoryEnabled(
bool enabled)
140 const QObject *sender = QObject::sender();
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool isDeveloperFlagSet() const
Running with dev.flag?
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
virtual bool isAircraftPartsHistoryEnabled() const =0
Is storing the aircraft parts history enabled?
virtual swift::misc::CStatusMessageList getAircraftPartsHistory(const swift::misc::aviation::CCallsign &callsign) const =0
Get aircraft parts history.
virtual swift::misc::aviation::CAircraftPartsList getRemoteAircraftParts(const swift::misc::aviation::CCallsign &callsign) const =0
Get remote aircraft parts.
virtual void enableAircraftPartsHistory(bool enabled)=0
Enable storing of aircraft parts.
History frame for received aircraft parts.
virtual ~CAircraftPartsHistory()
Destructor.
void validChangedCallsignEntered()
Changed callsign entered.
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of a callsign.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information about a connection status.
bool isConnected() const
Query status.
bool isDisconnected() const
Query status.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.