From aa52889767ae1dd06b9c9c2b5c5fbfa11faff6f2 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 13 Oct 2017 20:04:21 +0200 Subject: [PATCH] Ref T171, use callsign completer in history and matcher log * "private slots" -> "private" * UI connects as Qt::QueuedConnection --- .../components/aircraftpartshistory.cpp | 61 +++++-------------- .../components/aircraftpartshistory.h | 8 --- .../components/aircraftpartshistory.ui | 29 ++++++--- .../components/modelmatcherlogcomponent.cpp | 55 ++++------------- .../components/modelmatcherlogcomponent.h | 13 ++-- .../components/modelmatcherlogcomponent.ui | 27 +++++--- 6 files changed, 69 insertions(+), 124 deletions(-) diff --git a/src/blackgui/components/aircraftpartshistory.cpp b/src/blackgui/components/aircraftpartshistory.cpp index d61feb98e..446f23240 100644 --- a/src/blackgui/components/aircraftpartshistory.cpp +++ b/src/blackgui/components/aircraftpartshistory.cpp @@ -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(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(); diff --git a/src/blackgui/components/aircraftpartshistory.h b/src/blackgui/components/aircraftpartshistory.h index 9c22eb131..c3efeec7a 100644 --- a/src/blackgui/components/aircraftpartshistory.h +++ b/src/blackgui/components/aircraftpartshistory.h @@ -39,11 +39,9 @@ namespace BlackGui private: QScopedPointer 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(); diff --git a/src/blackgui/components/aircraftpartshistory.ui b/src/blackgui/components/aircraftpartshistory.ui index 1df010c65..13debb7e8 100644 --- a/src/blackgui/components/aircraftpartshistory.ui +++ b/src/blackgui/components/aircraftpartshistory.ui @@ -6,8 +6,8 @@ 0 0 - 276 - 260 + 264 + 252 @@ -77,13 +77,6 @@ - - - - callsign - - - @@ -94,6 +87,16 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -112,6 +115,14 @@ + + + BlackGui::Components::CCallsignCompleter + QFrame +
blackgui/components/callsigncompleter.h
+ 1 +
+
diff --git a/src/blackgui/components/modelmatcherlogcomponent.cpp b/src/blackgui/components/modelmatcherlogcomponent.cpp index e588c34bf..a2b160c3f 100644 --- a/src/blackgui/components/modelmatcherlogcomponent.cpp +++ b/src/blackgui/components/modelmatcherlogcomponent.cpp @@ -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(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) diff --git a/src/blackgui/components/modelmatcherlogcomponent.h b/src/blackgui/components/modelmatcherlogcomponent.h index 57f372f7b..1242ca47a 100644 --- a/src/blackgui/components/modelmatcherlogcomponent.h +++ b/src/blackgui/components/modelmatcherlogcomponent.h @@ -39,7 +39,6 @@ namespace BlackGui private: QScopedPointer 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 diff --git a/src/blackgui/components/modelmatcherlogcomponent.ui b/src/blackgui/components/modelmatcherlogcomponent.ui index fe95f6122..4b9018738 100644 --- a/src/blackgui/components/modelmatcherlogcomponent.ui +++ b/src/blackgui/components/modelmatcherlogcomponent.ui @@ -7,7 +7,7 @@ 0 0 276 - 260 + 252 @@ -77,13 +77,6 @@ - - - - callsign - - - @@ -94,6 +87,16 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -112,6 +115,14 @@ + + + BlackGui::Components::CCallsignCompleter + QFrame +
blackgui/components/callsigncompleter.h
+ 1 +
+