mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T417, SimBrief data class
This commit is contained in:
committed by
Mat Sutcliffe
parent
74be3fa8c2
commit
3f66adfb94
@@ -41,6 +41,7 @@
|
||||
#include "blackmisc/aviation/selcal.h"
|
||||
#include "blackmisc/aviation/flightplan.h"
|
||||
#include "blackmisc/aviation/flightplanlist.h"
|
||||
#include "blackmisc/aviation/simbriefdata.h"
|
||||
#include "blackmisc/aviation/aircraftengine.h"
|
||||
#include "blackmisc/aviation/aircraftenginelist.h"
|
||||
#include "blackmisc/aviation/aircraftlights.h"
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace BlackMisc
|
||||
CComSystem::registerMetadata();
|
||||
CFlightPlan::registerMetadata();
|
||||
CFlightPlanList::registerMetadata();
|
||||
CSimBriefData::registerMetadata();
|
||||
CFlightPlanRemarks::registerMetadata();
|
||||
CHeading::registerMetadata();
|
||||
CInformationMessage::registerMetadata();
|
||||
|
||||
69
src/blackmisc/aviation/simbriefdata.cpp
Normal file
69
src/blackmisc/aviation/simbriefdata.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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. 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 "simbriefdata.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
const CLogCategoryList &CSimBriefData::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats { CLogCategory::flightPlan() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
CSimBriefData::CSimBriefData() : m_url("https://www.simbrief.com/api/xml.fetcher.php")
|
||||
{ }
|
||||
|
||||
CSimBriefData::CSimBriefData(const QString &url, const QString &username) :
|
||||
m_url(url), m_username(username)
|
||||
{ }
|
||||
|
||||
CUrl CSimBriefData::getUrlAndUsername() const
|
||||
{
|
||||
CUrl url(this->getUrl());
|
||||
if (!m_username.isEmpty()) { url.setQuery("username=" % m_username); }
|
||||
return url;
|
||||
}
|
||||
|
||||
CVariant CSimBriefData::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexUrl: return CVariant::from(m_url);
|
||||
case IndexUsername: return CVariant::from(m_username);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSimBriefData::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSimBriefData>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexUrl: m_url = variant.toQString(); break;
|
||||
case IndexUsername: m_username = variant.toQString(); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CSimBriefData::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return m_username % " " % m_url;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
100
src/blackmisc/aviation/simbriefdata.h
Normal file
100
src/blackmisc/aviation/simbriefdata.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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. 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 BLACKMISC_AVIATION_SIMBRIEFDATA_H
|
||||
#define BLACKMISC_AVIATION_SIMBRIEFDATA_H
|
||||
|
||||
#include "blackmisc/network/url.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object for a flight plan
|
||||
class BLACKMISC_EXPORT CSimBriefData : public CValueObject<CSimBriefData>
|
||||
{
|
||||
public:
|
||||
//! The log. catgeories
|
||||
static const CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Default constructor
|
||||
CSimBriefData();
|
||||
|
||||
//! Constructor
|
||||
CSimBriefData(const QString &url, const QString &username);
|
||||
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexUsername = CPropertyIndex::GlobalIndexCSimBriefData,
|
||||
IndexUrl
|
||||
};
|
||||
|
||||
//! Get username
|
||||
const QString &getUsername() const { return m_username; }
|
||||
|
||||
//! Set username
|
||||
void setUsername(const QString &un) { m_username = un; }
|
||||
|
||||
//! Get URL
|
||||
const QString &getUrl() const { return m_url; }
|
||||
|
||||
//! Get URL plus username
|
||||
Network::CUrl getUrlAndUsername() const;
|
||||
|
||||
//! Set URL
|
||||
void setUrl(const QString &url) { m_url = url; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString()
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
QString m_username;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSimBriefData,
|
||||
BLACK_METAMEMBER(url),
|
||||
BLACK_METAMEMBER(username)
|
||||
);
|
||||
};
|
||||
|
||||
namespace Data
|
||||
{
|
||||
//! Trait for global setup data
|
||||
struct TSimBriefData : public BlackMisc::TDataTrait<CSimBriefData>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "simbriefdata"; }
|
||||
|
||||
//! First load is synchronous
|
||||
static constexpr bool isPinned() { return true; }
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CSimBriefData)
|
||||
|
||||
#endif // guard
|
||||
@@ -102,9 +102,10 @@ namespace BlackMisc
|
||||
GlobalIndexCAircraftLights = 2700,
|
||||
GlobalIndexCLivery = 2800,
|
||||
GlobalIndexCFlightPlan = 2900,
|
||||
GlobalIndexCComSystem = 3000,
|
||||
GlobalIndexCModulator = 3100,
|
||||
GlobalIndexCTransponder = 3200,
|
||||
GlobalIndexCSimBriefData = 3000,
|
||||
GlobalIndexCComSystem = 3100,
|
||||
GlobalIndexCModulator = 3200,
|
||||
GlobalIndexCTransponder = 3300,
|
||||
GlobalIndexCAircraftCategory = 3500,
|
||||
GlobalIndexCAircraftIcaoCode = 3600,
|
||||
GlobalIndexCAirlineIcaoCode = 3700,
|
||||
|
||||
Reference in New Issue
Block a user