code format
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
void ChunkStream::setSource(const QByteArray & data) {
|
||||
stream_.setVersion(QDataStream::Qt_4_8);
|
||||
data_ = const_cast<QByteArray*>(&data);
|
||||
data_ = const_cast<QByteArray *>(&data);
|
||||
_init();
|
||||
}
|
||||
|
||||
@@ -25,13 +25,11 @@ void ChunkStream::setSource(QDataStream & str) {
|
||||
|
||||
int ChunkStream::read() {
|
||||
switch (version_) {
|
||||
case Version_1:
|
||||
stream_ >> last_id >> last_data;
|
||||
break;
|
||||
case Version_1: stream_ >> last_id >> last_data; break;
|
||||
case Version_2:
|
||||
last_id = readVInt(stream_);
|
||||
last_data.resize(readVInt(stream_));
|
||||
//piCout << last_id << last_data.size();
|
||||
// piCout << last_id << last_data.size();
|
||||
stream_.readRawData(last_data.data(), last_data.size());
|
||||
break;
|
||||
default: break;
|
||||
@@ -49,9 +47,7 @@ void ChunkStream::readAll() {
|
||||
}
|
||||
|
||||
|
||||
ChunkStream::~ChunkStream() {
|
||||
|
||||
}
|
||||
ChunkStream::~ChunkStream() {}
|
||||
|
||||
|
||||
void ChunkStream::_init() {
|
||||
@@ -66,7 +62,10 @@ void ChunkStream::_init() {
|
||||
if ((v & 0x80) == 0x80) {
|
||||
v &= 0x7f;
|
||||
switch (v) {
|
||||
case 2: version_ = (uchar)Version_2; stream_.skipRawData(1); break;
|
||||
case 2:
|
||||
version_ = (uchar)Version_2;
|
||||
stream_.skipRawData(1);
|
||||
break;
|
||||
default: version_ = Version_1; break;
|
||||
}
|
||||
} else
|
||||
@@ -77,15 +76,17 @@ void ChunkStream::_init() {
|
||||
|
||||
uint ChunkStream::readVInt(QDataStream & s) {
|
||||
if (s.atEnd()) return 0;
|
||||
uchar bytes[4]; s >> bytes[0];
|
||||
uchar bytes[4];
|
||||
s >> bytes[0];
|
||||
uchar abc = 0;
|
||||
for (abc = 0; abc < 3; ++abc) {
|
||||
uchar mask = (0x80 >> abc);
|
||||
if ((bytes[0] & mask) == mask) {
|
||||
//if (s.isEmpty()) return 0;
|
||||
// if (s.isEmpty()) return 0;
|
||||
bytes[0] &= (mask - 1);
|
||||
s >> bytes[abc + 1];
|
||||
} else break;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
uint ret = 0;
|
||||
for (int i = 0; i <= abc; ++i) {
|
||||
|
||||
@@ -1,89 +1,97 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHUNKSTREAM_H
|
||||
#define CHUNKSTREAM_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QBuffer>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include "qad_utils_export.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QByteArray>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
|
||||
class QAD_UTILS_EXPORT ChunkStream
|
||||
{
|
||||
|
||||
class QAD_UTILS_EXPORT ChunkStream {
|
||||
public:
|
||||
enum Version {
|
||||
Version_1 /*! First, old version */,
|
||||
Version_2 /*! Second, more optimized version */ = 2,
|
||||
};
|
||||
ChunkStream(const QByteArray & data): version_(Version_2) {setSource(data);}
|
||||
ChunkStream(QDataStream & str): version_(Version_2) {setSource(str);}
|
||||
ChunkStream(QByteArray * data = 0, Version v = Version_2): version_(v) {setSource(data);}
|
||||
ChunkStream(Version v): version_(v) {setSource(0);}
|
||||
ChunkStream(const QByteArray & data): version_(Version_2) { setSource(data); }
|
||||
ChunkStream(QDataStream & str): version_(Version_2) { setSource(str); }
|
||||
ChunkStream(QByteArray * data = 0, Version v = Version_2): version_(v) { setSource(data); }
|
||||
ChunkStream(Version v): version_(v) { setSource(0); }
|
||||
~ChunkStream();
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct Chunk {
|
||||
Chunk(int i, const T & d): id(i), data(d) {}
|
||||
int id;
|
||||
T data;
|
||||
};
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct ChunkConst {
|
||||
ChunkConst(int i, const T & d): id(i), data(d) {}
|
||||
int id;
|
||||
const T & data;
|
||||
};
|
||||
template <typename T> static ChunkConst<T> chunk(int id, const T & data) {return ChunkConst<T>(id, data);}
|
||||
template<typename T>
|
||||
static ChunkConst<T> chunk(int id, const T & data) {
|
||||
return ChunkConst<T>(id, data);
|
||||
}
|
||||
|
||||
template <typename T> ChunkStream & add(int id, const T & data) {*this << ChunkConst<T>(id, data); return *this;}
|
||||
template<typename T>
|
||||
ChunkStream & add(int id, const T & data) {
|
||||
*this << ChunkConst<T>(id, data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void setSource(const QByteArray & data);
|
||||
void setSource(QDataStream & str);
|
||||
void setSource(QByteArray * data);
|
||||
QDataStream & dataStream() {return stream_;}
|
||||
QByteArray data() const {return tmp_data;}
|
||||
bool atEnd() const {return stream_.atEnd();}
|
||||
Version version() const {return (Version)version_;}
|
||||
|
||||
QDataStream & dataStream() { return stream_; }
|
||||
QByteArray data() const { return tmp_data; }
|
||||
bool atEnd() const { return stream_.atEnd(); }
|
||||
Version version() const { return (Version)version_; }
|
||||
|
||||
|
||||
int read();
|
||||
void readAll();
|
||||
int getID() {return last_id;}
|
||||
int getID() { return last_id; }
|
||||
|
||||
template <typename T>
|
||||
void get(T & v) const {v = getData<T>();}
|
||||
template<typename T>
|
||||
void get(T & v) const {
|
||||
v = getData<T>();
|
||||
}
|
||||
|
||||
template <typename T> typename std::enable_if<!std::is_enum<T>::value, T>::type
|
||||
getData() const {
|
||||
template<typename T>
|
||||
typename std::enable_if<!std::is_enum<T>::value, T>::type getData() const {
|
||||
QDataStream s(last_data);
|
||||
s.setVersion(QDataStream::Qt_4_8);
|
||||
T ret;
|
||||
s >> ret;
|
||||
return ret;
|
||||
}
|
||||
template <typename T> typename std::enable_if<std::is_enum<T>::value, T>::type
|
||||
getData() const {
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_enum<T>::value, T>::type getData() const {
|
||||
QDataStream s(last_data);
|
||||
s.setVersion(QDataStream::Qt_4_8);
|
||||
typename std::underlying_type<T>::type ret;
|
||||
@@ -91,8 +99,8 @@ public:
|
||||
return (T)ret;
|
||||
}
|
||||
|
||||
template <typename T> typename std::enable_if<!std::is_enum<T>::value, const ChunkStream &>::type
|
||||
get(int id, T & v) const {
|
||||
template<typename T>
|
||||
typename std::enable_if<!std::is_enum<T>::value, const ChunkStream &>::type get(int id, T & v) const {
|
||||
QByteArray ba = data_map.value(id);
|
||||
if (!ba.isEmpty()) {
|
||||
QDataStream s(ba);
|
||||
@@ -101,8 +109,8 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T> typename std::enable_if<std::is_enum<T>::value, const ChunkStream &>::type
|
||||
get(int id, T & v) const {
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_enum<T>::value, const ChunkStream &>::type get(int id, T & v) const {
|
||||
QByteArray ba = data_map.value(id);
|
||||
if (!ba.isEmpty()) {
|
||||
QDataStream s(ba);
|
||||
@@ -122,53 +130,52 @@ private:
|
||||
|
||||
int last_id;
|
||||
uchar version_;
|
||||
QByteArray * data_, last_data, tmp_data;
|
||||
QByteArray *data_, last_data, tmp_data;
|
||||
QBuffer buffer;
|
||||
QDataStream stream_;
|
||||
QMap<int, QByteArray> data_map;
|
||||
|
||||
template <typename T> friend ChunkStream & operator <<(ChunkStream & s, const ChunkStream::Chunk<T> & c);
|
||||
template <typename T> friend ChunkStream & operator <<(ChunkStream & s, const ChunkStream::ChunkConst<T> & c);
|
||||
template<typename T>
|
||||
friend ChunkStream & operator<<(ChunkStream & s, const ChunkStream::Chunk<T> & c);
|
||||
template<typename T>
|
||||
friend ChunkStream & operator<<(ChunkStream & s, const ChunkStream::ChunkConst<T> & c);
|
||||
};
|
||||
|
||||
template <typename T> typename std::enable_if<!std::is_enum<T>::value, void>::type
|
||||
__writeChunkData(QByteArray & ba, const ChunkStream::Chunk<T> & c) {
|
||||
template<typename T>
|
||||
typename std::enable_if<!std::is_enum<T>::value, void>::type __writeChunkData(QByteArray & ba, const ChunkStream::Chunk<T> & c) {
|
||||
QDataStream bas(&ba, QIODevice::WriteOnly);
|
||||
bas.setVersion(QDataStream::Qt_4_8);
|
||||
bas << c.data;
|
||||
}
|
||||
template <typename T> typename std::enable_if<std::is_enum<T>::value, void>::type
|
||||
__writeChunkData(QByteArray & ba, const ChunkStream::Chunk<T> & c) {
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_enum<T>::value, void>::type __writeChunkData(QByteArray & ba, const ChunkStream::Chunk<T> & c) {
|
||||
QDataStream bas(&ba, QIODevice::WriteOnly);
|
||||
bas.setVersion(QDataStream::Qt_4_8);
|
||||
typename std::underlying_type<T>::type iv = c.data;
|
||||
bas << iv;
|
||||
}
|
||||
template <typename T> typename std::enable_if<!std::is_enum<T>::value, void>::type
|
||||
__writeChunkConstData(QByteArray & ba, const ChunkStream::ChunkConst<T> & c) {
|
||||
template<typename T>
|
||||
typename std::enable_if<!std::is_enum<T>::value, void>::type __writeChunkConstData(QByteArray & ba, const ChunkStream::ChunkConst<T> & c) {
|
||||
QDataStream bas(&ba, QIODevice::WriteOnly);
|
||||
bas.setVersion(QDataStream::Qt_4_8);
|
||||
bas << c.data;
|
||||
}
|
||||
template <typename T> typename std::enable_if<std::is_enum<T>::value, void>::type
|
||||
__writeChunkConstData(QByteArray & ba, const ChunkStream::ChunkConst<T> & c) {
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_enum<T>::value, void>::type __writeChunkConstData(QByteArray & ba, const ChunkStream::ChunkConst<T> & c) {
|
||||
QDataStream bas(&ba, QIODevice::WriteOnly);
|
||||
bas.setVersion(QDataStream::Qt_4_8);
|
||||
typename std::underlying_type<T>::type iv = c.data;
|
||||
bas << iv;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ChunkStream & operator <<(ChunkStream & s, const ChunkStream::Chunk<T> & c) {
|
||||
template<typename T>
|
||||
ChunkStream & operator<<(ChunkStream & s, const ChunkStream::Chunk<T> & c) {
|
||||
QByteArray ba;
|
||||
__writeChunkData(ba, c);
|
||||
switch (s.version_) {
|
||||
case ChunkStream::Version_1:
|
||||
s.stream_ << c.id << ba;
|
||||
break;
|
||||
case ChunkStream::Version_1: s.stream_ << c.id << ba; break;
|
||||
case ChunkStream::Version_2:
|
||||
if (s.data_->isEmpty())
|
||||
s.stream_ << uchar(uchar(s.version_) | 0x80);
|
||||
if (s.data_->isEmpty()) s.stream_ << uchar(uchar(s.version_) | 0x80);
|
||||
ChunkStream::writeVInt(s.stream_, c.id);
|
||||
ChunkStream::writeVInt(s.stream_, ba.size());
|
||||
s.stream_.writeRawData(ba.data(), ba.size());
|
||||
@@ -178,17 +185,14 @@ ChunkStream & operator <<(ChunkStream & s, const ChunkStream::Chunk<T> & c) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ChunkStream & operator <<(ChunkStream & s, const ChunkStream::ChunkConst<T> & c) {
|
||||
template<typename T>
|
||||
ChunkStream & operator<<(ChunkStream & s, const ChunkStream::ChunkConst<T> & c) {
|
||||
QByteArray ba;
|
||||
__writeChunkConstData(ba, c);
|
||||
switch (s.version_) {
|
||||
case ChunkStream::Version_1:
|
||||
s.stream_ << c.id << ba;
|
||||
break;
|
||||
case ChunkStream::Version_1: s.stream_ << c.id << ba; break;
|
||||
case ChunkStream::Version_2:
|
||||
if (s.data_->isEmpty())
|
||||
s.stream_ << uchar(uchar(s.version_) | 0x80);
|
||||
if (s.data_->isEmpty()) s.stream_ << uchar(uchar(s.version_) | 0x80);
|
||||
ChunkStream::writeVInt(s.stream_, c.id);
|
||||
ChunkStream::writeVInt(s.stream_, ba.size());
|
||||
s.stream_.writeRawData(ba.data(), ba.size());
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//#include "qpiconfigplugin.h"
|
||||
// #include "qpiconfigplugin.h"
|
||||
#include "qad_utils.h"
|
||||
|
||||
QADUtils::QADUtils(QObject * parent): QObject(parent) {
|
||||
//m_widgets.append(new QPIConfigPlugin(this));
|
||||
// m_widgets.append(new QPIConfigPlugin(this));
|
||||
}
|
||||
|
||||
|
||||
QList<QDesignerCustomWidgetInterface * > QADUtils::customWidgets() const {
|
||||
QList<QDesignerCustomWidgetInterface *> QADUtils::customWidgets() const {
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
#ifndef QAD_UTILS_H
|
||||
#define QAD_UTILS_H
|
||||
|
||||
#include <QtDesigner/QtDesigner>
|
||||
#include <QtCore/qplugin.h>
|
||||
#include <QtDesigner/QtDesigner>
|
||||
|
||||
class QADUtils: public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
class QADUtils
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetCollectionInterface {
|
||||
Q_OBJECT
|
||||
//Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
|
||||
// Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "qad.utils")
|
||||
#endif
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
|
||||
public:
|
||||
explicit QADUtils(QObject * parent = 0);
|
||||
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
|
||||
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const;
|
||||
|
||||
private:
|
||||
QList<QDesignerCustomWidgetInterface * > m_widgets;
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> m_widgets;
|
||||
};
|
||||
|
||||
#endif // QAD_UTILS_H
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QColor>
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
|
||||
PropertyStorage::PropertyStorage(const QVariantMap & pl) {
|
||||
QMapIterator<QString, QVariant> it(pl);
|
||||
@@ -13,7 +14,7 @@ PropertyStorage::PropertyStorage(const QVariantMap & pl) {
|
||||
|
||||
QVariantMap PropertyStorage::toVariantMap() const {
|
||||
QVariantMap ret;
|
||||
foreach (const Property & p, props)
|
||||
foreach(const Property & p, props)
|
||||
ret[p.name] = p.value;
|
||||
return ret;
|
||||
}
|
||||
@@ -21,8 +22,7 @@ QVariantMap PropertyStorage::toVariantMap() const {
|
||||
|
||||
bool PropertyStorage::isPropertyExists(const QString & _name) const {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == _name)
|
||||
return true;
|
||||
if (props[i].name == _name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,33 +57,29 @@ void PropertyStorage::removePropertiesByFlag(int flag) {
|
||||
|
||||
void PropertyStorage::updateProperties(const QList<PropertyStorage::Property> & properties_, int flag_ignore) {
|
||||
QVariantMap values;
|
||||
foreach (const PropertyStorage::Property & p, props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0))
|
||||
values[p.name] = p.value;
|
||||
foreach(const PropertyStorage::Property & p, props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0)) values[p.name] = p.value;
|
||||
props = properties_;
|
||||
for (int i = 0; i < props.size(); ++i) {
|
||||
PropertyStorage::Property & p(props[i]);
|
||||
if (values.contains(p.name)) {
|
||||
QVariant pv = values[p.name];
|
||||
if (pv.userType() == p.value.userType())
|
||||
p.value = pv;
|
||||
if (pv.userType() == p.value.userType()) p.value = pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PropertyStorage::Property PropertyStorage::propertyByName(const QString & name) const {
|
||||
foreach (const Property & p, props)
|
||||
if (p.name == name)
|
||||
return p;
|
||||
foreach(const Property & p, props)
|
||||
if (p.name == name) return p;
|
||||
return Property();
|
||||
}
|
||||
|
||||
|
||||
QVariant PropertyStorage::propertyValueByName(const QString & name) const {
|
||||
foreach (const Property & p, props)
|
||||
if (p.name == name)
|
||||
return p.value;
|
||||
foreach(const Property & p, props)
|
||||
if (p.name == name) return p.value;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@@ -120,8 +116,8 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
QString pn, pc, pt("s"), pv;
|
||||
if (l.contains('#')) {
|
||||
int i = l.indexOf('#');
|
||||
pn = l.left(i).trimmed();
|
||||
pc = l.right(l.length() - i - 1).trimmed();
|
||||
pn = l.left(i).trimmed();
|
||||
pc = l.right(l.length() - i - 1).trimmed();
|
||||
} else {
|
||||
if (l.contains('(')) {
|
||||
int bs = l.indexOf('('), be = l.indexOf(')');
|
||||
@@ -130,7 +126,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
l.remove(bs, be - bs + 1);
|
||||
} else {
|
||||
pc = l.right(l.length() - bs - 1).trimmed();
|
||||
l = l.left(bs);
|
||||
l = l.left(bs);
|
||||
}
|
||||
}
|
||||
pn = l.trimmed();
|
||||
@@ -141,36 +137,42 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
}
|
||||
if (pn.contains('=')) {
|
||||
int i = pn.indexOf('=');
|
||||
pv = pn.right(pn.length() - i - 1).trimmed();
|
||||
pv = pn.right(pn.length() - i - 1).trimmed();
|
||||
pn.truncate(i);
|
||||
pn = pn.trimmed();
|
||||
}
|
||||
ret.name = pn;
|
||||
ret.name = pn;
|
||||
ret.comment = pc;
|
||||
ret.value = QVariant(typeFromLetter(pt));
|
||||
ret.value = QVariant(typeFromLetter(pt));
|
||||
if (!pv.isEmpty()) {
|
||||
//qDebug() << "set value !" << pv;
|
||||
// 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;
|
||||
case QVariant::UInt: ret.value = pv.toUInt(); break;
|
||||
case QVariant::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QVariant::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QVariant::Double: ret.value = pv.toDouble(); break;
|
||||
case QVariant::Color: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
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;
|
||||
case QVariant::UInt: ret.value = pv.toUInt(); break;
|
||||
case QVariant::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QVariant::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QVariant::Double: ret.value = pv.toDouble(); break;
|
||||
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;
|
||||
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
|
||||
}
|
||||
@@ -180,8 +182,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
|
||||
PropertyStorage::Property & PropertyStorage::operator[](const QString & name) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name)
|
||||
return props[i];
|
||||
if (props[i].name == name) return props[i];
|
||||
addProperty(name, "");
|
||||
return props.back();
|
||||
}
|
||||
@@ -189,7 +190,6 @@ PropertyStorage::Property & PropertyStorage::operator[](const QString & name) {
|
||||
|
||||
const PropertyStorage::Property PropertyStorage::operator[](const QString & name) const {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name)
|
||||
return props[i];
|
||||
if (props[i].name == name) return props[i];
|
||||
return Property();
|
||||
}
|
||||
|
||||
@@ -1,92 +1,98 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROPERTYSTORAGE_H
|
||||
#define PROPERTYSTORAGE_H
|
||||
|
||||
#include "chunkstream.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLineF>
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QLineF>
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
#include "chunkstream.h"
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class QAD_UTILS_EXPORT PropertyStorage {
|
||||
public:
|
||||
PropertyStorage() {}
|
||||
|
||||
|
||||
struct QAD_UTILS_EXPORT Property {
|
||||
Property(const QString & n = QString(), const QString & c = QString(), const QVariant & v = QVariant(), int f = 0):
|
||||
name(n), comment(c), value(v), flags(f) {}
|
||||
bool toBool() const {return value.toBool();}
|
||||
int toInt() const {return value.toInt();}
|
||||
float toFloat() const {return value.toFloat();}
|
||||
double toDouble() const {return value.toDouble();}
|
||||
QString toString() const {return value.toString();}
|
||||
Property(const QString & n = QString(), const QString & c = QString(), const QVariant & v = QVariant(), int f = 0)
|
||||
: name(n)
|
||||
, comment(c)
|
||||
, value(v)
|
||||
, flags(f) {}
|
||||
bool toBool() const { return value.toBool(); }
|
||||
int toInt() const { return value.toInt(); }
|
||||
float toFloat() const { return value.toFloat(); }
|
||||
double toDouble() const { return value.toDouble(); }
|
||||
QString toString() const { return value.toString(); }
|
||||
QString name;
|
||||
QString comment;
|
||||
QVariant value;
|
||||
int flags;
|
||||
};
|
||||
|
||||
PropertyStorage(const QList<Property> & pl) {props = pl;}
|
||||
|
||||
PropertyStorage(const QList<Property> & pl) { props = pl; }
|
||||
PropertyStorage(const QVariantMap & pl);
|
||||
|
||||
|
||||
typedef QList<Property>::const_iterator const_iterator;
|
||||
typedef QList<Property>::iterator iterator;
|
||||
|
||||
iterator begin() {return props.begin();}
|
||||
const_iterator begin() const {return props.begin();}
|
||||
iterator end() {return props.end();}
|
||||
const_iterator end() const {return props.end();}
|
||||
|
||||
int count() const {return props.count();}
|
||||
int length() const {return props.length();}
|
||||
int size() const {return props.size();}
|
||||
bool isEmpty() const {return props.isEmpty();}
|
||||
Property & first() {return props.first();}
|
||||
const Property & first() const {return props.first();}
|
||||
Property & front() {return props.front();}
|
||||
const Property & front() const {return props.front();}
|
||||
Property & last() {return props.last();}
|
||||
const Property & last() const {return props.last();}
|
||||
Property & back() {return props.back();}
|
||||
const Property & back() const {return props.back();}
|
||||
void removeFirst() {props.removeFirst();}
|
||||
void removeLast() {props.removeLast();}
|
||||
void removeAt(int i) {props.removeAt(i);}
|
||||
Property value(int i) const {return props.value(i);}
|
||||
Property value(int i, const Property & defaultValue) const {return props.value(i, defaultValue);}
|
||||
void clear() {props.clear();}
|
||||
|
||||
PropertyStorage copy() const {return PropertyStorage(*this);}
|
||||
int propertiesCount() const {return props.size();}
|
||||
QList<Property> & properties() {return props;}
|
||||
const QList<Property> & properties() const {return props;}
|
||||
const PropertyStorage & propertyStorage() const {return *this;}
|
||||
|
||||
iterator begin() { return props.begin(); }
|
||||
const_iterator begin() const { return props.begin(); }
|
||||
iterator end() { return props.end(); }
|
||||
const_iterator end() const { return props.end(); }
|
||||
|
||||
int count() const { return props.count(); }
|
||||
int length() const { return props.length(); }
|
||||
int size() const { return props.size(); }
|
||||
bool isEmpty() const { return props.isEmpty(); }
|
||||
Property & first() { return props.first(); }
|
||||
const Property & first() const { return props.first(); }
|
||||
Property & front() { return props.front(); }
|
||||
const Property & front() const { return props.front(); }
|
||||
Property & last() { return props.last(); }
|
||||
const Property & last() const { return props.last(); }
|
||||
Property & back() { return props.back(); }
|
||||
const Property & back() const { return props.back(); }
|
||||
void removeFirst() { props.removeFirst(); }
|
||||
void removeLast() { props.removeLast(); }
|
||||
void removeAt(int i) { props.removeAt(i); }
|
||||
Property value(int i) const { return props.value(i); }
|
||||
Property value(int i, const Property & defaultValue) const { return props.value(i, defaultValue); }
|
||||
void clear() { props.clear(); }
|
||||
|
||||
PropertyStorage copy() const { return PropertyStorage(*this); }
|
||||
int propertiesCount() const { return props.size(); }
|
||||
QList<Property> & properties() { return props; }
|
||||
const QList<Property> & properties() const { return props; }
|
||||
const PropertyStorage & propertyStorage() const { return *this; }
|
||||
QVariantMap toVariantMap() const;
|
||||
bool isPropertyExists(const QString & _name) const;
|
||||
void clearProperties() {props.clear();}
|
||||
void clearProperties() { props.clear(); }
|
||||
void addProperty(const Property & p);
|
||||
void addProperty(const QString & _name, const QVariant & _def_value, const QString & _comment = QString(), int _flags = 0) {addProperty(Property(_name, _comment, _def_value, _flags));}
|
||||
void addProperty(const QString & _name, const QVariant & _def_value, const QString & _comment = QString(), int _flags = 0) {
|
||||
addProperty(Property(_name, _comment, _def_value, _flags));
|
||||
}
|
||||
void removeProperty(const QString & _name);
|
||||
void removePropertiesByFlag(int flag);
|
||||
void updateProperties(const QList<Property> & properties_, int flag_ignore = 0);
|
||||
@@ -95,31 +101,42 @@ public:
|
||||
void setPropertyValue(const QString & name, const QVariant & value);
|
||||
void setPropertyComment(const QString & name, const QString & comment);
|
||||
void setPropertyFlags(const QString & name, int flags);
|
||||
|
||||
PropertyStorage & operator <<(const PropertyStorage::Property & p) {props << p; return *this;}
|
||||
PropertyStorage & operator <<(const QList<Property> & p) {props << p; return *this;}
|
||||
PropertyStorage & operator <<(const PropertyStorage & p) {props << p.props; return *this;}
|
||||
Property & operator[](int i) {return props[i];}
|
||||
const Property & operator[](int i) const {return props[i];}
|
||||
|
||||
PropertyStorage & operator<<(const PropertyStorage::Property & p) {
|
||||
props << p;
|
||||
return *this;
|
||||
}
|
||||
PropertyStorage & operator<<(const QList<Property> & p) {
|
||||
props << p;
|
||||
return *this;
|
||||
}
|
||||
PropertyStorage & operator<<(const PropertyStorage & p) {
|
||||
props << p.props;
|
||||
return *this;
|
||||
}
|
||||
Property & operator[](int i) { return props[i]; }
|
||||
const Property & operator[](int i) const { return props[i]; }
|
||||
Property & operator[](const QString & name);
|
||||
const Property operator[](const QString & name) const;
|
||||
|
||||
static Property parsePropertyLine(QString l);
|
||||
|
||||
|
||||
protected:
|
||||
QList<Property> props;
|
||||
|
||||
};
|
||||
|
||||
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 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::Property & p) {
|
||||
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);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, PropertyStorage::Property & p) {
|
||||
inline QDataStream & operator>>(QDataStream & s, PropertyStorage::Property & p) {
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
@@ -132,8 +149,14 @@ 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;}
|
||||
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
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "qad_locations.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QTranslator>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
# include <QStandardPaths>
|
||||
#else
|
||||
@@ -17,10 +18,11 @@
|
||||
|
||||
class __QADTranslators__ {
|
||||
public:
|
||||
static QList<QTranslator * > & translators() {
|
||||
static QList<QTranslator * > ret;
|
||||
static QList<QTranslator *> & translators() {
|
||||
static QList<QTranslator *> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -29,25 +31,24 @@ QString QAD::userPath(QAD::LocationType loc, QString name) {
|
||||
QString dir, ext;
|
||||
switch (loc) {
|
||||
case ltConfig: ext = ".conf"; break;
|
||||
case ltCache : ext = ".cache"; break;
|
||||
case ltCache: ext = ".cache"; break;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QStandardPaths::StandardLocation l = QStandardPaths::AppConfigLocation;
|
||||
switch (loc) {
|
||||
case ltConfig: l = QStandardPaths::AppConfigLocation; break;
|
||||
case ltCache : l = QStandardPaths::CacheLocation; break;
|
||||
case ltCache: l = QStandardPaths::CacheLocation; break;
|
||||
}
|
||||
dir = QStandardPaths::writableLocation(l);
|
||||
#else
|
||||
QDesktopServices::StandardLocation l = QDesktopServices::DataLocation;
|
||||
switch (loc) {
|
||||
case ltConfig: l = QDesktopServices::DataLocation; break;
|
||||
case ltCache : l = QDesktopServices::CacheLocation; break;
|
||||
case ltCache: l = QDesktopServices::CacheLocation; break;
|
||||
}
|
||||
dir = QDesktopServices::storageLocation(l);
|
||||
#endif
|
||||
if (!QDir(dir).exists())
|
||||
QDir().mkpath(dir);
|
||||
if (!QDir(dir).exists()) QDir().mkpath(dir);
|
||||
return dir + "/" + name + ext;
|
||||
}
|
||||
|
||||
@@ -70,22 +71,20 @@ QStringList QAD::resourcePaths(QString type) {
|
||||
|
||||
void QAD::loadTranslations(QString lang) {
|
||||
unloadTranslations();
|
||||
if (lang.isEmpty())
|
||||
lang = QLocale().bcp47Name();
|
||||
if (lang.isEmpty()) lang = QLocale().bcp47Name();
|
||||
QString short_lang = lang.left(2);
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
QStringList dirs = resourcePaths("lang");
|
||||
for (const QString & d: dirs) {
|
||||
QDirIterator dit(d);
|
||||
while (dit.hasNext()) {
|
||||
dit.next();
|
||||
if (!dit.filePath().endsWith(".qm")) continue;
|
||||
if (!dit.fileInfo().baseName().endsWith(lang) &&
|
||||
!dit.fileInfo().baseName().endsWith(short_lang)) continue;
|
||||
if (!dit.fileInfo().baseName().endsWith(lang) && !dit.fileInfo().baseName().endsWith(short_lang)) continue;
|
||||
QTranslator * tr = new QTranslator();
|
||||
if (tr->load(dit.filePath())) {
|
||||
qApp->installTranslator(tr);
|
||||
__QADTranslators__::translators() << tr;
|
||||
//qDebug() << "Add tr" << dit.fileName();
|
||||
// qDebug() << "Add tr" << dit.fileName();
|
||||
} else {
|
||||
qDebug() << "Can`t load translation" << dit.fileName();
|
||||
delete tr;
|
||||
@@ -96,14 +95,13 @@ void QAD::loadTranslations(QString lang) {
|
||||
|
||||
|
||||
void QAD::unloadTranslations() {
|
||||
//qDebug() << "removeTranslator ...";
|
||||
// qDebug() << "removeTranslator ...";
|
||||
for (QTranslator * t: __QADTranslators__::translators()) {
|
||||
qApp->removeTranslator(t);
|
||||
delete t;
|
||||
}
|
||||
__QADTranslators__::translators().clear();
|
||||
//qDebug() << "removeTranslator done";
|
||||
|
||||
// qDebug() << "removeTranslator done";
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +127,7 @@ QStringList QAD::availableTranslations() {
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
QLocale loc(lang[i]);
|
||||
if (loc.language() != QLocale::C)
|
||||
ret << lang[i];
|
||||
if (loc.language() != QLocale::C) ret << lang[i];
|
||||
}
|
||||
}
|
||||
delete tr;
|
||||
|
||||
@@ -1,60 +1,61 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QAD_LOCATIONS_H
|
||||
#define QAD_LOCATIONS_H
|
||||
|
||||
#include <QString>
|
||||
#include "qad_utils_export.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace QAD {
|
||||
|
||||
enum LocationType {
|
||||
ltConfig,
|
||||
ltCache,
|
||||
};
|
||||
enum LocationType {
|
||||
ltConfig,
|
||||
ltCache,
|
||||
};
|
||||
|
||||
//! Create QStandardPaths::writableLocation(<loc>) directory
|
||||
//! and returns file name "<name>.<ext>".
|
||||
//! Extension is selected by "loc":
|
||||
//! * ltConfig - "conf"
|
||||
//! * ltCache - "cache"
|
||||
QAD_UTILS_EXPORT QString userPath(LocationType loc, QString name = QString());
|
||||
//! Create QStandardPaths::writableLocation(<loc>) directory
|
||||
//! and returns file name "<name>.<ext>".
|
||||
//! Extension is selected by "loc":
|
||||
//! * ltConfig - "conf"
|
||||
//! * ltCache - "cache"
|
||||
QAD_UTILS_EXPORT QString userPath(LocationType loc, QString name = QString());
|
||||
|
||||
|
||||
//! Returns search directories for resource "type"
|
||||
//! * <applicationDirPath>/<type> presents on all platforms
|
||||
//! * :/<type> on mobile platforms
|
||||
//! * <.app>/Resources/<type> on MacOS
|
||||
//! * /usr/share/[organizationName/]<applicationName>/<type> on Linux
|
||||
QAD_UTILS_EXPORT QStringList resourcePaths(QString type);
|
||||
//! Returns search directories for resource "type"
|
||||
//! * <applicationDirPath>/<type> presents on all platforms
|
||||
//! * :/<type> on mobile platforms
|
||||
//! * <.app>/Resources/<type> on MacOS
|
||||
//! * /usr/share/[organizationName/]<applicationName>/<type> on Linux
|
||||
QAD_UTILS_EXPORT QStringList resourcePaths(QString type);
|
||||
|
||||
|
||||
QAD_UTILS_EXPORT void loadTranslations(QString lang = QString());
|
||||
QAD_UTILS_EXPORT void unloadTranslations();
|
||||
QAD_UTILS_EXPORT void loadTranslations(QString lang = QString());
|
||||
QAD_UTILS_EXPORT void unloadTranslations();
|
||||
|
||||
|
||||
QAD_UTILS_EXPORT QStringList availableTranslations();
|
||||
|
||||
|
||||
}
|
||||
QAD_UTILS_EXPORT QStringList availableTranslations();
|
||||
|
||||
|
||||
} // namespace QAD
|
||||
|
||||
|
||||
#endif // QAD_LOCATIONS_H
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
#include <QMetaEnum>
|
||||
#include <QWidget>
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QWindow>
|
||||
# include <QScreen>
|
||||
# include <QWindow>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -16,7 +17,7 @@ __QADTypesRegistrator__::__QADTypesRegistrator__(int) {
|
||||
instance()->_inited = true;
|
||||
}
|
||||
|
||||
__QADTypesRegistrator__ *__QADTypesRegistrator__::instance() {
|
||||
__QADTypesRegistrator__ * __QADTypesRegistrator__::instance() {
|
||||
static __QADTypesRegistrator__ ret;
|
||||
return &ret;
|
||||
}
|
||||
@@ -65,7 +66,7 @@ QAD::Enum::Enum(const QMetaEnum & meta, int selected) {
|
||||
|
||||
|
||||
int QAD::Enum::selectedValue() const {
|
||||
for (const Enumerator & e : enum_list) {
|
||||
for (const Enumerator & e: enum_list) {
|
||||
if (e.name == selected) return e.value;
|
||||
}
|
||||
return 0;
|
||||
@@ -73,7 +74,7 @@ int QAD::Enum::selectedValue() const {
|
||||
|
||||
|
||||
bool QAD::Enum::selectValue(int v) {
|
||||
for (const Enumerator & e : enum_list) {
|
||||
for (const Enumerator & e: enum_list) {
|
||||
if (e.value == v) {
|
||||
selected = e.name;
|
||||
return true;
|
||||
@@ -84,7 +85,7 @@ bool QAD::Enum::selectValue(int v) {
|
||||
|
||||
|
||||
bool QAD::Enum::selectName(const QString & n) {
|
||||
for (const Enumerator & e : enum_list) {
|
||||
for (const Enumerator & e: enum_list) {
|
||||
if (e.name == n) {
|
||||
selected = e.name;
|
||||
return true;
|
||||
@@ -95,7 +96,7 @@ bool QAD::Enum::selectName(const QString & n) {
|
||||
|
||||
|
||||
int QAD::Enum::value(const QString & n) const {
|
||||
for (const Enumerator & e : enum_list) {
|
||||
for (const Enumerator & e: enum_list) {
|
||||
if (e.name == n) return e.value;
|
||||
}
|
||||
return 0;
|
||||
@@ -103,7 +104,7 @@ int QAD::Enum::value(const QString & n) const {
|
||||
|
||||
|
||||
QString QAD::Enum::name(int v) const {
|
||||
for (const Enumerator & e : enum_list) {
|
||||
for (const Enumerator & e: enum_list) {
|
||||
if (e.value == v) return e.name;
|
||||
}
|
||||
return QString();
|
||||
@@ -112,38 +113,39 @@ QString QAD::Enum::name(int v) const {
|
||||
|
||||
QList<int> QAD::Enum::values() const {
|
||||
QList<int> ret;
|
||||
for (const Enumerator & e : enum_list) ret << e.value;
|
||||
for (const Enumerator & e: enum_list)
|
||||
ret << e.value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QStringList QAD::Enum::names() const {
|
||||
QStringList ret;
|
||||
for (const Enumerator & e : enum_list) ret << e.name;
|
||||
for (const Enumerator & e: enum_list)
|
||||
ret << e.name;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QAD::Enum & QAD::Enum::operator <<(const QAD::Enumerator & v) {
|
||||
QAD::Enum & QAD::Enum::operator<<(const QAD::Enumerator & v) {
|
||||
enum_list << v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
QAD::Enum & QAD::Enum::operator <<(const QString & v) {
|
||||
QAD::Enum & QAD::Enum::operator<<(const QString & v) {
|
||||
enum_list << Enumerator(enum_list.size(), v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
QAD::Enum & QAD::Enum::operator <<(const QStringList & v) {
|
||||
for (const QString & s : v) (*this) << s;
|
||||
QAD::Enum & QAD::Enum::operator<<(const QStringList & v) {
|
||||
for (const QString & s: v)
|
||||
(*this) << s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QString QAD::IODevice::toString() const {
|
||||
QString s;
|
||||
if (__QADTypesRegistrator__::instance()->toString_funcs.contains(qMetaTypeId<QAD::IODevice>())) {
|
||||
@@ -155,14 +157,12 @@ QString QAD::IODevice::toString() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QVariant::Type
|
||||
#else
|
||||
QMetaType
|
||||
#endif
|
||||
typeFromLetter(const QString & l) {
|
||||
typeFromLetter(const QString & l) {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
if (l.isEmpty()) return QVariant::String;
|
||||
QString ft = l.left(1);
|
||||
@@ -185,19 +185,19 @@ QMetaType
|
||||
#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 == "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>();
|
||||
@@ -212,10 +212,11 @@ QString uniqueName(QString n, const QStringList & names) {
|
||||
if (n.right(1)[0].isDigit()) {
|
||||
num.push_front(n.right(1));
|
||||
n.chop(1);
|
||||
} else break;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (!n.endsWith('_') && num.isEmpty()) n += '_';
|
||||
int in = num.toInt() + 1;
|
||||
int in = num.toInt() + 1;
|
||||
QString nn = n + QString::number(in);
|
||||
while (names.contains(nn))
|
||||
nn = n + QString::number(++in);
|
||||
@@ -233,7 +234,7 @@ int fontHeight(const QWidget * window) {
|
||||
# else
|
||||
double add_scale = 1.0;
|
||||
# endif
|
||||
//qDebug() << "fontHeight" << w;
|
||||
// qDebug() << "fontHeight" << w;
|
||||
if (window) {
|
||||
QWidget * pw = window->window();
|
||||
if (pw) return QFontMetrics(pw->font()).height() * add_scale;
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QAD_TYPES_H
|
||||
#define QAD_TYPES_H
|
||||
|
||||
#include <QApplication>
|
||||
#include "propertystorage.h"
|
||||
#include "qad_utils_export.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
//! Set QCoreApplication properties from CMake "deploy_properties"
|
||||
//! Affect applicationName, organizationName and applicationVersion
|
||||
#define QAD_SETUP_APPLICATION \
|
||||
QCoreApplication::setApplicationName(__TARGET_NAME__); \
|
||||
#define QAD_SETUP_APPLICATION \
|
||||
QCoreApplication::setApplicationName(__TARGET_NAME__); \
|
||||
QCoreApplication::setOrganizationName(__TARGET_COMPANY__); \
|
||||
QCoreApplication::setApplicationVersion(__TARGET_VERSION__);
|
||||
|
||||
@@ -35,7 +36,7 @@
|
||||
# define QT_MID_BUTTON Qt::MidButton
|
||||
# include <QMapIterator>
|
||||
template<typename K, typename T>
|
||||
using QMultiMapIterator = QMapIterator<K,T>;
|
||||
using QMultiMapIterator = QMapIterator<K, T>;
|
||||
#else
|
||||
# define QT_MID_BUTTON Qt::MiddleButton
|
||||
#endif
|
||||
@@ -46,133 +47,211 @@ class QMetaEnum;
|
||||
|
||||
namespace QAD {
|
||||
|
||||
struct QAD_UTILS_EXPORT Enumerator {
|
||||
Enumerator(int v = 0, const QString & n = QString()): value(v), name(n) {}
|
||||
int value;
|
||||
QString name;
|
||||
};
|
||||
struct QAD_UTILS_EXPORT Enumerator {
|
||||
Enumerator(int v = 0, const QString & n = QString()): value(v), name(n) {}
|
||||
int value;
|
||||
QString name;
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT Enum {
|
||||
Enum(const QString & n = QString()): enum_name(n) {}
|
||||
Enum(const QMetaEnum & meta, int selected = 0);
|
||||
int selectedValue() const;
|
||||
QString selectedName() const {return selected;}
|
||||
bool selectValue(int v);
|
||||
bool selectName(const QString & n);
|
||||
int value(const QString & n) const;
|
||||
QString name(int v) const;
|
||||
QList<int> values() const;
|
||||
QStringList names() const;
|
||||
int size() const {return enum_list.size();}
|
||||
QString enum_name;
|
||||
QString selected;
|
||||
QList<Enumerator> enum_list;
|
||||
Enum & operator <<(const Enumerator & v);
|
||||
Enum & operator <<(const QString & v);
|
||||
Enum & operator <<(const QStringList & v);
|
||||
};
|
||||
struct QAD_UTILS_EXPORT Enum {
|
||||
Enum(const QString & n = QString()): enum_name(n) {}
|
||||
Enum(const QMetaEnum & meta, int selected = 0);
|
||||
int selectedValue() const;
|
||||
QString selectedName() const { return selected; }
|
||||
bool selectValue(int v);
|
||||
bool selectName(const QString & n);
|
||||
int value(const QString & n) const;
|
||||
QString name(int v) const;
|
||||
QList<int> values() const;
|
||||
QStringList names() const;
|
||||
int size() const { return enum_list.size(); }
|
||||
QString enum_name;
|
||||
QString selected;
|
||||
QList<Enumerator> enum_list;
|
||||
Enum & operator<<(const Enumerator & v);
|
||||
Enum & operator<<(const QString & v);
|
||||
Enum & operator<<(const QStringList & v);
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT File {
|
||||
File(const QString & p = QString(), const QString & f = QString(), bool abs = false, bool save_mode = false):
|
||||
file(p), filter(f), is_abs(abs), is_save(save_mode) {}
|
||||
QString toString() const {return file;}
|
||||
QString file;
|
||||
QString filter;
|
||||
bool is_abs;
|
||||
bool is_save;
|
||||
};
|
||||
struct QAD_UTILS_EXPORT File {
|
||||
File(const QString & p = QString(), const QString & f = QString(), bool abs = false, bool save_mode = false)
|
||||
: file(p)
|
||||
, filter(f)
|
||||
, is_abs(abs)
|
||||
, is_save(save_mode) {}
|
||||
QString toString() const { return file; }
|
||||
QString file;
|
||||
QString filter;
|
||||
bool is_abs;
|
||||
bool is_save;
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT Dir {
|
||||
Dir(const QString & d = QString(), bool abs = false):
|
||||
dir(d), is_abs(abs) {}
|
||||
QString toString() const {return dir;}
|
||||
QString dir;
|
||||
bool is_abs;
|
||||
};
|
||||
struct QAD_UTILS_EXPORT Dir {
|
||||
Dir(const QString & d = QString(), bool abs = false): dir(d), is_abs(abs) {}
|
||||
QString toString() const { return dir; }
|
||||
QString dir;
|
||||
bool is_abs;
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT IODevice {
|
||||
IODevice(const QString & device_prefix = QString(), const PropertyStorage & device_properties = PropertyStorage(),
|
||||
int open_mode = QIODevice::ReadWrite, int device_options = 0)
|
||||
: prefix(device_prefix), mode(open_mode), options(device_options), props(device_properties) {}
|
||||
QString toString() const;
|
||||
bool isValid() const {return !prefix.isEmpty();}
|
||||
QString prefix;
|
||||
int mode;
|
||||
int options;
|
||||
PropertyStorage props;
|
||||
};
|
||||
struct QAD_UTILS_EXPORT IODevice {
|
||||
IODevice(const QString & device_prefix = QString(),
|
||||
const PropertyStorage & device_properties = PropertyStorage(),
|
||||
int open_mode = QIODevice::ReadWrite,
|
||||
int device_options = 0)
|
||||
: prefix(device_prefix)
|
||||
, mode(open_mode)
|
||||
, options(device_options)
|
||||
, props(device_properties) {}
|
||||
QString toString() const;
|
||||
bool isValid() const { return !prefix.isEmpty(); }
|
||||
QString prefix;
|
||||
int mode;
|
||||
int options;
|
||||
PropertyStorage props;
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT MathVector {
|
||||
MathVector(const QVector<double> & vec = QVector<double>()) {v = vec;}
|
||||
QVector<double> v;
|
||||
};
|
||||
struct QAD_UTILS_EXPORT MathVector {
|
||||
MathVector(const QVector<double> & vec = QVector<double>()) { v = vec; }
|
||||
QVector<double> v;
|
||||
};
|
||||
|
||||
struct QAD_UTILS_EXPORT MathMatrix {
|
||||
MathMatrix(const QVector<QVector<double> > & mat = QVector<QVector<double> > ()) {m = mat;}
|
||||
QVector<QVector<double> > m; // [Row][Column]
|
||||
};
|
||||
struct QAD_UTILS_EXPORT MathMatrix {
|
||||
MathMatrix(const QVector<QVector<double>> & mat = QVector<QVector<double>>()) { m = mat; }
|
||||
QVector<QVector<double>> m; // [Row][Column]
|
||||
};
|
||||
|
||||
class QAD_UTILS_EXPORT CursorOverrider {
|
||||
public:
|
||||
CursorOverrider(const QCursor & c = Qt::WaitCursor) {QApplication::setOverrideCursor(c);}
|
||||
~CursorOverrider() {QApplication::restoreOverrideCursor();}
|
||||
};
|
||||
class QAD_UTILS_EXPORT CursorOverrider {
|
||||
public:
|
||||
CursorOverrider(const QCursor & c = Qt::WaitCursor) { QApplication::setOverrideCursor(c); }
|
||||
~CursorOverrider() { QApplication::restoreOverrideCursor(); }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace QAD
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::Enumerator)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::Enumerator & v) {s << v.value << v.name; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::Enumerator & v) {s >> v.value >> v.name; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::Enumerator & v) {s.nospace() << v.name << "(" << v.value << ")"; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::Enumerator & v) {
|
||||
s << v.value << v.name;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::Enumerator & v) {
|
||||
s >> v.value >> v.name;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::Enumerator & v) {
|
||||
s.nospace() << v.name << "(" << v.value << ")";
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::Enum)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::Enum & v) {s << v.enum_name << v.selected << v.enum_list; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::Enum & v) {s >> v.enum_name >> v.selected >> v.enum_list; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::Enum & v) {s.nospace() << v.selected; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::Enum & v) {
|
||||
s << v.enum_name << v.selected << v.enum_list;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::Enum & v) {
|
||||
s >> v.enum_name >> v.selected >> v.enum_list;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::Enum & v) {
|
||||
s.nospace() << v.selected;
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::File)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::File & v) {s << v.file << v.filter << uchar((v.is_abs ? 1 : 0) + (v.is_save ? 2 : 0)); return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::File & v) {uchar f(0); s >> v.file >> v.filter >> f; v.is_abs = ((f & 1) == 1); v.is_save = ((f & 2) == 2); return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::File & v) {s.nospace() << v.file; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::File & v) {
|
||||
s << v.file << v.filter << uchar((v.is_abs ? 1 : 0) + (v.is_save ? 2 : 0));
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::File & v) {
|
||||
uchar f(0);
|
||||
s >> v.file >> v.filter >> f;
|
||||
v.is_abs = ((f & 1) == 1);
|
||||
v.is_save = ((f & 2) == 2);
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::File & v) {
|
||||
s.nospace() << v.file;
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::Dir)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::Dir & v) {s << v.dir << v.is_abs; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::Dir & v) {s >> v.dir >> v.is_abs; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::Dir & v) {s.nospace() << v.dir; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::Dir & v) {
|
||||
s << v.dir << v.is_abs;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::Dir & v) {
|
||||
s >> v.dir >> v.is_abs;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::Dir & v) {
|
||||
s.nospace() << v.dir;
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::IODevice)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::IODevice & v) {s << v.prefix << v.mode << v.options << v.props; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::IODevice & v) {s.nospace() << v.toString(); return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::IODevice & v) {
|
||||
s << v.prefix << v.mode << v.options << v.props;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::IODevice & v) {
|
||||
s >> v.prefix >> v.mode >> v.options >> v.props;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::IODevice & v) {
|
||||
s.nospace() << v.toString();
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::MathVector)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::MathVector & v) {s << v.v; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::MathVector & v) {s >> v.v; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::MathVector & v) {s.nospace() << "Vector " << v.v; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::MathVector & v) {
|
||||
s << v.v;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::MathVector & v) {
|
||||
s >> v.v;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::MathVector & v) {
|
||||
s.nospace() << "Vector " << v.v;
|
||||
return s.space();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QAD::MathMatrix)
|
||||
inline QDataStream & operator <<(QDataStream & s, const QAD::MathMatrix & v) {s << v.m; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, QAD::MathMatrix & v) {s >> v.m; return s;}
|
||||
inline QDebug operator <<(QDebug s, const QAD::MathMatrix & v) {s.nospace() << "Matrix " << v.m; return s.space();}
|
||||
inline QDataStream & operator<<(QDataStream & s, const QAD::MathMatrix & v) {
|
||||
s << v.m;
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, QAD::MathMatrix & v) {
|
||||
s >> v.m;
|
||||
return s;
|
||||
}
|
||||
inline QDebug operator<<(QDebug s, const QAD::MathMatrix & v) {
|
||||
s.nospace() << "Matrix " << v.m;
|
||||
return s.space();
|
||||
}
|
||||
|
||||
|
||||
class QAD_UTILS_EXPORT __QADTypesRegistrator__ {
|
||||
public:
|
||||
__QADTypesRegistrator__(int);
|
||||
static __QADTypesRegistrator__ * instance();
|
||||
QMap<int, void(*)(const QVariant &, QString &)> toString_funcs;
|
||||
QMap<int, void (*)(const QVariant &, QString &)> toString_funcs;
|
||||
|
||||
private:
|
||||
__QADTypesRegistrator__();
|
||||
static bool _inited;
|
||||
};
|
||||
|
||||
|
||||
inline qreal quantize(qreal x, qreal q = 10.f) {return qRound(x / q) * q;}
|
||||
inline QPointF quantize(QPointF x, qreal q = 10.f) {return QPointF(quantize(x.x(), q), quantize(x.y(), q));}
|
||||
inline qreal quantize(qreal x, qreal q = 10.f) {
|
||||
return qRound(x / q) * q;
|
||||
}
|
||||
inline QPointF quantize(QPointF x, qreal q = 10.f) {
|
||||
return QPointF(quantize(x.x(), q), quantize(x.y(), q));
|
||||
}
|
||||
|
||||
inline qreal distPointToLine(const QPointF & lp0, const QPointF & lp1, const QPointF & p) {
|
||||
QLineF a(lp0, lp1), b(lp0, p), c(lp1, p);
|
||||
qreal f = qAbs(a.dx()*b.dy() - a.dy()*b.dx()) / a.length(), s = b.length() + c.length() - a.length();
|
||||
qreal f = qAbs(a.dx() * b.dy() - a.dy() * b.dx()) / a.length(), s = b.length() + c.length() - a.length();
|
||||
return qMax(f, s);
|
||||
}
|
||||
inline QPointF nearestPointOnLine(const QPointF & lp0, const QPointF & lp1, const QPointF & p) {
|
||||
@@ -180,10 +259,11 @@ inline QPointF nearestPointOnLine(const QPointF & lp0, const QPointF & lp1, cons
|
||||
return a.pointAt(b.length() / a.length());
|
||||
}
|
||||
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);
|
||||
return QRectF(r.left() - v + dx, r.top() - v + dy, r.width() + v + v, r.height() + v + v);
|
||||
}
|
||||
|
||||
template <typename T> QSet<T> QList2QSet(const QList<T> & 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
|
||||
@@ -191,17 +271,16 @@ template <typename T> QSet<T> QList2QSet(const QList<T> & l) {
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename K, typename T>
|
||||
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();
|
||||
if (!into.contains(it.key())) into[it.key()] = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename T>
|
||||
template<typename K, typename T>
|
||||
void addToMapOverwrite(QMap<K, T> & into, const QMap<K, T> & what) {
|
||||
QMapIterator<K, T> it(what);
|
||||
while (it.hasNext()) {
|
||||
@@ -212,11 +291,11 @@ void addToMapOverwrite(QMap<K, T> & into, const QMap<K, T> & what) {
|
||||
|
||||
QAD_UTILS_EXPORT
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QVariant::Type
|
||||
QVariant::Type
|
||||
#else
|
||||
QMetaType
|
||||
QMetaType
|
||||
#endif
|
||||
typeFromLetter(const QString & l);
|
||||
typeFromLetter(const QString & l);
|
||||
QAD_UTILS_EXPORT QString uniqueName(QString n, const QStringList & names);
|
||||
|
||||
QAD_UTILS_EXPORT int fontHeight(const QWidget * window = nullptr);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "qpiconfig.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
int QString2int(const QString & string) {
|
||||
@@ -14,17 +15,17 @@ int QString2int(const QString & string) {
|
||||
QRect QString2QRect(const QString & string) {
|
||||
int sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toInt();
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toInt();
|
||||
return QRect(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
@@ -32,17 +33,17 @@ QRect QString2QRect(const QString & string) {
|
||||
QRectF QString2QRectF(const QString & string) {
|
||||
double sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toDouble();
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toDouble();
|
||||
return QRectF(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
@@ -50,11 +51,11 @@ QRectF QString2QRectF(const QString & string) {
|
||||
QPoint QString2QPoint(const QString & string) {
|
||||
int sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toInt();
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toInt();
|
||||
return QPoint(sx, sy);
|
||||
}
|
||||
|
||||
@@ -62,28 +63,24 @@ QPoint QString2QPoint(const QString & string) {
|
||||
QPointF QString2QPointF(const QString & string) {
|
||||
double sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toDouble();
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toDouble();
|
||||
return QPointF(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
QString QRect2QString(const QRect & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
return QString::number(rect.left()) + ";" + QString::number(rect.top()) + ";" + QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
QString QRectF2QString(const QRectF & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
return QString::number(rect.left()) + ";" + QString::number(rect.top()) + ";" + QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
@@ -94,9 +91,11 @@ QPIConfig::Entry QPIConfig::Entry::_empty;
|
||||
QPIConfig::Branch QPIConfig::Branch::allLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
if (i->isLeaf()) b << i;
|
||||
else allLeaves(b, i);
|
||||
foreach(Entry * i, *this) {
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
else
|
||||
allLeaves(b, i);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
@@ -110,27 +109,27 @@ QPIConfig::Entry & QPIConfig::Branch::getValue(const QString & vname, const QStr
|
||||
return _empty;
|
||||
}
|
||||
QStringList tree = vname.split(delim);
|
||||
QString name = tree.front();
|
||||
QString name = tree.front();
|
||||
tree.pop_front();
|
||||
Entry * ce = 0;
|
||||
foreach (Entry * i, *this)
|
||||
foreach(Entry * i, *this)
|
||||
if (i->_name == name) {
|
||||
ce = i;
|
||||
break;
|
||||
}
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
@@ -143,14 +142,12 @@ QPIConfig::Entry & QPIConfig::Branch::getValue(const QString & vname, const QStr
|
||||
QPIConfig::Branch QPIConfig::Branch::getValues(const QString & name) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
foreach(Entry * i, *this) {
|
||||
if (i->isLeaf()) {
|
||||
if (i->_name.indexOf(name) >= 0)
|
||||
b << i;
|
||||
if (i->_name.indexOf(name) >= 0) b << i;
|
||||
} else {
|
||||
foreach (Entry * j, i->_children)
|
||||
if (j->_name.indexOf(name) >= 0)
|
||||
b << j;
|
||||
foreach(Entry * j, i->_children)
|
||||
if (j->_name.indexOf(name) >= 0) b << j;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
@@ -160,9 +157,8 @@ QPIConfig::Branch QPIConfig::Branch::getValues(const QString & name) {
|
||||
QPIConfig::Branch QPIConfig::Branch::getLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
foreach(Entry * i, *this)
|
||||
if (i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -170,9 +166,8 @@ QPIConfig::Branch QPIConfig::Branch::getLeaves() {
|
||||
QPIConfig::Branch QPIConfig::Branch::getBranches() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (!i->isLeaf())
|
||||
b << i;
|
||||
foreach(Entry * i, *this)
|
||||
if (!i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -190,10 +185,12 @@ QPIConfig::Branch & QPIConfig::Branch::filter(const QString & f) {
|
||||
|
||||
bool QPIConfig::Branch::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -201,13 +198,13 @@ bool QPIConfig::Branch::entryExists(const Entry * e, const QString & name) const
|
||||
|
||||
QPIConfig::Entry & QPIConfig::Entry::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = this;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = this;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
@@ -220,19 +217,20 @@ QPIConfig::Entry & QPIConfig::Entry::getValue(const QString & vname, const QStri
|
||||
QPIConfig::Branch QPIConfig::Entry::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, _children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
foreach(Entry * i, _children)
|
||||
if (i->_name.indexOf(vname) >= 0) b << i;
|
||||
return b;
|
||||
};
|
||||
|
||||
|
||||
bool QPIConfig::Entry::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -273,7 +271,7 @@ QPIConfig::QPIConfig(const QString & path, QPIConfig::FileType type_): QFile(pat
|
||||
|
||||
QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
init();
|
||||
type = type_;
|
||||
type = type_;
|
||||
buffer = str;
|
||||
parse();
|
||||
}
|
||||
@@ -281,9 +279,9 @@ QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
init();
|
||||
type = Config;
|
||||
type = Config;
|
||||
internal = true;
|
||||
dev = new QFile(path);
|
||||
dev = new QFile(path);
|
||||
dev->open(QIODevice::ReadOnly);
|
||||
incdirs = dirs;
|
||||
incdirs << QFileInfo(path).absoluteDir().path();
|
||||
@@ -313,7 +311,7 @@ QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
QPIConfig::~QPIConfig() {
|
||||
stream.setDevice(0);
|
||||
root.deleteBranch();
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
foreach(QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
@@ -321,13 +319,13 @@ QPIConfig::~QPIConfig() {
|
||||
|
||||
|
||||
void QPIConfig::init() {
|
||||
internal = false;
|
||||
buffer = 0;
|
||||
dev = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
empty.delim = delim;
|
||||
internal = false;
|
||||
buffer = 0;
|
||||
dev = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
empty.delim = delim;
|
||||
empty._parent = 0;
|
||||
}
|
||||
|
||||
@@ -335,8 +333,7 @@ void QPIConfig::init() {
|
||||
void QPIConfig::setFile(const QString & path, QIODevice::OpenMode mode) {
|
||||
buffer = 0;
|
||||
setFileName(path);
|
||||
if (open(mode))
|
||||
parse();
|
||||
if (open(mode)) parse();
|
||||
}
|
||||
|
||||
|
||||
@@ -357,26 +354,27 @@ void QPIConfig::setupCodec() {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
stream.setCodec(codec.toLatin1().data());
|
||||
#else
|
||||
QString cn = codec.toLower().remove(' ').remove('-').trimmed();
|
||||
QString cn = codec.toLower().remove(' ').remove('-').trimmed();
|
||||
QStringConverter::Encoding sc = QStringConverter::System;
|
||||
if (cn == "utf8" ) sc = QStringConverter::Utf8 ;
|
||||
else if (cn == "utf16") sc = QStringConverter::Utf16;
|
||||
if (cn == "utf8")
|
||||
sc = QStringConverter::Utf8;
|
||||
else if (cn == "utf16")
|
||||
sc = QStringConverter::Utf16;
|
||||
stream.setEncoding(sc);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = &root;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
if (exist != 0) *exist = false;
|
||||
empty._name = vname;
|
||||
empty._name = vname;
|
||||
empty._value = def;
|
||||
empty.delim = delim;
|
||||
empty.delim = delim;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
@@ -388,82 +386,85 @@ QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & de
|
||||
QPIConfig::Branch QPIConfig::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, root._children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
foreach(Entry * i, root._children)
|
||||
if (i->_name.indexOf(vname) >= 0) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::addEntry(const QString & name, const QString & value, const QString & type, bool write, bool node) {
|
||||
if (getValue(name)._parent != 0)
|
||||
return empty;
|
||||
QString sn = name, tn;
|
||||
if (getValue(name)._parent != 0) return empty;
|
||||
QString sn = name, tn;
|
||||
bool toRoot = false;
|
||||
while (sn.indexOf(delim) == 0) sn.remove(0, delim.length());
|
||||
while (sn.indexOf(delim) == 0)
|
||||
sn.remove(0, delim.length());
|
||||
QStringList tree = sn.split(delim);
|
||||
QString ename = tree.back();
|
||||
tn = tree.front();
|
||||
QString ename = tree.back();
|
||||
tn = tree.front();
|
||||
tree.pop_back();
|
||||
Entry * te, * ce, * entry = &root;
|
||||
Entry *te, *ce, *entry = &root;
|
||||
if (tree.isEmpty()) toRoot = true;
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = entry->_tab;
|
||||
ce->_line = entry->_line;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
//qDebug() << " [QPIC] add " + tn;
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = entry->_tab;
|
||||
ce->_line = entry->_line;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
// qDebug() << " [QPIC] add " + tn;
|
||||
ce->_full_name = tn;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
} else
|
||||
entry = te;
|
||||
tn += delim + i;
|
||||
}
|
||||
QPIConfig::Branch ch = entry->_children;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
te = (entry->isLeaf() ? 0 : ch.back());
|
||||
ce = new Entry();
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
te = (entry->isLeaf() ? 0 : ch.back());
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_name = ename;
|
||||
if (!node) ce->_value = value;
|
||||
ce->_type = type;
|
||||
if (te == 0) {
|
||||
//qDebug() << "[QPIC] te == 0";
|
||||
// qDebug() << "[QPIC] te == 0";
|
||||
ce->_tab = entry->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
if (toRoot)
|
||||
ce->_line = other.size();
|
||||
else {
|
||||
ch = entry->_parent->_children;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
ce->_line = ch.back()->_line + 1;
|
||||
}
|
||||
} else {
|
||||
ce->_tab = te->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
else ce->_line = te->_line + 1;
|
||||
if (toRoot)
|
||||
ce->_line = other.size();
|
||||
else
|
||||
ce->_line = te->_line + 1;
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " << entry->_name;
|
||||
// qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " << entry->_name;
|
||||
ce->_full_name = sn;
|
||||
ce->_parent = entry;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
//qDebug() << "[QPIC] children " << entry->childCount();
|
||||
// qDebug() << "[QPIC] children " << entry->childCount();
|
||||
if (!node) {
|
||||
other.insert(ce->_line, "");
|
||||
Branch b = allLeaves();
|
||||
//qDebug() << "[QPIC] allLeaves " << b.size();
|
||||
Branch b = allLeaves();
|
||||
// qDebug() << "[QPIC] allLeaves " << b.size();
|
||||
bool found = false;
|
||||
for (int i = 0; i < b.size(); ++i) {
|
||||
if (found) {
|
||||
@@ -473,13 +474,12 @@ QPIConfig::Entry & QPIConfig::addEntry(const QString & name, const QString & val
|
||||
if (b[i] == ce) {
|
||||
found = true;
|
||||
if (i > 0)
|
||||
if (b[i - 1]->_line == b[i]->_line)
|
||||
b[i - 1]->_line++;
|
||||
if (b[i - 1]->_line == b[i]->_line) b[i - 1]->_line++;
|
||||
}
|
||||
//qDebug() << b[i]->_line;
|
||||
// qDebug() << b[i]->_line;
|
||||
}
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " + entry->_name;
|
||||
// qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " + entry->_name;
|
||||
if (write) writeAll();
|
||||
return *ce;
|
||||
}
|
||||
@@ -492,7 +492,7 @@ void QPIConfig::setValue(const QString & name, const QString & value, const QStr
|
||||
return;
|
||||
}
|
||||
e._value = value;
|
||||
e._type = type;
|
||||
e._type = type;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
@@ -500,23 +500,22 @@ void QPIConfig::setValue(const QString & name, const QString & value, const QStr
|
||||
QPIConfig::Branch QPIConfig::allLeaves() {
|
||||
Branch b;
|
||||
allLeaves(b, &root);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(b.begin(), b.end(), Entry::compare);
|
||||
(b.begin(), b.end(), Entry::compare);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
int QPIConfig::entryIndex(const QString & name) {
|
||||
QStringList tree = name.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = &root;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0)
|
||||
return -1;
|
||||
if (ce == 0) return -1;
|
||||
}
|
||||
Branch b = allLeaves();
|
||||
return allLeaves().indexOf(ce);
|
||||
@@ -575,7 +574,7 @@ void QPIConfig::removeEntry(uint number, bool write) {
|
||||
|
||||
void QPIConfig::removeEntry(Branch & b, QPIConfig::Entry * e) {
|
||||
bool leaf = true;
|
||||
//qDebug() << " before " << b.size();
|
||||
// qDebug() << " before " << b.size();
|
||||
if (e->isLeaf()) other.removeAt(e->_line);
|
||||
if (!e->isLeaf() && !e->_value.isEmpty()) {
|
||||
e->_value.clear();
|
||||
@@ -597,7 +596,7 @@ void QPIConfig::removeEntry(Branch & b, QPIConfig::Entry * e) {
|
||||
if (ti >= 0) e->_parent->_children.remove(ti);
|
||||
ti = b.indexOf(e);
|
||||
if (ti >= 0) b.remove(ti);
|
||||
//qDebug() << " after " << b.size();
|
||||
// qDebug() << " after " << b.size();
|
||||
delete e;
|
||||
}
|
||||
|
||||
@@ -628,8 +627,7 @@ void QPIConfig::writeAll() {
|
||||
tprefix = getPrefixFromLine(other[i], &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
@@ -638,24 +636,28 @@ void QPIConfig::writeAll() {
|
||||
tprefix = getPrefixFromLine(other[i], &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
}
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
if (buffer == 0) flush();
|
||||
readAll();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::getPrefixFromLine(QString line, bool * exists) {
|
||||
line = line.trimmed();
|
||||
if (line.left(1) == "#") {if (exists) *exists = false; return QString();}
|
||||
if (line.left(1) == "#") {
|
||||
if (exists) *exists = false;
|
||||
return QString();
|
||||
}
|
||||
int ci = line.indexOf("#");
|
||||
if (ci >= 0) line = line.left(ci).trimmed();
|
||||
if (line.indexOf("=") >= 0) {if (exists) *exists = false; return QString();}
|
||||
if (line.indexOf("=") >= 0) {
|
||||
if (exists) *exists = false;
|
||||
return QString();
|
||||
}
|
||||
if (line.indexOf("[") >= 0 && line.indexOf("]") >= 0) {
|
||||
if (exists) *exists = true;
|
||||
line.remove(0, 1);
|
||||
@@ -671,7 +673,7 @@ QString QPIConfig::writeAllToString() {
|
||||
QTextStream s(&str);
|
||||
buildFullNames(&root);
|
||||
Branch b = allLeaves();
|
||||
int j = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < other.size(); ++i) {
|
||||
if (j >= 0 && j < b.size()) {
|
||||
if (b[j]->_line == i) {
|
||||
@@ -709,18 +711,19 @@ void QPIConfig::clear() {
|
||||
|
||||
|
||||
void QPIConfig::readAll() {
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
if (buffer == 0) flush();
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -729,7 +732,7 @@ bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
void QPIConfig::updateIncludes() {
|
||||
if (internal) return;
|
||||
all_includes.clear();
|
||||
foreach (QPIConfig * c, includes)
|
||||
foreach(QPIConfig * c, includes)
|
||||
all_includes << c->allLeaves();
|
||||
}
|
||||
|
||||
@@ -739,17 +742,17 @@ QString QPIConfig::parseLine(QString v) {
|
||||
while (1) {
|
||||
i = v.indexOf("${");
|
||||
if (i < 0) break;
|
||||
l = v.indexOf("}", i + 1);
|
||||
QString w = v.mid(i + 2, l - i - 2), r;
|
||||
l = w.length() + 3;
|
||||
w = parseLine(w);
|
||||
w = w.trimmed();
|
||||
bool ex = false;
|
||||
l = v.indexOf("}", i + 1);
|
||||
QString w = v.mid(i + 2, l - i - 2), r;
|
||||
l = w.length() + 3;
|
||||
w = parseLine(w);
|
||||
w = w.trimmed();
|
||||
bool ex = false;
|
||||
QPIConfig::Entry & me = getValue(w, "", &ex);
|
||||
if (ex) {
|
||||
r = me._value;
|
||||
} else {
|
||||
foreach (QPIConfig::Entry * e, all_includes) {
|
||||
foreach(QPIConfig::Entry * e, all_includes) {
|
||||
if (e->_full_name == w) {
|
||||
r = e->_value;
|
||||
break;
|
||||
@@ -767,10 +770,10 @@ void QPIConfig::parse(QString content) {
|
||||
root.clear();
|
||||
QString src, str, tab, comm, all, name, type, prefix, tprefix;
|
||||
QStringList tree;
|
||||
Entry * entry = 0, * te = 0, * ce = 0;
|
||||
Entry *entry = 0, *te = 0, *ce = 0;
|
||||
int ind, sind;
|
||||
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
foreach(QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
@@ -790,15 +793,14 @@ void QPIConfig::parse(QString content) {
|
||||
while (!stream.atEnd()) {
|
||||
other.push_back(QString());
|
||||
src = str = parseLine(stream.readLine());
|
||||
tprefix = getPrefixFromLine(src, &isPrefix);
|
||||
tprefix = getPrefixFromLine(src, &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
all = str;
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
all = str;
|
||||
|
||||
sind = str.indexOf('#');
|
||||
if (sind > 0) {
|
||||
@@ -806,7 +808,8 @@ void QPIConfig::parse(QString content) {
|
||||
if (comm.length() > 0) {
|
||||
type = comm[0];
|
||||
comm = comm.mid(1).trimmed();
|
||||
} else type = "s";
|
||||
} else
|
||||
type = "s";
|
||||
str = str.left(sind).trimmed();
|
||||
} else {
|
||||
type = "s";
|
||||
@@ -831,11 +834,11 @@ void QPIConfig::parse(QString content) {
|
||||
ce = 0;
|
||||
wasMultiline = isMultiline;
|
||||
|
||||
ind = str.indexOf('=');
|
||||
ind = str.indexOf('=');
|
||||
if ((ind > 0) && !(str[0] == '#')) {
|
||||
tree = (prefix + str.left(ind).trimmed()).split(delim);
|
||||
if (tree.front() == "include") {
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
QPIConfig * iconf = new QPIConfig(name, incdirs);
|
||||
if (!iconf->dev) {
|
||||
delete iconf;
|
||||
@@ -849,39 +852,41 @@ void QPIConfig::parse(QString content) {
|
||||
name = tree.back();
|
||||
tree.pop_back();
|
||||
entry = &root;
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_line = lines;
|
||||
ce->_name = i;
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_line = lines;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
} else
|
||||
entry = te;
|
||||
}
|
||||
isNew = false;
|
||||
ce = entry->findChild(name);
|
||||
ce = entry->findChild(name);
|
||||
if (ce == 0) {
|
||||
ce = new Entry();
|
||||
ce = new Entry();
|
||||
isNew = true;
|
||||
}
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.mid(ind + 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.mid(ind + 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->_comment = comm;
|
||||
ce->_line = lines;
|
||||
ce->_all = all;
|
||||
ce->_line = lines;
|
||||
ce->_all = all;
|
||||
if (isNew) {
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
}
|
||||
}
|
||||
} else other.back() = src;
|
||||
} else
|
||||
other.back() = src;
|
||||
lines++;
|
||||
}
|
||||
setEntryDelim(&root, delim);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QPICONFIG_H
|
||||
@@ -305,7 +305,7 @@ public:
|
||||
|
||||
bool toBool() const {
|
||||
return (_value.toLower().trimmed() == "true" || _value.toLower().trimmed() == "yes" || _value.toLower().trimmed() == "on" ||
|
||||
_value.toInt() > 0);
|
||||
_value.toInt() > 0);
|
||||
}
|
||||
char toChar() const { return (_value.isEmpty() ? 0 : _value[0].toLatin1()); }
|
||||
short toShort() const { return _value.toShort(); }
|
||||
|
||||
Reference in New Issue
Block a user