mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:28:15 +08:00
refs #844, settings for ATC stations (value object + trait)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a7469d2959
commit
d1e5566579
56
src/blackgui/settings/atcstationssettings.cpp
Normal file
56
src/blackgui/settings/atcstationssettings.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 "atcstationssettings.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CAtcStationsSettings::CAtcStationsSettings()
|
||||
{ }
|
||||
|
||||
QString CAtcStationsSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
static const QString s("In range only: %1");
|
||||
return s.arg(
|
||||
boolToOnOff(this->showOnlyInRange())
|
||||
);
|
||||
}
|
||||
|
||||
CVariant CAtcStationsSettings::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexInRangeOnly: return CVariant::fromValue(m_showOnlyInRange);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationsSettings::setPropertyByIndex(const CPropertyIndex &index, const BlackMisc::CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAtcStationsSettings>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexInRangeOnly:
|
||||
this->setShowOnlyInRange(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
74
src/blackgui/settings/atcstationssettings.h
Normal file
74
src/blackgui/settings/atcstationssettings.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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_SETTINGS_ATCSTATIONSSETTINGS_H
|
||||
#define BLACKGUI_SETTINGS_ATCSTATIONSSETTINGS_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include <QString>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! How to display ATC stations
|
||||
class BLACKGUI_EXPORT CAtcStationsSettings :
|
||||
public BlackMisc::CValueObject<CAtcStationsSettings>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexInRangeOnly = BlackMisc::CPropertyIndex::GlobalIndexCAtcStationsSettings,
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CAtcStationsSettings();
|
||||
|
||||
//! Show in range ATC stations only
|
||||
bool showOnlyInRange() const { return m_showOnlyInRange; }
|
||||
|
||||
//! Show in range ATC stations only?
|
||||
void setShowOnlyInRange(bool onlyInRange) { m_showOnlyInRange = onlyInRange; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
bool m_showOnlyInRange = true;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CAtcStationsSettings,
|
||||
BLACK_METAMEMBER(showOnlyInRange)
|
||||
);
|
||||
};
|
||||
|
||||
//! ATC stations settings
|
||||
struct TAtcStationsSettings : public BlackMisc::TSettingTrait<CAtcStationsSettings>
|
||||
{
|
||||
//! \copydoc BlackCore::TSettingTrait::key
|
||||
static const char *key() { return "atcstations"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CAtcStationsSettings)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CAtcStationsSettings>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CAtcStationsSettings>)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user