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

View File

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

View File

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

View File

@@ -33,22 +33,18 @@ namespace BlackGui
ui(new Ui::CModelMatcherLogComponent) ui(new Ui::CModelMatcherLogComponent)
{ {
ui->setupUi(this); 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->initGui();
this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet()); this->m_text.setDefaultStyleSheet(CStatusMessageList::htmlStyleSheet());
connect(ui->le_Callsign, &QLineEdit::returnPressed, this, &CModelMatcherLogComponent::ps_callsignEntered); connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CModelMatcherLogComponent::callsignEntered);
connect(ui->cb_LogReverseLookup, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_enabledCheckboxChanged); connect(ui->cb_LogReverseLookup, &QCheckBox::toggled, this, &CModelMatcherLogComponent::enabledCheckboxChanged);
connect(ui->cb_LogMatchingMessages, &QCheckBox::toggled, this, &CModelMatcherLogComponent::ps_enabledCheckboxChanged); connect(ui->cb_LogMatchingMessages, &QCheckBox::toggled, this, &CModelMatcherLogComponent::enabledCheckboxChanged);
if (this->hasContexts()) if (this->hasContexts())
{ {
connect(sGui->getIContextSimulator(), &IContextSimulator::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::ps_valuesChanged); connect(sGui->getIContextSimulator(), &IContextSimulator::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::valuesChanged, Qt::QueuedConnection);
connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::ps_valuesChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::changedLogOrDebugSettings, this, &CModelMatcherLogComponent::valuesChanged, Qt::QueuedConnection);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CModelMatcherLogComponent::ps_connectionStatusChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CModelMatcherLogComponent::connectionStatusChanged, Qt::QueuedConnection);
} }
connect(&this->m_updateCompleterTimer, &QTimer::timeout, this, &CModelMatcherLogComponent::ps_updateCallsignCompleter);
} }
CModelMatcherLogComponent::~CModelMatcherLogComponent() CModelMatcherLogComponent::~CModelMatcherLogComponent()
@@ -56,17 +52,6 @@ namespace BlackGui
void CModelMatcherLogComponent::initGui() 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 // avoid signal roundtrip
bool c = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled(); bool c = sGui->getIContextNetwork()->isReverseLookupMessagesEnabled();
ui->cb_LogReverseLookup->setChecked(c); ui->cb_LogReverseLookup->setChecked(c);
@@ -85,27 +70,11 @@ namespace BlackGui
return this->hasContexts() && (ui->cb_LogMatchingMessages->isChecked() || ui->cb_LogReverseLookup->isChecked()); return this->hasContexts() && (ui->cb_LogMatchingMessages->isChecked() || ui->cb_LogReverseLookup->isChecked());
} }
void CModelMatcherLogComponent::ps_updateCallsignCompleter() void CModelMatcherLogComponent::callsignEntered()
{
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()
{ {
if (!this->hasContexts()) { return; } 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 reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs); const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs);
@@ -117,12 +86,12 @@ namespace BlackGui
ui->te_Messages->setDocument(&this->m_text); ui->te_Messages->setDocument(&this->m_text);
} }
void CModelMatcherLogComponent::ps_valuesChanged() void CModelMatcherLogComponent::valuesChanged()
{ {
this->initGui(); this->initGui();
} }
void CModelMatcherLogComponent::ps_enabledCheckboxChanged(bool enabled) void CModelMatcherLogComponent::enabledCheckboxChanged(bool enabled)
{ {
if (!sGui || !sGui->getIContextNetwork() || !sGui->getIContextSimulator()) { return; } if (!sGui || !sGui->getIContextNetwork() || !sGui->getIContextSimulator()) { return; }
const QObject *sender = QObject::sender(); 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); Q_UNUSED(from);
if (to == INetwork::Connected || to == INetwork::Disconnected) if (to == INetwork::Connected || to == INetwork::Disconnected)

View File

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

View File

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