mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
Ref T171, use a shared completer for callsign completion
* CSharedStringListCompleter utility class supporting timestamp checks * avoid unnecessary DBus transfer * less memory consumption Remark: No totally clear if a QCompleter can be shared, but I have not noticed a problem so far
This commit is contained in:
@@ -33,6 +33,7 @@ namespace BlackGui
|
||||
ui->setupUi(this);
|
||||
CUpperCaseValidator *ucv = new CUpperCaseValidator(ui->le_Callsign);
|
||||
ui->le_Callsign->setValidator(ucv);
|
||||
ui->le_Callsign->setCompleter(*completer());
|
||||
ui->led_Status->setToolTips("connected", "disconnected");
|
||||
ui->led_Status->setShape(CLedWidget::Rounded);
|
||||
ui->led_Status->setToolTips("network connected", "network disconnected", "data");
|
||||
@@ -68,19 +69,10 @@ namespace BlackGui
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
if (!sGui->getIContextNetwork()) { return; }
|
||||
if (completer()->wasUpdatedWithinTime(1500)) { return; } // avoid context call via DBus
|
||||
m_validCallsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns();
|
||||
const QStringList modelData = m_validCallsigns.getCallsignStrings(true);
|
||||
if (!m_currentCompleter)
|
||||
{
|
||||
m_currentCompleter = new QCompleter(modelData, ui->le_Callsign);
|
||||
ui->le_Callsign->setCompleter(m_currentCompleter);
|
||||
}
|
||||
else
|
||||
{
|
||||
QStringListModel *model = qobject_cast<QStringListModel *>(m_currentCompleter->model());
|
||||
Q_ASSERT(model);
|
||||
model->setStringList(modelData);
|
||||
}
|
||||
completer()->updateData(modelData, 2000);
|
||||
ui->led_Status->setTriState(500);
|
||||
}
|
||||
|
||||
@@ -102,15 +94,13 @@ namespace BlackGui
|
||||
void CCallsignCompleter::onChangedConnectionStatus(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to)
|
||||
{
|
||||
Q_UNUSED(from);
|
||||
const bool on = (INetwork::Connected == to);
|
||||
ui->led_Status->setOn(on);
|
||||
const bool connected = (INetwork::Connected == to);
|
||||
ui->led_Status->setOn(connected);
|
||||
ui->le_Callsign->clear();
|
||||
ui->le_Callsign->setEnabled(on);
|
||||
if (!on)
|
||||
ui->le_Callsign->setEnabled(connected);
|
||||
if (!connected)
|
||||
{
|
||||
QStringListModel *model = qobject_cast<QStringListModel *>(m_currentCompleter->model());
|
||||
Q_ASSERT(model);
|
||||
model->setStringList(QStringList());
|
||||
completer()->clearData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,5 +110,11 @@ namespace BlackGui
|
||||
if (!CCallsign::isValidAircraftCallsign(callsignString)) { return false; }
|
||||
return m_validCallsigns.contains(CCallsign(callsignString));
|
||||
}
|
||||
|
||||
CSharedStringListCompleter *CCallsignCompleter::completer()
|
||||
{
|
||||
static CSharedStringListCompleter *c = new CSharedStringListCompleter();
|
||||
return c;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKGUI_COMPONENTS_CALLSIGNCOMPLETER_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/sharedstringlistcompleter.h"
|
||||
#include "blackmisc/digestsignal.h"
|
||||
#include "blackmisc/aviation/callsignset.h"
|
||||
#include "blackcore/network.h"
|
||||
@@ -63,8 +64,10 @@ namespace BlackGui
|
||||
void onChangedConnectionStatus(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to);
|
||||
bool isValidKnownCallsign(const QString &callsignString) const;
|
||||
|
||||
//! Shared completer data
|
||||
static CSharedStringListCompleter *completer();
|
||||
|
||||
QScopedPointer <Ui::CCallsignCompleter> ui;
|
||||
QCompleter *m_currentCompleter = nullptr;
|
||||
BlackMisc::Aviation::CCallsignSet m_validCallsigns;
|
||||
BlackMisc::CDigestSignal m_dsAircraftsInRangeChanged { this, &CCallsignCompleter::onChangedAircraftInRange, 5000, 5 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user