mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #452 airline selector component UI widget
This commit is contained in:
committed by
Mathew Sutcliffe
parent
2143b20ae5
commit
cd259259c8
198
src/blackgui/components/dbairlineicaoselectorcomponent.cpp
Normal file
198
src/blackgui/components/dbairlineicaoselectorcomponent.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "dbairlineicaoselectorcomponent.h"
|
||||
#include "ui_dbairlineicaoselectorcomponent.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include <QMimeData>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CDbAirlineIcaoSelectorComponent::CDbAirlineIcaoSelectorComponent(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CDbAirlineIcaoSelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setAcceptDrops(true);
|
||||
this->setAcceptedMetaTypeIds({qMetaTypeId<CAirlineIcaoCode>(), qMetaTypeId<CAirlineIcaoCodeList>()});
|
||||
|
||||
connect(ui->le_Airline, &QLineEdit::returnPressed, this, &CDbAirlineIcaoSelectorComponent::ps_dataChanged);
|
||||
}
|
||||
|
||||
CDbAirlineIcaoSelectorComponent::~CDbAirlineIcaoSelectorComponent()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::setProvider(Network::IWebDataServicesProvider *webDataReaderProvider)
|
||||
{
|
||||
if (!webDataReaderProvider) { return; }
|
||||
CWebDataServicesAware::setProvider(webDataReaderProvider);
|
||||
connectSwiftDatabaseSignals(
|
||||
this,
|
||||
std::bind(&CDbAirlineIcaoSelectorComponent::ps_codesRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
|
||||
);
|
||||
int c = this->getAirlineIcaoCodesCount();
|
||||
if (c > 0)
|
||||
{
|
||||
this->ps_codesRead(CDbFlags::AirlineIcaoEntity, CDbFlags::ReadFinished, c);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::setAirlineIcao(const CAirlineIcaoCode &icao)
|
||||
{
|
||||
QString icaoStr(icao.getVDesignator());
|
||||
this->ui->le_Airline->setText(icaoStr);
|
||||
ui->lbl_Description->setText(icao.getName());
|
||||
if (icao != m_currentIcao)
|
||||
{
|
||||
m_currentIcao = icao;
|
||||
emit changedAirlineIcao(icao);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::setAirlineIcao(int key)
|
||||
{
|
||||
CAirlineIcaoCode icao(getAirlineIcaoCodeForDbKey(key));
|
||||
ui->lbl_Description->setText("");
|
||||
if (icao.hasCompleteData())
|
||||
{
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
}
|
||||
|
||||
CAirlineIcaoCode CDbAirlineIcaoSelectorComponent::getAirlineIcao() const
|
||||
{
|
||||
int key = CDatastoreUtility::extractIntegerKey(this->ui->le_Airline->text());
|
||||
if (key < 0) { return CAirlineIcaoCode(); }
|
||||
CAirlineIcaoCode icao(getAirlineIcaoCodeForDbKey(key));
|
||||
return icao;
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::setReadOnly(bool readOnly)
|
||||
{
|
||||
this->ui->le_Airline->setReadOnly(readOnly);
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::withIcaoDescription(bool description)
|
||||
{
|
||||
this->ui->lbl_Description->setVisible(description);
|
||||
}
|
||||
|
||||
bool CDbAirlineIcaoSelectorComponent::isSet() const
|
||||
{
|
||||
return this->getAirlineIcao().hasCompleteData();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::clear()
|
||||
{
|
||||
this->ui->le_Airline->clear();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
if (!event) { return; }
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
CVariant valueVariant(toCVariant(event->mimeData()));
|
||||
if (valueVariant.isValid())
|
||||
{
|
||||
if (valueVariant.canConvert<CAirlineIcaoCode>())
|
||||
{
|
||||
CAirlineIcaoCode icao(valueVariant.value<CAirlineIcaoCode>());
|
||||
if (!icao.hasValidDbKey()) { return; }
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
else if (valueVariant.canConvert<CAirlineIcaoCodeList>())
|
||||
{
|
||||
CAirlineIcaoCodeList icaos(valueVariant.value<CAirlineIcaoCodeList>());
|
||||
if (icaos.isEmpty()) { return; }
|
||||
this->setAirlineIcao(icaos.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::ps_codesRead(CDbFlags::Entity entity, CDbFlags::ReadState readState, int count)
|
||||
{
|
||||
if (!hasProvider()) { return; }
|
||||
if (entity.testFlag(CDbFlags::AirlineIcaoEntity) && readState == CDbFlags::ReadFinished)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
QCompleter *c = new QCompleter(this->getAirlineIcaoCodes().toCompleterStrings(), this);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->setMaxVisibleItems(10);
|
||||
this->connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &CDbAirlineIcaoSelectorComponent::ps_completerActivated);
|
||||
|
||||
this->ui->le_Airline->setCompleter(c);
|
||||
m_completerIcaoDescription.reset(c); // deletes any old completer
|
||||
this->setReadOnly(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_completerIcaoDescription.reset(nullptr);
|
||||
this->setReadOnly(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::ps_dataChanged()
|
||||
{
|
||||
if (!hasProvider()) { return; }
|
||||
QString s(this->ui->le_Airline->text());
|
||||
if (s.isEmpty()) { return; }
|
||||
int dbKey = CDatastoreUtility::extractIntegerKey(s);
|
||||
if (dbKey >= 0)
|
||||
{
|
||||
CAirlineIcaoCode icao(getAirlineIcaoCodeForDbKey(dbKey));
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
else
|
||||
{
|
||||
// second choice, first object found by designator
|
||||
CAirlineIcaoCode icao(getAirlineIcaoCodeForDesignator(s));
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::ps_completerActivated(const QString &icaoString)
|
||||
{
|
||||
int dbKey = CDatastoreUtility::extractIntegerKey(icaoString);
|
||||
if (dbKey < 0) { return; }
|
||||
this->setAirlineIcao(dbKey);
|
||||
}
|
||||
|
||||
}// class
|
||||
} // ns
|
||||
105
src/blackgui/components/dbairlineicaoselectorcomponent.h
Normal file
105
src/blackgui/components/dbairlineicaoselectorcomponent.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_DBAIRLINEICAOSELECTORCOMPONENT_H
|
||||
#define BLACKGUI_DBAIRLINEICAOSELECTORCOMPONENT_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackgui/dropbase.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
#include <QCompleter>
|
||||
|
||||
namespace Ui { class CDbAirlineIcaoSelectorComponent; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
/*!
|
||||
* Distributor selector
|
||||
*/
|
||||
class BLACKGUI_EXPORT CDbAirlineIcaoSelectorComponent :
|
||||
public QFrame,
|
||||
public BlackMisc::Network::CWebDataServicesAware,
|
||||
public BlackGui::CDropBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CDbAirlineIcaoSelectorComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CDbAirlineIcaoSelectorComponent();
|
||||
|
||||
//! \copydoc CWebDataReaderAware::setProvider
|
||||
virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *webDataReaderProvider) override;
|
||||
|
||||
//! Current airline ICAO
|
||||
void setAirlineIcao(const BlackMisc::Aviation::CAirlineIcaoCode &icao);
|
||||
|
||||
//! Current airline ICAO
|
||||
void setAirlineIcao(int key);
|
||||
|
||||
//! Distributor
|
||||
BlackMisc::Aviation::CAirlineIcaoCode getAirlineIcao() const;
|
||||
|
||||
//! Read only
|
||||
void setReadOnly(bool readOnly);
|
||||
|
||||
//! Display distributor description
|
||||
void withIcaoDescription(bool description);
|
||||
|
||||
//! Set with valid Distributor
|
||||
bool isSet() const;
|
||||
|
||||
//! Clear selection
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
//! ICAO was changed
|
||||
void changedAirlineIcao(const BlackMisc::Aviation::CAirlineIcaoCode &icao);
|
||||
|
||||
protected:
|
||||
//! \copydoc QWidget::dragEnterEvent
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
||||
//! \copydoc QWidget::dragMoveEvent
|
||||
virtual void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
|
||||
//! \copydoc QWidget::dragLeaveEvent
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
|
||||
//! \copydoc QWidget::dropEvent
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private slots:
|
||||
//! Distributors have been read
|
||||
void ps_codesRead(BlackMisc::Network::CDbFlags::Entity entity, BlackMisc::Network::CDbFlags::ReadState readState, int count);
|
||||
|
||||
//! Data have been changed
|
||||
void ps_dataChanged();
|
||||
|
||||
//! Data have been changed
|
||||
void ps_completerActivated(const QString &icaoString);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbAirlineIcaoSelectorComponent> ui;
|
||||
QScopedPointer<QCompleter> m_completerIcaoDescription;
|
||||
QList<QMetaObject::Connection> m_signals;
|
||||
BlackMisc::Aviation::CAirlineIcaoCode m_currentIcao;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
62
src/blackgui/components/dbairlineicaoselectorcomponent.ui
Normal file
62
src/blackgui/components/dbairlineicaoselectorcomponent.ui
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDbAirlineIcaoSelectorComponent</class>
|
||||
<widget class="QFrame" name="CDbAirlineIcaoSelectorComponent">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>189</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gl_AirlineIcaoSelectorComponent">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="le_Airline">
|
||||
<property name="placeholderText">
|
||||
<string>ICAO</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="lbl_Description">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user