From d1e5566579ff8481e2d7baeb85180945877d00ad Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 24 Dec 2016 23:36:06 +0100 Subject: [PATCH] refs #844, settings for ATC stations (value object + trait) --- src/blackgui/registermetadata.cpp | 2 + src/blackgui/settings/atcstationssettings.cpp | 56 ++++++++++++++ src/blackgui/settings/atcstationssettings.h | 74 +++++++++++++++++++ src/blackmisc/propertyindex.h | 5 +- 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/blackgui/settings/atcstationssettings.cpp create mode 100644 src/blackgui/settings/atcstationssettings.h diff --git a/src/blackgui/registermetadata.cpp b/src/blackgui/registermetadata.cpp index 4a054a3cb..9d5f69dee 100644 --- a/src/blackgui/registermetadata.cpp +++ b/src/blackgui/registermetadata.cpp @@ -13,6 +13,7 @@ #include "blackgui/settings/viewupdatesettings.h" #include "blackgui/settings/guisettings.h" #include "blackgui/settings/textmessagesettings.h" +#include "blackgui/settings/atcstationssettings.h" #include "blackgui/components/registermetadatacomponents.h" namespace BlackGui @@ -24,6 +25,7 @@ namespace BlackGui BlackGui::Settings::CViewUpdateSettings::registerMetadata(); BlackGui::Settings::CGeneralGuiSettings::registerMetadata(); BlackGui::Settings::CTextMessageSettings::registerMetadata(); + BlackGui::Settings::CAtcStationsSettings::registerMetadata(); BlackGui::Components::registerMetadata(); } } diff --git a/src/blackgui/settings/atcstationssettings.cpp b/src/blackgui/settings/atcstationssettings.cpp new file mode 100644 index 000000000..fa362745e --- /dev/null +++ b/src/blackgui/settings/atcstationssettings.cpp @@ -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(); + 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(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexInRangeOnly: + this->setShowOnlyInRange(variant.toBool()); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + } // ns +} // ns diff --git a/src/blackgui/settings/atcstationssettings.h b/src/blackgui/settings/atcstationssettings.h new file mode 100644 index 000000000..6abce6230 --- /dev/null +++ b/src/blackgui/settings/atcstationssettings.h @@ -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 + +namespace BlackGui +{ + namespace Settings + { + //! How to display ATC stations + class BLACKGUI_EXPORT CAtcStationsSettings : + public BlackMisc::CValueObject + { + 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 + { + //! \copydoc BlackCore::TSettingTrait::key + static const char *key() { return "atcstations"; } + }; + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackGui::Settings::CAtcStationsSettings) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif // guard diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 2a861b0be..2825fb756 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -144,8 +144,9 @@ namespace BlackMisc GlobalIndexCViewUpdateSettings = 14500, GlobalIndexCGeneralGuiSettings = 14600, GlobalIndexCTextMessageSettings = 14700, - GlobalIndexCInterpolatioRenderingSetup = 15000, - GlobalIndexCInterpolationHints = 15100, + GlobalIndexCAtcStationsSettings = 14800, + GlobalIndexCInterpolatioRenderingSetup = 16000, + GlobalIndexCInterpolationHints = 16100, GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers };