mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #247 Using CVariant in samples and tests.
This commit is contained in:
@@ -60,7 +60,7 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
// put Jane in the tower
|
// put Jane in the tower
|
||||||
CPropertyIndexVariantMap newController;
|
CPropertyIndexVariantMap newController;
|
||||||
newController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("112233", "Jane Doe")));
|
newController.addValue(CAtcStation::IndexController, CVariant::fromValue(CUser("112233", "Jane Doe")));
|
||||||
atcList.applyIf(
|
atcList.applyIf(
|
||||||
BlackMisc::Predicates::MemberEqual(&CAtcStation::getCallsign, CCallsign("eddm_twr")),
|
BlackMisc::Predicates::MemberEqual(&CAtcStation::getCallsign, CCallsign("eddm_twr")),
|
||||||
newController);
|
newController);
|
||||||
@@ -69,7 +69,7 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
// now Jane's time is over
|
// now Jane's time is over
|
||||||
CPropertyIndexVariantMap anotherController;
|
CPropertyIndexVariantMap anotherController;
|
||||||
anotherController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("445566", "Fuzzy")));
|
anotherController.addValue(CAtcStation::IndexController, CVariant::fromValue(CUser("445566", "Fuzzy")));
|
||||||
atcList.applyIf(newController, anotherController);
|
atcList.applyIf(newController, anotherController);
|
||||||
|
|
||||||
qDebug() << "-- after update via value map";
|
qDebug() << "-- after update via value map";
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace BlackMiscTest
|
|||||||
atcList.push_back(station1);
|
atcList.push_back(station1);
|
||||||
CAtcStation station1Cpy(station1);
|
CAtcStation station1Cpy(station1);
|
||||||
CFrequency changedFrequency(118.25, CFrequencyUnit::MHz());
|
CFrequency changedFrequency(118.25, CFrequencyUnit::MHz());
|
||||||
CPropertyIndexVariantMap vm(CAtcStation::IndexFrequency, changedFrequency.toQVariant());
|
CPropertyIndexVariantMap vm(CAtcStation::IndexFrequency, changedFrequency.toCVariant());
|
||||||
|
|
||||||
|
|
||||||
// demonstration apply
|
// demonstration apply
|
||||||
|
|||||||
@@ -8,12 +8,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "samplesvariant.h"
|
#include "samplesvariant.h"
|
||||||
|
#include "blackmisc/variant.h"
|
||||||
#include "blackmisc/pqallquantities.h"
|
#include "blackmisc/pqallquantities.h"
|
||||||
#include "blackmisc/avallclasses.h"
|
#include "blackmisc/avallclasses.h"
|
||||||
#include "blackmisc/blackmiscfreefunctions.h"
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
|
|
||||||
@@ -25,36 +27,38 @@ namespace BlackMiscTest
|
|||||||
BlackMisc::registerMetadata();
|
BlackMisc::registerMetadata();
|
||||||
|
|
||||||
CAngle a1(30.0, CAngleUnit::deg());
|
CAngle a1(30.0, CAngleUnit::deg());
|
||||||
QVariant qva = a1.toQVariant();
|
CVariant cva = a1.toCVariant();
|
||||||
qDebug() << a1 << qva.userType();
|
qDebug() << a1 << cva.userType();
|
||||||
|
|
||||||
CHeading h1(45, CHeading::True, CAngleUnit::deg());
|
CHeading h1(45, CHeading::True, CAngleUnit::deg());
|
||||||
CHeading h2(60, CHeading::True, CAngleUnit::deg());
|
CHeading h2(60, CHeading::True, CAngleUnit::deg());
|
||||||
|
|
||||||
QVariant qvh = h1.toQVariant();
|
CVariant cvh = h1.toCVariant();
|
||||||
qDebug() << h1 << qvh.userType();
|
qDebug() << h1 << cvh.userType();
|
||||||
|
|
||||||
|
qDebug() << cva << cvh; // CVariant knows how to stringify the contained value object
|
||||||
|
|
||||||
CAngle *ap_heading = &h1; // angle actually heading
|
CAngle *ap_heading = &h1; // angle actually heading
|
||||||
CAngle *ap_angle = &a1; // angle really heading
|
CAngle *ap_angle = &a1; // angle really heading
|
||||||
qDebug() << (*ap_heading) << ap_heading->toQVariant().userType();
|
qDebug() << (*ap_heading) << ap_heading->toCVariant().userType();
|
||||||
qDebug() << (*ap_angle) << ap_angle->toQVariant().userType();
|
qDebug() << (*ap_angle) << ap_angle->toCVariant().userType();
|
||||||
|
|
||||||
// This works, because ap is actually heading
|
// This works, because ap is actually heading
|
||||||
ap_heading->convertFromQVariant(h2.toQVariant());
|
ap_heading->convertFromCVariant(h2.toCVariant());
|
||||||
qDebug() << (*ap_heading) << ap_heading->toQVariant().userType();
|
qDebug() << (*ap_heading) << ap_heading->toCVariant().userType();
|
||||||
|
|
||||||
// This works, angle from variant angle
|
// This works, angle from variant angle
|
||||||
ap_angle->convertFromQVariant(a1.toQVariant());
|
ap_angle->convertFromCVariant(a1.toCVariant());
|
||||||
qDebug() << (*ap_angle) << ap_angle->toQVariant().userType();
|
qDebug() << (*ap_angle) << ap_angle->toCVariant().userType();
|
||||||
|
|
||||||
// This gives me an unwanted(!) assert, canConvert is not smart enough to detect upcasting
|
// This gives me an unwanted(!) assert, canConvert is not smart enough to detect upcasting
|
||||||
// because CValueObjects are not QObjects
|
// because CValueObjects are not QObjects
|
||||||
ap_angle->convertFromQVariant(h2.toQVariant());
|
ap_angle->convertFromCVariant(h2.toCVariant());
|
||||||
qDebug() << (*ap_angle) << ap_angle->toQVariant().userType();
|
qDebug() << (*ap_angle) << ap_angle->toCVariant().userType();
|
||||||
|
|
||||||
// This gives me the intended assert, because I assign angle to heading
|
// This gives me the intended assert, because I assign angle to heading
|
||||||
ap_heading->convertFromQVariant(a1.toQVariant());
|
ap_heading->convertFromCVariant(a1.toCVariant());
|
||||||
qDebug() << (*ap_heading) << ap_heading->toQVariant().userType();
|
qDebug() << (*ap_heading) << ap_heading->toCVariant().userType();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -378,21 +378,21 @@ namespace BlackMiscTest
|
|||||||
cv = testserviceInterface.pingCVariant(client);
|
cv = testserviceInterface.pingCVariant(client);
|
||||||
qDebug() << "Pinged CVariant via interface" << cv.toQString();
|
qDebug() << "Pinged CVariant via interface" << cv.toQString();
|
||||||
|
|
||||||
// test variant lists with different types wrapped in QVariant
|
// test variant lists with different types wrapped in CVariant
|
||||||
qDebug() << "----------------- variant tests ----------------";
|
qDebug() << "----------------- variant tests ----------------";
|
||||||
QVariantList qvList;
|
CVariantList cvList;
|
||||||
qvList << QVariant::fromValue(len);
|
cvList.push_back(CVariant::fromValue(len));
|
||||||
qvList << QVariant::fromValue(alt);
|
cvList.push_back(CVariant::fromValue(alt));
|
||||||
QList<QVariant> lengthsV;
|
CVariantList lengthsV;
|
||||||
lengthsV.append(QVariant::fromValue(len));
|
lengthsV.push_back(CVariant::fromValue(len));
|
||||||
lengthsV.append(QVariant::fromValue(alt));
|
lengthsV.push_back(CVariant::fromValue(alt));
|
||||||
testserviceInterface.receiveLengthsQvl(qvList);
|
testserviceInterface.receiveLengthsQvl(cvList);
|
||||||
qDebug() << "Send lengths via interface as QListVariant:";
|
qDebug() << "Send lengths via interface as CVariantList:";
|
||||||
testserviceInterface.receiveLengthsQl(lengthsV);
|
testserviceInterface.receiveLengthsQl(lengthsV);
|
||||||
qDebug() << "Send lengths via interface as QList<QVariant>:";
|
qDebug() << "Send lengths via interface as QList<CVariant>:";
|
||||||
foreach(QVariant lv, qvList)
|
foreach(CVariant lv, cvList)
|
||||||
{
|
{
|
||||||
qDebug() << " " << "Send length in list:" << BlackMisc::qVariantToString(lv);
|
qDebug() << " " << "Send length in list:" << lv;
|
||||||
}
|
}
|
||||||
QThread::msleep(2500);
|
QThread::msleep(2500);
|
||||||
|
|
||||||
|
|||||||
@@ -41,12 +41,9 @@ namespace BlackMiscTest
|
|||||||
/*
|
/*
|
||||||
* Receive variant
|
* Receive variant
|
||||||
*/
|
*/
|
||||||
void Testservice::receiveVariant(const QDBusVariant &variant, int localMetaType)
|
void Testservice::receiveVariant(const CVariant &variant)
|
||||||
{
|
{
|
||||||
QVariant qv = variant.variant();
|
qDebug() << "Pid:" << ServiceTool::getPid() << "Received variant:" << variant;
|
||||||
QVariant qvF = BlackMisc::fixQVariantFromDbusArgument(qv, localMetaType);
|
|
||||||
QString s = BlackMisc::qVariantToString(qvF, true);
|
|
||||||
qDebug() << "Pid:" << ServiceTool::getPid() << "Received variant:" << s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace BlackMiscTest
|
|||||||
void receiveStringMessage(const QString &message);
|
void receiveStringMessage(const QString &message);
|
||||||
|
|
||||||
//! Receive a QVariant
|
//! Receive a QVariant
|
||||||
void receiveVariant(const QDBusVariant &variant, int localMetaType);
|
void receiveVariant(const BlackMisc::CVariant &variant);
|
||||||
|
|
||||||
//! Receive speed
|
//! Receive speed
|
||||||
void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed);
|
void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed);
|
||||||
|
|||||||
@@ -206,14 +206,14 @@ namespace BlackMiscTest
|
|||||||
return asyncCallWithArgumentList(QLatin1String("receiveLength"), argumentList);
|
return asyncCallWithArgumentList(QLatin1String("receiveLength"), argumentList);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QDBusPendingReply<> receiveLengthsQl(const QVariantList &lengthsList)
|
inline QDBusPendingReply<> receiveLengthsQl(const BlackMisc::CVariantList &lengthsList)
|
||||||
{
|
{
|
||||||
QList<QVariant> argumentList;
|
QList<QVariant> argumentList;
|
||||||
argumentList << QVariant::fromValue(lengthsList);
|
argumentList << QVariant::fromValue(lengthsList);
|
||||||
return asyncCallWithArgumentList(QLatin1String("receiveLengthsQl"), argumentList);
|
return asyncCallWithArgumentList(QLatin1String("receiveLengthsQl"), argumentList);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QDBusPendingReply<> receiveLengthsQvl(const QVariantList &lengthsVariantList)
|
inline QDBusPendingReply<> receiveLengthsQvl(const BlackMisc::CVariantList &lengthsVariantList)
|
||||||
{
|
{
|
||||||
QList<QVariant> argumentList;
|
QList<QVariant> argumentList;
|
||||||
argumentList << QVariant::fromValue(lengthsVariantList);
|
argumentList << QVariant::fromValue(lengthsVariantList);
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "samplesphysicalquantities.h"
|
#include "samplesphysicalquantities.h"
|
||||||
|
#include "blackmisc/variant.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
namespace BlackMiscTest
|
namespace BlackMiscTest
|
||||||
@@ -18,7 +20,7 @@ namespace BlackMiscTest
|
|||||||
// parsing
|
// parsing
|
||||||
CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
|
CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
|
||||||
CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
|
CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
|
||||||
QVariant parsedPq3 = CPqString::parseToVariant("666");
|
CVariant parsedPq3 = CPqString::parseToVariant("666");
|
||||||
qDebug() << "parsed" << parsedPq1 << parsedPq2 << parsedPq3;
|
qDebug() << "parsed" << parsedPq1 << parsedPq2 << parsedPq3;
|
||||||
|
|
||||||
CSpeed speedParsed = CPqString::parse<CSpeed>("111.33ft/s");
|
CSpeed speedParsed = CPqString::parse<CSpeed>("111.33ft/s");
|
||||||
|
|||||||
@@ -84,6 +84,15 @@ namespace BlackMisc
|
|||||||
return !((*this) == other);
|
return !((*this) == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Less than?
|
||||||
|
*/
|
||||||
|
bool CTestValueObject::operator <(const CTestValueObject &other) const
|
||||||
|
{
|
||||||
|
if (this == &other) return false;
|
||||||
|
return TupleConverter<CTestValueObject>::toTuple(*this) < TupleConverter<CTestValueObject>::toTuple(other);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hash
|
* Hash
|
||||||
*/
|
*/
|
||||||
@@ -95,16 +104,16 @@ namespace BlackMisc
|
|||||||
/*
|
/*
|
||||||
* Property by index
|
* Property by index
|
||||||
*/
|
*/
|
||||||
QVariant CTestValueObject::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
CVariant CTestValueObject::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { return this->toQVariant(); }
|
if (index.isMyself()) { return this->toCVariant(); }
|
||||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexDescription:
|
case IndexDescription:
|
||||||
return QVariant::fromValue(this->m_description);
|
return CVariant::fromValue(this->m_description);
|
||||||
case IndexName:
|
case IndexName:
|
||||||
return QVariant::fromValue(this->m_name);
|
return CVariant::fromValue(this->m_name);
|
||||||
default:
|
default:
|
||||||
return CValueObject::propertyByIndex(index);
|
return CValueObject::propertyByIndex(index);
|
||||||
}
|
}
|
||||||
@@ -113,11 +122,11 @@ namespace BlackMisc
|
|||||||
/*
|
/*
|
||||||
* Property by index (setter)
|
* Property by index (setter)
|
||||||
*/
|
*/
|
||||||
void CTestValueObject::setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index)
|
void CTestValueObject::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||||
{
|
{
|
||||||
if (index.isMyself())
|
if (index.isMyself())
|
||||||
{
|
{
|
||||||
this->convertFromQVariant(variant);
|
this->convertFromCVariant(variant);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ namespace BlackMisc
|
|||||||
//! Unequal operator !=
|
//! Unequal operator !=
|
||||||
bool operator !=(const CTestValueObject &other) const;
|
bool operator !=(const CTestValueObject &other) const;
|
||||||
|
|
||||||
|
//! Less than operator <
|
||||||
|
bool operator <(const CTestValueObject &other) const;
|
||||||
|
|
||||||
//! \copydoc CValueObject::getValueHash()
|
//! \copydoc CValueObject::getValueHash()
|
||||||
virtual uint getValueHash() const override;
|
virtual uint getValueHash() const override;
|
||||||
|
|
||||||
@@ -72,11 +75,11 @@ namespace BlackMisc
|
|||||||
//! \copydoc TupleConverter<>::jsonMembers()
|
//! \copydoc TupleConverter<>::jsonMembers()
|
||||||
static const QStringList &jsonMembers();
|
static const QStringList &jsonMembers();
|
||||||
|
|
||||||
//! \copydoc CValueObject::propertyByIndex(int)
|
//! \copydoc CValueObject::propertyByIndex
|
||||||
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||||
|
|
||||||
//! \copydoc CValueObject::setPropertyByIndex(const QVariant &, int index)
|
//! \copydoc CValueObject::setPropertyByIndex
|
||||||
void setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
//! \copydoc CValueObject::toQVariant
|
||||||
virtual QVariant toQVariant() const override
|
virtual QVariant toQVariant() const override
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace BlackMiscTest
|
|||||||
QVERIFY2(!(l1 > l4), "Null length and non-null length should not be comparable");
|
QVERIFY2(!(l1 > l4), "Null length and non-null length should not be comparable");
|
||||||
QVERIFY2(compare(l1, l4) < 0, "Null length and non-null length should be sortable");
|
QVERIFY2(compare(l1, l4) < 0, "Null length and non-null length should be sortable");
|
||||||
|
|
||||||
QVariant station1qv = QVariant::fromValue(station1);
|
CVariant station1qv = CVariant::fromValue(station1);
|
||||||
QVERIFY2(station1 == station1, "Station should be equal");
|
QVERIFY2(station1 == station1, "Station should be equal");
|
||||||
|
|
||||||
QVERIFY(station1.getController() == station2.getController());
|
QVERIFY(station1.getController() == station2.getController());
|
||||||
@@ -60,10 +60,10 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
QVERIFY2(station1 == station2, "Station should be equal");
|
QVERIFY2(station1 == station2, "Station should be equal");
|
||||||
QVERIFY2(station1 != station3, "Station should not be equal");
|
QVERIFY2(station1 != station3, "Station should not be equal");
|
||||||
QVERIFY2(station1qv == station1, "Station should be equal (QVariant)");
|
QVERIFY2(station1qv == station1, "Station should be equal (CVariant)");
|
||||||
QVERIFY2(station1 == station1qv, "Station should be equal (QVariant)");
|
QVERIFY2(station1 == station1qv, "Station should be equal (CVariant)");
|
||||||
QVERIFY2(station2 == station1qv, "Station should be equal (QVariant)");
|
QVERIFY2(station2 == station1qv, "Station should be equal (CVariant)");
|
||||||
QVERIFY2(station3 != station1qv, "Station should be equal (QVariant)");
|
QVERIFY2(station3 != station1qv, "Station should be equal (CVariant)");
|
||||||
|
|
||||||
QVERIFY2(compare(station1, station1) == 0, "Station should be equal");
|
QVERIFY2(compare(station1, station1) == 0, "Station should be equal");
|
||||||
QVERIFY2(compare(station1, station2) == 0, "Station should be equal");
|
QVERIFY2(compare(station1, station2) == 0, "Station should be equal");
|
||||||
|
|||||||
Reference in New Issue
Block a user