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();
104 temp.setNeedsEscape(
true);
110 if (input.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
120 return ((type == qMetaTypeId<Cutelee::SafeString>())
136 static const auto primitives = getPrimitives();
137 return primitives.contains(input.
userType());
147 if (lhs.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
148 if (rhs.
userType() == qMetaTypeId<Cutelee::SafeString>()) {
154 }
else if (rhs.
userType() == qMetaTypeId<Cutelee::SafeString>()
157 }
else if (rhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
158 if (lhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
159 equal = (rhs.
value<MetaEnumVariable>() == lhs.
value<MetaEnumVariable>());
160 }
else if (lhs.
userType() == qMetaTypeId<int>()) {
161 equal = (rhs.
value<MetaEnumVariable>() == lhs.
value<
int>());
163 }
else if (lhs.
userType() == qMetaTypeId<MetaEnumVariable>()) {
164 if (rhs.
userType() == qMetaTypeId<int>()) {
165 equal = (lhs.
value<MetaEnumVariable>() == rhs.
value<
int>());
168 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 179 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 182 return QVariant::compare(lhs, rhs) == QPartialOrdering::Greater;
188 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 191 return equals(lhs, rhs) || gt(lhs, rhs);
197 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 200 return QVariant::compare(lhs, rhs) == QPartialOrdering::Less;
207 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 210 return equals(lhs, rhs) || lt(lhs, rhs);
217 std::pair<qreal,QString> ret;
219 int _unitSystem = unitSystem;
221 if ((_unitSystem != 2) && (_unitSystem != 10)) {
222 qWarning(
"%s",
"Unrecognized file size unit system. Falling back to decimal unit system.");
228 ret.second = QStringLiteral(
"bytes");
230 }
else if ((size == 1.0) || (size == -1.0)) {
232 ret.second = QStringLiteral(
"byte");
236 qreal _size = size * multiplier;
238 const bool positiveValue = (_size > 0);
240 if (!positiveValue) {
245 QStringLiteral(
"bytes"),
246 QStringLiteral(
"KiB"),
247 QStringLiteral(
"MiB"),
248 QStringLiteral(
"GiB"),
249 QStringLiteral(
"TiB"),
250 QStringLiteral(
"PiB"),
251 QStringLiteral(
"EiB"),
252 QStringLiteral(
"ZiB"),
253 QStringLiteral(
"YiB")
257 QStringLiteral(
"bytes"),
258 QStringLiteral(
"KB"),
259 QStringLiteral(
"MB"),
260 QStringLiteral(
"GB"),
261 QStringLiteral(
"TB"),
262 QStringLiteral(
"PB"),
263 QStringLiteral(
"EB"),
264 QStringLiteral(
"ZB"),
269 const qreal baseVal = (_unitSystem == 10) ? 1000.0f : 1024.0f;
270 #if FLT_EVAL_METHOD == 2 273 volatile qreal current = 1.0F;
275 qreal current = 1.0f;
277 int units = decimalUnits.
size();
278 while (count < units) {
280 if (_size < current) {
286 if (count >= units) {
290 qreal devider = current/baseVal;
291 _size = _size/devider;
293 if (!positiveValue) {
298 ret.second = (_unitSystem == 10) ? decimalUnits.at(count) : binaryUnits.at(count);
306 auto it = list.constBegin();
307 const auto end = list.constEnd();
309 const auto item = *it;
311 output += QStringLiteral(
"u\'")
315 if ((item.userType() == qMetaTypeId<int>())
316 || (item.userType() == qMetaTypeId<uint>())
317 || (item.userType() == qMetaTypeId<double>())
318 || (item.userType() == qMetaTypeId<float>())
319 || (item.userType() == qMetaTypeId<long long>())
320 || (item.userType() == qMetaTypeId<unsigned long long>())) {
321 output += item.toString();
323 if (item.userType() == qMetaTypeId<QVariantList>()) {
325 +=
static_cast<QString>(toString(item.value<QVariantList>()).get());
328 output += QStringLiteral(
", ");
bool variantIsTrue(const QVariant &variant)
QString & append(QChar ch)
Cutelee::SafeString markSafe(const Cutelee::SafeString &input)
bool supportedOutputType(const QVariant &input)
bool equals(const QVariant &lhs, const QVariant &rhs)
bool isSafeString(const QVariant &input)
Cutelee::SafeString markForEscaping(const Cutelee::SafeString &input)
QString unescapeStringLiteral(const QString &input)
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(int position, int 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.