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>());
171 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 182 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 185 return QVariant::compare(lhs, rhs) == QPartialOrdering::Greater;
191 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 194 return equals(lhs, rhs) || gt(lhs, rhs);
200 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 203 return QVariant::compare(lhs, rhs) == QPartialOrdering::Less;
210 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 213 return equals(lhs, rhs) || lt(lhs, rhs);
220 std::pair<qreal,QString> ret;
222 int _unitSystem = unitSystem;
224 if ((_unitSystem != 2) && (_unitSystem != 10)) {
225 qWarning(
"%s",
"Unrecognized file size unit system. Falling back to decimal unit system.");
231 ret.second = QStringLiteral(
"bytes");
233 }
else if ((size == 1.0) || (size == -1.0)) {
235 ret.second = QStringLiteral(
"byte");
239 qreal _size = size * multiplier;
241 const bool positiveValue = (_size > 0);
243 if (!positiveValue) {
248 QStringLiteral(
"bytes"),
249 QStringLiteral(
"KiB"),
250 QStringLiteral(
"MiB"),
251 QStringLiteral(
"GiB"),
252 QStringLiteral(
"TiB"),
253 QStringLiteral(
"PiB"),
254 QStringLiteral(
"EiB"),
255 QStringLiteral(
"ZiB"),
256 QStringLiteral(
"YiB")
260 QStringLiteral(
"bytes"),
261 QStringLiteral(
"KB"),
262 QStringLiteral(
"MB"),
263 QStringLiteral(
"GB"),
264 QStringLiteral(
"TB"),
265 QStringLiteral(
"PB"),
266 QStringLiteral(
"EB"),
267 QStringLiteral(
"ZB"),
272 const qreal baseVal = (_unitSystem == 10) ? 1000.0f : 1024.0f;
273 #if FLT_EVAL_METHOD == 2 276 volatile qreal current = 1.0F;
278 qreal current = 1.0f;
280 int units = decimalUnits.
size();
281 while (count < units) {
283 if (_size < current) {
289 if (count >= units) {
293 qreal devider = current/baseVal;
294 _size = _size/devider;
296 if (!positiveValue) {
301 ret.second = (_unitSystem == 10) ? decimalUnits.at(count) : binaryUnits.at(count);
309 auto it = list.constBegin();
310 const auto end = list.constEnd();
312 const auto item = *it;
314 output += QStringLiteral(
"u\'")
318 if ((item.userType() == qMetaTypeId<int>())
319 || (item.userType() == qMetaTypeId<uint>())
320 || (item.userType() == qMetaTypeId<double>())
321 || (item.userType() == qMetaTypeId<float>())
322 || (item.userType() == qMetaTypeId<long long>())
323 || (item.userType() == qMetaTypeId<unsigned long long>())) {
324 output += item.toString();
326 if (item.userType() == qMetaTypeId<QVariantList>()) {
328 +=
static_cast<QString>(toString(item.value<QVariantList>()).get());
331 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.