Files
pilotclient/src/blackgui/components/modelmatcherlogcomponent.cpp
Klaus Basan aa52889767 Ref T171, use callsign completer in history and matcher log
* "private slots" -> "private"
* UI connects as Qt::QueuedConnection
2017-10-18 22:58:44 +02:00

118 lines
4.8 KiB
C++

/* Copyright (C) 2016
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "modelmatcherlogcomponent.h"
#include "ui_modelmatcherlogcomponent.h"
#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>
#include <QStringListModel>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackCore;
using namespace BlackCore::Context;
namespace BlackGui
{
namespace Components
{
CModelMatcherLogComponent::CModelMatcherLogComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CModelMatcherLogComponent)
{
ui->setupUi(this);
this->initGui();
this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CModelMatcherLogComponent::callsignEntered);
connect(ui->cb_LogReverseLookup, &QCheckBox::toggled, this, &CModelMatcherLogComponent::enabledCheckboxChanged);
connect(ui->cb_LogMatchingMessages, &QCheckBox::toggled, this, &CModelMatcherLogComponent::enabledCheckboxChanged);
if (this->hasContexts())
{
connect(sGui->getIContextSimulator(), &IContextSimulator::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::valuesChanged, Qt::QueuedConnection);
connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::valuesChanged, Qt::QueuedConnection);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CModelMatcherLogComponent::connectionStatusChanged, Qt::QueuedConnection);
}
}
CModelMatcherLogComponent::~CModelMatcherLogComponent()
{ }
void CModelMatcherLogComponent::initGui()
{
// 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::callsignEntered()
{
if (!this->hasContexts()) { return; }
const CCallsign cs(ui->comp_CallsignCompleter->getCallsign());
if (cs.isEmpty()) { return; }
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();
this->m_text.setHtml(html);
ui->te_Messages->setDocument(&this->m_text);
}
void CModelMatcherLogComponent::valuesChanged()
{
this->initGui();
}
void CModelMatcherLogComponent::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::connectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
{
Q_UNUSED(from);
if (to == INetwork::Connected || to == INetwork::Disconnected)
{
this->initGui();
}
}
} // ns
} // ns