MauiKit Controls

fmh.cpp
1#include "fmh.h"
2
3#include <QDebug>
4#include <QFileInfo>
5
6namespace FMH
7{
9{
10 const auto keys = model.keys();
11 return std::accumulate(keys.begin(), keys.end(), QVector<int>(), [](QVector<int> &res, const FMH::MODEL_KEY &key) {
12 res.append(key);
13 return res;
14 });
15}
16
17const QString mapValue(const QVariantMap &map, const FMH::MODEL_KEY &key)
18{
19 return map[FMH::MODEL_NAME[key]].toString();
20}
21
22const QVariantMap toMap(const FMH::MODEL &model)
23{
24 QVariantMap map;
25 const auto keys = model.keys();
26 for (const auto &key : keys)
27 {
28 map.insert(FMH::MODEL_NAME[key], model[key]);
29 }
30
31 return map;
32}
33
34const FMH::MODEL toModel(const QVariantMap &map)
35{
36 FMH::MODEL model;
37 const auto keys = map.keys();
38 for (const auto &key : keys)
39 {
40 model.insert(FMH::MODEL_NAME_KEY[key], map[key].toString());
41 }
42
43 return model;
44}
45
46const FMH::MODEL_LIST toModelList(const QVariantList &list)
47{
49 return std::accumulate(list.constBegin(), list.constEnd(), res, [](FMH::MODEL_LIST &res, const QVariant &item) -> FMH::MODEL_LIST {
50 res << FMH::toModel(item.toMap());
51 return res;
52 });
53}
54
55const QVariantList toMapList(const FMH::MODEL_LIST &list)
56{
57 QVariantList res;
58 return std::accumulate(list.constBegin(), list.constEnd(), res, [](QVariantList &res, const FMH::MODEL &item) -> QVariantList {
59 res << FMH::toMap(item);
60 return res;
61 });
62}
63
65{
66 FMH::MODEL res;
67 return std::accumulate(keys.constBegin(), keys.constEnd(), res, [=](FMH::MODEL &res, const FMH::MODEL_KEY &key) -> FMH::MODEL {
68 if (model.contains(key))
69 res[key] = model[key];
70 return res;
71 });
72}
73
75{
76 QStringList res;
77 return std::accumulate(list.constBegin(), list.constEnd(), res, [key](QStringList &res, const FMH::MODEL &item) -> QStringList {
78 if (item.contains(key))
79 res << item[key];
80 return res;
81 });
82}
83
85{
86#if defined(Q_OS_ANDROID)
87 return true;
88#else
89 return false;
90#endif
91}
92
94{
95#if defined(Q_OS_WIN32)
96 return true;
97#elif defined(Q_OS_WIN64)
98 return true;
99#else
100 return false;
101#endif
102}
103
105{
106#if (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined Q_OS_ANDROID
107 return true;
108#else
109 return false;
110#endif
111}
112
113bool isMac()
114{
115#if defined(Q_OS_MACOS)
116 return true;
117#elif defined(Q_OS_MAC)
118 return true;
119#else
120 return false;
121#endif
122}
123
124bool isIOS()
125{
126#if defined(Q_OS_iOS)
127 return true;
128#else
129 return false;
130#endif
131}
132
133bool fileExists(const QUrl &path)
134{
135 if (!path.isLocalFile()) {
136 qWarning() << "URL recived is not a local file" << path;
137 return false;
138 }
139 return QFileInfo::exists(path.toLocalFile());
140}
141
142
143}
A set of helpers for managing the key-value model data type.
Definition fmh.cpp:7
const FMH::MODEL filterModel(const FMH::MODEL &model, const QVector< FMH::MODEL_KEY > &keys)
Creates a new MODEL from another by filtering in the given array of MODEL_KEY.
Definition fmh.cpp:64
static const QHash< QString, MODEL_KEY > MODEL_NAME_KEY
The mapping of a string text into a FMH::MODEL_KEY.
Definition fmh.h:378
const QVariantList toMapList(const FMH::MODEL_LIST &list)
Creates a QVariantList from a MODEL_LIST.
Definition fmh.cpp:55
const QString mapValue(const QVariantMap &map, const FMH::MODEL_KEY &key)
Extracts a value associated with that given FMH::MODEL_KEY key in a map.
Definition fmh.cpp:17
bool isLinux()
Whether the platform running is GNU/Linux.
Definition fmh.cpp:104
const QVector< int > modelRoles(const FMH::MODEL &model)
Given a FMH::MODEL, this function will extract all the FMH::MODEL_KEY values used as the keys/roles.
Definition fmh.cpp:8
const FMH::MODEL_LIST toModelList(const QVariantList &list)
Creates a FMH::MODEL_LIST from a QVariantList.
Definition fmh.cpp:46
bool isIOS()
Whether the platform running is IOS.
Definition fmh.cpp:124
const QStringList modelToList(const FMH::MODEL_LIST &list, const FMH::MODEL_KEY &key)
Extracts from a MODEL_LIST the values from a given MODEL::KEY into a QStringList.
Definition fmh.cpp:74
bool fileExists(const QUrl &path)
Checks if a local file exists.
Definition fmh.cpp:133
static const QHash< MODEL_KEY, QString > MODEL_NAME
The mapping of the FMH::MODEL_KEY enum values to its string representation.
Definition fmh.h:219
MODEL_KEY
The MODEL_KEY enum values.
Definition fmh.h:64
bool isWindows()
Whether the platform running is Window.
Definition fmh.cpp:93
const FMH::MODEL toModel(const QVariantMap &map)
Converts a QVariantMap to a FMH::MODEl.
Definition fmh.cpp:34
const QVariantMap toMap(const FMH::MODEL &model)
Converts a FMH::MODEL object to a QVariantMap.
Definition fmh.cpp:22
bool isMac()
Whether the platform running is Mac.
Definition fmh.cpp:113
bool isAndroid()
Whether the platform running is Android.
Definition fmh.cpp:84
bool exists() const const
iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
const_iterator constBegin() const const
const_iterator constEnd() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:50:53 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.