Ref T171, use callsign completer in history and matcher log

* "private slots" -> "private"
* UI connects as Qt::QueuedConnection
This commit is contained in:
Klaus Basan
2017-10-13 20:04:21 +02:00
parent a51f696bee
commit aa52889767
6 changed files with 69 additions and 124 deletions

View File

@@ -35,17 +35,12 @@ namespace BlackGui
ui(new Ui::CAircraftPartsHistory)
{
ui->setupUi(this);
ui->le_Callsign->setValidator(new CUpperCaseValidator(this));
ui->le_Callsign->setCompleter(new QCompleter(ui->le_Callsign));
ui->cb_PartsHistoryEnabled->setChecked(sApp && sApp->isRunningInDeveloperEnvironment()); // default
this->m_timerCallsignUpdate.setInterval(20 * 1000);
this->m_timerUpdateHistory.setInterval(2 * 1000);
m_timerUpdateHistory.setInterval(2 * 1000);
this->initGui();
this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
connect(ui->le_Callsign, &QLineEdit::textEdited, this, &CAircraftPartsHistory::callsignModified);
connect(ui->le_Callsign, &QLineEdit::returnPressed, this, &CAircraftPartsHistory::callsignEntered);
m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CAircraftPartsHistory::callsignEntered);
connect(ui->cb_PartsHistoryEnabled, &QCheckBox::toggled, this, &CAircraftPartsHistory::toggleHistoryEnabled);
if (this->hasContexts())
@@ -53,8 +48,7 @@ namespace BlackGui
connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CAircraftPartsHistory::valuesChanged);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftPartsHistory::connectionStatusChanged);
}
connect(&this->m_timerCallsignUpdate, &QTimer::timeout, this, &CAircraftPartsHistory::updateCallsignCompleter);
connect(&this->m_timerUpdateHistory, &QTimer::timeout, this, &CAircraftPartsHistory::updatePartsHistory);
connect(&m_timerUpdateHistory, &QTimer::timeout, this, &CAircraftPartsHistory::updatePartsHistory);
}
CAircraftPartsHistory::~CAircraftPartsHistory()
@@ -63,20 +57,17 @@ namespace BlackGui
void CAircraftPartsHistory::initGui()
{
const bool needCallsigns = this->partsHistoryEnabled();
if (needCallsigns && !m_timerCallsignUpdate.isActive() && !m_timerUpdateHistory.isActive())
if (needCallsigns && !m_timerUpdateHistory.isActive())
{
this->m_timerCallsignUpdate.start();
this->m_timerUpdateHistory.start();
this->updateCallsignCompleter();
m_timerUpdateHistory.start();
}
else if (!needCallsigns)
{
this->m_timerCallsignUpdate.stop();
this->m_timerUpdateHistory.stop();
m_timerUpdateHistory.stop();
}
// avoid signal roundtrip
bool c = sGui->getIContextNetwork()->isAircraftPartsHistoryEnabled();
const bool c = sGui->getIContextNetwork()->isAircraftPartsHistoryEnabled();
ui->cb_PartsHistoryEnabled->setChecked(c);
}
@@ -90,30 +81,12 @@ namespace BlackGui
return this->hasContexts();
}
void CAircraftPartsHistory::updateCallsignCompleter()
{
if (!this->hasContexts() || !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 CAircraftPartsHistory::updatePartsHistory()
{
if (!this->hasContexts()) { return; }
if (!this->isVisible()) { return; }
if (m_isBeingModified) { return; }
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
if (cs.isEmpty()) { return; }
const CCallsign cs(ui->comp_CallsignCompleter->getCallsign());
if (cs.isEmpty()) { return; } // no or invalid callsign
const auto currentAircraftParts = sGui->getIContextNetwork()->getRemoteAircraftParts(cs, -1).frontOrDefault();
const auto aircraftPartsHistory = sGui->getIContextNetwork()->getAircraftPartsHistory(cs);
@@ -154,11 +127,11 @@ namespace BlackGui
}
}
uint hash = qHash(html);
const uint hash = qHash(html);
if (hash == m_htmlHash) { return; } // avoid to always scroll to the end when there is no update
m_htmlHash = hash;
this->m_text.setHtml(html);
ui->te_Messages->setDocument(&this->m_text);
m_text.setHtml(html);
ui->te_Messages->setDocument(&m_text);
if (ui->cb_AutoScrollEnabled->isChecked())
{
@@ -170,16 +143,10 @@ namespace BlackGui
void CAircraftPartsHistory::callsignEntered()
{
m_isBeingModified = false;
updatePartsHistory();
this->updatePartsHistory();
m_timerUpdateHistory.start();
}
void CAircraftPartsHistory::callsignModified()
{
m_isBeingModified = true;
}
void CAircraftPartsHistory::valuesChanged()
{
this->initGui();

View File

@@ -39,11 +39,9 @@ namespace BlackGui
private:
QScopedPointer<Ui::CAircraftPartsHistory> ui;
QTimer m_timerCallsignUpdate { this };
QTimer m_timerUpdateHistory { this };
QTextDocument m_text { this };
uint m_htmlHash = 0;
bool m_isBeingModified = false;
//! Init
void initGui();
@@ -55,18 +53,12 @@ namespace BlackGui
bool partsHistoryEnabled() const;
private:
//! Update the completer
void updateCallsignCompleter();
//! Update parts history
void updatePartsHistory();
//! Callsign was entered
void callsignEntered();
//! Callsign was modified
void callsignModified();
//! When values changed elsewhere
void valuesChanged();

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>260</height>
<width>264</width>
<height>252</height>
</rect>
</property>
<property name="windowTitle">
@@ -77,13 +77,6 @@
</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_AutoScrollEnabled">
<property name="text">
@@ -94,6 +87,16 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="BlackGui::Components::CCallsignCompleter" name="comp_CallsignCompleter">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -112,6 +115,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CCallsignCompleter</class>
<extends>QFrame</extends>
<header>blackgui/components/callsigncompleter.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -33,22 +33,18 @@ namespace BlackGui
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_updateCompleterTimer.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_enabledCheckboxChanged);
connect(ui->cb_LogMatchingMessages, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_enabledCheckboxChanged);
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::ps_valuesChanged);
connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::ps_valuesChanged);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CModelMatcherLogComponent::ps_connectionStatusChanged);
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);
}
connect(&this->m_updateCompleterTimer, &QTimer::timeout, this, &CModelMatcherLogComponent::ps_updateCallsignCompleter);
}
CModelMatcherLogComponent::~CModelMatcherLogComponent()
@@ -56,17 +52,6 @@ namespace BlackGui
void CModelMatcherLogComponent::initGui()
{
const bool needCallsigns = this->enabledMessages();
if (needCallsigns && !this->m_updateCompleterTimer.isActive())
{
this->m_updateCompleterTimer.start();
this->ps_updateCallsignCompleter();
}
else if (!needCallsigns)
{
this->m_updateCompleterTimer.stop();
}
// avoid signal roundtrip
bool c = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
ui->cb_LogReverseLookup->setChecked(c);
@@ -85,27 +70,11 @@ namespace BlackGui
return this->hasContexts() && (ui->cb_LogMatchingMessages->isChecked() || ui->cb_LogReverseLookup->isChecked());
}
void CModelMatcherLogComponent::ps_updateCallsignCompleter()
{
if (!this->hasContexts() || !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()
void CModelMatcherLogComponent::callsignEntered()
{
if (!this->hasContexts()) { return; }
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
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);
@@ -117,12 +86,12 @@ namespace BlackGui
ui->te_Messages->setDocument(&this->m_text);
}
void CModelMatcherLogComponent::ps_valuesChanged()
void CModelMatcherLogComponent::valuesChanged()
{
this->initGui();
}
void CModelMatcherLogComponent::ps_enabledCheckboxChanged(bool enabled)
void CModelMatcherLogComponent::enabledCheckboxChanged(bool enabled)
{
if (!sGui || !sGui->getIContextNetwork() || !sGui->getIContextSimulator()) { return; }
const QObject *sender = QObject::sender();
@@ -136,7 +105,7 @@ namespace BlackGui
}
}
void CModelMatcherLogComponent::ps_connectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
void CModelMatcherLogComponent::connectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
{
Q_UNUSED(from);
if (to == INetwork::Connected || to == INetwork::Disconnected)

View File

@@ -39,7 +39,6 @@ namespace BlackGui
private:
QScopedPointer<Ui::CModelMatcherLogComponent> ui;
QTimer m_updateCompleterTimer { this };
QTextDocument m_text { this };
//! Init
@@ -51,21 +50,17 @@ namespace BlackGui
//! Enabled messages
bool enabledMessages() const;
private slots:
//! Update the completer
void ps_updateCallsignCompleter();
//! Callsign was entered
void ps_callsignEntered();
void callsignEntered();
//! When values changed elsewhere
void ps_valuesChanged();
void valuesChanged();
//! Flag changed
void ps_enabledCheckboxChanged(bool enabled);
void enabledCheckboxChanged(bool enabled);
//! Connection status changed
void ps_connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to);
void connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to);
};
} // ns
} // ns

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>276</width>
<height>260</height>
<height>252</height>
</rect>
</property>
<property name="windowTitle">
@@ -77,13 +77,6 @@
</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">
@@ -94,6 +87,16 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="BlackGui::Components::CCallsignCompleter" name="comp_CallsignCompleter">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -112,6 +115,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CCallsignCompleter</class>
<extends>QFrame</extends>
<header>blackgui/components/callsigncompleter.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>