mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T226, using airport completer
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
#include "pilotform.h"
|
||||
#include "ui_pilotform.h"
|
||||
#include "blackgui/components/airportsmallcompleter.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/uppercasevalidator.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/network/user.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
@@ -22,7 +22,7 @@ using namespace BlackConfig;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackCore;
|
||||
using namespace BlackGui::Components;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -38,18 +38,11 @@ namespace BlackGui
|
||||
ui->lblp_Password->setToolTips("ok", "wrong");
|
||||
ui->lblp_RealName->setToolTips("ok", "wrong");
|
||||
|
||||
ui->le_HomeAirport->setValidator(new CUpperCaseValidator(this));
|
||||
this->initCompleters(CEntityFlags::AirportEntity);
|
||||
|
||||
connect(ui->tb_UnhidePassword, &QToolButton::clicked, this, &CPilotForm::unhidePassword);
|
||||
connect(ui->le_Id, &QLineEdit::editingFinished, this, &CPilotForm::doValidation);
|
||||
connect(ui->le_HomeAirport, &QLineEdit::editingFinished, this, &CPilotForm::doValidation);
|
||||
connect(ui->comp_HomeAirport, &CAirportSmallCompleter::editingFinished, this, &CPilotForm::doValidation);
|
||||
connect(ui->le_Password, &QLineEdit::editingFinished, this, &CPilotForm::doValidation);
|
||||
connect(ui->le_RealName, &QLineEdit::editingFinished, this, &CPilotForm::doValidation);
|
||||
|
||||
// web service data
|
||||
Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Need web data services");
|
||||
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CPilotForm::onWebServiceDataRead);
|
||||
}
|
||||
|
||||
CPilotForm::~CPilotForm()
|
||||
@@ -65,7 +58,7 @@ namespace BlackGui
|
||||
CUser CPilotForm::getUser() const
|
||||
{
|
||||
CUser user = CUser(ui->le_Id->text().trimmed(), CUser::beautifyRealName(ui->le_RealName->text()), "", ui->le_Password->text());
|
||||
user.setHomeBase(CAirportIcaoCode(ui->le_HomeAirport->text().trimmed()));
|
||||
user.setHomeBase(ui->comp_HomeAirport->getAirportIcaoCode());
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -79,14 +72,14 @@ namespace BlackGui
|
||||
ui->le_RealName->setText(user.getRealName());
|
||||
if (user.hasHomeBase())
|
||||
{
|
||||
ui->le_HomeAirport->setText(user.getHomeBase().asString());
|
||||
ui->comp_HomeAirport->setAirportIcaoCode(user.getHomeBase());
|
||||
}
|
||||
}
|
||||
else if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
ui->le_Id->setText("1288459");
|
||||
ui->le_Password->setText("4769");
|
||||
ui->le_HomeAirport->setText("LOWI");
|
||||
ui->comp_HomeAirport->setAirportIcaoCode("LOWI");
|
||||
ui->le_RealName->setText("Swift Project");
|
||||
}
|
||||
this->validate();
|
||||
@@ -97,7 +90,7 @@ namespace BlackGui
|
||||
{
|
||||
ui->le_Id->clear();
|
||||
ui->le_Password->clear();
|
||||
ui->le_HomeAirport->clear();
|
||||
ui->comp_HomeAirport->clear();
|
||||
ui->le_RealName->clear();
|
||||
|
||||
ui->lblp_Id->setTicked(false);
|
||||
@@ -108,7 +101,7 @@ namespace BlackGui
|
||||
|
||||
void CPilotForm::setReadOnly(bool readonly)
|
||||
{
|
||||
ui->le_HomeAirport->setReadOnly(readonly);
|
||||
ui->comp_HomeAirport->setReadOnly(readonly);
|
||||
ui->le_Id->setReadOnly(readonly);
|
||||
ui->le_Password->setReadOnly(readonly);
|
||||
ui->le_RealName->setReadOnly(readonly);
|
||||
@@ -154,35 +147,6 @@ namespace BlackGui
|
||||
});
|
||||
}
|
||||
|
||||
void CPilotForm::initCompleters(CEntityFlags::Entity entity)
|
||||
{
|
||||
// completers where possible
|
||||
if (sGui && sGui->hasWebDataServices())
|
||||
{
|
||||
if (entity.testFlag(CEntityFlags::AirportEntity) && !ui->le_HomeAirport->completer())
|
||||
{
|
||||
// one time init
|
||||
const QStringList airports = sGui->getWebDataServices()->getAirports().allIcaoCodes(true);
|
||||
if (!airports.isEmpty())
|
||||
{
|
||||
QCompleter *completer = new QCompleter(airports, this);
|
||||
QStyledItemDelegate *itemDelegate = new QStyledItemDelegate(completer);
|
||||
completer->popup()->setItemDelegate(itemDelegate);
|
||||
ui->le_HomeAirport->setCompleter(completer);
|
||||
completer->popup()->setObjectName("AirportCompleter");
|
||||
completer->popup()->setMinimumWidth(175);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPilotForm::onWebServiceDataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number)
|
||||
{
|
||||
if (state != CEntityFlags::ReadFinished) { return; }
|
||||
Q_UNUSED(number);
|
||||
this->initCompleters(entity);
|
||||
}
|
||||
|
||||
void CPilotForm::doValidation()
|
||||
{
|
||||
this->validate();
|
||||
|
||||
@@ -59,12 +59,6 @@ namespace BlackGui
|
||||
//! Unhide password
|
||||
void unhidePassword();
|
||||
|
||||
//! Completers
|
||||
void initCompleters(BlackMisc::Network::CEntityFlags::Entity entity);
|
||||
|
||||
//! Web services read
|
||||
void onWebServiceDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
//! Call validation
|
||||
void doValidation();
|
||||
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
<ui version="4.0">
|
||||
<class>CPilotForm</class>
|
||||
<widget class="QFrame" name="CPilotForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>295</width>
|
||||
<height>57</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Pilot info</string>
|
||||
</property>
|
||||
@@ -21,7 +29,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Id">
|
||||
<property name="text">
|
||||
<string>Id:</string>
|
||||
<string>Id</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -35,27 +43,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="lbl_Password">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QToolButton" name="tb_UnhidePassword">
|
||||
<property name="toolTip">
|
||||
<string>unhide password</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/question-button.png</normaloff>:/diagona/icons/diagona/icons/question-button.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QLineEdit" name="le_Password">
|
||||
<property name="echoMode">
|
||||
@@ -63,24 +50,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<item row="0" column="7">
|
||||
<widget class="BlackGui::CTickLabel" name="lblp_Password">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_RealName">
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="lbl_Password">
|
||||
<property name="text">
|
||||
<string>Real name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_RealName">
|
||||
<property name="placeholderText">
|
||||
<string>e.g. Joe Doe</string>
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -101,23 +81,51 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4" colspan="2">
|
||||
<widget class="QLineEdit" name="le_HomeAirport">
|
||||
<property name="maxLength">
|
||||
<number>4</number>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_RealName">
|
||||
<property name="toolTip">
|
||||
<string>Real name</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>e.g. "KLAX"</string>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="6">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_RealName">
|
||||
<property name="placeholderText">
|
||||
<string>e.g. Joe Doe</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="7">
|
||||
<widget class="BlackGui::CTickLabel" name="lblp_HomeAirport">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<widget class="QToolButton" name="tb_UnhidePassword">
|
||||
<property name="toolTip">
|
||||
<string>unhide password</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/question-button.png</normaloff>:/diagona/icons/diagona/icons/question-button.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5" colspan="2">
|
||||
<widget class="BlackGui::Components::CAirportSmallCompleter" name="comp_HomeAirport">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@@ -126,7 +134,19 @@
|
||||
<extends>QLabel</extends>
|
||||
<header>blackgui/ticklabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CAirportSmallCompleter</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/airportsmallcompleter.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>le_Id</tabstop>
|
||||
<tabstop>le_Password</tabstop>
|
||||
<tabstop>tb_UnhidePassword</tabstop>
|
||||
<tabstop>le_RealName</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user