mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 21:05:34 +08:00
Gimmick and formatting
* flags for VATSIM servers * improved country resolution
This commit is contained in:
@@ -321,10 +321,11 @@ namespace BlackGui
|
||||
|
||||
if (entity == CEntityFlags::VatsimDataFile)
|
||||
{
|
||||
const CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
|
||||
CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
|
||||
if (vatsimFsdServers.isEmpty()) { return; }
|
||||
vatsimFsdServers.sortBy(&CServer::getName);
|
||||
const CServer currentServer = this->m_currentVatsimServer.get();
|
||||
this->ui->comp_VatsimServer->setServers(vatsimFsdServers);
|
||||
this->ui->comp_VatsimServer->setServers(vatsimFsdServers, true);
|
||||
this->ui->comp_VatsimServer->preSelect(currentServer.getName());
|
||||
}
|
||||
else
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
// forward declaration to break compile dependency from all components
|
||||
class CAircraftComponent;
|
||||
class CAtcStationComponent;
|
||||
// forward declaration to break compile dependency from all components
|
||||
class CCockpitComponent;
|
||||
class CFlightPlanComponent;
|
||||
class CLogComponent;
|
||||
@@ -122,10 +122,8 @@ namespace BlackGui
|
||||
void selectSettingsTab(int index);
|
||||
|
||||
protected:
|
||||
//! \copydoc CInfoArea::getPreferredSizeWhenFloating
|
||||
// CInfoArea overrides
|
||||
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const override;
|
||||
|
||||
//! \copydoc CInfoArea::indexToPixmap
|
||||
virtual const QPixmap &indexToPixmap(int areaIndex) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,11 +8,18 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/components/serverlistselector.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackcore/db/icaodatareader.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackGui;
|
||||
using namespace BlackCore;
|
||||
using namespace BlackCore::Db;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -20,13 +27,12 @@ namespace BlackGui
|
||||
{
|
||||
CServerListSelector::CServerListSelector(QWidget *parent) :
|
||||
QComboBox(parent)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
void CServerListSelector::setServers(const BlackMisc::Network::CServerList &servers)
|
||||
void CServerListSelector::setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry)
|
||||
{
|
||||
if (this->m_servers == servers) { return; }
|
||||
this->setItemStrings(servers);
|
||||
this->setServerItems(servers, nameIsCountry);
|
||||
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
|
||||
{
|
||||
this->preSelect(m_pendingPreselect);
|
||||
@@ -60,23 +66,41 @@ namespace BlackGui
|
||||
return false;
|
||||
}
|
||||
|
||||
void CServerListSelector::setItemStrings(const CServerList &servers)
|
||||
void CServerListSelector::setServerItems(const CServerList &servers, bool nameToCountry)
|
||||
{
|
||||
QString currentlySelected(this->currentText());
|
||||
int index = -1;
|
||||
this->m_servers = servers;
|
||||
this->m_items.clear();
|
||||
this->clear(); // ui
|
||||
|
||||
nameToCountry = nameToCountry && knowsAllCountries();
|
||||
for (const CServer &server : servers)
|
||||
{
|
||||
QString d(server.getName() + ": " + server.getDescription());
|
||||
const QString d(server.getName() + ": " + server.getDescription());
|
||||
m_items.append(d);
|
||||
if (!currentlySelected.isEmpty() && index < 0 && d == currentlySelected)
|
||||
{
|
||||
index = m_items.size() - 1;
|
||||
}
|
||||
|
||||
if (nameToCountry)
|
||||
{
|
||||
const CCountry country(findCountry(server));
|
||||
if (country.getName().isEmpty())
|
||||
{
|
||||
this->addItem(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->addItem(country.toPixmap(), d);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->addItem(d);
|
||||
}
|
||||
}
|
||||
this->clear(); // ui
|
||||
this->addItems(m_items);
|
||||
|
||||
// reselect
|
||||
if (this->m_items.isEmpty()) { return; }
|
||||
@@ -89,5 +113,17 @@ namespace BlackGui
|
||||
this->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool CServerListSelector::knowsAllCountries()
|
||||
{
|
||||
return (sGui && sGui->getWebDataServices() && sGui->getWebDataServices()->getCountriesCount() > 0);
|
||||
}
|
||||
|
||||
CCountry CServerListSelector::findCountry(const CServer &server)
|
||||
{
|
||||
if (!knowsAllCountries()) { return CCountry(); }
|
||||
static const CCountryList countries(sGui->getWebDataServices()->getCountries());
|
||||
return countries.findBestMatchByCountryName(server.getName());
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
#include "blackmisc/network/serverlist.h"
|
||||
#include "blackmisc/country.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QObject>
|
||||
@@ -36,7 +37,7 @@ namespace BlackGui
|
||||
explicit CServerListSelector(QWidget *parent = nullptr);
|
||||
|
||||
//! Set the servers
|
||||
void setServers(const BlackMisc::Network::CServerList &servers);
|
||||
void setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry = false);
|
||||
|
||||
//! Get the current server
|
||||
BlackMisc::Network::CServer currentServer() const;
|
||||
@@ -46,7 +47,13 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
//! Build the item string descriptions
|
||||
void setItemStrings(const BlackMisc::Network::CServerList &servers);
|
||||
void setServerItems(const BlackMisc::Network::CServerList &servers, bool nameToCountry);
|
||||
|
||||
//! Do we know all countries?
|
||||
static bool knowsAllCountries();
|
||||
|
||||
//! Turn server name into country (for VATSIM servers)
|
||||
static BlackMisc::CCountry findCountry(const BlackMisc::Network::CServer &server);
|
||||
|
||||
BlackMisc::Network::CServerList m_servers; //!< corresponding servers
|
||||
QStringList m_items; //!< items strings
|
||||
|
||||
@@ -119,8 +119,7 @@ namespace BlackMisc
|
||||
if (this->m_designator.length() > 2)
|
||||
{
|
||||
// relative to images
|
||||
return CIcon("airlines/" + m_designator.toLower() + ".png",
|
||||
this->convertToQString());
|
||||
return CIcon("airlines/" + m_designator.toLower() + ".png", this->convertToQString());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace BlackMisc
|
||||
if (this->m_dbKey.length() == 2)
|
||||
{
|
||||
// relative to images
|
||||
return CIcon("flags/" + m_dbKey.toLower() + ".png",
|
||||
this->convertToQString());
|
||||
return CIcon("flags/" + m_dbKey.toLower() + ".png", this->convertToQString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -73,7 +72,7 @@ namespace BlackMisc
|
||||
if (name.isEmpty() || m_name.isEmpty()) { return false; }
|
||||
if (name.length() < 5)
|
||||
{
|
||||
return m_name.length() == name.length() && m_name.startsWith(name, Qt::CaseInsensitive);
|
||||
return m_name.length() == name.length() && (m_name.startsWith(name, Qt::CaseInsensitive) || name.startsWith(m_name, Qt::CaseInsensitive));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -32,17 +32,22 @@ namespace BlackMisc
|
||||
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
|
||||
{
|
||||
if (countryName.isEmpty()) { return CCountry(); }
|
||||
|
||||
static const QRegExp reg("[^a-z]", Qt::CaseInsensitive);
|
||||
QString cn(countryName);
|
||||
cn.remove(reg);
|
||||
CCountryList countries = this->findBy([&](const CCountry & country)
|
||||
{
|
||||
return country.matchesCountryName(countryName);
|
||||
return country.matchesCountryName(cn);
|
||||
});
|
||||
if (countries.size() < 2) { return countries.frontOrDefault(); }
|
||||
|
||||
// find best match
|
||||
// find best match by further reducing
|
||||
for (const CCountry &c : countries)
|
||||
{
|
||||
if (c.getName() == countryName) { return c; }
|
||||
if (c.getName().startsWith(countryName, Qt::CaseInsensitive)) { return c; }
|
||||
if (c.getName() == cn) { return c; }
|
||||
if (c.getName().startsWith(cn, Qt::CaseInsensitive)) { return c; }
|
||||
if (cn.startsWith(c.getName(), Qt::CaseInsensitive)) { return c; }
|
||||
}
|
||||
return countries.front();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user