code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -1,14 +1,16 @@
#include "piqt.h"
#include "qvariantedit.h"
#ifdef PIQT_HAS_GEOPOSITION
# include <QGeoCoordinate>
# include "pigeoposition.h"
# include <QGeoCoordinate>
#endif
const QAD::Enum PI2QADEnum(const PIVariantTypes::Enum & el) {
QAD::Enum ret;
piForeachC (PIVariantTypes::Enumerator & e, el.enum_list)
piForeachC(PIVariantTypes::Enumerator & e, el.enum_list)
ret << QAD::Enumerator(e.value, PI2QString(e.name));
ret.selectValue(el.selectedValue());
return ret;
@@ -17,7 +19,7 @@ const QAD::Enum PI2QADEnum(const PIVariantTypes::Enum & el) {
const PIVariantTypes::Enum QAD2PIEnum(const QAD::Enum & el) {
PIVariantTypes::Enum ret;
foreach (const QAD::Enumerator & e, el.enum_list)
foreach(const QAD::Enumerator & e, el.enum_list)
ret << PIVariantTypes::Enumerator(e.value, Q2PIString(e.name));
ret.selectValue(el.selectedValue());
return ret;
@@ -54,7 +56,7 @@ const QVariant PI2QVariant(const PIVariant & v) {
case PIVariant::pivIODevice: return QVariant::fromValue(PI2QADIODevice(v.toIODevice()));
case PIVariant::pivMathVector: return QVariant::fromValue(PI2QMathVector(v.toMathVector()));
case PIVariant::pivMathMatrix: return QVariant::fromValue(PI2QMathMatrix(v.toMathMatrix()));
//case PIVariant::pivSystemTime: return QVariant(v.to());
// case PIVariant::pivSystemTime: return QVariant(v.to());
default: return QVariant();
}
return QVariant();
@@ -168,13 +170,13 @@ const PIVariant Q2PIVariant(const QVariant & v) {
case QMetaType::QLine:
case QMetaType::QLineF:
#endif
return PIVariant(Q2PILine(v.toLineF()));
return PIVariant(Q2PILine(v.toLineF()));
default: break;
}
if (v.canConvert<float>()) return PIVariant(v.value<float>());
if (v.canConvert<QAD::Enum>()) return PIVariant(QAD2PIEnum(v.value<QAD::Enum>()));
if (v.canConvert<QAD::File>()) return PIVariant(QAD2PIFile(v.value<QAD::File>()));
if (v.canConvert<QAD::Dir>()) return PIVariant(QAD2PIDir(v.value<QAD::Dir>()));
if (v.canConvert<QAD::Dir>()) return PIVariant(QAD2PIDir(v.value<QAD::Dir>()));
if (v.canConvert<QAD::IODevice>()) return PIVariant(QAD2PIIODevice(v.value<QAD::IODevice>()));
if (v.canConvert<QAD::MathVector>()) return PIVariant(Q2PIMathVector(v.value<QAD::MathVector>()));
if (v.canConvert<QAD::MathMatrix>()) return PIVariant(Q2PIMathMatrix(v.value<QAD::MathMatrix>()));
@@ -185,8 +187,8 @@ const PIVariant Q2PIVariant(const QVariant & v) {
const PIVariantTypes::IODevice QAD2PIIODevice(const QAD::IODevice & v) {
PIVariantTypes::IODevice d;
d.set(Q2PIPropertyStorage(v.props));
d.prefix = Q2PIString(v.prefix);
d.mode = v.mode;
d.prefix = Q2PIString(v.prefix);
d.mode = v.mode;
d.options = v.options;
return d;
}

View File

@@ -1,43 +1,43 @@
/*
PIQt - PIP <-> Qt convertions
PIQt - PIP <-> Qt convertions
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 PIQT_H
#define PIQT_H
#include <QVector3D>
#include <QPolygonF>
#include <QDateTime>
#include <QColor>
#include <QImage>
#include "pimathmatrix.h"
#include "pipropertystorage.h"
#include "qad_types.h"
#include "piqt_macros.h"
#include "qad_types.h"
#include <QColor>
#include <QDateTime>
#include <QImage>
#include <QPolygonF>
#include <QVector3D>
#if QT_VERSION_MAJOR == 5
# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
# define PIQT_HAS_GEOPOSITION
# define PIQT_HAS_GEOPOSITION
# endif
#endif
#if QT_VERSION_MAJOR == 6
# if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
# define PIQT_HAS_GEOPOSITION
# define PIQT_HAS_GEOPOSITION
# endif
#endif
#ifdef PIQT_HAS_GEOPOSITION
@@ -50,114 +50,187 @@ class PIGeoPosition;
QAD_PIQT_EXPORT const QVariant PI2QVariant(const PIVariant & v);
QAD_PIQT_EXPORT const PIVariant Q2PIVariant(const QVariant & v);
//inline const QString PI2QString(const PIString & v) {return QString::fromLocal8Bit(v.data());}
inline const QString PI2QString(const PIString & v) {return QString::fromUtf8(v.dataUTF8());}
#if PIP_VERSION >= PIP_MAKE_VERSION(2,38,0)
inline const QString PI2QString(const PIConstChars & v) {return QString::fromLatin1(v.data(), v.length());}
// inline const QString PI2QString(const PIString & v) {return QString::fromLocal8Bit(v.data());}
inline const QString PI2QString(const PIString & v) {
return QString::fromUtf8(v.dataUTF8());
}
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 38, 0)
inline const QString PI2QString(const PIConstChars & v) {
return QString::fromLatin1(v.data(), v.length());
}
#endif
//inline const PIString Q2PIString(const QString & v) {return PIString(v.toLocal8Bit().data());}
inline const PIString Q2PIString(const QString & v) {return PIString::fromUTF8(v.toUtf8().data());}
// inline const PIString Q2PIString(const QString & v) {return PIString(v.toLocal8Bit().data());}
inline const PIString Q2PIString(const QString & v) {
return PIString::fromUTF8(v.toUtf8().data());
}
inline const QStringList PI2QStringList(const PIStringList & v) {QStringList ret; piForeachC (PIString & s, v) ret << PI2QString(s); return ret;}
inline const QStringList PI2QStringList(const PIStringList & v) {
QStringList ret;
piForeachC(PIString & s, v)
ret << PI2QString(s);
return ret;
}
inline const PIStringList Q2PIStringList(const QStringList & v) {PIStringList ret; foreach (const QString & s, v) ret << Q2PIString(s); return ret;}
inline const PIStringList Q2PIStringList(const QStringList & v) {
PIStringList ret;
foreach(const QString & s, v)
ret << Q2PIString(s);
return ret;
}
inline const QByteArray PI2QByteArray(const PIByteArray & v) {return QByteArray((const char *)(v.data()), v.size_s());}
inline const QByteArray PI2QByteArray(const PIByteArray & v) {
return QByteArray((const char *)(v.data()), v.size_s());
}
inline const PIByteArray Q2PIByteArray(const QByteArray & v) {return PIByteArray(v.constData(), v.size());}
inline const PIByteArray Q2PIByteArray(const QByteArray & v) {
return PIByteArray(v.constData(), v.size());
}
inline const QPointF PI2QVector2(const PIMathVectorT2d & v) {return QPointF(v[0], v[1]);}
inline const QVector3D PI2QVector3(const PIMathVectorT3d & v) {return QVector3D(v[0], v[1], v[2]);}
inline const QPointF PI2QVector2(const PIMathVectorT2d & v) {
return QPointF(v[0], v[1]);
}
inline const QVector3D PI2QVector3(const PIMathVectorT3d & v) {
return QVector3D(v[0], v[1], v[2]);
}
inline const PIMathVectorT2d Q2PIVector2(const QPointF & v) {return PIMathVectorT2d({double(v.x()), double(v.y())});}
inline const PIMathVectorT3d Q2PIVector3(const QVector3D & v) {return PIMathVectorT3d({double(v.x()), double(v.y()), double(v.z())});}
inline const PIMathVectorT2d Q2PIVector2(const QPointF & v) {
return PIMathVectorT2d({double(v.x()), double(v.y())});
}
inline const PIMathVectorT3d Q2PIVector3(const QVector3D & v) {
return PIMathVectorT3d({double(v.x()), double(v.y()), double(v.z())});
}
inline const QPointF PI2QPoint(const PIPointd & v) {return QPointF(v.x, v.y);}
inline const PIPointd Q2PIPoint(const QPointF & v) {return PIPointd(v.x(), v.y());}
inline const QPointF PI2QPoint(const PIPointd & v) {
return QPointF(v.x, v.y);
}
inline const PIPointd Q2PIPoint(const QPointF & v) {
return PIPointd(v.x(), v.y());
}
inline const QRectF PI2QRect(const PIRectd & v) {return QRectF(v.left(), v.bottom(), v.width(), v.height());}
inline const PIRectd Q2PIRect(const QRectF & v) {return PIRectd(v.left(), v.top(), v.width(), v.height());}
inline const QRectF PI2QRect(const PIRectd & v) {
return QRectF(v.left(), v.bottom(), v.width(), v.height());
}
inline const PIRectd Q2PIRect(const QRectF & v) {
return PIRectd(v.left(), v.top(), v.width(), v.height());
}
inline const QLineF PI2QLine(const PILined & v) {return QLineF(PI2QPoint(v.p0), PI2QPoint(v.p1));}
inline const PILined Q2PILine(const QLineF & v) {return PILined(Q2PIPoint(v.p1()), Q2PIPoint(v.p2()));}
inline const QLineF PI2QLine(const PILined & v) {
return QLineF(PI2QPoint(v.p0), PI2QPoint(v.p1));
}
inline const PILined Q2PILine(const QLineF & v) {
return PILined(Q2PIPoint(v.p1()), Q2PIPoint(v.p2()));
}
inline const QAD::MathVector PI2QMathVector(const PIMathVectord & v) {
QVector<double> q = QVector<double>(v.size());
memcpy(q.data(), v.data(), q.size()*sizeof(double));
memcpy(q.data(), v.data(), q.size() * sizeof(double));
return QAD::MathVector(q);
}
inline const PIMathVectord Q2PIMathVector(const QAD::MathVector & v) {
PIMathVectord p = PIMathVectord(v.v.size());
memcpy(p.data(), v.v.data(), p.size()*sizeof(double));
memcpy(p.data(), v.v.data(), p.size() * sizeof(double));
return p;
}
inline const QAD::MathMatrix PI2QMathMatrix(const PIMathMatrixd & v) {
PIVector<PIVector<double> > p = v.toVectors();
QVector<QVector<double> > q = QVector<QVector<double> >(p.size());
PIVector<PIVector<double>> p = v.toVectors();
QVector<QVector<double>> q = QVector<QVector<double>>(p.size());
for (int i = 0; i < q.size(); ++i) {
q[i].resize(p[i].size());
memcpy(q[i].data(), p[i].data(), q[i].size()*sizeof(double));
memcpy(q[i].data(), p[i].data(), q[i].size() * sizeof(double));
}
return QAD::MathMatrix(q);
}
inline const PIMathMatrixd Q2PIMathMatrix(const QAD::MathMatrix & v) {
PIVector<PIVector<double> > p = PIVector<PIVector<double> >(v.m.size());
PIVector<PIVector<double>> p = PIVector<PIVector<double>>(v.m.size());
for (int i = 0; i < v.m.size(); ++i) {
p[i].resize(v.m[i].size());
memcpy(p[i].data(), v.m[i].data(), p[i].size()*sizeof(double));
memcpy(p[i].data(), v.m[i].data(), p[i].size() * sizeof(double));
}
return PIMathMatrixd(p);
}
inline const QDate PI2QDate(const PIDate & v) {return QDate(v.year, v.month, v.day);}
inline const QTime PI2QTime(const PITime & v) {return QTime(v.hours, v.minutes, v.seconds, v.milliseconds);}
inline const QDateTime PI2QDateTime(const PIDateTime & v) {return QDateTime(PI2QDate(v.date()), PI2QTime(v.time()));}
inline const QDate PI2QDate(const PIDate & v) {
return QDate(v.year, v.month, v.day);
}
inline const QTime PI2QTime(const PITime & v) {
return QTime(v.hours, v.minutes, v.seconds, v.milliseconds);
}
inline const QDateTime PI2QDateTime(const PIDateTime & v) {
return QDateTime(PI2QDate(v.date()), PI2QTime(v.time()));
}
inline const PIDate Q2PIDate(const QDate & v) {return PIDate(v.year(), v.month(), v.day());}
inline const PITime Q2PITime(const QTime & v) {return PITime(v.hour(), v.minute(), v.second(), v.msec());}
inline const PIDateTime Q2PIDateTime(const QDateTime & v) {return PIDateTime(Q2PIDate(v.date()), Q2PITime(v.time()));}
inline const PIDate Q2PIDate(const QDate & v) {
return PIDate(v.year(), v.month(), v.day());
}
inline const PITime Q2PITime(const QTime & v) {
return PITime(v.hour(), v.minute(), v.second(), v.msec());
}
inline const PIDateTime Q2PIDateTime(const QDateTime & v) {
return PIDateTime(Q2PIDate(v.date()), Q2PITime(v.time()));
}
inline const QColor PI2QColor(const PIVariantTypes::Color & v) {return QColor::fromRgba(v.rgba);}
inline const PIVariantTypes::Color Q2PIColor(const QColor & v) {return PIVariantTypes::Color(v.rgba());}
inline const QColor PI2QColor(const PIVariantTypes::Color & v) {
return QColor::fromRgba(v.rgba);
}
inline const PIVariantTypes::Color Q2PIColor(const QColor & v) {
return PIVariantTypes::Color(v.rgba());
}
template<typename T>
inline const QVector<T> PI2QVector(const PIVector<T> & v) {QVector<T> ret; ret.reserve(v.size_s()); for (int i = 0; i < v.size_s(); ++i) ret << v[i]; return ret;}
inline const QVector<T> PI2QVector(const PIVector<T> & v) {
QVector<T> ret;
ret.reserve(v.size_s());
for (int i = 0; i < v.size_s(); ++i)
ret << v[i];
return ret;
}
template<typename T>
inline const PIVector<T> Q2PIVector(const QVector<T> & v) {if (v.isEmpty()) return PIVector<T>(); return PIVector<T>(v.constData(), (size_t)v.size());}
inline const PIVector<T> Q2PIVector(const QVector<T> & v) {
if (v.isEmpty()) return PIVector<T>();
return PIVector<T>(v.constData(), (size_t)v.size());
}
template <typename K, typename T>
template<typename K, typename T>
inline QMap<K, T> PI2QMap(const PIMap<K, T> & v) {
QMap<K, T> ret;
auto it = v.makeIterator();
while (it.hasNext()) {it.next(); ret[it.key()] = it.value();}
return ret;}
template <typename K, typename T>
while (it.hasNext()) {
it.next();
ret[it.key()] = it.value();
}
return ret;
}
template<typename K, typename T>
inline PIMap<K, T> Q2PIMap(const QMap<K, T> & v) {
PIMap<K, T> ret;
ret.reserve((size_t)v.size());
QMapIterator<K, T> it(v);
while (it.hasNext()) {it.next(); ret[it.key()] = it.value();}
return ret;}
while (it.hasNext()) {
it.next();
ret[it.key()] = it.value();
}
return ret;
}
inline PIPropertyStorage Q2PIPropertyStorage(const PropertyStorage & props) {
PIPropertyStorage ret;
foreach (const PropertyStorage::Property & p, props)
foreach(const PropertyStorage::Property & p, props)
ret.addProperty(Q2PIString(p.name), Q2PIVariant(p.value), Q2PIString(p.comment), p.flags);
return ret;
}
inline PropertyStorage PI2QPropertyStorage(const PIPropertyStorage & props) {
PropertyStorage ret;
piForeachC (PIPropertyStorage::Property & p, props)
piForeachC(PIPropertyStorage::Property & p, props)
ret.addProperty(PI2QString(p.name), PI2QVariant(p.value), PI2QString(p.comment), p.flags);
return ret;
}
@@ -172,186 +245,451 @@ QAD_PIQT_EXPORT const PIVariantTypes::File QAD2PIFile(const QAD::File & v);
QAD_PIQT_EXPORT const PIVariantTypes::Dir QAD2PIDir(const QAD::Dir & v);
QAD_PIQT_EXPORT const PIVariantTypes::IODevice QAD2PIIODevice(const QAD::IODevice & v);
//inline const PIVariant QString2PIVariant(const QString & v) {return PIVariant::readFromString(QString2PIString(v));}
// inline const PIVariant QString2PIVariant(const QString & v) {return PIVariant::readFromString(QString2PIString(v));}
#ifdef PIQT_HAS_GEOPOSITION
QAD_PIQT_EXPORT const QGeoCoordinate PI2QGeoPosition(const PIGeoPosition & v);
QAD_PIQT_EXPORT const PIGeoPosition Q2PIGeoPosition(const QGeoCoordinate & v);
#endif
template <typename From>
template<typename From>
class __PIQtConverter {
public:
__PIQtConverter(const From & v): val(v) {}
template <typename To> operator To() {return To();}
template<typename To>
operator To() {
return To();
}
From val;
};
template<typename From> inline __PIQtConverter<From> __PIQtConvert(const From & f) {return __PIQtConverter<From>(f);}
template<typename From>
inline __PIQtConverter<From> __PIQtConvert(const From & f) {
return __PIQtConverter<From>(f);
}
#define _PIQt_CONVERT(ft, tt, ftc, tfc) \
template<> template<> inline __PIQtConverter<ft>::operator tt() {return ftc(val);} \
template<> template<> inline __PIQtConverter<tt>::operator ft() {return tfc(val);}
#define _PIQt_CONVERT(ft, tt, ftc, tfc) \
template<> \
template<> \
inline __PIQtConverter<ft>::operator tt() { \
return ftc(val); \
} \
template<> \
template<> \
inline __PIQtConverter<tt>::operator ft() { \
return tfc(val); \
}
#define _PIQt_CONVERT_S(t) _PIQt_CONVERT(PI##t, Q##t, PI2Q##t, Q2PI##t)
_PIQt_CONVERT_S(String)
_PIQt_CONVERT_S(ByteArray)
_PIQt_CONVERT_S(Time)
_PIQt_CONVERT_S(Date)
_PIQt_CONVERT_S(DateTime)
_PIQt_CONVERT(PIMathVectorT2d, QPointF, PI2QVector2, Q2PIVector2)
_PIQt_CONVERT(PIMathVectorT3d, QVector3D, PI2QVector3, Q2PIVector3)
_PIQt_CONVERT_S(String) _PIQt_CONVERT_S(ByteArray) _PIQt_CONVERT_S(Time) _PIQt_CONVERT_S(Date) _PIQt_CONVERT_S(DateTime)
_PIQt_CONVERT(PIMathVectorT2d, QPointF, PI2QVector2, Q2PIVector2) _PIQt_CONVERT(PIMathVectorT3d, QVector3D, PI2QVector3, Q2PIVector3)
#define piqt __PIQtConvert
#define qtpi __PIQtConvert
#ifndef PIP_BINARY_STREAM
inline PIByteArray & operator <<(PIByteArray & s, const QString & v) {s << Q2PIString(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QString & v) {PIString t; s >> t; v = PI2QString(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QStringList & v) {s << Q2PIStringList(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QStringList & v) {PIStringList t; s >> t; v = PI2QStringList(t); return s;}
template <typename T> inline PIByteArray & operator <<(PIByteArray & s, const QVector<T> & v) {s << PIVector<T>(v.constData(), (size_t)v.size()); return s;}
template <typename T> inline PIByteArray & operator >>(PIByteArray & s, QVector<T> & v) {
PIVector<T> t; s >> t;
v.resize(t.size_s());
for (int i = 0; i < t.size_s(); ++i)
v[i] = t[i];
return s;}
template <typename K, typename T> inline PIByteArray & operator <<(PIByteArray & s, const QMap<K, T> & v) {
PIMap<K, T> t;
t.reserve(v.size());
QMapIterator<K, T> it(v);
while (it.hasNext()) {it.next(); t[it.key()] = it.value();}
s << t;
return s;}
template <typename K, typename T> inline PIByteArray & operator >>(PIByteArray & s, QMap<K, T> & v) {
v.clear();
PIMap<K, T> t; s >> t;
auto it = t.makeIterator();
while (it.hasNext()) {it.next(); v[it.key()] = it.value();}
return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QPolygonF & v) {s << (QVector<QPointF>)v; return s;}
inline PIByteArray & operator >>(PIByteArray & s, QPolygonF & v) {QVector<QPointF> t; s >> t; v = t; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QByteArray & v) {s << Q2PIByteArray(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QByteArray & v) {PIByteArray t; s >> t; v = PI2QByteArray(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QDate & v) {s << Q2PIDate(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QDate & v) {PIDate t; s >> t; v = PI2QDate(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QTime & v) {s << Q2PITime(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QTime & v) {PITime t; s >> t; v = PI2QTime(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QDateTime & v) {s << Q2PIDateTime(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QDateTime & v) {PIDateTime t; s >> t; v = PI2QDateTime(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QVariant & v) {s << Q2PIVariant(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QVariant & v) {PIVariant t; s >> t; v = PI2QVariant(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PropertyStorage & v) {s << Q2PIPropertyStorage(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, PropertyStorage & v) {PIPropertyStorage t; s >> t; v = PI2QPropertyStorage(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QColor & v) {s << Q2PIColor(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QColor & v) {PIVariantTypes::Color t; s >> t; v = PI2QColor(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::Enum & v) {s << QAD2PIEnum(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::Enum & v) {PIVariantTypes::Enum t; s >> t; v = PI2QADEnum(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::File & v) {s << QAD2PIFile(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::File & v) {PIVariantTypes::File t; s >> t; v = PI2QADFile(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::Dir & v) {s << QAD2PIDir(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::Dir & v) {PIVariantTypes::Dir t; s >> t; v = PI2QADDir(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::IODevice & v) {s << QAD2PIIODevice(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::IODevice & v) {PIVariantTypes::IODevice t; s >> t; v = PI2QADIODevice(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QImage & v) {
QByteArray ba; QBuffer buf(&ba);
v.save(&buf, "png");
s << Q2PIByteArray(ba);
return s;}
inline PIByteArray & operator >>(PIByteArray & s, QImage & v) {
PIByteArray pba; s >> pba;
QByteArray ba = PI2QByteArray(pba);
if (!v.loadFromData(ba, "png"))
v = QImage();
return s;}
#else
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const QVector<T> & v) {
inline PIByteArray &
operator<<(PIByteArray & s, const QString & v) {
s << Q2PIString(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QString & v) {
PIString t;
s >> t;
v = PI2QString(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QStringList & v) {
s << Q2PIStringList(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QStringList & v) {
PIStringList t;
s >> t;
v = PI2QStringList(t);
return s;
}
template<typename T>
inline PIByteArray & operator<<(PIByteArray & s, const QVector<T> & v) {
s << PIVector<T>(v.constData(), (size_t)v.size());
return s;
}
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, QVector<T> & v) {
PIVector<T> t; s >> t;
template<typename T>
inline PIByteArray & operator>>(PIByteArray & s, QVector<T> & v) {
PIVector<T> t;
s >> t;
v.resize(t.size_s());
for (int i = 0; i < t.size_s(); ++i)
v[i] = t[i];
return s;
}
template<typename K, typename T>
inline PIByteArray & operator<<(PIByteArray & s, const QMap<K, T> & v) {
PIMap<K, T> t;
t.reserve(v.size());
QMapIterator<K, T> it(v);
while (it.hasNext()) {
it.next();
t[it.key()] = it.value();
}
s << t;
return s;
}
template<typename K, typename T>
inline PIByteArray & operator>>(PIByteArray & s, QMap<K, T> & v) {
v.clear();
PIMap<K, T> t;
s >> t;
auto it = t.makeIterator();
while (it.hasNext()) {
it.next();
v[it.key()] = it.value();
}
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QPolygonF & v) {
s << (QVector<QPointF>)v;
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QPolygonF & v) {
QVector<QPointF> t;
s >> t;
v = t;
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QByteArray & v) {
s << Q2PIByteArray(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QByteArray & v) {
PIByteArray t;
s >> t;
v = PI2QByteArray(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QDate & v) {
s << Q2PIDate(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QDate & v) {
PIDate t;
s >> t;
v = PI2QDate(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QTime & v) {
s << Q2PITime(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QTime & v) {
PITime t;
s >> t;
v = PI2QTime(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QDateTime & v) {
s << Q2PIDateTime(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QDateTime & v) {
PIDateTime t;
s >> t;
v = PI2QDateTime(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QVariant & v) {
s << Q2PIVariant(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QVariant & v) {
PIVariant t;
s >> t;
v = PI2QVariant(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const PropertyStorage & v) {
s << Q2PIPropertyStorage(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, PropertyStorage & v) {
PIPropertyStorage t;
s >> t;
v = PI2QPropertyStorage(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QColor & v) {
s << Q2PIColor(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QColor & v) {
PIVariantTypes::Color t;
s >> t;
v = PI2QColor(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QAD::Enum & v) {
s << QAD2PIEnum(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QAD::Enum & v) {
PIVariantTypes::Enum t;
s >> t;
v = PI2QADEnum(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QAD::File & v) {
s << QAD2PIFile(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QAD::File & v) {
PIVariantTypes::File t;
s >> t;
v = PI2QADFile(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QAD::Dir & v) {
s << QAD2PIDir(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QAD::Dir & v) {
PIVariantTypes::Dir t;
s >> t;
v = PI2QADDir(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QAD::IODevice & v) {
s << QAD2PIIODevice(v);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QAD::IODevice & v) {
PIVariantTypes::IODevice t;
s >> t;
v = PI2QADIODevice(t);
return s;
}
inline PIByteArray & operator<<(PIByteArray & s, const QImage & v) {
QByteArray ba;
QBuffer buf(&ba);
v.save(&buf, "png");
s << Q2PIByteArray(ba);
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, QImage & v) {
PIByteArray pba;
s >> pba;
QByteArray ba = PI2QByteArray(pba);
if (!v.loadFromData(ba, "png")) v = QImage();
return s;
}
#else
template<typename P, typename T>
inline PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const QVector<T> & v) {
s << PIVector<T>(v.constData(), (size_t)v.size());
return s;
}
template<typename P, typename T>
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, QVector<T> & v) {
PIVector<T> t;
s >> t;
v.resize(t.size_s());
for (int i = 0; i < t.size_s(); ++i)
v[i] = t[i];
return s;
}
template<typename P, typename K, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const QMap<K, T> & v) {
template<typename P, typename K, typename T>
inline PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const QMap<K, T> & v) {
PIMap<K, T> t;
t.reserve(v.size());
QMapIterator<K, T> it(v);
while (it.hasNext()) {it.next(); t[it.key()] = it.value();}
while (it.hasNext()) {
it.next();
t[it.key()] = it.value();
}
s << t;
return s;
}
template<typename P, typename K, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, QMap<K, T> & v) {
template<typename P, typename K, typename T>
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, QMap<K, T> & v) {
v.clear();
PIMap<K, T> t; s >> t;
PIMap<K, T> t;
s >> t;
auto it = t.makeIterator();
while (it.hasNext()) {it.next(); v[it.key()] = it.value();}
while (it.hasNext()) {
it.next();
v[it.key()] = it.value();
}
return s;
}
BINARY_STREAM_WRITE(QString) {s << Q2PIString(v); return s;}
BINARY_STREAM_READ (QString) {PIString t; s >> t; v = PI2QString(t); return s;}
BINARY_STREAM_WRITE(QString) {
s << Q2PIString(v);
return s;
}
BINARY_STREAM_READ(QString) {
PIString t;
s >> t;
v = PI2QString(t);
return s;
}
BINARY_STREAM_WRITE(QStringList) {s << Q2PIStringList(v); return s;}
BINARY_STREAM_READ (QStringList) {PIStringList t; s >> t; v = PI2QStringList(t); return s;}
BINARY_STREAM_WRITE(QStringList) {
s << Q2PIStringList(v);
return s;
}
BINARY_STREAM_READ(QStringList) {
PIStringList t;
s >> t;
v = PI2QStringList(t);
return s;
}
BINARY_STREAM_WRITE(QPolygonF) {s << (QVector<QPointF>)v; return s;}
BINARY_STREAM_READ (QPolygonF) {QVector<QPointF> t; s >> t; v = t; return s;}
BINARY_STREAM_WRITE(QPolygonF) {
s << (QVector<QPointF>)v;
return s;
}
BINARY_STREAM_READ(QPolygonF) {
QVector<QPointF> t;
s >> t;
v = t;
return s;
}
BINARY_STREAM_WRITE(QByteArray) {s << Q2PIByteArray(v); return s;}
BINARY_STREAM_READ (QByteArray) {PIByteArray t; s >> t; v = PI2QByteArray(t); return s;}
BINARY_STREAM_WRITE(QByteArray) {
s << Q2PIByteArray(v);
return s;
}
BINARY_STREAM_READ(QByteArray) {
PIByteArray t;
s >> t;
v = PI2QByteArray(t);
return s;
}
BINARY_STREAM_WRITE(QDate) {s << Q2PIDate(v); return s;}
BINARY_STREAM_READ (QDate) {PIDate t; s >> t; v = PI2QDate(t); return s;}
BINARY_STREAM_WRITE(QDate) {
s << Q2PIDate(v);
return s;
}
BINARY_STREAM_READ(QDate) {
PIDate t;
s >> t;
v = PI2QDate(t);
return s;
}
BINARY_STREAM_WRITE(QTime) {s << Q2PITime(v); return s;}
BINARY_STREAM_READ (QTime) {PITime t; s >> t; v = PI2QTime(t); return s;}
BINARY_STREAM_WRITE(QTime) {
s << Q2PITime(v);
return s;
}
BINARY_STREAM_READ(QTime) {
PITime t;
s >> t;
v = PI2QTime(t);
return s;
}
BINARY_STREAM_WRITE(QDateTime) {s << Q2PIDateTime(v); return s;}
BINARY_STREAM_READ (QDateTime) {PIDateTime t; s >> t; v = PI2QDateTime(t); return s;}
BINARY_STREAM_WRITE(QDateTime) {
s << Q2PIDateTime(v);
return s;
}
BINARY_STREAM_READ(QDateTime) {
PIDateTime t;
s >> t;
v = PI2QDateTime(t);
return s;
}
BINARY_STREAM_WRITE(QVariant) {s << Q2PIVariant(v); return s;}
BINARY_STREAM_READ (QVariant) {PIVariant t; s >> t; v = PI2QVariant(t); return s;}
BINARY_STREAM_WRITE(QVariant) {
s << Q2PIVariant(v);
return s;
}
BINARY_STREAM_READ(QVariant) {
PIVariant t;
s >> t;
v = PI2QVariant(t);
return s;
}
BINARY_STREAM_WRITE(PropertyStorage) {s << Q2PIPropertyStorage(v); return s;}
BINARY_STREAM_READ (PropertyStorage) {PIPropertyStorage t; s >> t; v = PI2QPropertyStorage(t); return s;}
BINARY_STREAM_WRITE(PropertyStorage) {
s << Q2PIPropertyStorage(v);
return s;
}
BINARY_STREAM_READ(PropertyStorage) {
PIPropertyStorage t;
s >> t;
v = PI2QPropertyStorage(t);
return s;
}
BINARY_STREAM_WRITE(QColor) {s << Q2PIColor(v); return s;}
BINARY_STREAM_READ (QColor) {PIVariantTypes::Color t; s >> t; v = PI2QColor(t); return s;}
BINARY_STREAM_WRITE(QColor) {
s << Q2PIColor(v);
return s;
}
BINARY_STREAM_READ(QColor) {
PIVariantTypes::Color t;
s >> t;
v = PI2QColor(t);
return s;
}
BINARY_STREAM_WRITE(QAD::Enum) {s << QAD2PIEnum(v); return s;}
BINARY_STREAM_READ (QAD::Enum) {PIVariantTypes::Enum t; s >> t; v = PI2QADEnum(t); return s;}
BINARY_STREAM_WRITE(QAD::Enum) {
s << QAD2PIEnum(v);
return s;
}
BINARY_STREAM_READ(QAD::Enum) {
PIVariantTypes::Enum t;
s >> t;
v = PI2QADEnum(t);
return s;
}
BINARY_STREAM_WRITE(QAD::File) {s << QAD2PIFile(v); return s;}
BINARY_STREAM_READ (QAD::File) {PIVariantTypes::File t; s >> t; v = PI2QADFile(t); return s;}
BINARY_STREAM_WRITE(QAD::File) {
s << QAD2PIFile(v);
return s;
}
BINARY_STREAM_READ(QAD::File) {
PIVariantTypes::File t;
s >> t;
v = PI2QADFile(t);
return s;
}
BINARY_STREAM_WRITE(QAD::Dir) {s << QAD2PIDir(v); return s;}
BINARY_STREAM_READ (QAD::Dir) {PIVariantTypes::Dir t; s >> t; v = PI2QADDir(t); return s;}
BINARY_STREAM_WRITE(QAD::Dir) {
s << QAD2PIDir(v);
return s;
}
BINARY_STREAM_READ(QAD::Dir) {
PIVariantTypes::Dir t;
s >> t;
v = PI2QADDir(t);
return s;
}
BINARY_STREAM_WRITE(QAD::IODevice) {s << QAD2PIIODevice(v); return s;}
BINARY_STREAM_READ (QAD::IODevice) {PIVariantTypes::IODevice t; s >> t; v = PI2QADIODevice(t); return s;}
BINARY_STREAM_WRITE(QAD::IODevice) {
s << QAD2PIIODevice(v);
return s;
}
BINARY_STREAM_READ(QAD::IODevice) {
PIVariantTypes::IODevice t;
s >> t;
v = PI2QADIODevice(t);
return s;
}
BINARY_STREAM_WRITE(QImage) {
QByteArray ba; QBuffer buf(&ba);
QByteArray ba;
QBuffer buf(&ba);
v.save(&buf, "png");
s << Q2PIByteArray(ba);
return s;
}
BINARY_STREAM_READ (QImage) {
PIByteArray pba; s >> pba;
BINARY_STREAM_READ(QImage) {
PIByteArray pba;
s >> pba;
QByteArray ba = PI2QByteArray(pba);
if (!v.loadFromData(ba, "png"))
v = QImage();
if (!v.loadFromData(ba, "png")) v = QImage();
return s;
}
@@ -360,7 +698,8 @@ BINARY_STREAM_READ (QImage) {
/// pure Qt
template <typename T> QByteArray qSerialize(const T & value, int version = -1) {
template<typename T>
QByteArray qSerialize(const T & value, int version = -1) {
QByteArray ret;
QDataStream s(&ret, QIODevice::ReadWrite);
if (version > 0) s.setVersion((QDataStream::Version)version);
@@ -368,7 +707,8 @@ template <typename T> QByteArray qSerialize(const T & value, int version = -1) {
return ret;
}
template <typename T> T qDeserialize(const QByteArray & data, int version = -1) {
template<typename T>
T qDeserialize(const QByteArray & data, int version = -1) {
T ret;
if (!data.isEmpty()) {
QDataStream s(data);
@@ -382,13 +722,15 @@ template <typename T> T qDeserialize(const QByteArray & data, int version = -1)
/// PIP with QByteArray
template <typename T> QByteArray piqSerialize(const T & value) {
template<typename T>
QByteArray piqSerialize(const T & value) {
PIByteArray ret;
ret << value;
return PI2QByteArray(ret);
}
template <typename T> T piqDeserialize(const QByteArray & data) {
template<typename T>
T piqDeserialize(const QByteArray & data) {
T ret;
if (!data.isEmpty()) {
PIByteArray ba = Q2PIByteArray(data);

View File

@@ -1,78 +1,89 @@
/*
PIQt - PIP <-> Qt convertions
Ivan Pelipenko peri4ko@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 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/>.
*/
#ifndef PIQT_MACROS_H
#define PIQT_MACROS_H
#include <piobject.h>
#include <QObject>
#include "qad_piqt_export.h"
/// connect PIP event "event" of object "src" directly to Qt slot "slot" of object "tgt"
/// e.g. PIQCONNECT(&pip_obj, someEvent, &qt_obj, someSlot)
#define PIQCONNECT(src, event, tgt, slot) \
PIQt::piqConnect(src, #event, &(src)->__stat_eh_##event##__, tgt, &decltype(PIQt::removePtr(tgt))::slot);
/// connect PIP event "event" of object "src" to Qt slot "slot" of object "tgt" via Qt::QueuedConnection
/// Note! All argument types must be registered in Qt meta-system!
/// e.g. PIQCONNECT_QUEUED(&pip_obj, someEvent, &qt_obj, someSlot)
#define PIQCONNECT_QUEUED(src, event, tgt, slot) \
PIQt::piqConnectQ(src, #event, &(src)->__stat_eh_##event##__, tgt, #slot);
/// connect Qt signal "sig" of object "src" directly to PIP event handler "handler" of object "tgt"
/// e.g. QPICONNECT(&qt_obj, someSignal, &pip_obj, someHandler)
/// Returns QMetaObject::Connection
#define QPICONNECT(src, sig, tgt, handler) \
PIQt::qpiConnect(src, &decltype(PIQt::removePtr(src))::sig, tgt, &(tgt)->__stat_eh_##handler##__);
namespace PIQt {
template<typename T> T removePtr(T*) {}
template<typename T> QArgument<T> qargument(const T & v) {
return QArgument<T>(
#if QT_VERSION_MAJOR <= 5
QMetaType::typeName(qMetaTypeId<T>())
#else
QMetaType::fromType<T>().name()
#endif
, v);}
template <typename SR, typename O, typename... ARGS>
void piqConnect(PIObject * source, const char * event, void(*func)(void*,ARGS...), O * target, SR(O::*slot)(ARGS...)) {
PIObject::piConnectLS(source, PIStringAscii(event), PIObject::__newFunctor(func, [target,slot](ARGS... args){(target->*slot)(args...);}), LOCATION);
}
template <typename... ARGS>
void piqConnectQ(PIObject * source, const char * event, void(*func)(void*,ARGS...), QObject * target, const char * slot) {
PIObject::piConnectLS(source, PIStringAscii(event), PIObject::__newFunctor(func, [target,slot](ARGS... args){
QMetaObject::invokeMethod(target, slot, Qt::QueuedConnection, qargument(args)...);
}), LOCATION);
}
template <typename SR, typename O, typename... ARGS>
QMetaObject::Connection qpiConnect(O * source, SR(O::*signal)(ARGS...), PIObject * target, void(*handler)(void*,ARGS...)) {
return QObject::connect(source, signal, source, [target,handler](ARGS... args){handler(target, args...);});
}
}
#endif // PIQT_MACROS_H
/*
PIQt - PIP <-> Qt convertions
Ivan Pelipenko peri4ko@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 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/>.
*/
#ifndef PIQT_MACROS_H
#define PIQT_MACROS_H
#include "qad_piqt_export.h"
#include <QObject>
#include <piobject.h>
/// connect PIP event "event" of object "src" directly to Qt slot "slot" of object "tgt"
/// e.g. PIQCONNECT(&pip_obj, someEvent, &qt_obj, someSlot)
#define PIQCONNECT(src, event, tgt, slot) \
PIQt::piqConnect(src, #event, &(src)->__stat_eh_##event##__, tgt, &decltype(PIQt::removePtr(tgt))::slot);
/// connect PIP event "event" of object "src" to Qt slot "slot" of object "tgt" via Qt::QueuedConnection
/// Note! All argument types must be registered in Qt meta-system!
/// e.g. PIQCONNECT_QUEUED(&pip_obj, someEvent, &qt_obj, someSlot)
#define PIQCONNECT_QUEUED(src, event, tgt, slot) PIQt::piqConnectQ(src, #event, &(src)->__stat_eh_##event##__, tgt, #slot);
/// connect Qt signal "sig" of object "src" directly to PIP event handler "handler" of object "tgt"
/// e.g. QPICONNECT(&qt_obj, someSignal, &pip_obj, someHandler)
/// Returns QMetaObject::Connection
#define QPICONNECT(src, sig, tgt, handler) \
PIQt::qpiConnect(src, &decltype(PIQt::removePtr(src))::sig, tgt, &(tgt)->__stat_eh_##handler##__);
namespace PIQt {
template<typename T>
T removePtr(T *) {}
template<typename T>
QArgument<T> qargument(const T & v) {
return QArgument<T>(
#if QT_VERSION_MAJOR <= 5
QMetaType::typeName(qMetaTypeId<T>())
#else
QMetaType::fromType<T>().name()
#endif
,
v);
}
template<typename SR, typename O, typename... ARGS>
void piqConnect(PIObject * source, const char * event, void (*func)(void *, ARGS...), O * target, SR (O::*slot)(ARGS...)) {
PIObject::piConnectLS(source,
PIStringAscii(event),
PIObject::__newFunctor(func, [target, slot](ARGS... args) { (target->*slot)(args...); }),
LOCATION);
}
template<typename... ARGS>
void piqConnectQ(PIObject * source, const char * event, void (*func)(void *, ARGS...), QObject * target, const char * slot) {
PIObject::piConnectLS(source,
PIStringAscii(event),
PIObject::__newFunctor(func,
[target, slot](ARGS... args) {
QMetaObject::invokeMethod(target, slot, Qt::QueuedConnection, qargument(args)...);
}),
LOCATION);
}
template<typename SR, typename O, typename... ARGS>
QMetaObject::Connection qpiConnect(O * source, SR (O::*signal)(ARGS...), PIObject * target, void (*handler)(void *, ARGS...)) {
return QObject::connect(source, signal, source, [target, handler](ARGS... args) { handler(target, args...); });
}
} // namespace PIQt
#endif // PIQT_MACROS_H

View File

@@ -18,13 +18,19 @@ bool QPIConnection::loadFromCMFile(const QString & file) {
void QPIConnection::piDataRec(const PIString & from, const PIByteArray & data) {
//piCout << from << PICoutManipulators::Hex << data;
QMetaObject::invokeMethod(this, "qDataReceivedEvent", Qt::QueuedConnection,
Q_ARG(QString, PI2QString(from)), Q_ARG(QByteArray, PI2QByteArray(data)));
// piCout << from << PICoutManipulators::Hex << data;
QMetaObject::invokeMethod(this,
"qDataReceivedEvent",
Qt::QueuedConnection,
Q_ARG(QString, PI2QString(from)),
Q_ARG(QByteArray, PI2QByteArray(data)));
}
void QPIConnection::piPacketRec(const PIString & from, const PIByteArray & data) {
QMetaObject::invokeMethod(this, "qPacketReceivedEvent", Qt::QueuedConnection,
Q_ARG(QString, PI2QString(from)), Q_ARG(QByteArray, PI2QByteArray(data)));
QMetaObject::invokeMethod(this,
"qPacketReceivedEvent",
Qt::QueuedConnection,
Q_ARG(QString, PI2QString(from)),
Q_ARG(QByteArray, PI2QByteArray(data)));
}

View File

@@ -1,56 +1,59 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
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 QPICONNECTION_H
#define QPICONNECTION_H
#include <QObject>
#include <QMetaObject>
#include "piconnection.h"
#include "qpiconfig.h"
#include "piqt.h"
#include "qad_piqt_export.h"
#include "qpiconfig.h"
#include <QMetaObject>
#include <QObject>
class QAD_PIQT_EXPORT QPIConnection: public QObject, public PIConnection {
class QAD_PIQT_EXPORT QPIConnection
: public QObject
, public PIConnection {
Q_OBJECT
PIOBJECT_SUBCLASS(QPIConnection, PIConnection);
public:
QPIConnection(const QString & name = QString());
bool loadFromCMFile(const QString & file);
protected:
#if PIP_VERSION >= PIP_MAKE_VERSION(2,38,0)
void propertyChanged(const char *) override {setObjectName(PI2QString(name()));}
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 38, 0)
void propertyChanged(const char *) override { setObjectName(PI2QString(name())); }
#else
void propertyChanged(const PIString &) override {setObjectName(PI2QString(name()));}
void propertyChanged(const PIString &) override { setObjectName(PI2QString(name())); }
#endif
EVENT_HANDLER2(void, piDataRec, const PIString &, from, const PIByteArray &, data);
EVENT_HANDLER2(void, piPacketRec, const PIString &, from, const PIByteArray &, data);
public slots:
signals:
void qDataReceivedEvent(QString from, QByteArray data);
void qPacketReceivedEvent(QString from, QByteArray data);
};
#endif // QPICONNECTION_H