swift
Loading...
Searching...
No Matches
modelmatcherlogcomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QCompleter>
7#include <QStringListModel>
8
9#include "ui_modelmatcherlogcomponent.h"
10
13#include "gui/guiapplication.h"
15#include "misc/htmlutils.h"
17
18using namespace swift::misc;
19using namespace swift::misc::aviation;
20using namespace swift::core;
21using namespace swift::core::context;
22
24{
27 {
28 ui->setupUi(this);
29 m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
30 connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEnteredDigest, this,
31 &CModelMatcherLogComponent::callsignEntered);
32 }
33
35
36 bool CModelMatcherLogComponent::hasContexts() const
37 {
38 return sGui && sGui->getIContextSimulator() && sGui->getIContextNetwork();
39 }
40
41 bool CModelMatcherLogComponent::enabledMessages() const
42 {
43 return this->hasContexts() &&
44 (ui->comp_EnableLog->isMatchingLogEnabled() || ui->comp_EnableLog->isReverseLookupLogEnabled());
45 }
46
47 void CModelMatcherLogComponent::callsignEntered()
48 {
49 if (!this->hasContexts())
50 {
51 return;
52 }
53 const CCallsign cs(ui->comp_CallsignCompleter->getCallsign());
54 if (cs.isEmpty())
55 {
56 return;
57 }
58 const CStatusMessageList reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
59 const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs);
60
61 CStatusMessageList allMessages(reverseLookupMessages);
62 allMessages.push_back(matchingMessages);
63
64 const QString html = allMessages.toHtml();
65 m_text.setHtml(html);
66 ui->te_Messages->setDocument(&m_text);
67 }
68} // namespace swift::gui::components
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
virtual swift::misc::CStatusMessageList getReverseLookupMessages(const swift::misc::aviation::CCallsign &callsign) const =0
Get reverse lookup messages.
virtual swift::misc::CStatusMessageList getMatchingMessages(const swift::misc::aviation::CCallsign &callsign) const =0
Get mapping messages.
void validCallsignEnteredDigest()
Changed callsign entered.
CModelMatcherLogComponent(QWidget *parent=nullptr)
Constructor.
static const QString & htmlStyleSheet()
Default style sheet which can be used with CStatusMessageList::toHtml.
Value object encapsulating information of a callsign.
Definition callsign.h:30
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.
Definition actionbind.cpp:7
High level reusable GUI components.
Free functions in swift::misc.
QFrame(QWidget *parent, Qt::WindowFlags f)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QWidget(QWidget *parent, Qt::WindowFlags f)