refs #786, adjust matcher log to also support matching messages

This commit is contained in:
Klaus Basan
2016-10-23 03:09:26 +02:00
parent 514bcdd055
commit 8c282a33bf
3 changed files with 106 additions and 25 deletions

View File

@@ -13,6 +13,7 @@
#include "blackmisc/propertyindexlist.h" #include "blackmisc/propertyindexlist.h"
#include "blackmisc/htmlutils.h" #include "blackmisc/htmlutils.h"
#include "blackcore/context/contextnetwork.h" #include "blackcore/context/contextnetwork.h"
#include "blackcore/context/contextsimulator.h"
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/uppercasevalidator.h" #include "blackgui/uppercasevalidator.h"
#include <QCompleter> #include <QCompleter>
@@ -21,6 +22,7 @@
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackCore; using namespace BlackCore;
using namespace BlackCore::Context;
namespace BlackGui namespace BlackGui
{ {
@@ -37,7 +39,15 @@ namespace BlackGui
this->initGui(); this->initGui();
this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet()); this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
connect(ui->le_Callsign, &QLineEdit::returnPressed, this, &CModelMatcherLogComponent::ps_callsignEntered); 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); connect(&this->m_timer, &QTimer::timeout, this, &CModelMatcherLogComponent::ps_updateCallsignCompleter);
} }
@@ -46,27 +56,38 @@ namespace BlackGui
void CModelMatcherLogComponent::initGui() void CModelMatcherLogComponent::initGui()
{ {
bool reverseLookup = false; const bool needCallsigns = this->enabledMessages();
if (sGui && sGui->getIContextNetwork()) if (needCallsigns && !this->m_timer.isActive())
{
reverseLookup = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
}
if (reverseLookup && !this->m_timer.isActive())
{ {
this->m_timer.start(); this->m_timer.start();
this->ps_updateCallsignCompleter(); this->ps_updateCallsignCompleter();
} }
else if (!reverseLookup) else if (!needCallsigns)
{ {
this->m_timer.stop(); 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() 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); const QStringList callsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns().toStringList(false);
QCompleter *completer = ui->le_Callsign->completer(); QCompleter *completer = ui->le_Callsign->completer();
@@ -83,20 +104,46 @@ namespace BlackGui
void CModelMatcherLogComponent::ps_callsignEntered() void CModelMatcherLogComponent::ps_callsignEntered()
{ {
if (!sGui || !sGui->getIContextNetwork()) { return; } if (!this->hasContexts()) { return; }
static const CPropertyIndexList properties({ CPropertyIndex::GlobalIndexLineNumber, CStatusMessage::IndexMessage }); static const CPropertyIndexList properties({ CPropertyIndex::GlobalIndexLineNumber, CStatusMessage::IndexMessage });
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper()); const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
const CStatusMessageList msgs = sGui->getIContextNetwork()->getReverseLookupMessages(cs); const CStatusMessageList reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
const QString html = msgs.toHtml(properties); 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); this->m_text.setHtml(html);
ui->te_Messages->setDocument(&this->m_text); 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(); 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
} // ns } // ns

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H #ifndef BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
#define BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H #define BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
#include "blackcore/network.h"
#include <QFrame> #include <QFrame>
#include <QTabWidget> #include <QTabWidget>
#include <QTimer> #include <QTimer>
@@ -44,6 +45,12 @@ namespace BlackGui
//! Init //! Init
void initGui(); void initGui();
//! Contexts available
bool hasContexts() const;
//! Enabled messages
bool enabledMessages() const;
private slots: private slots:
//! Update the completer //! Update the completer
void ps_updateCallsignCompleter(); void ps_updateCallsignCompleter();
@@ -51,8 +58,14 @@ namespace BlackGui
//! Callsign was entered //! Callsign was entered
void ps_callsignEntered(); void ps_callsignEntered();
//! When values changed elsewhere
void ps_valuesChanged();
//! Flag changed //! 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
} // ns } // ns

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>276</width>
<height>300</height> <height>260</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -53,9 +53,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
<item row="0" column="1">
<widget class="QLineEdit" name="le_Callsign"/>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="lbl_Callsign"> <widget class="QLabel" name="lbl_Callsign">
<property name="text"> <property name="text">
@@ -63,13 +60,37 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="1" column="1">
<widget class="QCheckBox" name="cb_LogReverseLookup"> <widget class="QCheckBox" name="cb_LogReverseLookup">
<property name="toolTip"> <property name="toolTip">
<string>enable logging of reverse lookup messages</string> <string>enable logging of reverse lookup messages</string>
</property> </property>
<property name="text"> <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> </property>
</widget> </widget>
</item> </item>