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  CGeneralGuiSettings::CGeneralGuiSettings() {}
15 
16  void CGeneralGuiSettings::setWidgetStyle(const QString &widgetStyle)
17  {
18  if (this->m_widgetStyle == widgetStyle) { return; }
19  const auto availableStyles = QStyleFactory::keys();
20  if (availableStyles.contains(widgetStyle)) { m_widgetStyle = widgetStyle; }
21  }
22 
23  bool CGeneralGuiSettings::isDifferentValidWidgetStyle(const QString &style) const
24  {
25  if (!QStyleFactory::keys().contains(style)) { return false; }
26  return style != this->m_widgetStyle;
27  }
28 
29  QAbstractItemView::SelectionMode CGeneralGuiSettings::getPreferredSelection() const
30  {
31  return static_cast<QAbstractItemView::SelectionMode>(m_preferredSelection);
32  }
33 
34  void CGeneralGuiSettings::setPreferredSelection(QAbstractItemView::SelectionMode selection)
35  {
36  this->m_preferredSelection = static_cast<int>(selection);
37  }
38 
39  QString CGeneralGuiSettings::convertToQString(bool i18n) const
40  {
41  Q_UNUSED(i18n);
42  return QStringLiteral("Widget style: %1").arg(this->m_widgetStyle);
43  }
44 
45  QVariant CGeneralGuiSettings::propertyByIndex(swift::misc::CPropertyIndexRef index) const
46  {
47  if (index.isMyself()) { return QVariant::fromValue(*this); }
48  const ColumnIndex i = index.frontCasted<ColumnIndex>();
49  switch (i)
50  {
51  case IndexWidgetStyle: return QVariant::fromValue(this->m_widgetStyle);
52  case IndexPreferredSelection: return QVariant::fromValue(this->m_preferredSelection);
53  default: return CValueObject::propertyByIndex(index);
54  }
55  }
56 
57  void CGeneralGuiSettings::setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
58  {
59  if (index.isMyself())
60  {
61  (*this) = variant.value<CGeneralGuiSettings>();
62  return;
63  }
64  const ColumnIndex i = index.frontCasted<ColumnIndex>();
65  switch (i)
66  {
67  case IndexWidgetStyle: this->setWidgetStyle(variant.toString()); break;
68  case IndexPreferredSelection: this->m_preferredSelection = variant.toInt(); break;
69  default: CValueObject::setPropertyByIndex(index, variant); break;
70  }
71  }
72 } // 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:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
Free functions in swift::misc.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67