📄 qdbusargument.cpp
字号:
/*! Opens a D-BUS structure suitable for extracting elements. This function is used usually in \c{operator>>} streaming operators, as in the following example: \code const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct) { argument.beginStructure() argument >> mystruct.member1 >> mystruct.member2 >> mystruct.member3 >> ...; argument.endStructure(); return argument; } \endcode \sa endStructure(), beginArray(), beginMap()*/void QDBusArgument::beginStructure() const{ if (d && d->checkRead()) d = d->demarshaller()->beginStructure();}/*! Closes the D-BUS structure and allow extracting of the next element after the structure. \sa beginStructure()*/void QDBusArgument::endStructure() const{ if (d && d->checkRead()) d = d->demarshaller()->endStructure();}/*! Recurses into the D-BUS array to allow extraction of the array elements. This function is used usually in \c{operator>>} streaming operators, as in the following example: \code // extract a MyArray array of MyElement elements const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myarray) { argument.beginArray(); myarray.clear(); while ( !argument.atEnd() ) { MyElement element; argument >> element; myarray.append( element ); } argument.endArray(); return argument; } \endcode If the type you want to demarshall is a QList, QVector or any of the Qt's \l {containers.html}{containers} that take one template parameter, you need not declare an \c{operator>>} function for it, since QtDBus provides generic templates to do the job of demarshalling the data. The same applies for STL's sequence containers, such as \c {std::list}, \c {std::vector}, etc. \sa atEnd(), beginStructure(), beginMap()*/void QDBusArgument::beginArray() const{ if (d && d->checkRead()) d = d->demarshaller()->beginArray();}/*! Closes the D-BUS array and allow extracting of the next element after the array. \sa beginArray()*/void QDBusArgument::endArray() const{ if (d && d->checkRead()) d = d->demarshaller()->endArray();}/*! Recurses into the D-BUS map to allow extraction of the map's elements. This function is used usually in \c{operator>>} streaming operators, as in the following example: \code // extract a MyDictionary map that associates ints to MyValue elements const QDBusArgument &operator>>(const QDBusArgument &argument, MyDictionary &mydict) { argument.beginMap(); mydict.clear(); while ( !argMap.atEnd() ) { int key; MyValue value; argument.beginMapEntry(); argument >> key >> value; argument.endMapEntry(); mydict.append( key, value ); } argument.endMap(); return argument; } \endcode If the type you want to demarshall is a QMap or QHash, you need not declare an \c{operator>>} function for it, since QtDBus provides generic templates to do the job of demarshalling the data. \sa endMap(), beginStructure(), beginArray(), beginMapEntry()*/void QDBusArgument::beginMap() const{ if (d && d->checkRead()) d = d->demarshaller()->beginMap();}/*! Closes the D-BUS map and allow extracting of the next element after the map. \sa beginMap()*/void QDBusArgument::endMap() const{ if (d && d->checkRead()) d = d->demarshaller()->endMap();}/*! Recurses into the D-BUS map entry to allow extraction of the key and value pair. See beginMap() for an example of how this function is usually used. \sa endMapEntry(), beginMap()*/void QDBusArgument::beginMapEntry() const{ if (d && d->checkRead()) d = d->demarshaller()->beginMapEntry();}/*! Closes the D-BUS map entry and allow extracting of the next element on the map. \sa beginMapEntry()*/void QDBusArgument::endMapEntry() const{ if (d && d->checkRead()) d = d->demarshaller()->endMapEntry();}/*! Returns true if there are no more elements to be extracted from this QDBusArgument. This function is usually used in QDBusArgument objects returned from beginMap() and beginArray().*/bool QDBusArgument::atEnd() const{ if (d && d->checkRead()) return d->demarshaller()->atEnd(); return true; // at least, stop reading}// for optimization purposes, we include the marshallers here#include "qdbusmarshaller.cpp"#include "qdbusdemarshaller.cpp"// QDBusArgument operatorsconst QDBusArgument &operator>>(const QDBusArgument &a, QVariant &v){ QDBusVariant dbv; a >> dbv; v = dbv.variant(); return a;}// QVariant types#ifndef QDBUS_NO_SPECIALTYPESconst QDBusArgument &operator>>(const QDBusArgument &a, QDate &date){ int y, m, d; a.beginStructure(); a >> y >> m >> d; a.endStructure(); if (y != 0 && m != 0 && d != 0) date.setYMD(y, m, d); else date = QDate(); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QDate &date){ a.beginStructure(); if (date.isValid()) a << date.year() << date.month() << date.day(); else a << 0 << 0 << 0; a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QTime &time){ int h, m, s, ms; a.beginStructure(); a >> h >> m >> s >> ms; a.endStructure(); if (h < 0) time = QTime(); else time.setHMS(h, m, s, ms); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QTime &time){ a.beginStructure(); if (time.isValid()) a << time.hour() << time.minute() << time.second() << time.msec(); else a << -1 << -1 << -1 << -1; a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt){ QDate date; QTime time; int timespec; a.beginStructure(); a >> date >> time >> timespec; a.endStructure(); dt = QDateTime(date, time, Qt::TimeSpec(timespec)); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt){ a.beginStructure(); a << dt.date() << dt.time() << int(dt.timeSpec()); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QRect &rect){ int x, y, width, height; a.beginStructure(); a >> x >> y >> width >> height; a.endStructure(); rect.setRect(x, y, width, height); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QRect &rect){ a.beginStructure(); a << rect.x() << rect.y() << rect.width() << rect.height(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QRectF &rect){ qreal x, y, width, height; a.beginStructure(); a >> x >> y >> width >> height; a.endStructure(); rect.setRect(x, y, width, height); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QRectF &rect){ a.beginStructure(); a << rect.x() << rect.y() << rect.width() << rect.height(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QSize &size){ a.beginStructure(); a >> size.rwidth() >> size.rheight(); a.endStructure(); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QSize &size){ a.beginStructure(); a << size.width() << size.height(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QSizeF &size){ a.beginStructure(); a >> size.rwidth() >> size.rheight(); a.endStructure(); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QSizeF &size){ a.beginStructure(); a << size.width() << size.height(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QPoint &pt){ a.beginStructure(); a >> pt.rx() >> pt.ry(); a.endStructure(); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QPoint &pt){ a.beginStructure(); a << pt.x() << pt.y(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QPointF &pt){ a.beginStructure(); a >> pt.rx() >> pt.ry(); a.endStructure(); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QPointF &pt){ a.beginStructure(); a << pt.x() << pt.y(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QLine &line){ QPoint p1, p2; a.beginStructure(); a >> p1 >> p2; a.endStructure(); line = QLine(p1, p2); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QLine &line){ a.beginStructure(); a << line.p1() << line.p2(); a.endStructure(); return a;}const QDBusArgument &operator>>(const QDBusArgument &a, QLineF &line){ QPointF p1, p2; a.beginStructure(); a >> p1 >> p2; a.endStructure(); line = QLineF(p1, p2); return a;}QDBusArgument &operator<<(QDBusArgument &a, const QLineF &line){ a.beginStructure(); a << line.p1() << line.p2(); a.endStructure(); return a;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -