refs #702, GUI to display reverse lookup messages

This commit is contained in:
Klaus Basan
2016-07-05 13:11:52 +02:00
parent 83eca195a8
commit 299c82e113
3 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
/* 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/contextnetwork.h"
#include "blackgui/guiapplication.h"
#include "blackgui/uppercasevalidator.h"
#include <QCompleter>
#include <QStringListModel>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackCore;
namespace BlackGui
{
namespace Components
{
CModelMatcherLogComponent::CModelMatcherLogComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CModelMatcherLogComponent)
{
ui->setupUi(this);
ui->le_Callsign->setValidator(new CUpperCaseValidator(this));
ui->le_Callsign->setCompleter(new QCompleter(ui->le_Callsign));
this->m_timer.setInterval(20 * 1000);
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(&this->m_timer, &QTimer::timeout, this, &CModelMatcherLogComponent::ps_updateCallsignCompleter);
}
CModelMatcherLogComponent::~CModelMatcherLogComponent()
{ }
void CModelMatcherLogComponent::initGui()
{
bool reverseLookup = false;
if (sGui && sGui->getIContextNetwork())
{
reverseLookup = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
}
if (reverseLookup && !this->m_timer.isActive())
{
this->m_timer.start();
this->ps_updateCallsignCompleter();
}
else if (!reverseLookup)
{
this->m_timer.stop();
}
ui->cb_LogReverseLookup->setChecked(reverseLookup);
ui->le_Callsign->setReadOnly(!reverseLookup);
}
void CModelMatcherLogComponent::ps_updateCallsignCompleter()
{
if (!sGui || !sGui->getIContextNetwork()->isConnected()) { return; }
const QStringList callsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns().toStringList(false);
QCompleter *completer = ui->le_Callsign->completer();
Q_ASSERT_X(completer, Q_FUNC_INFO, "missing completer");
if (!completer->model())
{
completer->setModel(new QStringListModel(callsigns, completer));
}
else
{
qobject_cast<QStringListModel *>(completer->model())->setStringList(callsigns);
}
}
void CModelMatcherLogComponent::ps_callsignEntered()
{
if (!sGui || !ui->cb_LogReverseLookup->isChecked()) { return; }
static const CPropertyIndexList properties({ CStatusMessage::IndexMessage });
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
const CStatusMessageList msgs = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
const QString html = msgs.toHtml(properties);
this->m_text.setHtml(html);
ui->te_Messages->setDocument(&this->m_text);
}
void CModelMatcherLogComponent::ps_reverseLookupEnabled(bool enabled)
{
if (!sGui || !sGui->getIContextNetwork()) { return; }
sGui->getIContextNetwork()->enableReverseLookupMessages(enabled);
this->initGui();
}
} // ns
} // ns

View File

@@ -0,0 +1,60 @@
/* 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.
*/
//! \file
#ifndef BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
#define BLACKGUI_COMPONENT_MODELMATCHERLOGCOMPONENT_H
#include <QFrame>
#include <QTabWidget>
#include <QTimer>
#include <QTextDocument>
namespace Ui { class CModelMatcherLogComponent; }
namespace BlackGui
{
namespace Components
{
/*!
* Special logs for matching and reverse lookup
*/
class CModelMatcherLogComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CModelMatcherLogComponent(QWidget *parent = nullptr);
//! Constructor
~CModelMatcherLogComponent();
private:
QScopedPointer<Ui::CModelMatcherLogComponent> ui;
QTimer m_timer { this };
QTextDocument m_text { this };
//! Init
void initGui();
private slots:
//! Update the completer
void ps_updateCallsignCompleter();
//! Callsign was entered
void ps_callsignEntered();
//! Flag changed
void ps_reverseLookupEnabled(bool enabled);
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CModelMatcherLogComponent</class>
<widget class="QFrame" name="CModelMatcherLogComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QFrame" name="fr_DataEntry">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<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">
<string>Callsign:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="cb_LogReverseLookup">
<property name="text">
<string>reverse lookup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="te_Messages">
<property name="documentTitle">
<string>Messages</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Result will go here</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>