6#ifndef SWIFT_MISC_MIXIN_MIXININDEX_H
7#define SWIFT_MISC_MIXIN_MIXININDEX_H
11#include <QDBusArgument>
38 template <
class Derived>
53 bool skipEqualValues =
false);
68 const Derived *derived()
const;
74 void myself(
const QVariant &variant);
85 template <
class Derived>
86 const Derived *Index<Derived>::derived()
const
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>)
107 qFatal(
"isMyself should have been handled before reaching here");
112 template <
class Derived>
113 template <
typename T>
114 void Index<Derived>::myself(
const QVariant &variant)
116 if constexpr (std::is_default_constructible_v<T>)
118 *derived() = variant.
value<T>();
122 qFatal(
"isMyself should have been handled before reaching here");
126 template <
class Derived>
127 template <
typename T>
128 QVariant Index<Derived>::basePropertyByIndex(
const T *base, CPropertyIndexRef index)
const
130 return base->propertyByIndex(index);
133 template <
class Derived>
134 template <
typename T>
135 void Index<Derived>::baseSetPropertyByIndex(T *base,
const QVariant &var, CPropertyIndexRef index)
137 base->setPropertyByIndex(index, var);
140 template <
class Derived>
141 QVariant Index<Derived>::basePropertyByIndex(
const void *, CPropertyIndexRef)
const
144 qFatal(
"Property by index not found");
148 template <
class Derived>
149 void Index<Derived>::baseSetPropertyByIndex(
void *,
const QVariant &, CPropertyIndexRef)
152 qFatal(
"Property by index not found");
159#define SWIFT_MISC_DECLARE_USING_MIXIN_INDEX(DERIVED) \
160 using ::swift::misc::mixin::Index<DERIVED>::apply; \
161 using ::swift::misc::mixin::Index<DERIVED>::setPropertyByIndex; \
162 using ::swift::misc::mixin::Index<DERIVED>::propertyByIndex; \
163 using ::swift::misc::mixin::Index<DERIVED>::comparePropertyByIndex; \
164 using ::swift::misc::mixin::Index<DERIVED>::equalsPropertyByIndex;
166 template <
class Derived>
171 myself<Derived>(variant);
179 template <
class Derived>
184 return myself<Derived>();
191 case IndexString:
return QVariant(derived()->toQString());
196 template <
class Derived>
199 return derived()->propertyByIndex(index) == compareValue;
202 template <
class Derived>
205 if (
this == &compareValue)
212 return derived()->toQString().compare(compareValue.toQString());
225 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?
Mixin classes which implement common operations for value classes.
Free functions in swift::misc.
typename TIndexBaseOf< T >::type TIndexBaseOfT
Alias for typename TIndexBaseOf<T>::type.
QVariant fromValue(T &&value)