version 2.0.0_alpha
Important! All QtWraps macros renamed! Qt 6 support Graphic export feature qad_types cross-Qt small changes
This commit is contained in:
@@ -150,6 +150,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
ret.value = QVariant(typeFromLetter(pt));
|
||||
if (!pv.isEmpty()) {
|
||||
//qDebug() << "set value !" << pv;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
switch (ret.value.type()) {
|
||||
case QVariant::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break;
|
||||
case QVariant::Int: ret.value = pv.toInt(); break;
|
||||
@@ -160,6 +161,18 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
case QVariant::Color: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
};
|
||||
#else
|
||||
switch (ret.value.metaType().id()) {
|
||||
case QMetaType::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break;
|
||||
case QMetaType::Int: ret.value = pv.toInt(); break;
|
||||
case QMetaType::UInt: ret.value = pv.toUInt(); break;
|
||||
case QMetaType::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QMetaType::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QMetaType::Double: ret.value = pv.toDouble(); break;
|
||||
case QMetaType::QColor: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -115,9 +115,6 @@ protected:
|
||||
|
||||
inline QDebug operator <<(QDebug s, const PropertyStorage::Property & p) {s.nospace() << p.name << " (0x" << QString::number(p.flags, 16) << ") = " << p.value; return s.space();}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const PropertyStorage & p) {s << p.properties(); return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, PropertyStorage & p) {s >> p.properties(); return s;}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const PropertyStorage::Property & p) {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, p.name) << cs.chunk(2, p.comment) << cs.chunk(3, p.value) << cs.chunk(4, p.flags);
|
||||
@@ -137,5 +134,8 @@ inline QDataStream & operator >>(QDataStream & s, PropertyStorage::Property & p)
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const PropertyStorage & p) {s << p.properties(); return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, PropertyStorage & p) {s >> p.properties(); return s;}
|
||||
|
||||
|
||||
#endif // PROPERTYSTORAGE_H
|
||||
|
||||
@@ -26,25 +26,22 @@ __QADTypesRegistrator__::__QADTypesRegistrator__() {
|
||||
_inited = true;
|
||||
|
||||
qRegisterMetaType<QAD::Enumerator>("QAD::Enumerator");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enumerator>("QAD::Enumerator");
|
||||
|
||||
qRegisterMetaType<QAD::Enum>("QAD::Enum");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enum>("QAD::Enum");
|
||||
|
||||
qRegisterMetaType<QAD::File>("QAD::File");
|
||||
qRegisterMetaTypeStreamOperators<QAD::File>("QAD::File");
|
||||
|
||||
qRegisterMetaType<QAD::Dir>("QAD::Dir");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Dir>("QAD::Dir");
|
||||
|
||||
qRegisterMetaType<QAD::IODevice>("QAD::IODevice");
|
||||
qRegisterMetaTypeStreamOperators<QAD::IODevice>("QAD::IODevice");
|
||||
|
||||
qRegisterMetaType<QAD::MathVector>("QAD::MathVector");
|
||||
qRegisterMetaTypeStreamOperators<QAD::MathVector>("QAD::MathVector");
|
||||
|
||||
qRegisterMetaType<QAD::MathMatrix>("QAD::MathMatrix");
|
||||
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enumerator>("QAD::Enumerator");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Enum>("QAD::Enum");
|
||||
qRegisterMetaTypeStreamOperators<QAD::File>("QAD::File");
|
||||
qRegisterMetaTypeStreamOperators<QAD::Dir>("QAD::Dir");
|
||||
qRegisterMetaTypeStreamOperators<QAD::IODevice>("QAD::IODevice");
|
||||
qRegisterMetaTypeStreamOperators<QAD::MathVector>("QAD::MathVector");
|
||||
qRegisterMetaTypeStreamOperators<QAD::MathMatrix>("QAD::MathMatrix");
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= 0x050200
|
||||
QMetaType::registerConverter<QAD::Enum, int>(&QAD::Enum::selectedValue);
|
||||
@@ -185,7 +182,13 @@ QString QAD::IODevice::toString() const {
|
||||
|
||||
|
||||
|
||||
QVariant::Type typeFromLetter(const QString & l) {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QVariant::Type
|
||||
#else
|
||||
QMetaType
|
||||
#endif
|
||||
typeFromLetter(const QString & l) {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
if (l.isEmpty()) return QVariant::String;
|
||||
QString ft = l.left(1);
|
||||
if (ft == "l") return QVariant::StringList;
|
||||
@@ -204,6 +207,26 @@ QVariant::Type typeFromLetter(const QString & l) {
|
||||
if (ft == "V") return (QVariant::Type)qMetaTypeId<QAD::MathVector>();
|
||||
if (ft == "M") return (QVariant::Type)qMetaTypeId<QAD::MathMatrix>();
|
||||
return QVariant::String;
|
||||
#else
|
||||
if (l.isEmpty()) return QMetaType::fromType<QString>();
|
||||
QString ft = l.left(1);
|
||||
if (ft == "l") return QMetaType::fromType<QStringList >();
|
||||
if (ft == "b") return QMetaType::fromType<bool >();
|
||||
if (ft == "n") return QMetaType::fromType<int >();
|
||||
if (ft == "f") return QMetaType::fromType<double >();
|
||||
if (ft == "c") return QMetaType::fromType<QColor >();
|
||||
if (ft == "r") return QMetaType::fromType<QRect >();
|
||||
if (ft == "a") return QMetaType::fromType<QRectF >();
|
||||
if (ft == "p") return QMetaType::fromType<QPoint >();
|
||||
if (ft == "v") return QMetaType::fromType<QPointF >();
|
||||
if (ft == "e") return QMetaType::fromType<QAD::Enum >();
|
||||
if (ft == "F") return QMetaType::fromType<QAD::File >();
|
||||
if (ft == "D") return QMetaType::fromType<QAD::Dir >();
|
||||
if (ft == "d") return QMetaType::fromType<QAD::IODevice >();
|
||||
if (ft == "V") return QMetaType::fromType<QAD::MathVector>();
|
||||
if (ft == "M") return QMetaType::fromType<QAD::MathMatrix>();
|
||||
return QMetaType::fromType<QString>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +275,11 @@ int fontHeight(const QWidget * w) {
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
return QApplication::fontMetrics().size(0, "0").height();
|
||||
#else
|
||||
return QFontMetricsF(QApplication::font()).size(0, "0").height();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -276,3 +303,10 @@ QSize preferredIconSize(float x, const QWidget * w) {
|
||||
double appScale(const QWidget * w) {
|
||||
return qMax<double>(fontHeight(w) / 15., 1.);
|
||||
}
|
||||
|
||||
|
||||
void enableHighDPI() {
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef QAD_TYPES_H
|
||||
#define QAD_TYPES_H
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QApplication>
|
||||
#include "propertystorage.h"
|
||||
#include "qad_utils_export.h"
|
||||
|
||||
@@ -31,6 +31,16 @@
|
||||
QCoreApplication::setOrganizationName(__TARGET_COMPANY__); \
|
||||
QCoreApplication::setApplicationVersion(__TARGET_VERSION__);
|
||||
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
# define QT_MID_BUTTON Qt::MidButton
|
||||
# include <QMapIterator>
|
||||
template<typename K, typename T>
|
||||
using QMultiMapIterator = QMapIterator<K,T>;
|
||||
#else
|
||||
# define QT_MID_BUTTON Qt::MiddleButton
|
||||
#endif
|
||||
|
||||
|
||||
class QMetaEnum;
|
||||
|
||||
|
||||
@@ -167,13 +177,47 @@ inline QRectF enlargedRect(const QRectF & r, qreal dx, qreal dy, qreal v) {
|
||||
return QRectF(r.left() - v + dx, r.top() - v + dy, r.width() + v+v, r.height() + v+v);
|
||||
}
|
||||
|
||||
QAD_UTILS_EXPORT QVariant::Type typeFromLetter(const QString & l);
|
||||
template <typename T> QSet<T> QList2QSet(const QList<T> & l) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
return QSet<T>(l.begin(), l.end());
|
||||
#else
|
||||
return QSet<T>::fromList(l);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename K, typename T>
|
||||
void addToMap(QMap<K, T> & into, const QMap<K, T> & what) {
|
||||
QMapIterator<K, T> it(what);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (!into.contains(it.key()))
|
||||
into[it.key()] = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename T>
|
||||
void addToMapOverwrite(QMap<K, T> & into, const QMap<K, T> & what) {
|
||||
QMapIterator<K, T> it(what);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
into[it.key()] = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
QAD_UTILS_EXPORT
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QVariant::Type
|
||||
#else
|
||||
QMetaType
|
||||
#endif
|
||||
typeFromLetter(const QString & l);
|
||||
QAD_UTILS_EXPORT QString uniqueName(QString n, const QStringList & names);
|
||||
|
||||
QAD_UTILS_EXPORT int fontHeight(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT int lineThickness(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT QSize preferredIconSize(float x = 1.f, const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT double appScale(const QWidget * w = 0);
|
||||
QAD_UTILS_EXPORT void enableHighDPI();
|
||||
|
||||
|
||||
#endif // QAD_TYPES_H
|
||||
|
||||
@@ -303,6 +303,9 @@ QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
return;
|
||||
}
|
||||
dev->close();
|
||||
#if QT_VERSION_MAJOR > 5
|
||||
stream.setEncoding(QStringConverter::Utf8);
|
||||
#endif
|
||||
setFileName(cp);
|
||||
open(QIODevice::ReadOnly);
|
||||
parse();
|
||||
@@ -347,7 +350,15 @@ void QPIConfig::setString(QString * str) {
|
||||
|
||||
void QPIConfig::setCodec(const char * codecName) {
|
||||
codec = codecName;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
stream.setCodec(codecName);
|
||||
#else
|
||||
QString cn = QString(codecName).toLower().remove(' ').remove('-').trimmed();
|
||||
QStringConverter::Encoding sc = QStringConverter::System;
|
||||
if (cn == "utf8" ) sc = QStringConverter::Utf8 ;
|
||||
else if (cn == "utf16") sc = QStringConverter::Utf16;
|
||||
stream.setEncoding(sc);
|
||||
#endif
|
||||
parse();
|
||||
}
|
||||
|
||||
@@ -770,8 +781,10 @@ void QPIConfig::parse(QString content) {
|
||||
stream.seek(0);
|
||||
other.clear();
|
||||
lines = centry = 0;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
if (!codec.isEmpty())
|
||||
stream.setCodec(codec.toLatin1().data());
|
||||
#endif
|
||||
while (!stream.atEnd()) {
|
||||
other.push_back(QString());
|
||||
src = str = parseLine(stream.readLine());
|
||||
|
||||
Reference in New Issue
Block a user