swift
swiftpluginsettings.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "misc/stringutils.h"
7 
8 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation::settings, CSwiftPluginSettings)
9 
10 namespace swift::misc::simulation::settings
11 {
13 
15  {
16  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
17  m_emulatedSimulator = simulator;
18  }
19 
21  {
22  Q_UNUSED(i18n);
23  static const QString ms("Emulated simulator: %1, default model: '%2', log.function calls: %3");
24  return ms.arg(this->m_emulatedSimulator.toQString(), m_defaultModel.getModelStringAndDbKey(),
25  boolToYesNo(m_logFunctionCalls));
26  }
27 
29  {
30  if (index.isMyself()) { return QVariant::fromValue(*this); }
31  const ColumnIndex i = index.frontCasted<ColumnIndex>();
32  switch (i)
33  {
34  case IndexEmulatedSimulator: return this->m_emulatedSimulator.propertyByIndex(index.copyFrontRemoved());
35  case IndexOwnModel: return QVariant::fromValue(m_ownModel);
36  case IndexDefaultModel: return QVariant::fromValue(m_defaultModel);
37  case IndexLoggingFunctionCalls: return QVariant::fromValue(m_logFunctionCalls);
38  default: return CValueObject::propertyByIndex(index);
39  }
40  }
41 
43  {
44  if (index.isMyself())
45  {
46  (*this) = variant.value<CSwiftPluginSettings>();
47  return;
48  }
49  const ColumnIndex i = index.frontCasted<ColumnIndex>();
50  switch (i)
51  {
52  case IndexEmulatedSimulator:
53  this->m_emulatedSimulator.setPropertyByIndex(index.copyFrontRemoved(), variant);
54  break;
55  case IndexOwnModel: this->m_ownModel.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
56  case IndexDefaultModel: this->m_defaultModel.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
57  case IndexLoggingFunctionCalls: this->m_logFunctionCalls = variant.toBool(); break;
58  default: CValueObject::setPropertyByIndex(index, variant); break;
59  }
60  }
61 } // namespace swift::misc::simulation::settings
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
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
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:74
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getModelStringAndDbKey() const
Model string and DB key (if available)
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
bool isSingleSimulator() const
Single simulator selected.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString convertToQString(bool i18n=false) const
Cast as QString.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setEmulatedSimulator(const CSimulatorInfo &simulator)
Emulated simualtor.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
QString arg(Args &&... args) const const
QVariant fromValue(T &&value)
bool toBool() 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