swift
guisettings.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "guisettings.h"
5 
6 #include <QStyleFactory>
7 
8 using namespace swift::misc;
9 
10 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::gui::settings, CGeneralGuiSettings)
11 
12 namespace swift::gui::settings
13 {
14  void CGeneralGuiSettings::setWidgetStyle(const QString &widgetStyle)
15  {
16  if (this->m_widgetStyle == widgetStyle) { return; }
17  const auto availableStyles = QStyleFactory::keys();
18  if (availableStyles.contains(widgetStyle)) { m_widgetStyle = widgetStyle; }
19  }
20 
21  bool CGeneralGuiSettings::isDifferentValidWidgetStyle(const QString &style) const
22  {
23  if (!QStyleFactory::keys().contains(style)) { return false; }
24  return style != this->m_widgetStyle;
25  }
26 
27  QAbstractItemView::SelectionMode CGeneralGuiSettings::getPreferredSelection() const
28  {
29  return static_cast<QAbstractItemView::SelectionMode>(m_preferredSelection);
30  }
31 
32  void CGeneralGuiSettings::setPreferredSelection(QAbstractItemView::SelectionMode selection)
33  {
34  this->m_preferredSelection = static_cast<int>(selection);
35  }
36 
37  QString CGeneralGuiSettings::convertToQString(bool i18n) const
38  {
39  Q_UNUSED(i18n);
40  return QStringLiteral("Widget style: %1").arg(this->m_widgetStyle);
41  }
42 
43  QVariant CGeneralGuiSettings::propertyByIndex(swift::misc::CPropertyIndexRef index) const
44  {
45  if (index.isMyself()) { return QVariant::fromValue(*this); }
46  const auto i = index.frontCasted<ColumnIndex>();
47  switch (i)
48  {
49  case IndexWidgetStyle: return QVariant::fromValue(this->m_widgetStyle);
50  case IndexPreferredSelection: return QVariant::fromValue(this->m_preferredSelection);
51  default: return CValueObject::propertyByIndex(index);
52  }
53  }
54 
55  void CGeneralGuiSettings::setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
56  {
57  if (index.isMyself())
58  {
59  (*this) = variant.value<CGeneralGuiSettings>();
60  return;
61  }
62  const auto i = index.frontCasted<ColumnIndex>();
63  switch (i)
64  {
65  case IndexWidgetStyle: this->setWidgetStyle(variant.toString()); break;
66  case IndexPreferredSelection: this->m_preferredSelection = variant.toInt(); break;
67  default: CValueObject::setPropertyByIndex(index, variant); break;
68  }
69  }
70 } // namespace swift::gui::settings
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:158
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:165
Free functions in swift::misc.
QStringList keys()
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67