21 #include <QQmlListProperty>
23 #include <QTouchEvent>
24 #include <QVariantList>
27 #include "VariantConverter.h"
49 newList.reserve(list.
size());
51 for (
const T& item : list) {
52 newList.append(converter.
toVariant(item));
67 convertedList.
reserve(list.size());
70 convertedList.
append(converter.fromVariant(v));
84 QVariantMap convertedMap;
86 for (
auto it = map.
cbegin(); it != map.
cend(); ++it) {
87 convertedMap.insert(it.key(), converter.
toVariant(it.value()));
103 for (
auto it = map.cbegin(); it != map.cend(); ++it) {
104 convertedMap.
insert(it.key(), converter.fromVariant(it.value()));
124 template <
typename TObject,
typename TData,
typename TListType, TListType TObject::* TObjectField,
125 void (TObject::* TChangeFunc)() =
nullptr>
136 &QQmlListPropertyOnQList::appendFunc,
137 &QQmlListPropertyOnQList::countFunc,
138 &QQmlListPropertyOnQList::atFunc,
139 &QQmlListPropertyOnQList::clearFunc);
144 TObject* owner =
static_cast<TObject*
>(property->object);
145 TListType& list = (owner->*TObjectField);
147 callChangeFunc(property);
151 TObject* owner =
static_cast<TObject*
>(property->object);
152 TListType& list = (owner->*TObjectField);
157 TObject* owner =
static_cast<TObject*
>(property->object);
158 TListType& list = (owner->*TObjectField);
159 return list.at(index);
163 TObject* owner =
static_cast<TObject*
>(property->object);
164 TListType& list = (owner->*TObjectField);
166 callChangeFunc(property);
170 TObject* owner =
static_cast<TObject*
>(property->object);
172 (owner->*TChangeFunc)();
183 template <
typename T>
184 inline const T&
clamp(
const T& a,
const T& min,
const T& max) {
185 return std::max<T>(min, std::min<T>(max, a));
200 return 6 * t5 - 15 * t4 + 10 * t3;
207 return qrand() / ((float) RAND_MAX + 1);
215 template <
typename TObject>
219 TObject* obj = qobject_cast<TObject*>(node);
const_iterator cend() const
QString getPathToSound(const QString &soundPath)
Returns the platform dependent path to the sound in soundPath.
QMap< QString, T > toMap(const QVariantMap &map)
Returns map converted to a QMap.
Definition: Util.h:100
bool deviceHasTouchScreen()
Returns true if the device on which the game is running has a touch screen.
QRectF united(const QRectF &rect, const QPointF &point)
Expands a QRectF's span to include a point.
QUrl getUrlPathToAsset(const QString &assetPath)
Returns platform dependent path URL to assetPath.
QString getPathToMovie(const QString &moviePath)
Returns the platform dependent path to the movie in moviePath.
QString getPathToData(const QString &dataPath)
Returns the platform dependent path to the data file in dataPath.
void append(const T &value)
QVariantMap toVariantMap(const QMap< QString, T > map)
Returns map converted to a QVariantMap.
Definition: Util.h:83
QList< T > toList(const QVariantList &list)
Returns list converted to a QList.
Definition: Util.h:65
QVariant toVariant(const T &value)
Returns value converted as a QVariant.
Definition: VariantConverter.h:45
QVariantList toVariantList(const QList< T > &list)
Returns list converted to a QVariantList.
Definition: Util.h:47
static float qrandF()
Returns a pseudo-random number in the range [0, 1).
Definition: Util.h:206
static float smoothstep(float t)
Computes the value of a smoothed interpolation curve between 0.0f and 1.0f.
Definition: Util.h:195
int getDeviceTouchScreenDeviceId()
Returns the device id of the touch screen on the device, or -1 if none exists.
QString readFileAsQString(const QString &path)
Returns the entire contents of a text file as a QString.
const_iterator cbegin() const
TObject * findParentOfType(QObject *node)
Returns our closest ancestor which is of type TObject.
Definition: Util.h:216
Helper class which creates QQmlListProperty objects directly on QList members fields.
Definition: Util.h:126
QString getPathToAsset(const QString &assetPath)
Returns the platform dependent path to assetPath.
static QQmlListProperty< TData > createList(TObject *owner)
Create and return a QQmlListProperty.
Definition: Util.h:132
QString getPathToImage(const QString &imagePath)
Returns the platform dependent path to the image in imagePath.
const T & clamp(const T &a, const T &min, const T &max)
Returns the value a clamped between min and max.
Definition: Util.h:184
iterator insert(const Key &key, const T &value)
bool javaScriptFuncExists(QObject *object, const char *method)
Checks if a javascript function exists.
QString getPathToFont(const QString &fontPath)
Returns the platform dependent path to the font in fontPath.
QString getPathToLevel(const QString &levelPath)
Returns the platform dependent path to the level in levelPath.
Helper template class to convert QVariants to and from a specific type, for example, QPointFs.
Definition: VariantConverter.h:59
std::string readFileAsStdString(const QString &path)
Returns the entire contents of a text file as a std::string.