mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
refs #452 aircraft ICAO selector GUI widget
This commit is contained in:
committed by
Mathew Sutcliffe
parent
513eb07a13
commit
3bbaecb0d8
185
src/blackgui/components/dbaircrafticaoselectorcomponent.cpp
Normal file
185
src/blackgui/components/dbaircrafticaoselectorcomponent.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
/* 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 "dbaircrafticaoselectorcomponent.h"
|
||||
#include "ui_dbaircrafticaoselectorcomponent.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
|
||||
{
|
||||
CDbAircraftIcaoSelectorComponent::CDbAircraftIcaoSelectorComponent(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CDbAircraftIcaoSelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setAcceptDrops(true);
|
||||
this->setAcceptedMetaTypeIds({qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>()});
|
||||
|
||||
connect(ui->le_Aircraft, &QLineEdit::returnPressed, this, &CDbAircraftIcaoSelectorComponent::ps_dataChanged);
|
||||
}
|
||||
|
||||
CDbAircraftIcaoSelectorComponent::~CDbAircraftIcaoSelectorComponent()
|
||||
{ }
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setProvider(Network::IWebDataServicesProvider *webDataReaderProvider)
|
||||
{
|
||||
if (!webDataReaderProvider) { return; }
|
||||
CWebDataServicesAware::setProvider(webDataReaderProvider);
|
||||
connectSwiftDatabaseSignals(
|
||||
this,
|
||||
std::bind(&CDbAircraftIcaoSelectorComponent::ps_codesRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
|
||||
);
|
||||
int c = this->getAircraftIcaoCodesCount();
|
||||
if (c > 0)
|
||||
{
|
||||
this->ps_codesRead(CDbFlags::AircraftIcaoEntity, CDbFlags::ReadFinished, c);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setAircraftIcao(const CAircraftIcaoCode &icao)
|
||||
{
|
||||
QString icaoStr(icao.getDesignator());
|
||||
this->ui->le_Aircraft->setText(icaoStr);
|
||||
ui->lbl_Description->setText(icao.getManufacturer());
|
||||
if (icao != m_currentIcao)
|
||||
{
|
||||
m_currentIcao = icao;
|
||||
emit changedAircraftIcao(icao);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setAircraftIcao(int key)
|
||||
{
|
||||
CAircraftIcaoCode icao(getAircraftIcaoCodeForDbKey(key));
|
||||
ui->lbl_Description->setText("");
|
||||
if (icao.hasCompleteData())
|
||||
{
|
||||
this->setAircraftIcao(icao);
|
||||
}
|
||||
}
|
||||
|
||||
CAircraftIcaoCode CDbAircraftIcaoSelectorComponent::getAircraftIcao() const
|
||||
{
|
||||
int key = CDatastoreUtility::extractIntegerKey(this->ui->le_Aircraft->text());
|
||||
if (key < 0) { return CAircraftIcaoCode(); }
|
||||
CAircraftIcaoCode icao(getAircraftIcaoCodeForDbKey(key));
|
||||
return icao;
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setReadOnly(bool readOnly)
|
||||
{
|
||||
this->ui->le_Aircraft->setReadOnly(readOnly);
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::withIcaoDescription(bool description)
|
||||
{
|
||||
this->ui->lbl_Description->setVisible(description);
|
||||
}
|
||||
|
||||
bool CDbAircraftIcaoSelectorComponent::isSet() const
|
||||
{
|
||||
return this->getAircraftIcao().hasCompleteData();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::clear()
|
||||
{
|
||||
this->ui->le_Aircraft->clear();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
if (!event) { return; }
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
CVariant valueVariant(toCVariant(event->mimeData()));
|
||||
if (valueVariant.isValid())
|
||||
{
|
||||
if (valueVariant.canConvert<CAircraftIcaoCode>())
|
||||
{
|
||||
CAircraftIcaoCode icao(valueVariant.value<CAircraftIcaoCode>());
|
||||
if (!icao.hasValidDbKey()) { return; }
|
||||
this->setAircraftIcao(icao);
|
||||
}
|
||||
else if (valueVariant.canConvert<CAircraftIcaoCodeList>())
|
||||
{
|
||||
CAircraftIcaoCodeList icaos(valueVariant.value<CAircraftIcaoCodeList>());
|
||||
if (icaos.isEmpty()) { return; }
|
||||
this->setAircraftIcao(icaos.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_codesRead(CDbFlags::Entity entity, CDbFlags::ReadState readState, int count)
|
||||
{
|
||||
if (!hasProvider()) { return; }
|
||||
if (entity.testFlag(CDbFlags::AircraftIcaoEntity) && readState == CDbFlags::ReadFinished)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
QCompleter *c = new QCompleter(this->getAircraftIcaoCodes().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, &CDbAircraftIcaoSelectorComponent::ps_completerActivated);
|
||||
|
||||
this->ui->le_Aircraft->setCompleter(c);
|
||||
m_completerIcaoDescription.reset(c); // deletes any old completer
|
||||
this->setReadOnly(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_completerIcaoDescription.reset(nullptr);
|
||||
this->setReadOnly(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_dataChanged()
|
||||
{
|
||||
if (!hasProvider()) { return; }
|
||||
int key = CDatastoreUtility::extractIntegerKey(this->ui->le_Aircraft->text());
|
||||
CAircraftIcaoCode icao(getAircraftIcaoCodeForDbKey(key));
|
||||
this->setAircraftIcao(icao);
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_completerActivated(const QString &icaoString)
|
||||
{
|
||||
int dbKey = CDatastoreUtility::extractIntegerKey(icaoString);
|
||||
if (dbKey < 0) { return; }
|
||||
this->setAircraftIcao(dbKey);
|
||||
}
|
||||
|
||||
}// class
|
||||
} // ns
|
||||
104
src/blackgui/components/dbaircrafticaoselectorcomponent.h
Normal file
104
src/blackgui/components/dbaircrafticaoselectorcomponent.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* 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_DBAIRCRAFTICAOSELECTORCOMPONENT_H
|
||||
#define BLACKGUI_DBAIRCRAFTICAOSELECTORCOMPONENT_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackgui/dropbase.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
#include <QCompleter>
|
||||
|
||||
namespace Ui { class CDbAircraftIcaoSelectorComponent; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
/*!
|
||||
* Distributor selector
|
||||
*/
|
||||
class BLACKGUI_EXPORT CDbAircraftIcaoSelectorComponent :
|
||||
public QFrame,
|
||||
public BlackMisc::Network::CWebDataServicesAware,
|
||||
public BlackGui::CDropBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CDbAircraftIcaoSelectorComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CDbAircraftIcaoSelectorComponent();
|
||||
|
||||
//! \copydoc CWebDataReaderAware::setProvider
|
||||
virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *webDataReaderProvider) override;
|
||||
|
||||
//! Current aircraft ICAO
|
||||
void setAircraftIcao(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
|
||||
|
||||
//! Current aircraft ICAO
|
||||
void setAircraftIcao(int key);
|
||||
|
||||
//! Distributor
|
||||
BlackMisc::Aviation::CAircraftIcaoCode getAircraftIcao() 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 changedAircraftIcao(const BlackMisc::Aviation::CAircraftIcaoCode &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::CDbAircraftIcaoSelectorComponent> ui;
|
||||
QScopedPointer<QCompleter> m_completerIcaoDescription;
|
||||
BlackMisc::Aviation::CAircraftIcaoCode m_currentIcao;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
62
src/blackgui/components/dbaircrafticaoselectorcomponent.ui
Normal file
62
src/blackgui/components/dbaircrafticaoselectorcomponent.ui
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDbAircraftIcaoSelectorComponent</class>
|
||||
<widget class="QFrame" name="CDbAircraftIcaoSelectorComponent">
|
||||
<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_AircraftIcaoSelectorComponent">
|
||||
<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_Aircraft">
|
||||
<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