23 #include "metaenumvariable_p.h" 26 #include <QtCore/QStringList> 33 return input.
mid(1, input.
size() - 2)
49 return variant.
value<
int>() > 0;
52 return variant.
value<uint>() > 0;
55 return variant.
value<qlonglong>() > 0;
58 return variant.
value<qulonglong>() > 0;
61 return variant.
value<
double>() > 0;
64 return variant.
value<
float>() > 0;
67 return variant.
value<
char>() > 0;
74 if (obj->property(
"__true__").isValid()) {
80 return !variant.
value<QVariantList>().isEmpty();
83 return !variant.
value<QVariantHash>().isEmpty();
86 return !variant.
value<QVariantMap>().isEmpty();
107 temp.setNeedsEscape(
true);
113 if (input.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
123 return ((type == qMetaTypeId<Cutelee::SafeString>())
139 static const auto primitives = getPrimitives();
140 return primitives.contains(input.
userType());
150 if (lhs.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
151 if (rhs.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
157 }
else if (rhs.
userType() == qMetaTypeId<Cutelee::SafeString>()
160 }
else if (rhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
161 if (lhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
162 equal = (rhs.
value<MetaEnumVariable>() == lhs.
value<MetaEnumVariable>());
163 }
else if (lhs.
userType() == qMetaTypeId<int>()) {
164 equal = (rhs.
value<MetaEnumVariable>() == lhs.
value<
int>());
166 }
else if (lhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
167 if (rhs.
userType() == qMetaTypeId<int>()) {
168 equal = (lhs.
value<MetaEnumVariable>() == rhs.
value<
int>());
183 return equals(lhs, rhs) || gt(lhs, rhs);
193 return equals(lhs, rhs) || lt(lhs, rhs);
198 std::pair<qreal,QString> ret;
200 int _unitSystem = unitSystem;
202 if ((_unitSystem != 2) && (_unitSystem != 10)) {
203 qWarning(
"%s",
"Unrecognized file size unit system. Falling back to decimal unit system.");
209 ret.second = QStringLiteral(
"bytes");
211 }
else if ((size == 1.0) || (size == -1.0)) {
213 ret.second = QStringLiteral(
"byte");
217 qreal _size = size * multiplier;
219 const bool positiveValue = (_size > 0);
221 if (!positiveValue) {
226 QStringLiteral(
"bytes"),
227 QStringLiteral(
"KiB"),
228 QStringLiteral(
"MiB"),
229 QStringLiteral(
"GiB"),
230 QStringLiteral(
"TiB"),
231 QStringLiteral(
"PiB"),
232 QStringLiteral(
"EiB"),
233 QStringLiteral(
"ZiB"),
234 QStringLiteral(
"YiB")
238 QStringLiteral(
"bytes"),
239 QStringLiteral(
"KB"),
240 QStringLiteral(
"MB"),
241 QStringLiteral(
"GB"),
242 QStringLiteral(
"TB"),
243 QStringLiteral(
"PB"),
244 QStringLiteral(
"EB"),
245 QStringLiteral(
"ZB"),
250 const qreal baseVal = (_unitSystem == 10) ? 1000.0f : 1024.0f;
251 #if FLT_EVAL_METHOD == 2 254 volatile qreal current = 1.0F;
256 qreal current = 1.0f;
258 int units = decimalUnits.
size();
259 while (count < units) {
261 if (_size < current) {
267 if (count >= units) {
271 qreal devider = current/baseVal;
272 _size = _size/devider;
274 if (!positiveValue) {
279 ret.second = (_unitSystem == 10) ? decimalUnits.at(count) : binaryUnits.at(count);
287 auto it = list.constBegin();
288 const auto end = list.constEnd();
290 const auto item = *it;
292 output += QStringLiteral(
"u\'")
296 if ((item.userType() == qMetaTypeId<int>())
297 || (item.userType() == qMetaTypeId<uint>())
298 || (item.userType() == qMetaTypeId<double>())
299 || (item.userType() == qMetaTypeId<float>())
300 || (item.userType() == qMetaTypeId<long long>())
301 || (item.userType() == qMetaTypeId<unsigned long long>())) {
302 output += item.toString();
304 if (item.userType() == qMetaTypeId<QVariantList>()) {
306 +=
static_cast<QString>(toString(item.value<QVariantList>()).get());
309 output += QStringLiteral(
", ");
bool variantIsTrue(const QVariant &variant)
QString & append(QChar ch)
Cutelee::SafeString markSafe(const Cutelee::SafeString &input)
qsizetype size() const const
bool supportedOutputType(const QVariant &input)
bool equals(const QVariant &lhs, const QVariant &rhs)
qsizetype size() const const
bool isSafeString(const QVariant &input)
Cutelee::SafeString markForEscaping(const Cutelee::SafeString &input)
QString unescapeStringLiteral(const QString &input)
QPartialOrdering compare(const QVariant &lhs, const QVariant &rhs)
QVariant property(const char *name) const const
bool isEmpty() const const
Utility functions used throughout Cutelee.
A QString wrapper class for containing whether a string is safe or needs to be escaped.
int userType() const const
QString mid(qsizetype position, qsizetype n) const const
bool toBool() const const
bool isValid() const const
std::pair< qreal, QString > calcFileSize(qreal size, int unitSystem=10, qreal multiplier=1.0)
QString toString() const const
const NestedString & get() const
Cutelee::SafeString getSafeString(const QVariant &input)
The string is safe and requires no further escaping.