26#ifndef KDB_TOOLS_UTILS_H
27#define KDB_TOOLS_UTILS_H
29#include "kdb_export.h"
30#include "config-kdb.h"
41KDB_EXPORT
bool hasParent(QObject* par, QObject* o);
45inline type findParent(QObject* o,
const char* className =
nullptr)
49 while ((o = o->
parent())) {
50 if (::qobject_cast< type >(o) && (!className || o->
inherits(className)))
51 return ::qobject_cast< type >(o);
64KDB_EXPORT QString toISODateStringWithMs(
const QTime &time);
74KDB_EXPORT QString toISODateStringWithMs(
const QDateTime &dateTime);
87KDB_EXPORT QTime timeFromISODateStringWithMs(
const QString &
string);
100KDB_EXPORT QDateTime dateTimeFromISODateStringWithMs(
const QString &
string);
103KDB_EXPORT QDateTime stringToHackedQTime(
const QString& s);
108KDB_EXPORT
void serializeMap(
const QMap<QString, QString>& map, QByteArray *array);
113KDB_EXPORT
void serializeMap(
const QMap<QString, QString>& map, QString *
string);
117KDB_EXPORT QMap<QString, QString> deserializeMap(
const QByteArray& array);
121KDB_EXPORT QMap<QString, QString> deserializeMap(
const QString&
string);
134KDB_EXPORT QString stringToFileName(
const QString&
string);
141KDB_EXPORT
void simpleCrypt(QString *
string);
149KDB_EXPORT
bool simpleDecrypt(QString *
string);
152KDB_EXPORT QString pointerToStringInternal(
void* pointer,
int size);
154KDB_EXPORT
void* stringToPointerInternal(
const QString&
string,
int size);
158QString pointerToString(type *pointer)
160 return pointerToStringInternal(pointer,
sizeof(type*));
165type* stringToPointer(
const QString&
string)
167 return static_cast<type*
>(stringToPointerInternal(
string,
sizeof(type*)));
174KDB_EXPORT QVariant squeezedValue(
const QVariant &value);
177template <
class Key,
class T>
195 void setAutoDelete(
bool set) {
198 bool autoDelete()
const {
218 if (oldValue && oldValue !=
value) {
224 int remove(
const Key &
key) {
251 :
QList<T>(other), m_autoDelete(false) {}
258 if (m_autoDelete) qDeleteAll(*
this);
260 void setAutoDelete(
bool set) {
263 bool autoDelete()
const {
266 void removeAt(
int i) {
275 void replace(
int i,
const T&
value) {
278 void insert(
int i,
const T&
value) {
293 while (afirst != alast) {
306 int removeAll(
const T&
value) {
310 int removedCount = 0;
337template <
typename Key,
typename T>
338class CaseInsensitiveHash :
public QHash<Key, T>
348 bool contains(
const Key& key)
const {
351 int count(
const Key& key)
const {
360 const Key key(
const T& value,
const Key& defaultKey)
const {
363 int remove(
const Key& key) {
366 const T take(
const Key& key) {
369 const T value(
const Key& key)
const {
372 const T value(
const Key& key,
const T& defaultValue)
const {
378 T& operator[](
const Key& key) {
381 const T operator[](
const Key& key)
const {
387class KDB_EXPORT StaticSetOfStrings
390 StaticSetOfStrings();
391 explicit StaticSetOfStrings(
const char*
const array[]);
392 ~StaticSetOfStrings();
393 void setStrings(
const char*
const array[]);
394 bool isEmpty()
const;
401 Q_DISABLE_COPY(StaticSetOfStrings)
406QString debugString(
const T&
object)
415enum class FindExeOption {
421Q_DECLARE_FLAGS(FindExeOptions, FindExeOption)
439QString findExe(
const QString& appname,
440 const QString& path = QString(),
441 FindExeOptions options = FindExeOption::None);
457 bool operator==(
const Property &other)
const;
459 bool operator!=(
const Property &other)
const {
return !operator==(other); }
465 void setValue(
const QVariant &value);
469 void setCaption(
const QString &caption);
479class KDB_EXPORT PropertySet
484 PropertySet(
const PropertySet &other);
489 PropertySet&
operator=(
const PropertySet &other);
493 bool operator==(
const PropertySet &other)
const;
AutodeletedHash(bool autoDelete=true)
Creates empty autodeleting hash.
AutodeletedHash(const AutodeletedHash &other)
Creates autodeleting hash as a copy of other.
AutodeletedList(bool autoDelete=true)
Creates empty autodeleting list.
AutodeletedList(const AutodeletedList &other)
Creates autodeleting list as a copy of other.
PropertySet & operator=(const PropertySet &other)
Assigns other to this property set and returns a reference to this property set.
bool operator!=(const PropertySet &other) const
bool operator==(const PropertySet &other) const
Property()
Constructs a null property.
bool contains(const QByteArray &string) const
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
const_iterator constFind(const Key &key) const const
bool contains(const Key &key) const const
qsizetype count() const const
iterator erase(const_iterator pos)
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
Key key(const T &value) const const
T & operator[](const Key &key)
bool remove(const Key &key)
T value(const Key &key) const const
QList< T > values() const const
iterator erase(const_iterator begin, const_iterator end)
iterator insert(const_iterator before, parameter_type value)
qsizetype removeAll(const AT &t)
T value(qsizetype i) const const
bool inherits(const char *className) const const
QObject * parent() const const