6 #ifndef SWIFT_MISC_MIXIN_MIXININDEX_H
7 #define SWIFT_MISC_MIXIN_MIXININDEX_H
11 #include <QDBusArgument>
27 class CPropertyIndexList;
28 class CPropertyIndexVariantMap;
38 template <
class Derived>
53 bool skipEqualValues =
false);
68 const Derived *derived()
const;
72 QVariant myself()
const;
74 void myself(
const QVariant &variant);
79 void baseSetPropertyByIndex(T *base,
const QVariant &var,
CPropertyIndexRef index);
85 template <
class Derived>
88 return static_cast<const Derived *
>(
this);
91 template <
class Derived>
92 Derived *Index<Derived>::derived()
94 return static_cast<Derived *
>(
this);
97 template <
class Derived>
99 QVariant Index<Derived>::myself()
const
101 if constexpr (std::is_default_constructible_v<T>) {
return QVariant::fromValue(*derived()); }
104 qFatal(
"isMyself should have been handled before reaching here");
109 template <
class Derived>
110 template <
typename T>
111 void Index<Derived>::myself(
const QVariant &variant)
113 if constexpr (std::is_default_constructible_v<T>) { *derived() = variant.value<T>(); }
114 else { qFatal(
"isMyself should have been handled before reaching here"); }
117 template <
class Derived>
118 template <
typename T>
119 QVariant Index<Derived>::basePropertyByIndex(
const T *base, CPropertyIndexRef index)
const
121 return base->propertyByIndex(index);
124 template <
class Derived>
125 template <
typename T>
126 void Index<Derived>::baseSetPropertyByIndex(T *base,
const QVariant &var, CPropertyIndexRef index)
128 base->setPropertyByIndex(index, var);
131 template <
class Derived>
132 QVariant Index<Derived>::basePropertyByIndex(
const void *, CPropertyIndexRef)
const
135 qFatal(
"Property by index not found");
139 template <
class Derived>
140 void Index<Derived>::baseSetPropertyByIndex(
void *,
const QVariant &, CPropertyIndexRef)
143 qFatal(
"Property by index not found");
151 #define SWIFT_MISC_DECLARE_USING_MIXIN_INDEX(DERIVED) \
152 using ::swift::misc::mixin::Index<DERIVED>::apply; \
153 using ::swift::misc::mixin::Index<DERIVED>::setPropertyByIndex; \
154 using ::swift::misc::mixin::Index<DERIVED>::propertyByIndex; \
155 using ::swift::misc::mixin::Index<DERIVED>::comparePropertyByIndex; \
156 using ::swift::misc::mixin::Index<DERIVED>::equalsPropertyByIndex;
159 template <
class Derived>
162 if (index.
isMyself()) { myself<Derived>(variant); }
166 template <
class Derived>
169 if (index.
isMyself()) {
return myself<Derived>(); }
175 case IndexString:
return QVariant(derived()->toQString());
180 template <
class Derived>
183 return derived()->propertyByIndex(index) == compareValue;
186 template <
class Derived>
189 if (
this == &compareValue) {
return 0; }
193 return derived()->toQString().compare(compareValue.toQString());
206 return derived()->toQString().compare(compareValue.toQString());
static QVariant toVariant(IconIndex icon)
Variant containing CIcon.
static QVariant toVariantPixmap(IconIndex icon)
Variant containing QPixmap.
Value object encapsulating a list of property indexes.
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.
Specialized value object compliant map for variants, based on indexes.
CRTP class template from which a derived class can inherit property indexing functions.
ColumnIndex
Base class enums.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
CPropertyIndexList apply(const CPropertyIndexVariantMap &indexMap, bool skipEqualValues=false)
Update by variant map.
bool equalsPropertyByIndex(const QVariant &compareValue, CPropertyIndexRef index) const
Is given variant equal to value of property index?
Free functions in swift::misc.
typename TIndexBaseOf< T >::type TIndexBaseOfT
Alias for typename TIndexBaseOf<T>::type.