diff --git a/src/blackgui/registermetadata.cpp b/src/blackgui/registermetadata.cpp index 2cf84bba2..a0c992ea5 100644 --- a/src/blackgui/registermetadata.cpp +++ b/src/blackgui/registermetadata.cpp @@ -11,6 +11,7 @@ #include "blackgui/settings/dockwidgetsettings.h" #include "blackgui/settings/navigatorsettings.h" #include "blackgui/settings/viewupdatesettings.h" +#include "blackgui/settings/guisettings.h" #include "blackgui/components/registermetadatacomponents.h" namespace BlackGui @@ -20,6 +21,7 @@ namespace BlackGui BlackGui::Settings::CDockWidgetSettings::registerMetadata(); BlackGui::Settings::CNavigatorSettings::registerMetadata(); BlackGui::Settings::CViewUpdateSettings::registerMetadata(); + BlackGui::Settings::CGeneralGuiSettings::registerMetadata(); BlackGui::Components::registerMetadata(); } } diff --git a/src/blackgui/settings/guisettings.cpp b/src/blackgui/settings/guisettings.cpp new file mode 100644 index 000000000..7f6c54f3c --- /dev/null +++ b/src/blackgui/settings/guisettings.cpp @@ -0,0 +1,88 @@ +/* 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 "guisettings.h" +#include + +using namespace BlackMisc; + +namespace BlackGui +{ + namespace Settings + { + CGeneralGuiSettings::CGeneralGuiSettings() + { } + + void CGeneralGuiSettings::setWidgetStyle(const QString &widgetStyle) + { + if (this->m_widgetStyle == widgetStyle) { return; } + const auto availableStyles = QStyleFactory::keys(); + if (availableStyles.contains(widgetStyle)) + { + m_widgetStyle = widgetStyle; + } + } + + bool CGeneralGuiSettings::isDifferentValidWidgetStyle(const QString &style) const + { + if (!QStyleFactory::keys().contains(style)) { return false; } + return style != this->m_widgetStyle; + } + + QAbstractItemView::SelectionMode CGeneralGuiSettings::getPreferredSelection() const + { + return static_cast(m_preferredSelection); + } + + void CGeneralGuiSettings::setPreferredSelection(QAbstractItemView::SelectionMode selection) + { + this->m_preferredSelection = static_cast(selection); + } + + QString CGeneralGuiSettings::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + static const QString s("Widget style: %1"); + return s.arg(this->m_widgetStyle); + } + + BlackMisc::CVariant CGeneralGuiSettings::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexWidgetStyle: + return CVariant::fromValue(this->m_widgetStyle); + case IndexPreferredSelection: + return CVariant::fromValue(this->m_preferredSelection); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CGeneralGuiSettings::setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexWidgetStyle: + this->setWidgetStyle(variant.toQString()); + break; + case IndexPreferredSelection: + this->m_preferredSelection = variant.toInt(); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + } // ns +} // ns diff --git a/src/blackgui/settings/guisettings.h b/src/blackgui/settings/guisettings.h index 84a5e72af..c00b97cd0 100644 --- a/src/blackgui/settings/guisettings.h +++ b/src/blackgui/settings/guisettings.h @@ -17,28 +17,80 @@ #include "blackmisc/simulation/aircraftmodel.h" #include +#include namespace BlackGui { namespace Settings { + //! General GUI settings + class BLACKGUI_EXPORT CGeneralGuiSettings : + public BlackMisc::CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexWidgetStyle = BlackMisc::CPropertyIndex::GlobalIndexCGeneralGuiSettings, + IndexPreferredSelection + }; + + //! Default constructor + CGeneralGuiSettings(); + + //! Widget style + const QString &getWidgetStyle() const { return m_widgetStyle; } + + //! Widget style + void setWidgetStyle(const QString &widgetStyle); + + //! Has changed widget style + bool isDifferentValidWidgetStyle(const QString &style) const; + + //! Preferred selection + QAbstractItemView::SelectionMode getPreferredSelection() const; + + //! Preferred selection + void setPreferredSelection(QAbstractItemView::SelectionMode selection); + + //! \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: + QString m_widgetStyle { "Fusion" }; + int m_preferredSelection = static_cast(QAbstractItemView::ExtendedSelection); + + BLACK_METACLASS( + CGeneralGuiSettings, + BLACK_METAMEMBER(widgetStyle), + BLACK_METAMEMBER(preferredSelection) + ); + }; + + //! General GUI settings + struct TGeneralGui : public BlackMisc::TSettingTrait + { + //! \copydoc BlackCore::TSettingTrait::key + static const char *key() { return "guigeneral"; } + }; + //! Settings for last manual entries of own aircraft mode struct TOwnAircraftModel : public BlackMisc::TSettingTrait { //! Key in data cache static const char *key() { return "guinownaircraftmodel"; } }; - - //! Widget Style - struct TWidgetStyle : public BlackMisc::TSettingTrait - { - //! \copydoc BlackCore::TSettingTrait::key - static const char *key() { return "application/widgetstyle"; } - - //! \copydoc BlackCore::TSettingTrait::defaultValue - static QString defaultValue() { return QStringLiteral("Fusion"); } - }; } // ns } // ns +Q_DECLARE_METATYPE(BlackGui::Settings::CGeneralGuiSettings) +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 534903722..e861e5817 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -141,6 +141,7 @@ namespace BlackMisc GlobalIndexCNavigatorSettings = 14300, GlobalIndexCSettingsReaders = 14400, GlobalIndexCViewUpdateSettings = 14500, + GlobalIndexCGeneralGuiSettings = 14600, GloablIndexInterpolatorSetup = 15000, GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers }; diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 198dcd1b2..d73ba8750 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -43,6 +43,7 @@ namespace BlackMisc CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); CSimulatorSettings::registerMetadata(); + CModelSettings::registerMetadata(); CSimulatorMessagesSettings::registerMetadata(); } } // ns