mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #786, adjust matcher log to also support matching messages
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/propertyindexlist.h"
|
||||
#include "blackmisc/htmlutils.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/context/contextsimulator.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/uppercasevalidator.h"
|
||||
#include <QCompleter>
|
||||
@@ -21,6 +22,7 @@
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackCore;
|
||||
using namespace BlackCore::Context;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -37,7 +39,15 @@ namespace BlackGui
|
||||
this->initGui();
|
||||
this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
|
||||
connect(ui->le_Callsign, &QLineEdit::returnPressed, this, &CModelMatcherLogComponent::ps_callsignEntered);
|
||||
connect(ui->cb_LogReverseLookup, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_reverseLookupEnabled);
|
||||
connect(ui->cb_LogReverseLookup, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_enabledCheckboxChanged);
|
||||
connect(ui->cb_LogMatchingMessages, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_enabledCheckboxChanged);
|
||||
|
||||
if (this->hasContexts())
|
||||
{
|
||||
connect(sGui->getIContextSimulator(), &IContextSimulator::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::ps_valuesChanged);
|
||||
connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::ps_valuesChanged);
|
||||
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CModelMatcherLogComponent::ps_connectionStatusChanged);
|
||||
}
|
||||
connect(&this->m_timer, &QTimer::timeout, this, &CModelMatcherLogComponent::ps_updateCallsignCompleter);
|
||||
}
|
||||
|
||||
@@ -46,27 +56,38 @@ namespace BlackGui
|
||||
|
||||
void CModelMatcherLogComponent::initGui()
|
||||
{
|
||||
bool reverseLookup = false;
|
||||
if (sGui && sGui->getIContextNetwork())
|
||||
{
|
||||
reverseLookup = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
|
||||
}
|
||||
if (reverseLookup && !this->m_timer.isActive())
|
||||
const bool needCallsigns = this->enabledMessages();
|
||||
if (needCallsigns && !this->m_timer.isActive())
|
||||
{
|
||||
this->m_timer.start();
|
||||
this->ps_updateCallsignCompleter();
|
||||
}
|
||||
else if (!reverseLookup)
|
||||
else if (!needCallsigns)
|
||||
{
|
||||
this->m_timer.stop();
|
||||
}
|
||||
ui->cb_LogReverseLookup->setChecked(reverseLookup);
|
||||
ui->le_Callsign->setReadOnly(!reverseLookup);
|
||||
|
||||
// avoid signal roundtrip
|
||||
bool c = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
|
||||
ui->cb_LogReverseLookup->setChecked(c);
|
||||
|
||||
c = sGui->getIContextSimulator()->isMatchingMessagesEnabled();
|
||||
ui->cb_LogMatchingMessages->setChecked(c);
|
||||
}
|
||||
|
||||
bool CModelMatcherLogComponent::hasContexts() const
|
||||
{
|
||||
return sGui && sGui->getIContextSimulator() && sGui->getIContextNetwork();
|
||||
}
|
||||
|
||||
bool CModelMatcherLogComponent::enabledMessages() const
|
||||
{
|
||||
return this->hasContexts() && (ui->cb_LogMatchingMessages->isChecked() || ui->cb_LogReverseLookup->isChecked());
|
||||
}
|
||||
|
||||
void CModelMatcherLogComponent::ps_updateCallsignCompleter()
|
||||
{
|
||||
if (!sGui || !sGui->getIContextNetwork() || sGui->getIContextNetwork()->isEmptyObject() || !sGui->getIContextNetwork()->isConnected()) { return; }
|
||||
if (!this->hasContexts() || !sGui->getIContextNetwork()->isConnected()) { return; }
|
||||
|
||||
const QStringList callsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns().toStringList(false);
|
||||
QCompleter *completer = ui->le_Callsign->completer();
|
||||
@@ -83,20 +104,46 @@ namespace BlackGui
|
||||
|
||||
void CModelMatcherLogComponent::ps_callsignEntered()
|
||||
{
|
||||
if (!sGui || !sGui->getIContextNetwork()) { return; }
|
||||
if (!this->hasContexts()) { return; }
|
||||
static const CPropertyIndexList properties({ CPropertyIndex::GlobalIndexLineNumber, CStatusMessage::IndexMessage });
|
||||
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
|
||||
const CStatusMessageList msgs = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
|
||||
const QString html = msgs.toHtml(properties);
|
||||
const CStatusMessageList reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
|
||||
const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs);
|
||||
|
||||
CStatusMessageList allMessages(reverseLookupMessages);
|
||||
allMessages.push_back(matchingMessages);
|
||||
|
||||
const QString html = allMessages.toHtml(properties);
|
||||
this->m_text.setHtml(html);
|
||||
ui->te_Messages->setDocument(&this->m_text);
|
||||
}
|
||||
|
||||
void CModelMatcherLogComponent::ps_reverseLookupEnabled(bool enabled)
|
||||
void CModelMatcherLogComponent::ps_valuesChanged()
|
||||
{
|
||||
if (!sGui || !sGui->getIContextNetwork()) { return; }
|
||||
sGui->getIContextNetwork()->enableReverseLookupMessages(enabled);
|
||||
this->initGui();
|
||||
}
|
||||
|
||||
void CModelMatcherLogComponent::ps_enabledCheckboxChanged(bool enabled)
|
||||
{
|
||||
if (!sGui || !sGui->getIContextNetwork() || !sGui->getIContextSimulator()) { return; }
|
||||
const QObject *sender = QObject::sender();
|
||||
if (sender == ui->cb_LogReverseLookup)
|
||||
{
|
||||
sGui->getIContextNetwork()->enableReverseLookupMessages(enabled);
|
||||
}
|
||||
else if (sender == ui->cb_LogMatchingMessages)
|
||||
{
|
||||
sGui->getIContextSimulator()->enableMatchingMessages(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void CModelMatcherLogComponent::ps_connectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
|
||||
{
|
||||
Q_UNUSED(from);
|
||||
if (to == INetwork::Connected || to == INetwork::Disconnected)
|
||||
{
|
||||
this->initGui();
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
|
||||
#define BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
|
||||
|
||||
#include "blackcore/network.h"
|
||||
#include <QFrame>
|
||||
#include <QTabWidget>
|
||||
#include <QTimer>
|
||||
@@ -44,6 +45,12 @@ namespace BlackGui
|
||||
//! Init
|
||||
void initGui();
|
||||
|
||||
//! Contexts available
|
||||
bool hasContexts() const;
|
||||
|
||||
//! Enabled messages
|
||||
bool enabledMessages() const;
|
||||
|
||||
private slots:
|
||||
//! Update the completer
|
||||
void ps_updateCallsignCompleter();
|
||||
@@ -51,8 +58,14 @@ namespace BlackGui
|
||||
//! Callsign was entered
|
||||
void ps_callsignEntered();
|
||||
|
||||
//! When values changed elsewhere
|
||||
void ps_valuesChanged();
|
||||
|
||||
//! Flag changed
|
||||
void ps_reverseLookupEnabled(bool enabled);
|
||||
void ps_enabledCheckboxChanged(bool enabled);
|
||||
|
||||
//! Connection status changed
|
||||
void ps_connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>276</width>
|
||||
<height>260</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -53,9 +53,6 @@
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="le_Callsign"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Callsign">
|
||||
<property name="text">
|
||||
@@ -63,13 +60,37 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="cb_LogReverseLookup">
|
||||
<property name="toolTip">
|
||||
<string>enable logging of reverse lookup messages</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>enable rev. lookup msgs</string>
|
||||
<string>rev. lookup msgs.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Enable">
|
||||
<property name="text">
|
||||
<string>Enable:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="le_Callsign">
|
||||
<property name="placeholderText">
|
||||
<string>callsign</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QCheckBox" name="cb_LogMatchingMessages">
|
||||
<property name="toolTip">
|
||||
<string>enable matching messages</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>matching msgs.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user