From 8b512ba818ef228dcf99cdc2542df5eafdfdc5a4 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 22 Jul 2013 14:33:50 +0200 Subject: [PATCH 01/36] DBus enabling of base classes plus sample for testing / show how to use them. Also qdbuscpp2xml plugin for blackmisc classes. --- .gitignore | 3 +- client.pro | 5 +- .../sample_quantities_avionics.pro | 8 +- .../BlackMiscTest.Testservice.xml | 22 + samples/blackmiscquantities_dbus/main.cpp | 114 +++++ samples/blackmiscquantities_dbus/readme.txt | 9 + .../sample_quantities_avionics_dbus.pro | 30 ++ .../blackmiscquantities_dbus/testservice.cpp | 56 +++ .../blackmiscquantities_dbus/testservice.h | 89 ++++ .../testservicetool.cpp | 32 ++ .../testservicetool.h | 53 +++ .../sample_quantities_avionics_xmlplugin.pro | 25 + .../sampleplugin.cpp | 12 + .../sampleplugin.h | 21 + .../blackmiscvectorgeo/sample_vector_geo.pro | 2 +- samples/interpolator/sample_interpolator.pro | 2 +- src/blackcore/blackcore.pro | 2 +- src/blackmisc/avallclasses.h | 18 + src/blackmisc/avioadfsystem.h | 30 +- src/blackmisc/aviobase.h | 5 +- src/blackmisc/aviocomsystem.h | 1 + src/blackmisc/aviomodulator.cpp | 11 - src/blackmisc/aviomodulator.h | 51 +- src/blackmisc/avionavsystem.h | 1 + src/blackmisc/aviotransponder.h | 1 + src/blackmisc/basestreamstringifier.h | 2 +- src/blackmisc/blackmisc.pro | 3 +- src/blackmisc/blackmiscfreefunctions.cpp | 43 ++ src/blackmisc/blackmiscfreefunctions.h | 44 ++ src/blackmisc/coordinategeodetic.h | 1 + src/blackmisc/pqacceleration.h | 2 + src/blackmisc/pqallquantities.h | 3 +- src/blackmisc/pqangle.h | 2 + src/blackmisc/pqbase.h | 35 +- src/blackmisc/pqfrequency.h | 3 + src/blackmisc/pqlength.h | 3 + src/blackmisc/pqmass.h | 2 + src/blackmisc/pqphysicalquantity.h | 54 ++- src/blackmisc/pqpressure.h | 3 + src/blackmisc/pqspeed.h | 8 +- src/blackmisc/pqtemperature.h | 3 + src/blackmisc/pqtime.h | 2 + src/blackmisc/pqunits.h | 434 +++++++++++++++++- src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro | 19 + src/blackmisc_cpp2xml/blackmiscplugin.cpp | 15 + src/blackmisc_cpp2xml/blackmiscplugin.h | 28 ++ tests/blackcore/test_blackcore.pro | 2 +- tests/blackmisc/test_blackmisc.pro | 2 +- 48 files changed, 1264 insertions(+), 52 deletions(-) create mode 100644 samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml create mode 100644 samples/blackmiscquantities_dbus/main.cpp create mode 100644 samples/blackmiscquantities_dbus/readme.txt create mode 100644 samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro create mode 100644 samples/blackmiscquantities_dbus/testservice.cpp create mode 100644 samples/blackmiscquantities_dbus/testservice.h create mode 100644 samples/blackmiscquantities_dbus/testservicetool.cpp create mode 100644 samples/blackmiscquantities_dbus/testservicetool.h create mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro create mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp create mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h create mode 100644 src/blackmisc/avallclasses.h create mode 100644 src/blackmisc/blackmiscfreefunctions.cpp create mode 100644 src/blackmisc/blackmiscfreefunctions.h create mode 100644 src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro create mode 100644 src/blackmisc_cpp2xml/blackmiscplugin.cpp create mode 100644 src/blackmisc_cpp2xml/blackmiscplugin.h diff --git a/.gitignore b/.gitignore index 83118b313..6f275a76e 100644 --- a/.gitignore +++ b/.gitignore @@ -81,4 +81,5 @@ Thumbs.db desktop.ini # Editors temporary files -*~ \ No newline at end of file +*~ +/client.pro.user.2.7pre1 diff --git a/client.pro b/client.pro index e08006914..6806cdb7f 100644 --- a/client.pro +++ b/client.pro @@ -16,6 +16,7 @@ WITH_SAMPLES = ON equals(WITH_BLACKMISC, ON) { SUBDIRS += src/blackmisc + SUBDIRS += src/blackmisc_cpp2xml } equals(WITH_BLACKCORE, ON) { @@ -50,8 +51,10 @@ equals(WITH_SAMPLES, ON) { SUBDIRS += samples/logging/sample_logging.pro SUBDIRS += samples/plugin/sample_plugin.pro SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro - SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro + SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro + SUBDIRS += samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro + SUBDIRS += } equals(WITH_UNITTESTS, ON) { diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index 2e9e95d87..98c3d24c0 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -1,13 +1,13 @@ -QT += core +QT += core dbus QT -= gui -TARGET = sample_physicalquantities +TARGET = sample_quantities_avionics TEMPLATE = app CONFIG += console CONFIG -= app_bundle -DEPENDPATH += . ../../src +DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src LIBS += -L../../lib -lblackmisc @@ -19,3 +19,5 @@ DESTDIR = ../../bin HEADERS += *.h SOURCES += *.cpp + +OTHER_FILES += diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml new file mode 100644 index 000000000..fec10b6e1 --- /dev/null +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp new file mode 100644 index 000000000..905f4ca78 --- /dev/null +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -0,0 +1,114 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include +#include +#include + +#include "testservice.h" +#include "testservice_adaptor.h" +#include "testservice_interface.h" +#include "testservicetool.h" + +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMiscTest; + +/*! + * Sample tests + */ +int main(int argc, char *argv[]) +{ + BlackMisc::registerMetadata(); + QCoreApplication a(argc, argv); + + // init + if (argc < 1) { + qFatal("Missing name of executable"); + } + const QString executable = QString(argv[0]); + Testservice* pTestservice = NULL; + TestserviceAdaptor* pTestserviceAdaptor = NULL; + + // Create a Testservice instance and register it with the session bus only if + // the service isn't already available. + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.interface()->isServiceRegistered(Testservice::ServiceName)) { + pTestservice = new Testservice(&a); + pTestserviceAdaptor = new TestserviceAdaptor(pTestservice); + + if (!connection.registerService(Testservice::ServiceName)) { + QDBusError err = connection.lastError(); + qWarning() << err.message(); + qWarning() << "Started dbus-daemon.exe --session?"; + qWarning() << "Created directory session.d? See https://dev.vatsim-germany.org/projects/vatpilotclient/wiki/DBusExample#Running-the-example"; + qFatal("Could not register service!"); + } + + if (!connection.registerObject(Testservice::ServicePath, pTestservice)) { + qFatal("Could not register service object!"); + } + + qDebug() << "Registration running as pid: " << TestserviceTool::getPid(); + if (pTestservice) qDebug() << "Service registered"; + if (pTestserviceAdaptor) qDebug() << "Adaptor object registered"; + + new TestserviceAdaptor(pTestservice); // adaptor + QString service; // service not needed + if (QDBusConnection::sessionBus().connect( + service, Testservice::ServicePath, Testservice::ServiceName, + "sendStringMessage", pTestservice, + SLOT(receiveStringMessage(const QString &)))) { + qDebug() << "Connected object with bus sendStringMessage"; + } else { + qFatal("Cannot connect service with DBus"); + } + + // Call myself to implement client + TestserviceTool::startNewProcess(executable, &a); + + } else { + qDebug() << "Already registered, assuming 2nd pid: " << TestserviceTool::getPid(); + BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection, &a); + double speedValue = 200.0; + while (true) { + QDBusMessage m = QDBusMessage::createSignal( + Testservice::ServicePath, Testservice::ServiceName, + "sendStringMessage"); + + //The << operator is used to add the parameters for the slot + QDateTime dtnow = QDateTime::currentDateTimeUtc(); + QString msg = QString("Message from %1 at %2").arg(TestserviceTool::getPid()).arg(dtnow.toString("MM/dd/yyyy @ hh:mm:ss")); + m << msg; + + // We send this as a non-replying message. This is used for sending errors, replys, signals, + // and method calls (slots) that don't return + if (connection.send(m)) { + qDebug() << "Send via low level method" << m; + } + TestserviceTool::sleep(2500); + + // same as interface message + testserviceInterface.receiveStringMessage(msg); + qDebug() << "Send string via interface" << msg; + TestserviceTool::sleep(2500); + + // PQs + CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); + testserviceInterface.receiveSpeed(speed); + qDebug() << "Send speed via interface" << speed; + TestserviceTool::sleep(2500); + + // Aviation + CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom()); + testserviceInterface.receiveComUnit(comSystem); + qDebug() << "Send COM via interface" << comSystem; + TestserviceTool::sleep(2500); + } + } + + return a.exec(); +} diff --git a/samples/blackmiscquantities_dbus/readme.txt b/samples/blackmiscquantities_dbus/readme.txt new file mode 100644 index 000000000..4481e7f8f --- /dev/null +++ b/samples/blackmiscquantities_dbus/readme.txt @@ -0,0 +1,9 @@ +Starting: dbus-daemon.exe --session +- blocks CMD (sometimes daemon continues to run when pressing CTRL/C) +- does not start without directory session.d, i.e. ..\Qt\Qt5.1.0DBus\qtbase\etc\dbus-1\session.d + +qdbuscpp2xml testservice.h -x H:\Projects\QtBuilds\build-client-Qt_5_1_0_VATSIM_qmake_Microsoft_Visual_C_Compiler_10_0_x86_2-Release\bin\blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml + +Done automatically, but if required manually +Interface: qdbusxml2cpp blackbus.testservice.xml -p itestservice +Adaptor: qdbusxml2cpp blackbus.testservice.xml -a atestservice diff --git a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro new file mode 100644 index 000000000..52ddd002e --- /dev/null +++ b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro @@ -0,0 +1,30 @@ +QT += core dbus +QT -= gui + +TARGET = sample_quantities_avionics_dbus +TEMPLATE = app + +CONFIG += console +CONFIG -= app_bundle + +# Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, +# then automatically adds them to the sources to compile +DBUS_ADAPTORS += BlackMiscTest.Testservice.xml +DBUS_INTERFACES += BlackMiscTest.Testservice.xml +QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h +QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h + +DEPENDPATH += . ../../src/blackmisc +INCLUDEPATH += . ../../src + +LIBS += -L../../lib -lblackmisc + +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a + +DESTDIR = ../../bin + +HEADERS += *.h +SOURCES += *.cpp + +OTHER_FILES += readme.txt BlackMiscTest.Testservice.xml diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp new file mode 100644 index 000000000..bcfac37e3 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -0,0 +1,56 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "testservice.h" + +namespace BlackMiscTest +{ + +const QString Testservice::ServiceName = QString(BLACKMISCKTEST_SERVICENAME); +const QString Testservice::ServicePath = QString(BLACKMISCKTEST_SERVICEPATH); + +/* + * Constructor + */ +Testservice::Testservice(QObject *parent) : QObject(parent) +{ + // void +} + +/* + * Slot to receive messages + */ +void Testservice::receiveStringMessage(const QString &message) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received message:" << message; +} + +/* + * Receive variant + */ +void Testservice::receiveVariant(const QDBusVariant &variant) +{ + QVariant qv = variant.variant(); + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << qv; +} + +/* + * Receive speed + */ +void Testservice::receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received speed:" << speed; +} + +/* + * Receive COM unit + */ +void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received COM:" << comUnit; +} + + +} // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h new file mode 100644 index 000000000..6ce955b27 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -0,0 +1,89 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISCKTEST_TESTSERVICEPQAV_H +#define BLACKMISCKTEST_TESTSERVICEPQAV_H + +// clash with struct interace in objbase.h used to happen +#pragma push_macro("interface") +#undef interface + +#define BLACKMISCKTEST_SERVICENAME "blackmisctest.testservice" +#define BLACKMISCKTEST_SERVICEPATH "/blackbus" + +#include +#include +#include +#include "blackmisc/blackmiscfreefunctions.h" +#include "testservicetool.h" + +namespace BlackMiscTest { + +/*! + * \brief Testservice for PQ DBus tests + */ +class Testservice : public QObject +{ + // http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes#Write_a_class + // https://dev.vatsim-germany.org/projects/vatpilotclient/wiki/DBusExample + // http://qt-project.org/doc/qt-4.8/examples-dbus.html + // http://dbus.freedesktop.org/doc/dbus-tutorial.html#meta + + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKMISCKTEST_SERVICENAME) + + // For some reasons the interface name in the XML is not set correctly + // to the above name + + +signals: + /*! + * \brief Send string message + * \param message + */ + void sendStringMessage(const QString& message); + +public slots: + /*! + * \brief Receive string message + * \param message + */ + void receiveStringMessage(const QString &message); + + /*! + * \brief Receive a QVariant + * \param variant + */ + void receiveVariant(const QDBusVariant &variant); + + /*! + * \brief Receive speed + * \param speed + */ + void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed); + + /*! + * \brief receiveComUnit + * \param comUnit + */ + void receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit); + +public: + static const QString ServiceName; + static const QString ServicePath; + + /*! + * \brief Constructor + * \param parent + */ + explicit Testservice(QObject *parent = 0); + +}; + +} // namespace + +#pragma pop_macro("interface") + +#endif // BLACKMISCKTEST_TESTSERVICEPQAV_H diff --git a/samples/blackmiscquantities_dbus/testservicetool.cpp b/samples/blackmiscquantities_dbus/testservicetool.cpp new file mode 100644 index 000000000..8c40db048 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservicetool.cpp @@ -0,0 +1,32 @@ +#include "testservicetool.h" + +namespace BlackMiscTest +{ + +/* + * Start a new process + */ +QProcess * TestserviceTool::startNewProcess(const QString &executable, QObject *parent = 0) +{ + QProcess *process = new QProcess(parent); + process->startDetached(executable); + return process; +} + +/* + * Sleep + */ +void TestserviceTool::sleep(qint32 ms) +{ + if (ms < 1) return; + +#ifdef Q_OS_WIN + Sleep(uint(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif + +} + +} // namespace diff --git a/samples/blackmiscquantities_dbus/testservicetool.h b/samples/blackmiscquantities_dbus/testservicetool.h new file mode 100644 index 000000000..125db190e --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservicetool.h @@ -0,0 +1,53 @@ +#ifndef BLACKMISCTEST_TESTSERVICETOOL_H +#define BLACKMISCTEST_TESTSERVICETOOL_H + +#include +#include +#ifdef Q_OS_WIN +// for qdatetime, see here http://qt-project.org/forums/viewthread/22133 +#define NOMINMAX +#include // for Sleep +#endif + +namespace BlackMiscTest +{ + +/*! + * \brief Supporting functions for running the tests + */ +class TestserviceTool +{ +private: + /*! + * \brief Constructor + */ + TestserviceTool() {} + +public: + /*! + * \brief Get process id + * \return + */ + static qint64 getPid() { + return QCoreApplication::applicationPid(); + } + + /*! + * \brief Start a new process + * \param executable + * \param parent + * \return + */ + static QProcess *startNewProcess(const QString &executable, QObject *parent); + + /*! + * \brief Own sleep to avoid inlude of QTest + * \param ms + */ + static void sleep(qint32 ms); + +}; + +} // namespace + +#endif // BLACKMISCTEST_TESTSERVICETOOL_H diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro b/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro new file mode 100644 index 000000000..02804edab --- /dev/null +++ b/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro @@ -0,0 +1,25 @@ +QT += core dbus + +TARGET = sample_quantities_avionics_xmlplugin +TEMPLATE = lib + +CONFIG += plugin + +DEPENDPATH += . ../../src/blackmisc +INCLUDEPATH += . ../../src + +LIBS += -L../../lib -lblackmisc \ + ../blackmiscquantities_dbus/release/dummy.obj \ + ../blackmiscquantities_dbus/release/moc_dummy.obj \ + ../blackmiscquantities_dbus/release/dummynoq.obj + +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../samples/blackmiscquantities_dbus/release/dummy.obj +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../samples/blackmiscquantities_dbus/release/dummy.obj + +DESTDIR = ../../bin + +HEADERS += *.h +SOURCES += *.cpp + diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp new file mode 100644 index 000000000..edf3829ba --- /dev/null +++ b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp @@ -0,0 +1,12 @@ +#include "sampleplugin.h" + + +void CXmlSamplePlugin::registerMetaTypes() +{ + qRegisterMetaType("BlackMiscTest::Dummy"); + qDBusRegisterMetaType(); + + qRegisterMetaType("BlackMiscTest::DummyNoQ"); + qDBusRegisterMetaType(); + +} diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h new file mode 100644 index 000000000..921247b2b --- /dev/null +++ b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h @@ -0,0 +1,21 @@ +#ifndef SAMPLEPLUGIN_H +#define SAMPLEPLUGIN_H + +#include +#include +#include +#include +#include "../blackmiscquantities_dbus/dummy.h" +#include "../blackmiscquantities_dbus/dummynoq.h" + +class CXmlSamplePlugin : public QObject, public QDBusCpp2XmlPlugin +{ + Q_OBJECT + Q_INTERFACES(QDBusCpp2XmlPlugin) + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.DBus.Cpp2XmlPlugin") + +public: + virtual void registerMetaTypes(); +}; + +#endif // SAMPLEPLUGIN_H diff --git a/samples/blackmiscvectorgeo/sample_vector_geo.pro b/samples/blackmiscvectorgeo/sample_vector_geo.pro index a44bebc4a..134fc28fe 100644 --- a/samples/blackmiscvectorgeo/sample_vector_geo.pro +++ b/samples/blackmiscvectorgeo/sample_vector_geo.pro @@ -1,4 +1,4 @@ -QT += core +QT += core dbus TARGET = sample_vector_geo CONFIG += console diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index aa2fea407..97ede3805 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -1,4 +1,4 @@ -QT += core +QT += core dbus TARGET = sample_interpolator CONFIG += console diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 08d1b0717..98361abb9 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -1,5 +1,5 @@ # GUI is required for the matrix classes -QT += network +QT += network dbus TARGET = blackcore TEMPLATE = lib diff --git a/src/blackmisc/avallclasses.h b/src/blackmisc/avallclasses.h new file mode 100644 index 000000000..a1626c962 --- /dev/null +++ b/src/blackmisc/avallclasses.h @@ -0,0 +1,18 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_AVALLCLASSES_H +#define BLACKMISC_AVALLCLASSES_H + +#include "blackmisc/avaltitude.h" +#include "blackmisc/avheading.h" +#include "blackmisc/avioadfsystem.h" +#include "blackmisc/aviocomsystem.h" +#include "blackmisc/avionavsystem.h" +#include "blackmisc/aviotransponder.h" +#include "blackmisc/avtrack.h" +#include "blackmisc/avverticalpositions.h" + +#endif // guard diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index f940aad55..5cff56b5d 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -24,9 +24,9 @@ private: * \param f * \return */ - bool isValidFrequency(CFrequency f) const + bool isValidFrequency(PhysicalQuantities::CFrequency f) const { - double fr = f.valueRounded(CFrequencyUnit::kHz(), this->m_digits); + double fr = f.valueRounded(PhysicalQuantities::CFrequencyUnit::kHz(), this->m_digits); return fr >= 190.0 && fr <= 1750.0; } /*! @@ -38,7 +38,7 @@ private: * \param digits * */ - CAdfSystem(bool validate, const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CAdfSystem(bool validate, const QString &name, const PhysicalQuantities::CFrequency &activeFrequency, const PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): CModulator(name, activeFrequency, standbyFrequency, digits) { this->validate(validate); @@ -90,7 +90,7 @@ public: * \param standbyFrequency * \param digits */ - CAdfSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): + CAdfSystem(const QString &name, const PhysicalQuantities::CFrequency &activeFrequency, const PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { this->validate(true); @@ -108,7 +108,7 @@ public: * \brief Set standby frequency * \param frequencyKHz */ - void setFrequencyActiveKHz(double frequencyKHz) + void setFrequencyStandbyKHz(double frequencyKHz) { CModulator::setFrequencyStandbyKHz(frequencyKHz); this->validate(true); @@ -144,7 +144,7 @@ public: /*! * Try to get a ADF unit with given name and frequency. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. + * has been sucessfully created, otherwise returns a default object and false. * \param adfSystem * \param name * \param activeFrequencyKHz @@ -153,7 +153,7 @@ public: */ static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - adfSystem = CAdfSystem(false, name, CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + adfSystem = CAdfSystem(false, name, PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); bool s; if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default return s; @@ -168,7 +168,7 @@ public: * \param standbyFrequency * \return */ - static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); bool s; @@ -183,7 +183,7 @@ public: */ static CAdfSystem GetAdf1System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem(CModulator::NameCom1(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + return CAdfSystem(CModulator::NameCom1(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } /*! * \brief ADF1 unit @@ -191,7 +191,7 @@ public: * \param standbyFrequency * \return */ - static CAdfSystem GetAdf1System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static CAdfSystem GetAdf1System(PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } @@ -213,7 +213,7 @@ public: * \param standbyFrequency * \return */ - static bool tryGetAdf1Unit(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf1Unit(CAdfSystem &adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } @@ -225,7 +225,7 @@ public: */ static CAdfSystem GetAdf2System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem(CModulator::NameCom2(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + return CAdfSystem(CModulator::NameCom2(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } /*! * \brief ADF2 unit @@ -233,7 +233,7 @@ public: * \param standbyFrequency * \return */ - static CAdfSystem GetAdf2System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static CAdfSystem GetAdf2System(PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } @@ -255,7 +255,7 @@ public: * \param standbyFrequency * \return */ - static bool tryGetAdf2System(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf2System(CAdfSystem &adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); } @@ -263,6 +263,6 @@ public: } // namespace } // namespace - +Q_DECLARE_METATYPE(BlackMisc::Aviation::CAdfSystem) #endif // BLACKMISC_AVIOADFSYSTEM_H diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index 1973f1ee7..cd739cc35 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -22,11 +22,10 @@ namespace Aviation class CAvionicsBase : public CBaseStreamStringifier { -private: - QString m_name; //!< name of the unit - protected: + QString m_name; //!< name of the unit + /*! * \brief Default constructor */ diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index ba558c73c..57857b572 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -320,5 +320,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem) #endif // include guard diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index 6bf3bd4b8..d13c083c3 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -25,17 +25,6 @@ template void CModulator::toggleActiveStandby() this->m_frequencyStandby = a; } -/* - * String representation - */ -template QString CModulator::stringForConverter() const -{ - QString s(this->getName()); - s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3)); - s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3)); - return s; -} - /* * Assigment operator = */ diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 6a1bd90cd..dcb9e0cf3 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -5,6 +5,8 @@ #ifndef BLACKMISC_AVIOMODULATORUNIT_H #define BLACKMISC_AVIOMODULATORUNIT_H + +#include #include "blackmisc/aviobase.h" namespace BlackMisc @@ -52,7 +54,12 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter() const { + QString s(this->getName()); + s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3)); + s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3)); + return s; + } /*! * \brief Set active frequency @@ -254,6 +261,48 @@ public: { this->m_frequencyStandby = frequency; } + + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param aviationUnit + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &aviationUnit) { + argument.beginStructure(); + argument >> aviationUnit.m_frequencyActive; + argument >> aviationUnit.m_frequencyStandby; + argument >> aviationUnit.m_digits; + argument >> aviationUnit.m_name; + argument.endStructure(); + return argument; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param aviationUnit + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO& aviationUnit) + { + argument.beginStructure(); + argument << aviationUnit.m_frequencyActive; + argument << aviationUnit.m_frequencyStandby; + argument << aviationUnit.m_digits; + argument << aviationUnit.m_name; + argument.endStructure(); + return argument; + } + + /*! + * \brief Register metadata + */ + static void registerMetadata() + { + qRegisterMetaType(typeid(AVIO).name()); + qDBusRegisterMetaType(); + } }; } // namespace diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index 8beef0be8..b2d448037 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -273,5 +273,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CNavSystem) #endif // BLACKMISC_AVIONAVSYSTEM_H diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index c742e5240..ffff37c1a 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -315,5 +315,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder) #endif // BLACKMISC_AVIOTRANSPONDER_H diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 412ff78f6..7557f236f 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -23,7 +23,7 @@ class CBaseStreamStringifier */ friend QDebug operator<<(QDebug debug, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method + const CBaseStreamStringifier &sf = uc; // allows to access protected method debug << sf.stringForStreaming(); return debug; } diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 6eb4b7008..e2ca61f58 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -1,4 +1,4 @@ -QT += network +QT += network dbus TARGET = blackmisc TEMPLATE = lib @@ -16,5 +16,4 @@ DEFINES += LOG_IN_FILE HEADERS += *.h SOURCES += *.cpp - DESTDIR = ../../lib diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp new file mode 100644 index 000000000..7634b2843 --- /dev/null +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -0,0 +1,43 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmiscfreefunctions.h" + +/* + * Metadata for PQs + */ +void BlackMisc::PhysicalQuantities::registerMetadata() +{ + { + CAcceleration::registerMetadata(); + CAngle::registerMetadata(); + CFrequency::registerMetadata(); + CLength::registerMetadata(); + CMass::registerMetadata(); + CPressure::registerMetadata(); + CSpeed::registerMetadata(); + CTemperature::registerMetadata(); + CTime::registerMetadata(); + } +} + +/* + * Metadata for aviation + */ +void BlackMisc::Aviation::registerMetadata() +{ + CComSystem::registerMetadata(); + CAdfSystem::registerMetadata(); + CNavSystem::registerMetadata(); +} + +/* + * Metadata for Blackmisc + */ +void BlackMisc::registerMetadata() +{ + PhysicalQuantities::registerMetadata(); + Aviation::registerMetadata(); +} diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h new file mode 100644 index 000000000..22133fbf0 --- /dev/null +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_FREEFUNCTIONS_H +#define BLACKMISC_FREEFUNCTIONS_H +#include "avallclasses.h" +#include "pqallquantities.h" + +namespace BlackMisc { + +/*! + * Free functions in PQ + */ +namespace PhysicalQuantities { + +/*! + * \brief Register all metadata for PQs + */ +void registerMetadata(); + +} // PQ + +/*! + * Free functions in aviation + */ +namespace Aviation { + +/*! + * \brief Register metadata for aviation + */ +void registerMetadata(); + +} // Aviation + +/*! + * \brief Register all relevant metadata in BlackMisc + */ +void registerMetadata(); + +} // BlackMisc + +#endif // BLACKMISC_FREEFUNCTIONS_H diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 228ab7bed..0e68b021a 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -16,6 +16,7 @@ namespace Geo { /*! + * Latitude and longitude interface * \brief Interface for geodetic ccordinates */ class ICoordinateGeodetic diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 70962cd79..1a8c4bba4 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -51,4 +51,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAcceleration) + #endif // guard diff --git a/src/blackmisc/pqallquantities.h b/src/blackmisc/pqallquantities.h index 0381c0b60..1a402e504 100644 --- a/src/blackmisc/pqallquantities.h +++ b/src/blackmisc/pqallquantities.h @@ -7,7 +7,7 @@ #define BLACKMISC_PQUNITSALL_H // All units / quantities, required for the instantiations of the template -// especially as CRTP is used. +// especially as CRTP (Curiously recurring template pattern) is used. // http://www.parashift.com/c++-faq-lite/separate-template-fn-defn-from-decl.html // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern @@ -20,5 +20,6 @@ #include "blackmisc/pqangle.h" #include "blackmisc/pqtime.h" #include "blackmisc/pqacceleration.h" +#include "blackmisc/pqunits.h" #endif // guard diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 9ba211680..7fabb6df8 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -69,4 +69,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngle) + #endif // BLACKMISC_PQANGLE_H diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index ae37c6a8f..3c0dc5451 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -8,10 +8,12 @@ #include "blackmisc/basestreamstringifier.h" #include "blackmisc/debug.h" +#include #include #include #include + namespace BlackMisc { namespace PhysicalQuantities @@ -240,6 +242,19 @@ protected: */ typedef double(*UnitConverter)(const CMeasurementUnit &, double); + /*! + * \brief Get unit from DBus argument + * \param argument + * \return + */ + static QString unitNameUnmarshalling(const QDBusArgument &argument) { + QString type; + argument.beginStructure(); + argument >> type; + argument.endStructure(); + return type; + } + private: QString m_name; //!< name, e.g. "meter" QString m_unitName; //!< unit name, e.g. "m" @@ -250,8 +265,8 @@ private: double m_epsilon; //!< values with differences below epsilon are the equal int m_displayDigits; //!< standard rounding for string conversions CMeasurementPrefix m_multiplier; //!< multiplier (kilo, Mega) - UnitConverter m_fromSiConverter; //! allows an arbitrary conversion method as per object - UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object + UnitConverter m_fromSiConverter; //! allows an arbitrary conversion method as per object (e.g. angle, sexagesimal) + UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object (e.g. angle, sexagesimal) protected: /*! @@ -505,6 +520,21 @@ public: return abs(checkValue) <= this->m_epsilon; } + /*! + * Marshalling (to DBus) operator, unmarshalling to be found in specialized classes and + * mapping back to static object + * \brief Marshalling (to DBus) operator << + * \param argument + * \param unit + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const CMeasurementUnit& unit) { + argument.beginStructure(); + argument << unit.m_unitName; + argument.endStructure(); + return argument; + } + // -------------------------------------------------------------------- // -- static // -------------------------------------------------------------------- @@ -518,6 +548,7 @@ public: static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); return none; } + }; } // namespace diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 6a1fd94b4..def61d65d 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -46,4 +46,7 @@ public: }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequency) + #endif // BLACKMISC_PQFREQUENCY_H diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index 41846948b..a5b914174 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -46,4 +46,7 @@ public: }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLength) + #endif // BLACKMISC_PQLENGTH_H diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index f4127174b..414a2c9a7 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -51,4 +51,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMass) + #endif // guard diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 815bc9ca2..9d9701a86 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -10,6 +10,7 @@ #include "blackmisc/pqbase.h" #include "blackmisc/pqunits.h" #include "blackmisc/debug.h" +#include #include #include #include @@ -21,8 +22,10 @@ namespace PhysicalQuantities /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" */ + template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier { + private: double m_unitValueD; //!< value backed by double qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic @@ -236,7 +239,7 @@ public: qint32 convertedSiValueToInteger() const { return static_cast( - BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); + BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); } /*! @@ -417,6 +420,55 @@ public: { return this->isZeroEpsilon() || this->m_unitValueD < 0; } + + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param pq + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, PQ &pq) { + argument.beginStructure(); + argument >> pq.m_unitValueD; + argument >> pq.m_unitValueI; + argument >> pq.m_convertedSiUnitValueD; + argument >> pq.m_isIntegerBaseValue; + argument >> pq.m_unit; + argument >> pq.m_conversionSiUnit; + argument.endStructure(); + return argument; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const PQ& pq) + { + argument.beginStructure(); + argument << pq.m_unitValueD; + argument << pq.m_unitValueI; + argument << pq.m_convertedSiUnitValueD; + argument << pq.m_isIntegerBaseValue; + argument << pq.m_unit; + argument << pq.m_conversionSiUnit; + argument.endStructure(); + return argument; + } + + /*! + * \brief Register metadata of unit and quantity + */ + static void registerMetadata() + { + qRegisterMetaType(typeid(MU).name()); + qDBusRegisterMetaType(); + qRegisterMetaType(typeid(PQ).name()); + qDBusRegisterMetaType(); + } + }; } // namespace diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index c330d63fe..3cfd5fbdb 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -47,4 +47,7 @@ public: }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressure) + #endif // BLACKMISC_PQPRESSURE_H diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index ed4d2968e..e49dd3f2f 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -18,15 +18,16 @@ namespace PhysicalQuantities */ class CSpeed : public CPhysicalQuantity { + public: /*! * \brief Default constructor */ CSpeed() : CPhysicalQuantity(0, CSpeedUnit::m_s(), CSpeedUnit::m_s()) {} - /** + /*! *\brief Copy constructor */ - CSpeed(const CPhysicalQuantity &speed): CPhysicalQuantity(speed) {} + CSpeed(const CSpeed &speed): CPhysicalQuantity(speed) {} /*! * \brief Init by int value * \param value @@ -44,7 +45,10 @@ public: */ virtual ~CSpeed() {} }; + } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeed) + #endif // BLACKMISC_CSPEED_H diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index 892e88bbf..bec623817 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -46,4 +46,7 @@ public: }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperature) + #endif // BLACKMISC_CTEMPERATURE_H diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 00f3479a7..9641e8d45 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -48,4 +48,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTime) + #endif // BLACKMISC_PQTIME_H diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 736ef86b8..774bf5ebb 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -7,8 +7,11 @@ #define BLACKMISC_PQUNITS_H #include "blackmisc/pqbase.h" +#include +#include #include + // // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations @@ -25,7 +28,7 @@ class CLengthUnit : public CMeasurementUnit { private: /*! - * \brief Constructor Distance unit + * \brief Constructor length unit * \param name * \param unitName * \param isSiUnit @@ -41,6 +44,11 @@ private: // void } public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CLengthUnit() : CMeasurementUnit("meter", "m", "distance", true, true) {} + /*! * \brief Copy constructor * \param otherUnit @@ -120,7 +128,51 @@ public: return mi; } + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CLengthUnit::cm()); + u.append(CLengthUnit::ft()); + u.append(CLengthUnit::km()); + u.append(CLengthUnit::m()); + u.append(CLengthUnit::mi()); + u.append(CLengthUnit::miStatute()); + u.append(CLengthUnit::NM()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CLengthUnit &fromUnitName(const QString &unitName) { + QList units = CLengthUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CLengthUnit::m(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CLengthUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CLengthUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit) /*! * \brief Specialized class for angles (degrees, radian). @@ -160,6 +212,11 @@ private: static double conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit, double value); public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CAngleUnit() : CMeasurementUnit("radian", "rad", "angle", true, false) {} + /*! * \brief Copy constructor * \param otherUnit @@ -203,7 +260,48 @@ public: static CAngleUnit deg("segadecimal degree", "°", false, M_PI / 180, CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CAngleUnit::deg()); + u.append(CAngleUnit::rad()); + u.append(CAngleUnit::sexagesimalDeg()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CAngleUnit &fromUnitName(const QString &unitName) { + QList units = CAngleUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CAngleUnit::rad(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAngleUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CAngleUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit) /*! * \brief Specialized class for frequency (hertz, mega hertz, kilo hertz). @@ -225,6 +323,11 @@ private: CFrequencyUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CFrequencyUnit() : CMeasurementUnit("hertz", "Hz", "frequency", true, false) {} + /*! * \brief Copy constructor * \param otherUnit @@ -273,7 +376,49 @@ public: static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); return GHz; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CFrequencyUnit::GHz()); + u.append(CFrequencyUnit::Hz()); + u.append(CFrequencyUnit::kHz()); + u.append(CFrequencyUnit::MHz()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CFrequencyUnit &fromUnitName(const QString &unitName) { + QList units = CFrequencyUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CFrequencyUnit::Hz(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CFrequencyUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CFrequencyUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit) /*! * \brief Specialized class for mass units (kg, lbs). @@ -295,6 +440,11 @@ private: CMassUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "mass", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CMassUnit() : CMeasurementUnit("kilogram", "kg", "mass", true, true, 1.0, CMeasurementPrefix::k(), 1) {} + /*! * \brief Copy constructor * \param otherUnit @@ -343,7 +493,50 @@ public: static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); return lbs; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CMassUnit::g()); + u.append(CMassUnit::kg()); + u.append(CMassUnit::lb()); + u.append(CMassUnit::t()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CMassUnit &fromUnitName(const QString &unitName) { + QList units = CMassUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CMassUnit::kg(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CMassUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CMassUnit::fromUnitName(unitName); + return argument; + } + }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMassUnit) /*! * \brief Specialized class for pressure (psi, hPa, bar). @@ -363,8 +556,13 @@ private: * \param epsilon */ CPressureUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CMeasurementUnit(name, unitName, "pressure", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CPressureUnit() : CMeasurementUnit("pascal", "Pa", "pressure", true, false) {} + /*! * \brief Copy constructor * \param otherUnit @@ -443,7 +641,51 @@ public: static CPressureUnit inhg("Inch of mercury ", "inHg", false, 3386.5307486631); return inhg; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CPressureUnit::bar()); + u.append(CPressureUnit::hPa()); + u.append(CPressureUnit::inHg()); + u.append(CPressureUnit::inHgFL()); + u.append(CPressureUnit::mbar()); + u.append(CPressureUnit::psi()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CPressureUnit &fromUnitName(const QString &unitName) { + QList units = CPressureUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CPressureUnit::Pa(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CPressureUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CPressureUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit) /*! * \brief Specialized class for temperatur units (kelvin, centidegree). @@ -483,6 +725,11 @@ protected: virtual double conversionFromSiConversionUnit(double value) const; public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CTemperatureUnit() : CMeasurementUnit("Kelvin", "K", "temperature", true, true) {} + /*! * \brief Copy constructor * \param otherUnit @@ -529,7 +776,48 @@ public: static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0 / 9.0, 459.67); return F; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CTemperatureUnit::C()); + u.append(CTemperatureUnit::F()); + u.append(CTemperatureUnit::K()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CTemperatureUnit &fromUnitName(const QString &unitName) { + QList units = CTemperatureUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CTemperatureUnit::K(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTemperatureUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CTemperatureUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit) /*! * \brief Specialized class for speed units (m/s, ft/s, NM/h). @@ -552,6 +840,11 @@ private: CSpeedUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "speed", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CSpeedUnit() : CMeasurementUnit("meters/second", "m/s", "speed", true, false) {} + /*! * Constructor, allows to implement methods in base class * \param otherUnit @@ -617,7 +910,51 @@ public: static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); return kmh; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CSpeedUnit::ft_min()); + u.append(CSpeedUnit::ft_s()); + u.append(CSpeedUnit::km_h()); + u.append(CSpeedUnit::kts()); + u.append(CSpeedUnit::m_s()); + u.append(CSpeedUnit::NM_h()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CSpeedUnit &fromUnitName(const QString &unitName) { + QList units = CSpeedUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CSpeedUnit::m_s(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CSpeedUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CSpeedUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) /*! * \brief Specialized class for time units (ms, hour, min). @@ -640,6 +977,10 @@ private: CTimeUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CTimeUnit() : CMeasurementUnit("second", "s", "time", true, true, 1, CMeasurementPrefix::None()) {} /*! * Constructor, allows to implement methods in base class @@ -697,7 +1038,49 @@ public: return day; } + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CTimeUnit::d()); + u.append(CTimeUnit::h()); + u.append(CTimeUnit::min()); + u.append(CTimeUnit::ms()); + u.append(CTimeUnit::s()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CTimeUnit &fromUnitName(const QString &unitName) { + QList units = CTimeUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CTimeUnit::s(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTimeUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CTimeUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) /*! * \brief Specialized class for acceleration units (m/s2, ft/s2). @@ -718,8 +1101,13 @@ private: * \param epsilon */ CAccelerationUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CMeasurementUnit(name, unitName, "acceleration", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: + /*! + * Default constructor, we do not want this, but required for Qt Metasystem + */ + CAccelerationUnit() : CMeasurementUnit("meter/second²", "m/s²", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} + /*! * Constructor, allows to implement methods in base class * \param otherUnit @@ -745,7 +1133,47 @@ public: static CAccelerationUnit fts2("feet/seconds²", "ft/s²", true, false, 3.28084, CMeasurementPrefix::m(), 0); return fts2; } + + /*! + * \brief All units + * \return + */ + static const QList &units() + { + static QList u; + u.append(CAccelerationUnit::ft_s2()); + u.append(CAccelerationUnit::m_s2()); + return u; + } + + /*! + * \brief Unit from name + * \param unitName must be valid! + * \return + */ + static const CAccelerationUnit &fromUnitName(const QString &unitName) { + QList units = CAccelerationUnit::units(); + // read only, avoid deep copy + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getUnitName() == unitName) return (units.at(i)); + } + qFatal("Illegal unit name"); + return CAccelerationUnit::m_s2(); // just suppress "not all control paths return a value" + } + + /*! + * \brief Unmarshalling operator >>, map back to concrete static object + * \param argument + * \param dummy + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAccelerationUnit &unit) { + QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); + unit = CAccelerationUnit::fromUnitName(unitName); + return argument; + } }; +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) } // namespace } // namespace diff --git a/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro new file mode 100644 index 000000000..099fcf4d6 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro @@ -0,0 +1,19 @@ +QT += core dbus + +TARGET = blackmisc_cpp2xml +TEMPLATE = lib + +CONFIG += plugin + +DEPENDPATH += . ../../src/blackmisc +INCLUDEPATH += . ../../src + +LIBS += -L../../lib -lblackmisc + +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a + +DESTDIR = ../../bin + +HEADERS += *.h +SOURCES += *.cpp diff --git a/src/blackmisc_cpp2xml/blackmiscplugin.cpp b/src/blackmisc_cpp2xml/blackmiscplugin.cpp new file mode 100644 index 000000000..93beffe00 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmiscplugin.cpp @@ -0,0 +1,15 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmiscplugin.h" +#include "blackmisc/blackmiscfreefunctions.h" + +/* + * Register all metatypes + */ +void BlackmiscPlugin::registerMetaTypes() +{ + BlackMisc::registerMetadata(); +} diff --git a/src/blackmisc_cpp2xml/blackmiscplugin.h b/src/blackmisc_cpp2xml/blackmiscplugin.h new file mode 100644 index 000000000..b57584559 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmiscplugin.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_CPP2XML_H +#define BLACKMISC_CPP2XML_H + +#include +#include + +/*! + * \brief Plugin to register all relevant blackmisc classes for QDBusCpp2XmlPlugin + */ +class BlackmiscPlugin : public QObject, public QDBusCpp2XmlPlugin +{ + Q_OBJECT + Q_INTERFACES(QDBusCpp2XmlPlugin) + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.DBus.Cpp2XmlPlugin") + +public: + /*! + * \brief Register Metatypes + */ + virtual void registerMetaTypes(); +}; + +#endif // BLACKMISC_CPP2XML_H diff --git a/tests/blackcore/test_blackcore.pro b/tests/blackcore/test_blackcore.pro index d4076c16a..a64285298 100644 --- a/tests/blackcore/test_blackcore.pro +++ b/tests/blackcore/test_blackcore.pro @@ -1,4 +1,4 @@ -QT += core testlib +QT += core testlib dbus TARGET = test_blackcore TEMPLATE = app diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index dbbab21ba..d9e8ae911 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -1,4 +1,4 @@ -QT += core testlib +QT += core testlib dbus TARGET = test_blackmisc TEMPLATE = app From 9b2cb3b517f332d68348abe7fb3fad38faa5e197 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 24 Jul 2013 02:20:32 +0200 Subject: [PATCH 02/36] Shifted DBus operators to CBaseStreamStringifier, much easier to provide streaming - especially for derived classes. Still required but unwanted overloaded DBus operator in aviomodulator.h - no compilation without them. Need to be removed. Enabled more classes for DBus. --- .../BlackMiscTest.Testservice.xml | 6 +- samples/blackmiscquantities_dbus/main.cpp | 14 ++- samples/blackmiscquantities_dbus/readme.txt | 3 +- .../blackmiscquantities_dbus/testservice.cpp | 11 +- .../blackmiscquantities_dbus/testservice.h | 9 +- .../sample_quantities_avionics_xmlplugin.pro | 25 ---- .../sampleplugin.cpp | 12 -- .../sampleplugin.h | 21 ---- src/blackmisc/avaltitude.cpp | 9 ++ src/blackmisc/avaltitude.h | 25 ++++ src/blackmisc/aviobase.h | 23 +++- src/blackmisc/aviocomsystem.h | 6 +- src/blackmisc/aviomodulator.cpp | 13 +- src/blackmisc/aviomodulator.h | 90 ++++++++------ src/blackmisc/basestreamstringifier.h | 61 +++++++-- src/blackmisc/blackmiscfreefunctions.cpp | 3 +- src/blackmisc/pqbase.h | 78 ++++++++---- src/blackmisc/pqphysicalquantity.h | 43 +++---- src/blackmisc/pqunits.h | 117 ++++++++---------- 19 files changed, 335 insertions(+), 234 deletions(-) delete mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro delete mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp delete mode 100644 samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml index fec10b6e1..d8ba83ba6 100644 --- a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -15,8 +15,12 @@ - + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index 905f4ca78..785539601 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -60,8 +60,7 @@ int main(int argc, char *argv[]) QString service; // service not needed if (QDBusConnection::sessionBus().connect( service, Testservice::ServicePath, Testservice::ServiceName, - "sendStringMessage", pTestservice, - SLOT(receiveStringMessage(const QString &)))) { + "sendStringMessage", pTestservice, SLOT(receiveStringMessage(const QString &)))) { qDebug() << "Connected object with bus sendStringMessage"; } else { qFatal("Cannot connect service with DBus"); @@ -100,12 +99,23 @@ int main(int argc, char *argv[]) CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); testserviceInterface.receiveSpeed(speed); qDebug() << "Send speed via interface" << speed; + + speed.switchUnit(CSpeedUnit::kts()); + testserviceInterface.receiveSpeed(speed); + qDebug() << "Send speed via interface" << speed; TestserviceTool::sleep(2500); // Aviation CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom()); testserviceInterface.receiveComUnit(comSystem); qDebug() << "Send COM via interface" << comSystem; + + CAltitude al(1000, true, CLengthUnit::ft()); + QDBusVariant qv(QVariant::fromValue(al)); + testserviceInterface.receiveVariant(qv); + testserviceInterface.receiveAltitude(al); + qDebug() << "Send altitude via interface" << al; + TestserviceTool::sleep(2500); } } diff --git a/samples/blackmiscquantities_dbus/readme.txt b/samples/blackmiscquantities_dbus/readme.txt index 4481e7f8f..6c74d5ca4 100644 --- a/samples/blackmiscquantities_dbus/readme.txt +++ b/samples/blackmiscquantities_dbus/readme.txt @@ -2,7 +2,8 @@ Starting: dbus-daemon.exe --session - blocks CMD (sometimes daemon continues to run when pressing CTRL/C) - does not start without directory session.d, i.e. ..\Qt\Qt5.1.0DBus\qtbase\etc\dbus-1\session.d -qdbuscpp2xml testservice.h -x H:\Projects\QtBuilds\build-client-Qt_5_1_0_VATSIM_qmake_Microsoft_Visual_C_Compiler_10_0_x86_2-Release\bin\blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml +qdbuscpp2xml testservice.h -x blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml +Set search path for plugins: env.var. QT_PLUGIN_PATH Done automatically, but if required manually Interface: qdbusxml2cpp blackbus.testservice.xml -p itestservice diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp index bcfac37e3..bcca70f78 100644 --- a/samples/blackmiscquantities_dbus/testservice.cpp +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -33,7 +33,8 @@ void Testservice::receiveStringMessage(const QString &message) void Testservice::receiveVariant(const QDBusVariant &variant) { QVariant qv = variant.variant(); - qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << qv; + BlackMisc::Aviation::CAltitude altitude = qv.value(); + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << altitude; } /* @@ -52,5 +53,13 @@ void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit) qDebug() << "Pid:" << TestserviceTool::getPid() << "Received COM:" << comUnit; } +/* + * Receivealtitude + */ +void Testservice::receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received altitude:" << altitude; + +} } // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h index 6ce955b27..81e10e7b5 100644 --- a/samples/blackmiscquantities_dbus/testservice.h +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -65,11 +65,18 @@ public slots: void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed); /*! - * \brief receiveComUnit + * \brief Receive com unit * \param comUnit */ void receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit); + /*! + * \brief Receive altitude + * \param comUnit + */ + void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude); + + public: static const QString ServiceName; static const QString ServicePath; diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro b/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro deleted file mode 100644 index 02804edab..000000000 --- a/samples/blackmiscquantities_dbus_xmlplugin/sample_quantities_avionics_xmlplugin.pro +++ /dev/null @@ -1,25 +0,0 @@ -QT += core dbus - -TARGET = sample_quantities_avionics_xmlplugin -TEMPLATE = lib - -CONFIG += plugin - -DEPENDPATH += . ../../src/blackmisc -INCLUDEPATH += . ../../src - -LIBS += -L../../lib -lblackmisc \ - ../blackmiscquantities_dbus/release/dummy.obj \ - ../blackmiscquantities_dbus/release/moc_dummy.obj \ - ../blackmiscquantities_dbus/release/dummynoq.obj - -win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../samples/blackmiscquantities_dbus/release/dummy.obj -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../samples/blackmiscquantities_dbus/release/dummy.obj - -DESTDIR = ../../bin - -HEADERS += *.h -SOURCES += *.cpp - diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp deleted file mode 100644 index edf3829ba..000000000 --- a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "sampleplugin.h" - - -void CXmlSamplePlugin::registerMetaTypes() -{ - qRegisterMetaType("BlackMiscTest::Dummy"); - qDBusRegisterMetaType(); - - qRegisterMetaType("BlackMiscTest::DummyNoQ"); - qDBusRegisterMetaType(); - -} diff --git a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h b/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h deleted file mode 100644 index 921247b2b..000000000 --- a/samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SAMPLEPLUGIN_H -#define SAMPLEPLUGIN_H - -#include -#include -#include -#include -#include "../blackmiscquantities_dbus/dummy.h" -#include "../blackmiscquantities_dbus/dummynoq.h" - -class CXmlSamplePlugin : public QObject, public QDBusCpp2XmlPlugin -{ - Q_OBJECT - Q_INTERFACES(QDBusCpp2XmlPlugin) - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.DBus.Cpp2XmlPlugin") - -public: - virtual void registerMetaTypes(); -}; - -#endif // SAMPLEPLUGIN_H diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index c2965d61f..eef440e57 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -50,5 +50,14 @@ bool CAltitude::operator !=(const CAltitude &otherAltitude) return !((*this) == otherAltitude); } +/* + * Register metadata + */ +void CAltitude::registerMetadata() +{ + qRegisterMetaType(typeid(CAltitude).name()); + qDBusRegisterMetaType(); +} + } // namespace } // namespace diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 7bc24ee39..96316e3d5 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -28,6 +28,24 @@ protected: */ virtual QString stringForConverter() const; + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + CLength::marshallToDbus(argument); + argument << this->m_msl; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + CLength::unmarshallFromDbus(argument); + argument >> this->m_msl; + } + public: /*! @@ -105,9 +123,16 @@ public: { return this->m_msl; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); + }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CAltitude) #endif // guard diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index cd739cc35..e9b152acb 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -19,17 +19,16 @@ namespace Aviation /*! * \brief Base class for avionics */ -class CAvionicsBase : public CBaseStreamStringifier +class CAvionicsBase : public BlackMisc::CBaseStreamStringifier { - protected: QString m_name; //!< name of the unit /*! - * \brief Default constructor + * \brief Constructor */ - CAvionicsBase(const QString &name) : m_name(name) {} + CAvionicsBase(const QString &name) : CBaseStreamStringifier(), m_name(name) {} /*! * \brief Are the set values valid / in range @@ -60,6 +59,22 @@ protected: return this->m_name == otherSystem.m_name; } + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_name; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_name; + } + public: /*! * \brief Virtual destructor diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 57857b572..923746f13 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BLACKMISC_AVIOCOMUNIT_H -#define BLACKMISC_AVIOCOMUNIT_H +#ifndef BLACKMISC_AVIOCOMSYSTEM_H +#define BLACKMISC_AVIOCOMSYSTEM_H #include "blackmisc/aviomodulator.h" #include @@ -315,8 +315,10 @@ public: static bool tryGetCom3System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); } + }; + } // namespace } // namespace diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index d13c083c3..49e23a232 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -6,6 +6,7 @@ #include "blackmisc/aviomodulator.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" +#include "blackmisc/avioadfsystem.h" using BlackMisc::PhysicalQuantities::CFrequency; using BlackMisc::PhysicalQuantities::CFrequencyUnit; @@ -25,12 +26,20 @@ template void CModulator::toggleActiveStandby() this->m_frequencyStandby = a; } +/* + * Register metadata + */ +template void CModulator::registerMetadata() +{ + qRegisterMetaType(typeid(AVIO).name()); + qDBusRegisterMetaType(); +} + /* * Assigment operator = */ template CModulator& CModulator::operator=(const CModulator &otherModulator) { - if (this == &otherModulator) return *this; // Same object? this->m_frequencyActive = otherModulator.m_frequencyActive; this->m_frequencyStandby = otherModulator.m_frequencyStandby; @@ -63,6 +72,8 @@ template bool CModulator::operator !=(const CModulator // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CModulator; template class CModulator; +template class CModulator; + } // namespace } // namespace diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index dcb9e0cf3..e82270b0d 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -6,7 +6,7 @@ #ifndef BLACKMISC_AVIOMODULATORUNIT_H #define BLACKMISC_AVIOMODULATORUNIT_H -#include +#include #include "blackmisc/aviobase.h" namespace BlackMisc @@ -19,6 +19,33 @@ namespace Aviation */ template class CModulator : public CAvionicsBase { + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param uc + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) { + // If I do not have the method here, DBus metasystem tries to stream against + // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) + // Once someone solves this, this methods should go and the CBaseStreamStringifier signature + // should be used + CBaseStreamStringifier &sf = uc; + return argument >> sf; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO &uc) + { + const CBaseStreamStringifier &sf = uc; + return argument << sf; + } + private: BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency BlackMisc::PhysicalQuantities::CFrequency m_frequencyStandby; //!< standby frequency @@ -207,6 +234,28 @@ protected: return f; } + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + CAvionicsBase::marshallToDbus(argument); + argument << this->m_frequencyActive; + argument << this->m_frequencyStandby; + argument << this->m_digits; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + CAvionicsBase::unmarshallFromDbus(argument); + argument >> this->m_frequencyActive; + argument >> this->m_frequencyStandby; + argument >> this->m_digits; + } + public: /*! * \brief Virtual destructor @@ -262,47 +311,10 @@ public: this->m_frequencyStandby = frequency; } - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param aviationUnit - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &aviationUnit) { - argument.beginStructure(); - argument >> aviationUnit.m_frequencyActive; - argument >> aviationUnit.m_frequencyStandby; - argument >> aviationUnit.m_digits; - argument >> aviationUnit.m_name; - argument.endStructure(); - return argument; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param aviationUnit - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO& aviationUnit) - { - argument.beginStructure(); - argument << aviationUnit.m_frequencyActive; - argument << aviationUnit.m_frequencyStandby; - argument << aviationUnit.m_digits; - argument << aviationUnit.m_name; - argument.endStructure(); - return argument; - } - /*! * \brief Register metadata */ - static void registerMetadata() - { - qRegisterMetaType(typeid(AVIO).name()); - qDBusRegisterMetaType(); - } + static void registerMetadata(); }; } // namespace diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 7557f236f..393cf4565 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -2,6 +2,7 @@ #define BLACKMISC_BASESTREAMSTRINGIFIER_H #include "blackmisc/debug.h" +#include #include #include #include @@ -23,10 +24,10 @@ class CBaseStreamStringifier */ friend QDebug operator<<(QDebug debug, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to access protected method - debug << sf.stringForStreaming(); + debug << uc.stringForStreaming(); return debug; } + // msvc2010: friend QDebug &operator<<(QDebug &debug, const CBaseStreamStringifier &uc) // MinGW: No reference @@ -38,8 +39,7 @@ class CBaseStreamStringifier */ friend QTextStream &operator<<(QTextStream &textStream, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - textStream << sf.stringForStreaming(); + textStream << uc.stringForStreaming(); return textStream; } @@ -62,8 +62,7 @@ class CBaseStreamStringifier */ friend QDataStream &operator<<(QDataStream &stream, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - stream << sf.stringForStreaming(); + stream << uc.stringForStreaming(); return stream; } @@ -75,8 +74,7 @@ class CBaseStreamStringifier */ friend CLogMessage operator<<(CLogMessage log, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - log << sf.stringForStreaming(); + log << uc.stringForStreaming(); return log; } @@ -88,12 +86,39 @@ class CBaseStreamStringifier */ friend std::ostream &operator<<(std::ostream &ostr, const CBaseStreamStringifier &uc) { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - ostr << sf.stringForStreaming().toStdString(); + ostr << uc.stringForStreaming().toStdString(); return ostr; } + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param uc + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CBaseStreamStringifier &uc) { + argument.beginStructure(); + uc.unmarshallFromDbus(argument); + argument.endStructure(); + return argument; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const CBaseStreamStringifier &uc) + { + argument.beginStructure(); + uc.marshallToDbus(argument); + argument.endStructure(); + return argument; + } + public: + /*! * \brief Virtual destructor */ @@ -109,6 +134,10 @@ public: } protected: + /*! + * \brief Default constructor + */ + CBaseStreamStringifier() {} /*! * \brief String for streaming operators @@ -126,6 +155,18 @@ protected: */ virtual QString stringForConverter() const = 0; + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &) const { } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &) {} + /*! * \brief Copy assignment operator. * This is protected in order to forbid slicing an instance of one derived diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 7634b2843..51316b601 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -29,8 +29,9 @@ void BlackMisc::PhysicalQuantities::registerMetadata() void BlackMisc::Aviation::registerMetadata() { CComSystem::registerMetadata(); - CAdfSystem::registerMetadata(); CNavSystem::registerMetadata(); + CAdfSystem::registerMetadata(); + CAltitude::registerMetadata(); } /* diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 3c0dc5451..b0d37129b 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -50,6 +50,24 @@ protected: return this->m_name; } + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_name; + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString name; + argument >> name; + (*this) = CMeasurementPrefix::fromPrefixName(name); + } + public: /*! * \brief Copy constructor @@ -224,6 +242,40 @@ public: return milli; } + + /*! + * \brief All prefixes + * \return + */ + static const QList &prefixes() + { + static QList prefixes; + prefixes.append(CMeasurementPrefix::c()); + prefixes.append(CMeasurementPrefix::G()); + prefixes.append(CMeasurementPrefix::h()); + prefixes.append(CMeasurementPrefix::k()); + prefixes.append(CMeasurementPrefix::M()); + prefixes.append(CMeasurementPrefix::m()); + prefixes.append(CMeasurementPrefix::None()); + prefixes.append(CMeasurementPrefix::One()); + return prefixes; + } + + /*! + * \brief Prefix from name + * \param prefixName must be valid! + * \return + */ + static const CMeasurementPrefix &fromPrefixName(const QString &prefixName) { + QList prefixes = CMeasurementPrefix::prefixes(); + // read only, avoid deep copy + for (int i = 0; i < prefixes.size(); ++i) { + if (prefixes.at(i).getName() == prefixName) return (prefixes.at(i)); + } + qFatal("Illegal unit name"); + return CMeasurementPrefix::None(); // just suppress "not all control paths return a value" + } + }; // --------------------------------------------------------------------------------- @@ -243,16 +295,11 @@ protected: typedef double(*UnitConverter)(const CMeasurementUnit &, double); /*! - * \brief Get unit from DBus argument + * \brief Stream to DBus * \param argument - * \return */ - static QString unitNameUnmarshalling(const QDBusArgument &argument) { - QString type; - argument.beginStructure(); - argument >> type; - argument.endStructure(); - return type; + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_unitName; } private: @@ -520,21 +567,6 @@ public: return abs(checkValue) <= this->m_epsilon; } - /*! - * Marshalling (to DBus) operator, unmarshalling to be found in specialized classes and - * mapping back to static object - * \brief Marshalling (to DBus) operator << - * \param argument - * \param unit - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const CMeasurementUnit& unit) { - argument.beginStructure(); - argument << unit.m_unitName; - argument.endStructure(); - return argument; - } - // -------------------------------------------------------------------- // -- static // -------------------------------------------------------------------- diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 9d9701a86..97619de01 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -422,40 +422,29 @@ public: } /*! - * \brief Unmarshalling operator >>, DBus to object + * \brief Stream to DBus << * \param argument - * \param pq - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, PQ &pq) { - argument.beginStructure(); - argument >> pq.m_unitValueD; - argument >> pq.m_unitValueI; - argument >> pq.m_convertedSiUnitValueD; - argument >> pq.m_isIntegerBaseValue; - argument >> pq.m_unit; - argument >> pq.m_conversionSiUnit; - argument.endStructure(); - return argument; + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_unitValueD; + argument << this->m_unitValueI; + argument << this->m_convertedSiUnitValueD; + argument << this->m_isIntegerBaseValue; + argument << this->m_unit; + argument << this->m_conversionSiUnit; } /*! - * \brief Marshalling operator <<, object to DBus + * \brief Stream from DBus >> * \param argument - * \param pq - * \return */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const PQ& pq) - { - argument.beginStructure(); - argument << pq.m_unitValueD; - argument << pq.m_unitValueI; - argument << pq.m_convertedSiUnitValueD; - argument << pq.m_isIntegerBaseValue; - argument << pq.m_unit; - argument << pq.m_conversionSiUnit; - argument.endStructure(); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_unitValueD; + argument >> this->m_unitValueI; + argument >> this->m_convertedSiUnitValueD; + argument >> this->m_isIntegerBaseValue; + argument >> this->m_unit; + argument >> this->m_conversionSiUnit; } /*! diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 774bf5ebb..285d02042 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -160,16 +160,15 @@ public: return CLengthUnit::m(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CLengthUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CLengthUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CLengthUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit) @@ -289,16 +288,15 @@ public: return CAngleUnit::rad(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAngleUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CAngleUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CAngleUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit) @@ -406,16 +404,15 @@ public: return CFrequencyUnit::Hz(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CFrequencyUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CFrequencyUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CFrequencyUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit) @@ -523,16 +520,15 @@ public: return CMassUnit::kg(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CMassUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CMassUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CMassUnit::fromUnitName(unitName); } }; @@ -673,16 +669,15 @@ public: return CPressureUnit::Pa(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CPressureUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CPressureUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CPressureUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit) @@ -805,16 +800,15 @@ public: return CTemperatureUnit::K(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTemperatureUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CTemperatureUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CTemperatureUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit) @@ -942,16 +936,15 @@ public: return CSpeedUnit::m_s(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CSpeedUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CSpeedUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CSpeedUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) @@ -1068,16 +1061,15 @@ public: return CTimeUnit::s(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTimeUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CTimeUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CTimeUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) @@ -1161,16 +1153,15 @@ public: return CAccelerationUnit::m_s2(); // just suppress "not all control paths return a value" } +protected: /*! - * \brief Unmarshalling operator >>, map back to concrete static object + * \brief Stream from DBus * \param argument - * \param dummy - * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAccelerationUnit &unit) { - QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument); - unit = CAccelerationUnit::fromUnitName(unitName); - return argument; + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QString unitName; + argument >> unitName; + (*this) = CAccelerationUnit::fromUnitName(unitName); } }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) From 2fc08a037658e23ae4e4c362a026b87d39caaa8a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 25 Jul 2013 00:10:50 +0200 Subject: [PATCH 03/36] Enabled DBus with matrix classes, noticed issue with QList Signature (ad, addddd) --- .../BlackMiscTest.Testservice.xml | 8 +++ samples/blackmiscquantities_dbus/main.cpp | 24 +++++++- .../sample_quantities_avionics_dbus.pro | 1 - .../blackmiscquantities_dbus/testservice.cpp | 17 +++++- .../blackmiscquantities_dbus/testservice.h | 11 ++++ src/blackmisc/aviobase.h | 1 + src/blackmisc/aviomodulator.h | 1 + src/blackmisc/basestreamstringifier.h | 2 +- src/blackmisc/blackmiscfreefunctions.cpp | 13 +++++ src/blackmisc/blackmiscfreefunctions.h | 10 ++++ src/blackmisc/mathallclasses.h | 14 +++++ src/blackmisc/mathmatrix1x3.h | 1 + src/blackmisc/mathmatrix3x1.h | 1 + src/blackmisc/mathmatrix3x3.h | 1 + src/blackmisc/mathmatrixbase.cpp | 57 +++++++++++++++++++ src/blackmisc/mathmatrixbase.h | 51 +++++++++++++++++ src/blackmisc/pqbase.h | 27 ++++++--- 17 files changed, 225 insertions(+), 15 deletions(-) create mode 100644 src/blackmisc/mathallclasses.h diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml index d8ba83ba6..a0ff44680 100644 --- a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -22,5 +22,13 @@ + + + + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index 785539601..14d2bced8 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "testservice.h" #include "testservice_adaptor.h" @@ -15,6 +16,7 @@ using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Aviation; +using namespace BlackMisc::Math; using namespace BlackMiscTest; /*! @@ -88,12 +90,19 @@ int main(int argc, char *argv[]) if (connection.send(m)) { qDebug() << "Send via low level method" << m; } - TestserviceTool::sleep(2500); // same as interface message testserviceInterface.receiveStringMessage(msg); qDebug() << "Send string via interface" << msg; - TestserviceTool::sleep(2500); + + // a list + QList list; + list << 1.0 << 2.0 << 3.0; + testserviceInterface.receiveList(list); + qDebug() << "Send list via interface" << list; + qDebug() << "Key ......."; + getchar(); + // PQs CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); @@ -115,8 +124,17 @@ int main(int argc, char *argv[]) testserviceInterface.receiveVariant(qv); testserviceInterface.receiveAltitude(al); qDebug() << "Send altitude via interface" << al; - TestserviceTool::sleep(2500); + + // Math + CMatrix3x3 m33; + m33.setCellIndex(); + testserviceInterface.receiveMatrix(m33); + qDebug() << "Send matrix" << m33; + + // next round? + qDebug() << "Key ......."; + getchar(); } } diff --git a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro index 52ddd002e..afabcc8a9 100644 --- a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro +++ b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro @@ -1,5 +1,4 @@ QT += core dbus -QT -= gui TARGET = sample_quantities_avionics_dbus TEMPLATE = app diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp index bcca70f78..dbecd51c9 100644 --- a/samples/blackmiscquantities_dbus/testservice.cpp +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -54,12 +54,27 @@ void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit) } /* - * Receivealtitude + * Receive altitude */ void Testservice::receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude) { qDebug() << "Pid:" << TestserviceTool::getPid() << "Received altitude:" << altitude; +} +/* + * Receive matrix + */ +void Testservice::receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received matrix:" << matrix; +} + +/* + * + */ +void Testservice::receiveList(const QList &list) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received list:" << list; } } // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h index 81e10e7b5..db169fcda 100644 --- a/samples/blackmiscquantities_dbus/testservice.h +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -76,6 +76,17 @@ public slots: */ void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude); + /*! + * \brief Receive matrix + * \param matrix + */ + void receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix); + + /*! + * \brief Receive list + * \param list + */ + void receiveList(const QList &list); public: static const QString ServiceName; diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index e9b152acb..f99c0b583 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -21,6 +21,7 @@ namespace Aviation */ class CAvionicsBase : public BlackMisc::CBaseStreamStringifier { + protected: QString m_name; //!< name of the unit diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index e82270b0d..86419639c 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -11,6 +11,7 @@ namespace BlackMisc { + namespace Aviation { diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 393cf4565..9e4e50dee 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -159,7 +159,7 @@ protected: * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &) const { } + virtual void marshallToDbus(QDBusArgument &) const {} /*! * \brief Stream from DBus diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 51316b601..e15b7eb22 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -34,6 +34,18 @@ void BlackMisc::Aviation::registerMetadata() CAltitude::registerMetadata(); } + +/* + * Metadata for math + */ +void BlackMisc::Math::registerMetadata() +{ + CMatrix3x3::registerMetadata(); + CMatrix3x1::registerMetadata(); + CMatrix1x3::registerMetadata(); +} + + /* * Metadata for Blackmisc */ @@ -41,4 +53,5 @@ void BlackMisc::registerMetadata() { PhysicalQuantities::registerMetadata(); Aviation::registerMetadata(); + Math::registerMetadata(); } diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 22133fbf0..8309a12a3 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -7,6 +7,7 @@ #define BLACKMISC_FREEFUNCTIONS_H #include "avallclasses.h" #include "pqallquantities.h" +#include "mathallclasses.h" namespace BlackMisc { @@ -34,6 +35,15 @@ void registerMetadata(); } // Aviation +namespace Math { + +/*! + * \brief Register metadata for math (matrices, vectors) + */ +void registerMetadata(); + +} + /*! * \brief Register all relevant metadata in BlackMisc */ diff --git a/src/blackmisc/mathallclasses.h b/src/blackmisc/mathallclasses.h new file mode 100644 index 000000000..0bdf4325f --- /dev/null +++ b/src/blackmisc/mathallclasses.h @@ -0,0 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_MATHALLCLASSES_H +#define BLACKMISC_MATHALLCLASSES_H + +#include "blackmisc/mathmatrix1x3.h" +#include "blackmisc/mathmatrix3x3.h" +#include "blackmisc/mathmatrix3x1.h" +#include "blackmisc/mathvector3d.h" + +#endif // guard diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h index 614c456cc..0daeea83b 100644 --- a/src/blackmisc/mathmatrix1x3.h +++ b/src/blackmisc/mathmatrix1x3.h @@ -54,5 +54,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix1x3) #endif // guard diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h index c2da2aefd..e26b82810 100644 --- a/src/blackmisc/mathmatrix3x1.h +++ b/src/blackmisc/mathmatrix3x1.h @@ -76,5 +76,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x1) #endif // guard diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index 80878ac94..b4da2c090 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -177,5 +177,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x3) #endif // guard diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 07dfc60b2..2bd2be4b3 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -69,6 +69,53 @@ template bool CMatrixBase void CMatrixBase::setCellIndex() +{ + for (int r = 0; r < Rows; r++) + { + for (int c = 0; c < Columns; c++) + { + this->m_matrix(r, c) = r + 0.1 * c; + } + } +} + +/* + * To list + */ +template const QList CMatrixBase::toList() const +{ + QList list; + for (int r = 0; r < Rows; r++) + { + for (int c = 0; c < Columns; c++) + { + list.append(this->m_matrix(r, c)); + } + } + return list; +} + +/* + * From list + */ +template void CMatrixBase::fromList(const QList &list) +{ + Q_ASSERT_X(Rows * Columns == list.count(), "fromList()", "Mismatch of elements in list"); + int ct = 0; + for (int r = 0; r < Rows; r++) + { + for (int c = 0; c < Columns; c++) + { + this->m_matrix(r, c) = list.at(ct++); + } + } +} + /* * All values equal? */ @@ -120,6 +167,16 @@ template QString CMatrixBase void CMatrixBase::registerMetadata() +{ + qRegisterMetaType(typeid(ImplMatrix).name()); + qDBusRegisterMetaType(); +} + + // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CMatrixBase; diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index bfd2d8c81..f6d95bf41 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -9,6 +9,7 @@ #include "blackmisc/basestreamstringifier.h" #include "blackmisc/mathvector3dbase.h" #include +#include namespace BlackMisc { @@ -49,6 +50,34 @@ protected: */ QString stringForConverter() const; + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + const QList l = this->toList(); + + // there is an issue with the signature of QList, so I use + // individual values + foreach(double v, l) { + argument << v; + } + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + QList list; + double v; + while(!argument.atEnd()) { + argument >> v; + list.append(v); + } + this->fromList(list); + } + public: /*! * \brief Default constructor @@ -75,6 +104,18 @@ public: */ virtual ~CMatrixBase() {} + /*! + * \brief List of values + * \return + */ + const QList toList() const; + + /*! + * \brief List of values + * \return + */ + void fromList(const QList &list); + /*! * \brief Equal operator == * \param otherMatrix @@ -264,6 +305,11 @@ public: */ bool isZero() const; + /*! + * \brief Each cell gets a unique index (used primarily for testing) + */ + void setCellIndex(); + /*! * \brief Is identity matrix? Epsilon considered. * \return @@ -342,6 +388,11 @@ public: return this->getElement(row, column); } + /*! + * \brief Register metadata + */ + static void registerMetadata(); + private: /*! * \brief Check range of row / column diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index b0d37129b..4883035a6 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -294,14 +294,6 @@ protected: */ typedef double(*UnitConverter)(const CMeasurementUnit &, double); - /*! - * \brief Stream to DBus - * \param argument - */ - virtual void marshallToDbus(QDBusArgument &argument) const { - argument << this->m_unitName; - } - private: QString m_name; //!< name, e.g. "meter" QString m_unitName; //!< unit name, e.g. "m" @@ -347,7 +339,6 @@ protected: */ CMeasurementUnit &operator =(const CMeasurementUnit &otherUnit); -protected: /*! * \brief String for streaming operators is full name * \return @@ -397,6 +388,24 @@ protected: return value / this->m_conversionFactorToSIConversionUnit; } + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_unitName; + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &) { + // the concrete implementations will override this default + // this is required so I can also stream None + (*this) = CMeasurementUnit::None(); + } + public: /*! * \brief Equal operator == From 7316980a5c9d89a05563c78a996f93778ec69ebc Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 25 Jul 2013 12:37:51 +0200 Subject: [PATCH 04/36] Enabled coordinates for DBus --- src/blackmisc/aviomodulator.h | 4 +- src/blackmisc/avverticalpositions.h | 2 +- src/blackmisc/blackmiscfreefunctions.cpp | 16 ++++++- src/blackmisc/blackmiscfreefunctions.h | 14 ++++++- src/blackmisc/coordinateecef.h | 2 +- src/blackmisc/coordinategeodetic.h | 35 +++++++++++++--- src/blackmisc/coordinatened.h | 2 +- src/blackmisc/geoearthangle.h | 53 +++++++++++++++++++++++- src/blackmisc/geolatitude.h | 1 + src/blackmisc/geolongitude.h | 2 + src/blackmisc/mathvector3d.h | 2 + src/blackmisc/mathvector3dbase.cpp | 34 ++++++++++++++- src/blackmisc/mathvector3dbase.h | 44 ++++++++++++++++++++ src/blackmisc/pqphysicalquantity.h | 2 +- 14 files changed, 196 insertions(+), 17 deletions(-) diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 86419639c..a720320e5 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -29,8 +29,8 @@ template class CModulator : public CAvionicsBase friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) { // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the CBaseStreamStringifier signature - // should be used + // Once someone solves this, this methods should go and the + // CBaseStreamStringifier signature should be used CBaseStreamStringifier &sf = uc; return argument >> sf; } diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index 167739a57..1d67e64ac 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -37,7 +37,7 @@ class CAviationVerticalPositions friend CLogMessage operator<<(CLogMessage log, const CAviationVerticalPositions &positions); private: - CAltitude m_altitude; //!< altitude + BlackMisc::Aviation::CAltitude m_altitude; //!< altitude BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation BlackMisc::PhysicalQuantities::CLength m_height; //!< height diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index e15b7eb22..33649d118 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -36,16 +36,29 @@ void BlackMisc::Aviation::registerMetadata() /* - * Metadata for math + * Metadata for Math */ void BlackMisc::Math::registerMetadata() { CMatrix3x3::registerMetadata(); CMatrix3x1::registerMetadata(); CMatrix1x3::registerMetadata(); + CVector3D::registerMetadata(); } +/* + * Metadata for Geo + */ +void BlackMisc::Geo::registerMetadata() +{ + CCoordinateEcef::registerMetadata(); + CCoordinateNed::registerMetadata(); + CCoordinateGeodetic::registerMetadata(); + CLatitude::registerMetadata(); + CLongitude::registerMetadata(); +} + /* * Metadata for Blackmisc */ @@ -54,4 +67,5 @@ void BlackMisc::registerMetadata() PhysicalQuantities::registerMetadata(); Aviation::registerMetadata(); Math::registerMetadata(); + Geo::registerMetadata(); } diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 8309a12a3..15097647f 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -8,6 +8,7 @@ #include "avallclasses.h" #include "pqallquantities.h" #include "mathallclasses.h" +#include "geoallclasses.h" namespace BlackMisc { @@ -42,7 +43,18 @@ namespace Math { */ void registerMetadata(); -} +} // Math + +namespace Geo { + +/*! + * \brief Register metadata for geo (coordinates) + */ +void registerMetadata(); + +} // Geo + + /*! * \brief Register all relevant metadata in BlackMisc diff --git a/src/blackmisc/coordinateecef.h b/src/blackmisc/coordinateecef.h index ac9d27a52..0e21b8e20 100644 --- a/src/blackmisc/coordinateecef.h +++ b/src/blackmisc/coordinateecef.h @@ -117,6 +117,6 @@ protected: } // namespace } // namespace - +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateEcef) #endif // guard diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 0e68b021a..2ef42cfbc 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -37,14 +37,12 @@ class ICoordinateGeodetic /*! * \brief Geodetic coordinate */ -class CCoordinateGeodetic : - public CBaseStreamStringifier, - public ICoordinateGeodetic +class CCoordinateGeodetic : public CBaseStreamStringifier, public ICoordinateGeodetic { private: - CLatitude m_latitude; //!< Latitude - CLongitude m_longitude; //!< Longitude + BlackMisc::Geo::CLatitude m_latitude; //!< Latitude + BlackMisc::Geo::CLongitude m_longitude; //!< Longitude BlackMisc::PhysicalQuantities::CLength m_height; //!< height protected: @@ -58,6 +56,25 @@ protected: QString s = "Geodetic: {%1, %2, %3}"; return s.arg(this->m_latitude.unitValueRoundedWithUnit(6)).arg(this->m_longitude.unitValueRoundedWithUnit(6)).arg(this->m_height.unitValueRoundedWithUnit()); } + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + argument << this->m_latitude; + argument << this->m_longitude; + argument << this->m_height; + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_latitude; + argument >> this->m_longitude; + argument >> this->m_height; + } public: /*! @@ -203,10 +220,16 @@ public: this->m_longitude = otherGeodetic.m_longitude; return (*this); } + + /* + * Register metadata + */ + static void registerMetadata(); + }; } // namespace } // namespace - +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic) #endif // guard diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index d1677c795..c620aa83c 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -218,6 +218,6 @@ public: } // namespace } // namespace - +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateNed) #endif // guard diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 1c33b8c53..c211462d9 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -16,6 +16,33 @@ namespace Geo */ template class CEarthAngle : public BlackMisc::PhysicalQuantities::CAngle { + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param uc + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, LATorLON &uc) { + // If I do not have the method here, DBus metasystem tries to stream against + // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) + // Once someone solves this, this methods should go and the + // CBaseStreamStringifier signature should be used + CBaseStreamStringifier &sf = uc; + return argument >> sf; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const LATorLON &uc) + { + const CBaseStreamStringifier &sf = uc; + return argument << sf; + } + protected: /*! * \brief Default constructor @@ -44,8 +71,23 @@ protected: return this->unitValueRoundedWithUnit(6); } -public: + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + CAngle::marshallToDbus(argument); + } + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + CAngle::unmarshallFromDbus(argument); + } + +public: /*! * \brief Virtual destructor */ @@ -169,6 +211,15 @@ public: l -= latOrLon; return l; } + + /* + * Register metadata + */ + static void registerMetadata() + { + qRegisterMetaType(typeid(LATorLON).name()); + qDBusRegisterMetaType(); + } }; } // namespace diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 1f0d18d19..3ce1e9a4e 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -50,5 +50,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CLatitude) #endif // guard diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 1d47a9180..2bd89192a 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -50,4 +50,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CLongitude) + #endif // guard diff --git a/src/blackmisc/mathvector3d.h b/src/blackmisc/mathvector3d.h index 116c7f806..26a03cd37 100644 --- a/src/blackmisc/mathvector3d.h +++ b/src/blackmisc/mathvector3d.h @@ -97,4 +97,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CVector3D) + #endif // guard diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index 7d8c83bc0..241e88fb6 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -20,8 +20,8 @@ template QString CVector3DBase::stringForConverte { QString s = ("{%1, %2, %3}"); s = s.arg(QString::number(this->m_i, 'f')). - arg(QString::number(this->m_j, 'f')). - arg(QString::number(this->m_k, 'f')); + arg(QString::number(this->m_j, 'f')). + arg(QString::number(this->m_k, 'f')); return s; } @@ -131,6 +131,36 @@ template CMatrix3x1 CVector3DBase::toMatrix3x1() return CMatrix3x1(this->m_i, this->m_j, this->m_k); } + +/*! + * \brief Stream to DBus + * \param argument + */ +template void CVector3DBase::marshallToDbus(QDBusArgument &argument) const { + argument << this->m_i; + argument << this->m_j; + argument << this->m_k; +} + +/*! + * \brief Stream from DBus + * \param argument + */ +template void CVector3DBase::unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_i; + argument >> this->m_j; + argument >> this->m_k; +} + +/* + * Register metadata + */ +template void CVector3DBase::registerMetadata() +{ + qRegisterMetaType(typeid(ImplVector).name()); + qDBusRegisterMetaType(); +} + // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CVector3DBase; diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 48ea18b38..b772bbdeb 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -24,6 +24,33 @@ class CMatrix3x1; // forward declaration template class CVector3DBase : public CBaseStreamStringifier { + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param uc + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, ImplVector &uc) { + // If I do not have the method here, DBus metasystem tries to stream against + // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) + // Once someone solves this, this methods should go and the + // CBaseStreamStringifier signature should be used + CBaseStreamStringifier &sf = uc; + return argument >> sf; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const ImplVector &uc) + { + const CBaseStreamStringifier &sf = uc; + return argument << sf; + } + private: /*! * \brief Easy access to derived class (CRTP template parameter) @@ -81,6 +108,18 @@ protected: */ virtual QString stringForConverter() const; + /*! + * \brief Unmarshall from Dbus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); + + /*! + * \brief Marshall to Dbus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; + public: // getter and setters are implemented in the derived classes @@ -416,6 +455,11 @@ public: v.round(); return v; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 97619de01..4fb3eb4bb 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -271,7 +271,7 @@ public: void addUnitValue(double value); /*! - * \brief Substratc to the unit value. + * \brief Substract to the unit value. * \remarks Since overloading the - operator with double did lead to unintended conversions, as explicit method * \param value */ From 581638ec7f560f5c4962b7316b3b080cc211bd1d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 25 Jul 2013 23:58:09 +0200 Subject: [PATCH 05/36] Enabled coordinate classes for DBus, added generation method for lat/lng by WGS84 strings --- .../BlackMiscTest.Testservice.xml | 6 +- samples/blackmiscquantities_dbus/main.cpp | 13 +++- .../blackmiscquantities_dbus/testservice.cpp | 10 ++- .../blackmiscquantities_dbus/testservice.h | 6 ++ src/blackcore/multiplayer.cpp | 2 +- src/blackmisc/aviomodulator.cpp | 2 - src/blackmisc/avverticalpositions.cpp | 36 ++++++--- src/blackmisc/avverticalpositions.h | 49 ++++++------ src/blackmisc/basestreamstringifier.h | 1 + src/blackmisc/blackmiscfreefunctions.cpp | 2 +- src/blackmisc/blackmiscfreefunctions.h | 2 - src/blackmisc/coordinategeodetic.cpp | 50 ++++++++++++ src/blackmisc/coordinategeodetic.h | 19 +---- src/blackmisc/geoallclasses.h | 16 ++++ src/blackmisc/geoearthangle.cpp | 77 +++++++++++++++++++ src/blackmisc/geoearthangle.h | 26 +++++-- src/blackmisc/geolatitude.h | 10 +++ src/blackmisc/geolongitude.h | 6 ++ src/blackmisc/pqangle.h | 13 ++++ src/blackmisc/pqunits.cpp | 2 +- src/blackmisc/pqunits.h | 4 +- 21 files changed, 280 insertions(+), 72 deletions(-) create mode 100644 src/blackmisc/coordinategeodetic.cpp create mode 100644 src/blackmisc/geoallclasses.h create mode 100644 src/blackmisc/geoearthangle.cpp diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml index a0ff44680..d79b1c4e7 100644 --- a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -23,12 +23,16 @@ - + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index 14d2bced8..e389d33dc 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -17,6 +17,7 @@ using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Aviation; using namespace BlackMisc::Math; +using namespace BlackMisc::Geo; using namespace BlackMiscTest; /*! @@ -100,9 +101,6 @@ int main(int argc, char *argv[]) list << 1.0 << 2.0 << 3.0; testserviceInterface.receiveList(list); qDebug() << "Send list via interface" << list; - qDebug() << "Key ......."; - getchar(); - // PQs CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); @@ -132,6 +130,15 @@ int main(int argc, char *argv[]) testserviceInterface.receiveMatrix(m33); qDebug() << "Send matrix" << m33; + // Geo + // EDDF: 50° 2′ 0″ N, 8° 34′ 14″ E, 100m MSL + CLatitude lat = CLatitude::fromWgs84("50° 2′ 1″ 23 N"); + CLongitude lon = CLongitude::fromWgs84("8° 34′ 14″ E"); + CLength height(100, CLengthUnit::m()); + CCoordinateGeodetic geoPos(lat, lon, height); + testserviceInterface.receiveGeoPosition(geoPos); + qDebug() << "Send geo position" << geoPos; + // next round? qDebug() << "Key ......."; getchar(); diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp index dbecd51c9..1c00dc048 100644 --- a/samples/blackmiscquantities_dbus/testservice.cpp +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -70,11 +70,19 @@ void Testservice::receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix) } /* - * + * Receive a list */ void Testservice::receiveList(const QList &list) { qDebug() << "Pid:" << TestserviceTool::getPid() << "Received list:" << list; } +/* + * Receive a geo position + */ +void Testservice::receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic &geo) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received geo data:" << geo; +} + } // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h index db169fcda..c03bc02b1 100644 --- a/samples/blackmiscquantities_dbus/testservice.h +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -88,6 +88,12 @@ public slots: */ void receiveList(const QList &list); + /*! + * \brief Receive a geo position + * \param geo + */ + void receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic &geo); + public: static const QString ServiceName; static const QString ServicePath; diff --git a/src/blackcore/multiplayer.cpp b/src/blackcore/multiplayer.cpp index 79ab18a5c..68a9545cc 100644 --- a/src/blackcore/multiplayer.cpp +++ b/src/blackcore/multiplayer.cpp @@ -95,7 +95,7 @@ void CMultiPlayer::addPlane(CPlane *plane) void CMultiPlayer::removePlane(CPlane *plane) { - qint32 id; + qint32 id = 0; m_simulator->removePlane(id); } diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index 49e23a232..ce309642b 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -67,13 +67,11 @@ template bool CModulator::operator !=(const CModulator return !(otherModulator == (*this)); } - // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CModulator; template class CModulator; template class CModulator; - } // namespace } // namespace diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp index 398113626..6c8a43d7b 100644 --- a/src/blackmisc/avverticalpositions.cpp +++ b/src/blackmisc/avverticalpositions.cpp @@ -74,9 +74,9 @@ bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &o } /* - * String representation for streaming + * String representation for converter */ -QString CAviationVerticalPositions::stringForStreamingOperator() const +QString CAviationVerticalPositions::stringForConverter() const { QString s = QString("Altitude: "). append(this->m_altitude.unitValueRoundedWithUnit()). @@ -109,22 +109,34 @@ CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationI return CAviationVerticalPositions(a, e, h); } -/* - * Stream for log message + +/*! + * \brief Stream to DBus << + * \param argument */ -CLogMessage operator <<(CLogMessage log, const CAviationVerticalPositions &positions) -{ - log << positions.stringForStreamingOperator(); - return log; +void CAviationVerticalPositions::marshallToDbus(QDBusArgument &argument) const { + argument << this->m_altitude; + argument << this->m_elevation; + argument << this->m_height; +} + +/*! + * \brief Stream from DBus >> + * \param argument + */ +void CAviationVerticalPositions::unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_altitude; + argument >> this->m_elevation; + argument >> this->m_height; } /* - * Stream for qDebug + * Register metadata */ -QDebug operator <<(QDebug d, const CAviationVerticalPositions &positions) +void CAviationVerticalPositions::registerMetadata() { - d << positions.stringForStreamingOperator(); - return d; + qRegisterMetaType(typeid(CAviationVerticalPositions).name()); + qDBusRegisterMetaType(); } } // namespace diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index 1d67e64ac..583383f43 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -3,11 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BLACKMISC_AVLATERALPOSITION_H -#define BLACKMISC_AVLATERALPOSITION_H +#ifndef BLACKMISC_AVVERTICALPOSITION_H +#define BLACKMISC_AVVERTICALPOSITION_H #include "blackmisc/avaltitude.h" #include "blackmisc/pqconstants.h" +#include "blackmisc/basestreamstringifier.h" namespace BlackMisc { @@ -17,25 +18,8 @@ namespace Aviation /*! * \brief Vertical (Z) positions of an aircraft */ -class CAviationVerticalPositions +class CAviationVerticalPositions : public BlackMisc::CBaseStreamStringifier { - /*! - * \brief Stream << overload to be used in debugging messages - * \param d - * \param positions - * \return - */ - friend QDebug operator<<(QDebug d, const CAviationVerticalPositions &positions); - - /*! - * Stream operator for log messages - * \brief operator << - * \param log - * \param positions - * \return - */ - friend CLogMessage operator<<(CLogMessage log, const CAviationVerticalPositions &positions); - private: BlackMisc::Aviation::CAltitude m_altitude; //!< altitude BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation @@ -43,10 +27,22 @@ private: protected: /*! - * \brief Specific stream operation for heading + * \brief String for converter * \return */ - virtual QString stringForStreamingOperator() const; + virtual QString stringForConverter() const; + + /*! + * \brief Unmarshall from Dbus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); + + /*! + * \brief Unmarshall from Dbus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; public: /*! @@ -113,6 +109,7 @@ public: * \param elevationFt * \return */ + static CAviationVerticalPositions fromAltitudeAndElevationInFt(double altitudeMslFt, double elevationFt); /*! * \brief Factory getting tupel frome levation and altitude values in meters @@ -121,9 +118,15 @@ public: * \return */ static CAviationVerticalPositions fromAltitudeAndElevationInM(double altitudeMslM, double elevationM); + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CAviationVerticalPositions) -#endif // BLACKMISC_AVLATERALPOSITION_H +#endif // BLACKMISC_AVVERTICALPOSITION_H diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 9e4e50dee..ba5cbcd6b 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -14,6 +14,7 @@ namespace BlackMisc /*! * \brief Provides "to QString" and stream operators */ +// Virtual operators: http://stackoverflow.com/a/4571634/356726 class CBaseStreamStringifier { /*! diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 33649d118..0d7074297 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -32,9 +32,9 @@ void BlackMisc::Aviation::registerMetadata() CNavSystem::registerMetadata(); CAdfSystem::registerMetadata(); CAltitude::registerMetadata(); + CAviationVerticalPositions::registerMetadata(); } - /* * Metadata for Math */ diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 15097647f..f413249e7 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -54,8 +54,6 @@ void registerMetadata(); } // Geo - - /*! * \brief Register all relevant metadata in BlackMisc */ diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp new file mode 100644 index 000000000..1893e8231 --- /dev/null +++ b/src/blackmisc/coordinategeodetic.cpp @@ -0,0 +1,50 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/coordinategeodetic.h" + +namespace BlackMisc +{ +namespace Geo +{ + +/* + * String for converter + */ +QString CCoordinateGeodetic::stringForConverter() const +{ + QString s = "Geodetic: {%1, %2, %3}"; + return s.arg(this->m_latitude.unitValueRoundedWithUnit(6)).arg(this->m_longitude.unitValueRoundedWithUnit(6)).arg(this->m_height.unitValueRoundedWithUnit()); +} + +/* + * Marshall to Dbus + */ +void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const { + argument << this->m_latitude; + argument << this->m_longitude; + argument << this->m_height; +} + +/* + * Unmarshall from Dbus + */ +void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument) { + argument >> this->m_latitude; + argument >> this->m_longitude; + argument >> this->m_height; +} + +/* + * Register metadata + */ +void CCoordinateGeodetic::registerMetadata() +{ + qRegisterMetaType(typeid(CCoordinateGeodetic).name()); + qDBusRegisterMetaType(); +} + +} // namespace +} // namespace diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 2ef42cfbc..e065e8792 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -51,30 +51,19 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const - { - QString s = "Geodetic: {%1, %2, %3}"; - return s.arg(this->m_latitude.unitValueRoundedWithUnit(6)).arg(this->m_longitude.unitValueRoundedWithUnit(6)).arg(this->m_height.unitValueRoundedWithUnit()); - } + virtual QString stringForConverter() const; + /*! * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - argument << this->m_latitude; - argument << this->m_longitude; - argument << this->m_height; - } + virtual void marshallToDbus(QDBusArgument &argument) const; /*! * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - argument >> this->m_latitude; - argument >> this->m_longitude; - argument >> this->m_height; - } + virtual void unmarshallFromDbus(const QDBusArgument &argument); public: /*! diff --git a/src/blackmisc/geoallclasses.h b/src/blackmisc/geoallclasses.h new file mode 100644 index 000000000..a8b82f0e9 --- /dev/null +++ b/src/blackmisc/geoallclasses.h @@ -0,0 +1,16 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_GEOALLCLASSES_H +#define BLACKMISC_GEOALLCLASSES_H + +#include "blackmisc/geoearthangle.h" +#include "blackmisc/geolatitude.h" +#include "blackmisc/geolongitude.h" +#include "blackmisc/coordinateecef.h" +#include "blackmisc/coordinatened.h" +#include "blackmisc/coordinategeodetic.h" + +#endif // guard diff --git a/src/blackmisc/geoearthangle.cpp b/src/blackmisc/geoearthangle.cpp new file mode 100644 index 000000000..219bc85c0 --- /dev/null +++ b/src/blackmisc/geoearthangle.cpp @@ -0,0 +1,77 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/geoearthangle.h" +#include "blackmisc/geolatitude.h" +#include "blackmisc/geolongitude.h" + +namespace BlackMisc +{ +namespace Geo +{ + +/* + * Register metadata + */ +template void CEarthAngle::registerMetadata() +{ + qRegisterMetaType(typeid(LATorLON).name()); + qDBusRegisterMetaType(); +} + +/* + * Latitude or Longitude from a WGS string + */ +template LATorLON CEarthAngle::fromWgs84(const QString &wgsCoordinate) +{ + // http://www.regular-expressions.info/floatingpoint.html + QRegExp rx("([-+]?[0-9]*\\.?[0-9]+)"); + qint32 deg = 0; + qint32 min = 0; + double sec = 0.0; + double secFragment = 0.0; + int fragmentLength = 0; + int c = 0; + int pos= 0; + while ((pos = rx.indexIn(wgsCoordinate, pos)) != -1) { + QString cap = rx.cap(1); + pos += rx.matchedLength(); + switch(c++) { + case 0: + deg = cap.toInt(); + break; + case 1: + min = cap.toInt(); + break; + case 2: + sec = cap.toDouble(); + break; + case 3: + secFragment = cap.toDouble(); + fragmentLength = cap.length(); + break; + default: + break; + } + } + if (fragmentLength > 0) { + // we do have given ms + sec += secFragment / qPow(10,fragmentLength); + } + + if (wgsCoordinate.contains('S', Qt::CaseInsensitive) || + wgsCoordinate.contains('W', Qt::CaseInsensitive)) deg *= -1; + + CAngle a(deg, min, sec); + return LATorLON(a); +} + +// see here for the reason of thess forward instantiations +// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html +template class CEarthAngle; +template class CEarthAngle; + +} // namespace +} // namespace diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index c211462d9..7d1b2fc4f 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BLACKMISC_GEOLATLONBASE_H -#define BLACKMISC_GEOLATLONBASE_H +#ifndef BLACKMISC_GEOEARTHANGLE_H +#define BLACKMISC_GEOEARTHANGLE_H #include "blackmisc/pqangle.h" namespace BlackMisc @@ -62,6 +62,12 @@ protected: */ CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CAngle(value, unit) {} + /*! + * \brief Init by double value + * \param angle + */ + CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle): CAngle(angle) {} + /*! * \brief String for converter and streaming * \return @@ -212,14 +218,18 @@ public: return l; } - /* + /*! * Register metadata */ - static void registerMetadata() - { - qRegisterMetaType(typeid(LATorLON).name()); - qDBusRegisterMetaType(); - } + static void registerMetadata(); + + /*! + * \brief Latitude / Longitude from a WGS string such as + * \param wgsCoordinate 50° 2′ 0″ N / 8° 34′ 14″ E + * \return + */ + static LATorLON fromWgs84(const QString &wgsCoordinate); + }; } // namespace diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 3ce1e9a4e..a7187a60f 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -1,7 +1,10 @@ #ifndef BLACKMISC_GEOLATITUDE_H #define BLACKMISC_GEOLATITUDE_H + +#include #include "blackmisc/geoearthangle.h" + namespace BlackMisc { namespace Geo @@ -34,6 +37,12 @@ public: */ CLatitude(const CLatitude &latitude) : CEarthAngle(latitude) {} + /*! + * \brief Constructor + * \param angle + */ + CLatitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} + /*! * \brief Init by double value * \param value @@ -45,6 +54,7 @@ public: * \brief Virtual destructor */ virtual ~CLatitude() {} + }; } // namespace diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 2bd89192a..9099d10de 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -34,6 +34,12 @@ public: */ CLongitude(const CLongitude &Longitude) : CEarthAngle(Longitude) {} + /*! + * \brief Constructor + * \param angle + */ + CLongitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} + /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 7fabb6df8..4cd63098a 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -42,6 +42,19 @@ public: */ CAngle(double value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} + /*! + * \brief Intir as sexagesimal degrees + * \param degrees + * \param minutes + * \param seconds + */ + CAngle(qint32 degrees, qint32 minutes, double seconds) : + CPhysicalQuantity( + degrees + minutes / 100.0 + seconds / 10000.0, + CAngleUnit::sexagesimalDeg(), CAngleUnit::rad()) { + // void + } + /*! * \brief Virtual destructor */ diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 396f05332..cd143912e 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -76,7 +76,7 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const double mi = floor((value - de) * 100.0); double se = floor((value - de - mi / 100.0) * 1000000) / 100.0; QString ses = QLocale::system().toString(se, 'f', 2); - s = QString::number(de).append(this->getUnitName()).append(QString::number(mi)) + s = QString::number(de).append(" ").append(QString::number(mi)) .append("'").append(ses).append("\""); } else diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 285d02042..3d1ec1605 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -246,7 +246,7 @@ public: */ static const CAngleUnit °() { - static CAngleUnit deg("degree", "°", false, M_PI / 180); + static CAngleUnit deg("degree", "deg", false, M_PI / 180); return deg; } @@ -256,7 +256,7 @@ public: */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg("segadecimal degree", "°", false, M_PI / 180, + static CAngleUnit deg("segadecimal degree", "segd", false, M_PI / 180, CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; } From 40a97c3d829ac9d4640e7697109add8b9740136a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 27 Jul 2013 20:23:23 +0200 Subject: [PATCH 06/36] Added I18N for PQs, initial version. Hence resource file and language files. Changed samplesphysicalquantities to check some I18N topics. --- samples/blackmiscquantities/main.cpp | 14 ++- .../sample_quantities_avionics.pro | 1 - .../samplesphysicalquantities.cpp | 12 +- src/blackbox/blackbox.pro | 2 +- src/blackcore/fsd_client.cpp | 2 +- src/blackcore/multiplayer.cpp | 2 +- src/blackcore/multiplayer.h | 2 +- src/blackmisc/aviomodulator.h | 7 +- src/blackmisc/aviotransponder.cpp | 2 +- src/blackmisc/aviotransponder.h | 3 +- src/blackmisc/avverticalpositions.cpp | 2 +- src/blackmisc/avverticalpositions.h | 3 +- src/blackmisc/basestreamstringifier.h | 14 ++- src/blackmisc/blackmisc.pro | 9 +- src/blackmisc/blackmisc.qrc | 7 ++ src/blackmisc/blackmiscfreefunctions.cpp | 8 ++ src/blackmisc/blackmiscfreefunctions.h | 14 +++ src/blackmisc/com_server.cpp | 4 +- src/blackmisc/coordinategeodetic.cpp | 4 +- src/blackmisc/coordinategeodetic.h | 3 +- src/blackmisc/debug.cpp | 2 +- src/blackmisc/display.cpp | 2 +- src/blackmisc/mathmatrixbase.cpp | 2 +- src/blackmisc/mathmatrixbase.h | 3 +- src/blackmisc/mathvector3dbase.cpp | 2 +- src/blackmisc/mathvector3dbase.h | 3 +- src/blackmisc/pqbase.cpp | 4 +- src/blackmisc/pqbase.h | 26 ++-- src/blackmisc/pqphysicalquantity.cpp | 17 ++- src/blackmisc/pqphysicalquantity.h | 16 ++- src/blackmisc/pqunits.h | 49 ++++++-- .../translations/blackmisc_i18n_de.qm | Bin 0 -> 1426 bytes .../translations/blackmisc_i18n_de.ts | 118 ++++++++++++++++++ .../translations/blackmisc_i18n_en.qm | Bin 0 -> 302 bytes .../translations/blackmisc_i18n_en.ts | 118 ++++++++++++++++++ .../translations/blackmisc_i18n_fr.qm | Bin 0 -> 796 bytes .../translations/blackmisc_i18n_fr.ts | 118 ++++++++++++++++++ src/blackx/CMakeLists.txt | 0 38 files changed, 523 insertions(+), 72 deletions(-) create mode 100644 src/blackmisc/blackmisc.qrc create mode 100644 src/blackmisc/translations/blackmisc_i18n_de.qm create mode 100644 src/blackmisc/translations/blackmisc_i18n_de.ts create mode 100644 src/blackmisc/translations/blackmisc_i18n_en.qm create mode 100644 src/blackmisc/translations/blackmisc_i18n_en.ts create mode 100644 src/blackmisc/translations/blackmisc_i18n_fr.qm create mode 100644 src/blackmisc/translations/blackmisc_i18n_fr.ts delete mode 100644 src/blackx/CMakeLists.txt diff --git a/samples/blackmiscquantities/main.cpp b/samples/blackmiscquantities/main.cpp index 906cb356f..147754977 100644 --- a/samples/blackmiscquantities/main.cpp +++ b/samples/blackmiscquantities/main.cpp @@ -2,10 +2,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include "samplesphysicalquantities.h" #include "samplesaviation.h" -#include +#include "blackmisc/blackmiscfreefunctions.h" using namespace BlackMisc; using namespace BlackMiscTest; @@ -15,8 +16,19 @@ using namespace BlackMiscTest; */ int main(int argc, char *argv[]) { + BlackMisc::initResources(); + QFile file(":/translations/blackmisc_i18n_de.qm"); + qDebug() << (file.exists() ? "Found translations in resources" : "No translations in resources"); + + QTranslator translator; + translator.load("blackmisc_i18n_de", ":/translations/"); QCoreApplication a(argc, argv); + qDebug() << "Use I18N version, y? n?"; + int yn = getchar(); + bool t = (yn == 'y' || yn == 'Y') ? a.installTranslator(&translator) : false; + qDebug() << (t ? "Installed translator" : "No translator "); + CSamplesPhysicalQuantities::samples(); CSamplesAviation::samples(); diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index 98c3d24c0..dd34fafb5 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -1,5 +1,4 @@ QT += core dbus -QT -= gui TARGET = sample_quantities_avionics TEMPLATE = app diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index 7b4eaafeb..ca451855b 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -26,9 +26,9 @@ int CSamplesPhysicalQuantities::samples() CLengthUnit lu1(CLengthUnit::cm()); CLengthUnit lu2(CLengthUnit::ft()); - QString lu1s = lu1.toQString(); - QString lu2s = lu2.toQString(); - qDebug() << lu1 << lu2 << lu1s << lu2s; + QString lu1s = lu1.toQString(true); + QString lu2s = lu2.toQString(true); + qDebug() << lu1 << lu2 << lu1s << lu2s << lu1.getName(true) << lu2.getName(true); const CLength l1(5.0, CLengthUnit::ft()); // 5 ft CLength l2(1, CLengthUnit::NM()); // 1NM CLength l3(1, CLengthUnit::km()); @@ -89,8 +89,8 @@ int CSamplesPhysicalQuantities::samples() CTemperature t1; CTemperature t2(20, CTemperatureUnit::C()); CTemperature t3(1, CTemperatureUnit::F()); - qDebug() << t1 << t2 << t2.convertedSiValueRoundedWithUnit(); - qDebug() << t3 << t3.valueRoundedWithUnit(CTemperatureUnit::C()); + qDebug() << t1 << t2 << t2.convertedSiValueRoundedWithUnit(true); + qDebug() << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1 ,true) << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << "I18N/UTF"; // some logging with CLogMessage // bDebug << p1; @@ -111,7 +111,7 @@ int CSamplesPhysicalQuantities::samples() qDebug() << ti1 << ti2; CAcceleration ac1(10, CAccelerationUnit::m_s2()); - qDebug() << ac1; + qDebug() << ac1 << ac1.unitValueRoundedWithUnit(-1, true) << "I18N/UTF"; // bye qDebug() << "-----------------------------------------------"; diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index 79dad5973..9587feccc 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -4,7 +4,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets INCLUDEPATH += . .. -TARGET = BlackBox +TARGET = blackbox TEMPLATE = app SOURCES += *.cpp diff --git a/src/blackcore/fsd_client.cpp b/src/blackcore/fsd_client.cpp index 6a4e754c5..07796e03e 100644 --- a/src/blackcore/fsd_client.cpp +++ b/src/blackcore/fsd_client.cpp @@ -60,7 +60,7 @@ namespace FSD return m_tcp_socket->state() == QAbstractSocket::ConnectedState; } - QString CFSDClient::getErrorMessage(QAbstractSocket::SocketError error) + QString CFSDClient::getErrorMessage(QAbstractSocket::SocketError /* error */) { return QString("Unknown"); } diff --git a/src/blackcore/multiplayer.cpp b/src/blackcore/multiplayer.cpp index 68a9545cc..2a7da6c9d 100644 --- a/src/blackcore/multiplayer.cpp +++ b/src/blackcore/multiplayer.cpp @@ -93,7 +93,7 @@ void CMultiPlayer::addPlane(CPlane *plane) m_multiplayer_planes.insert(plane->callsign(), plane); } -void CMultiPlayer::removePlane(CPlane *plane) +void CMultiPlayer::removePlane(CPlane * /** plane **/) { qint32 id = 0; m_simulator->removePlane(id); diff --git a/src/blackcore/multiplayer.h b/src/blackcore/multiplayer.h index 3aea55864..c61863383 100644 --- a/src/blackcore/multiplayer.h +++ b/src/blackcore/multiplayer.h @@ -81,7 +81,7 @@ namespace BlackCore { void addPlane(CPlane *plane); - void removePlane(CPlane *plane); + void removePlane(CPlane *); bool needsToRemoved(CPlane *plane); diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index a720320e5..249b7e9bd 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -80,12 +80,13 @@ protected: /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const { + virtual QString stringForConverter(bool i18n = false) const { QString s(this->getName()); - s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3)); - s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3)); + s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3, i18n)); + s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3, i18n)); return s; } diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index d5ffbab9b..e471615c8 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -45,7 +45,7 @@ bool CTransponder::validate(bool strict) const /** * String representation */ -QString CTransponder::stringForConverter() const +QString CTransponder::stringForConverter(bool /** i18n **/) const { QString s = this->getName(); s = s.append(" ").append(this->getTransponderCodeFormatted()).append(" ").append(this->getModeAsString()); diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index ffff37c1a..50961eab7 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -90,9 +90,10 @@ protected: /*! * \brief Meaningful string representation + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; public: /*! diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp index 6c8a43d7b..cdb93f60e 100644 --- a/src/blackmisc/avverticalpositions.cpp +++ b/src/blackmisc/avverticalpositions.cpp @@ -76,7 +76,7 @@ bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &o /* * String representation for converter */ -QString CAviationVerticalPositions::stringForConverter() const +QString CAviationVerticalPositions::stringForConverter(bool /** i18n **/) const { QString s = QString("Altitude: "). append(this->m_altitude.unitValueRoundedWithUnit()). diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index 583383f43..0250d2598 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -28,9 +28,10 @@ private: protected: /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; /*! * \brief Unmarshall from Dbus diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index ba5cbcd6b..5e69e1af8 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -9,14 +9,15 @@ #include #include -namespace BlackMisc -{ +namespace BlackMisc { + /*! * \brief Provides "to QString" and stream operators */ // Virtual operators: http://stackoverflow.com/a/4571634/356726 class CBaseStreamStringifier { + /*! * \brief Stream << overload to be used in debugging messages * \param debug @@ -127,11 +128,12 @@ public: /*! * \brief Cast as QString + * \bool i18n * \remarks operator cast caused too many ambiguity trouble */ - QString toQString() const + QString toQString(bool i18n = false) const { - return this->stringForConverter(); + return this->stringForConverter(i18n); } protected: @@ -152,9 +154,10 @@ protected: /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const = 0; + virtual QString stringForConverter(bool i18n = false) const = 0; /*! * \brief Stream to DBus @@ -175,6 +178,7 @@ protected: * \return */ CBaseStreamStringifier& operator=(const CBaseStreamStringifier&) { return *this; } + }; } // namespace diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index e2ca61f58..796b2071b 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -6,14 +6,21 @@ CONFIG += staticlib INCLUDEPATH += .. # DEPENDPATH += . .. // BlackMisc should be independent - # PRECOMPILED_HEADER = stdpch.h precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += USING_PCH } DEFINES += LOG_IN_FILE +RESOURCES += blackmisc.qrc + +# lupdate +CODECFORTR = UTF-8 +TRANSLATIONS += translations/blackmisc_i18n_de.ts \ + translations/blackmisc_i18n_fr.ts \ + translations/blackmisc_i18n_en.ts HEADERS += *.h SOURCES += *.cpp DESTDIR = ../../lib +OTHER_FILES += $$TRANSLATIONS diff --git a/src/blackmisc/blackmisc.qrc b/src/blackmisc/blackmisc.qrc new file mode 100644 index 000000000..d2d0e250e --- /dev/null +++ b/src/blackmisc/blackmisc.qrc @@ -0,0 +1,7 @@ + + + translations/blackmisc_i18n_de.qm + translations/blackmisc_i18n_fr.qm + translations/blackmisc_i18n_en.qm + + diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 0d7074297..77028ea2d 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -69,3 +69,11 @@ void BlackMisc::registerMetadata() Math::registerMetadata(); Geo::registerMetadata(); } + +/* + * Init resources + */ +void BlackMisc::initResources() +{ + initBlackMiscResources(); +} diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index f413249e7..9cdf63641 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -10,6 +10,14 @@ #include "mathallclasses.h" #include "geoallclasses.h" +/*! + * \brief Workaround, to call initResource from namespace + */ +inline void initBlackMiscResources() { Q_INIT_RESOURCE(blackmisc); } + +/*! + * Free functions in BlackMisc + */ namespace BlackMisc { /*! @@ -59,6 +67,12 @@ void registerMetadata(); */ void registerMetadata(); +/*! + * \brief Init resources + */ +void initResources(); + + } // BlackMisc #endif // BLACKMISC_FREEFUNCTIONS_H diff --git a/src/blackmisc/com_server.cpp b/src/blackmisc/com_server.cpp index 4b67198aa..510f920b9 100644 --- a/src/blackmisc/com_server.cpp +++ b/src/blackmisc/com_server.cpp @@ -92,7 +92,7 @@ void CComServer::sendToAll(const QString &messageID, const QByteArray &data) } } -QString CComServer::getErrorMessage(const QAbstractSocket::SocketError error) +QString CComServer::getErrorMessage(const QAbstractSocket::SocketError /** error **/) { return QString(); } @@ -128,7 +128,7 @@ void CComServer::onClientDisconnected(uint clientID) m_client_buffers.take(clientID)->deleteLater(); } -void CComServer::onClientMessageReceived(uint clientID, QString &messageID, QByteArray &message) +void CComServer::onClientMessageReceived(uint /** clientID **/, QString &messageID, QByteArray &message) { emit doMessageReceived(messageID, message); } diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp index 1893e8231..cc6c503e2 100644 --- a/src/blackmisc/coordinategeodetic.cpp +++ b/src/blackmisc/coordinategeodetic.cpp @@ -13,10 +13,10 @@ namespace Geo /* * String for converter */ -QString CCoordinateGeodetic::stringForConverter() const +QString CCoordinateGeodetic::stringForConverter(bool i18n) const { QString s = "Geodetic: {%1, %2, %3}"; - return s.arg(this->m_latitude.unitValueRoundedWithUnit(6)).arg(this->m_longitude.unitValueRoundedWithUnit(6)).arg(this->m_height.unitValueRoundedWithUnit()); + return s.arg(this->m_latitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_longitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_height.unitValueRoundedWithUnit(i18n)); } /* diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index e065e8792..5f11bb2b3 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -49,9 +49,10 @@ protected: /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; /*! * \brief Stream to DBus diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index 01bef4277..a07368c82 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -14,7 +14,7 @@ CDebug::CDebug() } -void CDebug::create(const char *logPath, bool logInFile, bool eraseLastLog) +void CDebug::create(const char * /** logPath **/, bool logInFile, bool eraseLastLog) { if (!m_isInitialized) { diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index 843d024b2..3647bbf2c 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -225,7 +225,7 @@ namespace BlackMisc if (m_file->handle() == -1) { if ( !m_file->open(QIODevice::WriteOnly) ) - printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1().constData(), strerror (errno)); + printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1().constData(), strerror(errno)); } if (m_file->handle() != -1) diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 2bd2be4b3..17412a656 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -149,7 +149,7 @@ template void CMatrixBase QString CMatrixBase::stringForConverter() const +template QString CMatrixBase::stringForConverter(bool /** i18n **/) const { QString s = "{"; for (int r = 0; r < Rows; r++) diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index f6d95bf41..1463e4566 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -46,9 +46,10 @@ protected: /*! * \brief Conversion to string + * \param i18n * \return */ - QString stringForConverter() const; + QString stringForConverter(bool i18n = false) const; /*! * \brief Stream to DBus diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index 241e88fb6..fb2a0d8c2 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -16,7 +16,7 @@ namespace Math /* * Convert to string */ -template QString CVector3DBase::stringForConverter() const +template QString CVector3DBase::stringForConverter(bool /** i18n **/) const { QString s = ("{%1, %2, %3}"); s = s.arg(QString::number(this->m_i, 'f')). diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index b772bbdeb..90a9ed036 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -104,9 +104,10 @@ protected: /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; /*! * \brief Unmarshall from Dbus diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 3e612bd3e..3ebb7c286 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -162,9 +162,9 @@ double CMeasurementUnit::conversionToUnit(double value, const CMeasurementUnit & * Value to QString with unit, e.g. "5.00m" * @return */ -QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits) const +QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits, bool i18n) const { - return this->toQStringRounded(value, digits).append(this->getUnitName()); + return this->toQStringRounded(value, digits).append(this->getUnitName(i18n)); } /* diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 4883035a6..61f6d8d77 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -8,6 +8,7 @@ #include "blackmisc/basestreamstringifier.h" #include "blackmisc/debug.h" +#include #include #include #include @@ -43,9 +44,10 @@ private: protected: /*! * \brief Name as stringification + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString stringForConverter(bool /* i18n */ = false) const { return this->m_name; } @@ -345,16 +347,17 @@ protected: */ virtual QString stringForStreaming() const { - return this->m_name; + return this->getName(false); } /*! - * \brief String for converter is unit + * \brief Name as stringification + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString stringForConverter(bool i18n = false) const { - return this->m_unitName; + return this->getUnitName(i18n); } /*! @@ -450,20 +453,22 @@ public: /*! * \brief Name such as "meter" + * \param i18n * \return */ - QString getName() const + QString getName(bool i18n=false) const { - return this->m_name; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; } /*! * \brief Unit name such as "m" + * \param i18n * \return */ - QString getUnitName() const + QString getUnitName(bool i18n = false) const { - return this->m_unitName; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_unitName.toStdString().c_str()) : this->m_unitName; } /*! @@ -518,9 +523,10 @@ public: * \brief Value rounded with unit, e.g. "5.00m", "30kHz" * \param value * \param digits + * \param i18n * \return */ - virtual QString valueRoundedWithUnit(double value, int digits = -1) const; + virtual QString valueRoundedWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Threshold for rounding diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 611a928ba..72eb72eeb 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -339,9 +339,9 @@ template QString CPhysicalQuantity::unitValueToQStr /* * Rounded with unit */ -template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits) const +template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits, bool i18n) const { - return this->m_unit.valueRoundedWithUnit(this->m_unitValueD, digits); + return this->m_unit.valueRoundedWithUnit(this->m_unitValueD, digits, i18n); } /* @@ -356,20 +356,19 @@ template QString CPhysicalQuantity::convertedSiValu /* * SI base unit value with unit */ -template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const +template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits, bool i18n) const { - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->convertedSiValueToQStringRounded(digits).append(this->m_conversionSiUnit.getUnitName()); + return this->m_conversionSiUnit.valueRoundedWithUnit(this->m_convertedSiUnitValueD, digits, i18n); } /* * Value rounded in unit */ -template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits) const +template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const { - if (unit == this->m_unit) return this->unitValueRoundedWithUnit(digits); - if (unit == this->m_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits); - return unit.valueRoundedWithUnit(this->value(unit), digits); + if (unit == this->m_unit) return this->unitValueRoundedWithUnit(digits, i18n); + if (unit == this->m_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits, i18n); + return unit.valueRoundedWithUnit(this->value(unit), digits, i18n); } /* diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 4fb3eb4bb..8f1551289 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -71,12 +71,13 @@ protected: CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit); /*! - * \brief String for converter and streaming + * \brief Name as stringification + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString stringForConverter(bool i18n = false) const { - return this->unitValueRoundedWithUnit(-1); + return this->unitValueRoundedWithUnit(i18n); } /*! @@ -180,9 +181,10 @@ public: * \brief Value to QString with unit, e.g. "5.00m" * \param unit * \param digits + * \param i18n * \return */ - QString valueRoundedWithUnit(const MU &unit, int digits = -1) const; + QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; /*! * \brief Value as int @@ -205,9 +207,10 @@ public: /*! * \brief Value to QString with unit, e.g. "5.00m" * \param digits + * \param i18n * \return */ - QString unitValueRoundedWithUnit(int digits = -1) const; + QString unitValueRoundedWithUnit(int digits = -1, bool i18n = false) const; /*! * \brief Rounded value by n digits @@ -259,9 +262,10 @@ public: /*! * \brief SI Base unit value rounded * \param digits + * \param i18n * \return */ - QString convertedSiValueRoundedWithUnit(int digits = -1) const; + QString convertedSiValueRoundedWithUnit(int digits = -1, bool i18n = false) const; /*! * \brief Add to the unit value. diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 3d1ec1605..1e3377403 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -10,12 +10,15 @@ #include #include #include +#include // // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations // +// I18N: http://qt-project.org/doc/qt-4.8/linguist-programmers.html#translating-text-that-is-outside-of-a-qobject-subclass +// namespace BlackMisc { namespace PhysicalQuantities @@ -26,6 +29,7 @@ namespace PhysicalQuantities */ class CLengthUnit : public CMeasurementUnit { + private: /*! * \brief Constructor length unit @@ -43,6 +47,7 @@ private: { // void } + public: /*! * Default constructor, we do not want this, but required for Qt Metasystem @@ -66,16 +71,19 @@ public: { static CLengthUnit m("meter", "m", true, true); return m; + QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"); } + /*! * \brief Nautical miles NM * \return */ static const CLengthUnit &NM() { - static CLengthUnit NM("nautical miles", "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); + static CLengthUnit NM("nautical mile", "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); return NM; + QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"); } /*! @@ -86,8 +94,10 @@ public: { static CLengthUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); return ft; + QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"); } + /*! * \brief Kilometer km * \return @@ -96,6 +106,7 @@ public: { static CLengthUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); return km; + QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"); } /*! @@ -106,6 +117,7 @@ public: { static CLengthUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); return cm; + QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"); } /*! @@ -116,6 +128,7 @@ public: { static CLengthUnit mi("mile", "mi", false, false, 1609.344, CMeasurementPrefix::None(), 3); return mi; + QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"); } /*! @@ -126,6 +139,7 @@ public: { static CLengthUnit mi("mile(statute)", "mi(statute)", false, false, 1609.3472, CMeasurementPrefix::None(), 3); return mi; + QT_TRANSLATE_NOOP("CMeasurementUnit", "mile(statute)"); } /*! @@ -238,6 +252,7 @@ public: { static CAngleUnit rad("radian", "rad", true); return rad; + QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"); } /*! @@ -248,6 +263,8 @@ public: { static CAngleUnit deg("degree", "deg", false, M_PI / 180); return deg; + QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"); } /*! @@ -258,6 +275,7 @@ public: { static CAngleUnit deg("segadecimal degree", "segd", false, M_PI / 180, CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; + QT_TRANSLATE_NOOP("CMeasurementUnit", "segadecimal degree"); } /*! @@ -614,8 +632,9 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar("bar", "bar", false, 1E2); + static CPressureUnit bar("millibar", "bar", false, 1E2); return bar; + QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"); } /*! @@ -624,8 +643,9 @@ public: */ static const CPressureUnit &inHg() { - static CPressureUnit inhg("Inch of mercury 0°C", "inHg", false, 3386.389); + static CPressureUnit inhg("inch of mercury 0C", "inHg", false, 3386.389); return inhg; + QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"); } /*! @@ -634,8 +654,9 @@ public: */ static const CPressureUnit &inHgFL() { - static CPressureUnit inhg("Inch of mercury ", "inHg", false, 3386.5307486631); + static CPressureUnit inhg("inch of mercury", "inHg", false, 3386.5307486631); return inhg; + QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"); } /*! @@ -750,6 +771,7 @@ public: { static CTemperatureUnit K("Kelvin", "K", true, true); return K; + QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"); } /*! @@ -758,8 +780,10 @@ public: */ static const CTemperatureUnit &C() { - static CTemperatureUnit C("centigrade", "°C", false, false, 1.0, 273.15); + static CTemperatureUnit C("centigrade", "C", false, false, 1.0, 273.15); return C; + QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "C"); } /*! @@ -768,8 +792,10 @@ public: */ static const CTemperatureUnit &F() { - static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0 / 9.0, 459.67); + static CTemperatureUnit F("Fahrenheit", "F", false, false, 5.0 / 9.0, 459.67); return F; + QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "F"); } /*! @@ -1098,7 +1124,7 @@ public: /*! * Default constructor, we do not want this, but required for Qt Metasystem */ - CAccelerationUnit() : CMeasurementUnit("meter/second²", "m/s²", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} + CAccelerationUnit() : CMeasurementUnit("meter/second²", "m/s^2", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} /*! * Constructor, allows to implement methods in base class @@ -1112,8 +1138,10 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2("meter/second²", "m/s²", true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2("meter/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1); return ms2; + QT_TRANSLATE_NOOP("CMeasurementUnit", "meter/second^2"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"); } /*! @@ -1122,8 +1150,10 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2("feet/seconds²", "ft/s²", true, false, 3.28084, CMeasurementPrefix::m(), 0); + static CAccelerationUnit fts2("feet/seconds²", "ft/s^2", true, false, 3.28084, CMeasurementPrefix::m(), 0); return fts2; + QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"); } /*! @@ -1166,6 +1196,7 @@ protected: }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) + } // namespace } // namespace #endif // guard diff --git a/src/blackmisc/translations/blackmisc_i18n_de.qm b/src/blackmisc/translations/blackmisc_i18n_de.qm new file mode 100644 index 0000000000000000000000000000000000000000..cef1adb5b47de2cf7ee5e9737d672a3dcb2d154c GIT binary patch literal 1426 zcma)6J7^S96g{(_*>NQyEKxLuFd~8{lkSD&#nNuDQ$YkbK)x6>m%QJ-s$2~ z?FYYKEB@L;k9*tmXYbH|9=x^qh`1+`oA0yylEXZz8W&J$O0~fEP_-@$KlFqxoZyTj z17#z!){CqqM-DS*18sN^aOedjf*4t>8EsEEZ6SkXiV++q+&}|53n^g1gio3fevinc zJlXP$hDatF#<{MFfMA=efaYzYutgxeWQq*tV?eecTFH^xhUz$8WxOX+^o_7qAy!ew z43%}bc9^ulEXHG!fu;~a*%zkkG-k(>k5|{ZVqC82x+yg-qRDcUS=WUaqBeO@+8JY* zqC%5h)o}tXzAsR%q_6Z%Qb{^yTX&nfEj%;yF6)()(JJ92DJ;1EXwkNgwA?K^q!HJj zN8V0Pqlh|X_YXsUi&I8>n7`W9tKeXleVpNq)e2x(Y(ljhRUE2^Q*}oR?4!dDsHBL(9 q4V8wIEM;eR_FLWSE-*&{5rGvGlzh?RB{!u_6=@ghCVyTTMOg!iGdP$4 literal 0 HcmV?d00001 diff --git a/src/blackmisc/translations/blackmisc_i18n_de.ts b/src/blackmisc/translations/blackmisc_i18n_de.ts new file mode 100644 index 000000000..b72c46b01 --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_de.ts @@ -0,0 +1,118 @@ + + + + + CMeasurementUnit + + + meter + Meter + + + + nautical mile + Nautische Meile + + + + foot + Fuß + + + + kilometer + Kilometer + + + + centimeter + Zentimeter + + + + mile + Meile + + + + mile(statute) + Statute Meile + + + + radian + Bogenmaß + + + + degree + Grad + + + + deg + ° + + + + segadecimal degree + Segadezimal + + + + millibar + + + + + + inch of mercury 0C + Inch Hg bei 0°C + + + + Kelvin + + + + + centigrade + Grad Celcsius + + + + C + °C + + + + Fahrenheit + Fahrenheit + + + + F + °F + + + + meter/second^2 + Meter/Sekunde² + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + Fuß/Sekunde^2 + + + diff --git a/src/blackmisc/translations/blackmisc_i18n_en.qm b/src/blackmisc/translations/blackmisc_i18n_en.qm new file mode 100644 index 0000000000000000000000000000000000000000..0d750e7d9f9663003145a36259d0971a85cd5c65 GIT binary patch literal 302 zcmcE7ks@*G{hX<16=n7(EZlq7iGhJZ1Bji07zEsaSc`!nYdeq*VJOHH0@9n=u7l~i zOd#heGmv0m*udb-0c0?+0WqU9JCGD`_DxMJE-gyUP0cF_&C4udgsF5xsC2`vl8Iph yTpe>tYC3L}TnuRpB@Fru#SEL^I@r=m^o!$+aBJdV$VJn_nu}XU2hc-IjEn#P6g`mu literal 0 HcmV?d00001 diff --git a/src/blackmisc/translations/blackmisc_i18n_en.ts b/src/blackmisc/translations/blackmisc_i18n_en.ts new file mode 100644 index 000000000..902c5cd7e --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_en.ts @@ -0,0 +1,118 @@ + + + + + CMeasurementUnit + + + meter + + + + + nautical mile + + + + + foot + + + + + kilometer + + + + + centimeter + + + + + mile + + + + + mile(statute) + + + + + radian + + + + + degree + + + + + deg + ° + + + + segadecimal degree + + + + + millibar + + + + + + inch of mercury 0C + + + + + Kelvin + + + + + centigrade + + + + + C + °C + + + + Fahrenheit + + + + + F + °F + + + + meter/second^2 + + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + + + + diff --git a/src/blackmisc/translations/blackmisc_i18n_fr.qm b/src/blackmisc/translations/blackmisc_i18n_fr.qm new file mode 100644 index 0000000000000000000000000000000000000000..836d44dd289b965cb71203dfc14153e55a270fbe GIT binary patch literal 796 zcmah{Jxjw-6g^Ga7z2V75fO(v34#=yoeXr-NjH&(2x1rU z16&F^>f~N07j^cuV1i&`!hPo@Ip?1H?#)Wind!fu96rv^-PBL7UsnOt875g%d>md*YL7_lCHowhtZvMbXX%m*m}PFC*T9e!KL+=MCdr|K#^| z$>mt(nCvoG6W& z)e42*5;D$Cp`e=xR7W(knFbshG->vhC^RZUA+kj}8VGo&RTUdSkW-IAL5wOQT%<0I zxEgIQXS(u?WEP45k#ve|le_UocBMTkYC$UEq zs4&a0?zGwo-|EEDw%m#*-JHHovq8gQSfioX%;ItHCZ{e(qG>t8mL5~(4QZdhp`sSP E0cXpvRR910 literal 0 HcmV?d00001 diff --git a/src/blackmisc/translations/blackmisc_i18n_fr.ts b/src/blackmisc/translations/blackmisc_i18n_fr.ts new file mode 100644 index 000000000..6cee692ea --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_fr.ts @@ -0,0 +1,118 @@ + + + + + CMeasurementUnit + + + meter + mètre + + + + nautical mile + nautique mile + + + + foot + foot + + + + kilometer + kilomètre + + + + centimeter + + + + + mile + + + + + mile(statute) + + + + + radian + + + + + degree + degré + + + + deg + ° + + + + segadecimal degree + segadecimal + + + + millibar + + + + + + inch of mercury 0C + + + + + Kelvin + + + + + centigrade + + + + + C + °C + + + + Fahrenheit + Fahrenheit + + + + F + °F + + + + meter/second^2 + + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + + + + diff --git a/src/blackx/CMakeLists.txt b/src/blackx/CMakeLists.txt deleted file mode 100644 index e69de29bb..000000000 From a53ea0c5fdb01cc77b1e2cc06da275ffb2732e8d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 28 Jul 2013 03:20:04 +0200 Subject: [PATCH 07/36] DBus: track, heading, transponder. Added I18N for track/heading, added further I18N keys. Of course not all I18N strings are translated yet. --- .../BlackMiscTest.Testservice.xml | 8 + samples/blackmiscquantities_dbus/main.cpp | 19 ++- .../blackmiscquantities_dbus/testservice.cpp | 16 ++ .../blackmiscquantities_dbus/testservice.h | 12 ++ src/blackmisc/avaltitude.cpp | 2 +- src/blackmisc/avaltitude.h | 3 +- src/blackmisc/avheading.cpp | 13 +- src/blackmisc/avheading.h | 29 +++- src/blackmisc/aviocomsystem.h | 8 + src/blackmisc/aviomodulator.h | 1 + src/blackmisc/aviotransponder.cpp | 31 ++++ src/blackmisc/aviotransponder.h | 22 +++ src/blackmisc/avtrack.cpp | 13 +- src/blackmisc/avtrack.h | 30 +++- src/blackmisc/basestreamstringifier.h | 2 +- src/blackmisc/blackmisc.pro | 3 +- src/blackmisc/blackmiscfreefunctions.cpp | 3 + src/blackmisc/blackmiscfreefunctions.h | 1 + src/blackmisc/com_handler.cpp | 2 +- src/blackmisc/pqbase.cpp | 2 +- src/blackmisc/pqbase.h | 3 +- src/blackmisc/pqphysicalquantity.h | 2 +- src/blackmisc/pqunits.cpp | 7 +- src/blackmisc/pqunits.h | 28 +++- src/blackmisc/readme.txt | 1 + .../translations/blackmisc_i18n_de.qm | Bin 1426 -> 2193 bytes .../translations/blackmisc_i18n_de.ts | 148 +++++++++++++++--- .../translations/blackmisc_i18n_en.ts | 146 ++++++++++++++--- .../translations/blackmisc_i18n_fr.ts | 146 ++++++++++++++--- 29 files changed, 620 insertions(+), 81 deletions(-) create mode 100644 src/blackmisc/readme.txt diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml index d79b1c4e7..fc81aaae8 100644 --- a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -34,5 +34,13 @@ + + + + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index e389d33dc..446f24d4e 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -75,7 +75,10 @@ int main(int argc, char *argv[]) } else { qDebug() << "Already registered, assuming 2nd pid: " << TestserviceTool::getPid(); BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection, &a); - double speedValue = 200.0; + + CSpeed speed(200, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); + CAltitude al(1000, true, CLengthUnit::ft()); + while (true) { QDBusMessage m = QDBusMessage::createSignal( Testservice::ServicePath, Testservice::ServiceName, @@ -103,7 +106,6 @@ int main(int argc, char *argv[]) qDebug() << "Send list via interface" << list; // PQs - CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); testserviceInterface.receiveSpeed(speed); qDebug() << "Send speed via interface" << speed; @@ -111,17 +113,28 @@ int main(int argc, char *argv[]) testserviceInterface.receiveSpeed(speed); qDebug() << "Send speed via interface" << speed; TestserviceTool::sleep(2500); + speed.switchUnit(CSpeedUnit::km_h()); + speed.addUnitValue(1.0); // Aviation CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom()); testserviceInterface.receiveComUnit(comSystem); qDebug() << "Send COM via interface" << comSystem; - CAltitude al(1000, true, CLengthUnit::ft()); QDBusVariant qv(QVariant::fromValue(al)); testserviceInterface.receiveVariant(qv); testserviceInterface.receiveAltitude(al); qDebug() << "Send altitude via interface" << al; + al.addUnitValue(1); + + CTransponder transponder("transponder", 7000, CTransponder::ModeC); + testserviceInterface.receiveTransponder(transponder); + qDebug() << "Send transponder via interface" << transponder; + + CTrack track(123.45, true, CAngleUnit::deg()); + testserviceInterface.receiveTrack(track); + qDebug() << "Send track via interface" << track; + TestserviceTool::sleep(2500); // Math diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp index 1c00dc048..52715c063 100644 --- a/samples/blackmiscquantities_dbus/testservice.cpp +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -85,4 +85,20 @@ void Testservice::receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic & qDebug() << "Pid:" << TestserviceTool::getPid() << "Received geo data:" << geo; } +/* + * Receive transponder + */ +void Testservice::receiveTransponder(const BlackMisc::Aviation::CTransponder &transponder) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received transponder:" << transponder; +} + +/* + * Receive track + */ +void Testservice::receiveTrack(const BlackMisc::Aviation::CTrack &track) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received track:" << track; +} + } // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h index c03bc02b1..c31d5364b 100644 --- a/samples/blackmiscquantities_dbus/testservice.h +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -94,6 +94,18 @@ public slots: */ void receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic &geo); + /*! + * \brief Receive transponder + * \param transponder + */ + void receiveTransponder(const BlackMisc::Aviation::CTransponder &transponder); + + /*! + * \brief Receive track + * \param track + */ + void receiveTrack(const BlackMisc::Aviation::CTrack &track); + public: static const QString ServiceName; static const QString ServicePath; diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index eef440e57..db4a7a9f5 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -16,7 +16,7 @@ namespace Aviation /* * Own implementation for streaming */ -QString CAltitude::stringForConverter() const +QString CAltitude::stringForConverter(bool /** i18n **/) const { QString s = CLength::stringForConverter(); return s.append(this->m_msl ? " MSL" : " AGL"); diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 96316e3d5..4dec1c96f 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -24,9 +24,10 @@ private: protected: /*! * \brief Specific stream operation for Altitude + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n) const; /*! * \brief Stream to DBus << diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index b66f56eeb..985bf73ae 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -16,9 +16,9 @@ namespace Aviation /* * Own implementation for streaming */ -QString CHeading::stringForConverter() const +QString CHeading::stringForConverter(bool i18n) const { - QString s = CAngle::stringForConverter(); + QString s = CAngle::stringForConverter(i18n); return s.append(this->m_magnetic ? " magnetic" : " true"); } @@ -50,5 +50,14 @@ bool CHeading::operator !=(const CHeading &otherHeading) return !((*this) == otherHeading); } +/*! + * \brief Register metadata of unit and quantity + */ +void CHeading::registerMetadata() +{ + qRegisterMetaType(typeid(CHeading).name()); + qDBusRegisterMetaType(); +} + } // namespace } // namespace diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 778c44794..1a3897364 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -23,9 +23,28 @@ private: protected: /*! * \brief Specific stream operation for heading + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + CAngle::marshallToDbus(argument); + argument << this->m_magnetic; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + CAngle::unmarshallFromDbus(argument); + argument >> this->m_magnetic; + } public: /*! @@ -108,8 +127,16 @@ public: CAngle::switchUnit(newUnit); return (*this); } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::Aviation::CHeading) + #endif // guard diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 923746f13..9faac94ac 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -199,6 +199,7 @@ public: if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default return s; } + /*! * \brief COM1 unit * \param activeFrequencyMHz @@ -208,6 +209,7 @@ public: static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM1 unit * \param activeFrequency @@ -237,6 +239,7 @@ public: static bool tryGetCom1Unit(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } + /*! * \brief COM2 unit * \param activeFrequencyMHz @@ -246,6 +249,7 @@ public: static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM2 unit * \param activeFrequency @@ -255,6 +259,7 @@ public: static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get COM unit * \param comSystem @@ -265,6 +270,7 @@ public: static bool tryGetCom2System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit * \param comSystem @@ -285,6 +291,7 @@ public: static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom3(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM3 unit * \param activeFrequency @@ -305,6 +312,7 @@ public: static bool tryGetCom3System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit * \param comSystem diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 249b7e9bd..00ae1e42e 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -272,6 +272,7 @@ public: { return this->m_frequencyActive == CModulator::FrequencyNotSet(); } + /*! * \brief Toggle active and standby frequencies */ diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index e471615c8..d8ca230ee 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -99,5 +99,36 @@ QString CTransponder::getTransponderCodeFormatted() const return f.right(4); } +/*! + * \brief Stream to DBus << + * \param argument + */ +void CTransponder::marshallToDbus(QDBusArgument &argument) const { + CAvionicsBase::marshallToDbus(argument); + argument << this->m_transponderCode; + argument << static_cast(this->m_transponderMode); +} + +/*! + * \brief Stream from DBus >> + * \param argument + */ +void CTransponder::unmarshallFromDbus(const QDBusArgument &argument) { + CAvionicsBase::unmarshallFromDbus(argument); + qint32 tm; + argument >> this->m_transponderCode; + argument >> tm; + this->m_transponderMode = static_cast(tm); +} + +/*! + * \brief Register metadata of unit and quantity + */ +void CTransponder::registerMetadata() +{ + qRegisterMetaType(typeid(CTransponder).name()); + qDBusRegisterMetaType(); +} + } // namespace } // namespace diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 50961eab7..477441f53 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -31,6 +31,7 @@ public: ModeC = 12, ModeS = 20 }; + private: qint32 m_transponderCode; //m_transponderCode = -1; // will cause assert / exception this->validate(validate); } + protected: /*! * \brief Are the set values valid / in range? @@ -95,6 +97,18 @@ protected: */ virtual QString stringForConverter(bool i18n = false) const; + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); + public: /*! * Default constructor @@ -262,6 +276,7 @@ public: if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default return s; } + /*! * Try to get a Transponder unit with given name and code. Returns true in case an object * has been sucessfully created, otherwise returns a default object. @@ -278,6 +293,7 @@ public: if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default return s; } + /*! * \brief Transponder unit * \param transponderCode @@ -288,6 +304,7 @@ public: { return CTransponder("Transponder", transponderCode, mode); } + /*! * \brief Try to get Transponder unit * \param transponder @@ -312,6 +329,11 @@ public: return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); } + /*! + * \brief Register metadata of unit and quantity + */ + static void registerMetadata(); + }; } // namespace diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index c70aab144..4f9ed363f 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -16,9 +16,9 @@ namespace Aviation /* * Own implementation for streaming */ -QString CTrack::stringForConverter() const +QString CTrack::stringForConverter(bool i18n) const { - QString s = CAngle::stringForConverter(); + QString s = CAngle::stringForConverter(i18n); return s.append(this->m_magnetic ? " magnetic" : " true"); } @@ -50,5 +50,14 @@ bool CTrack::operator !=(const CTrack &otherTrack) return !((*this) == otherTrack); } +/*! + * \brief Register metadata of unit and quantity + */ +void CTrack::registerMetadata() +{ + qRegisterMetaType(typeid(CTrack).name()); + qDBusRegisterMetaType(); +} + } // namespace } // namespace diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index f81725634..e93cc280f 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -27,7 +27,25 @@ protected: * \brief Specific stream operation for Track * \return */ - virtual QString stringForConverter() const; + virtual QString stringForConverter(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const { + CAngle::marshallToDbus(argument); + argument << this->m_magnetic; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) { + CAngle::unmarshallFromDbus(argument); + argument >> this->m_magnetic; + } public: /*! @@ -85,7 +103,10 @@ public: */ bool isMagneticTrack() const { return this->m_magnetic; + QT_TRANSLATE_NOOP("Aviation", "magnetic"); + QT_TRANSLATE_NOOP("Aviation", "true"); } + /*! * \brief True Track? * \return @@ -93,10 +114,17 @@ public: bool isTrueTrack() const { return !this->m_magnetic; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CTrack) + #endif // BLACKMISC_AVTRACK_H diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 5e69e1af8..14e6c8c06 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -153,7 +153,7 @@ protected: } /*! - * \brief String for converter + * \brief String for QString conversion * \param i18n * \return */ diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 796b2071b..22a1e863c 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -23,4 +23,5 @@ TRANSLATIONS += translations/blackmisc_i18n_de.ts \ HEADERS += *.h SOURCES += *.cpp DESTDIR = ../../lib -OTHER_FILES += $$TRANSLATIONS +OTHER_FILES += $$TRANSLATIONS \ + readme.txt diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 77028ea2d..9d21ea7a4 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -33,6 +33,9 @@ void BlackMisc::Aviation::registerMetadata() CAdfSystem::registerMetadata(); CAltitude::registerMetadata(); CAviationVerticalPositions::registerMetadata(); + CTransponder::registerMetadata(); + CHeading::registerMetadata(); + CTrack::registerMetadata(); } /* diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 9cdf63641..4dce58ddd 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -13,6 +13,7 @@ /*! * \brief Workaround, to call initResource from namespace */ +// cannot be declare within namespace, see docu inline void initBlackMiscResources() { Q_INIT_RESOURCE(blackmisc); } /*! diff --git a/src/blackmisc/com_handler.cpp b/src/blackmisc/com_handler.cpp index ec87385d7..0a95e7e43 100644 --- a/src/blackmisc/com_handler.cpp +++ b/src/blackmisc/com_handler.cpp @@ -100,8 +100,8 @@ namespace BlackMisc ///////////////////////////////////////////////// data.resize(message_length); + // creates warning when compiled as RELEASE qint32 bytes = stream.readRawData(data.data(), message_length); - Q_ASSERT (bytes == message_length); Q_ASSERT (data.size() == message_length); diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 3ebb7c286..774e268df 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -179,7 +179,7 @@ double CMeasurementUnit::valueRounded(double value, int digits) const /* * Rounded to QString */ -QString CMeasurementUnit::toQStringRounded(double value, int digits) const +QString CMeasurementUnit::toQStringRounded(double value, int digits, bool /** i18n **/) const { if (digits < 0) digits = this->m_displayDigits; double v = CMath::round(value, digits); diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 61f6d8d77..e3aefaf9c 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -507,9 +507,10 @@ public: * specialized formatting * \param value * \param digits + * \param i18n * \return */ - virtual QString toQStringRounded(double value, int digits = -1) const; + virtual QString toQStringRounded(double value, int digits = -1, bool i18n = false) const; /*! * \brief Rounded value diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 8f1551289..14d72e494 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -77,7 +77,7 @@ protected: */ virtual QString stringForConverter(bool i18n = false) const { - return this->unitValueRoundedWithUnit(i18n); + return this->unitValueRoundedWithUnit(-1, i18n); } /*! diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index cd143912e..90962792e 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -66,7 +66,7 @@ double CAngleUnit::conversionSexagesimalToSi(const CMeasurementUnit &, double va /* * Rounded to QString */ -QString CAngleUnit::toQStringRounded(double value, int digits) const +QString CAngleUnit::toQStringRounded(double value, int digits, bool i18n) const { QString s; if ((*this) == CAngleUnit::sexagesimalDeg()) @@ -76,8 +76,9 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const double mi = floor((value - de) * 100.0); double se = floor((value - de - mi / 100.0) * 1000000) / 100.0; QString ses = QLocale::system().toString(se, 'f', 2); - s = QString::number(de).append(" ").append(QString::number(mi)) - .append("'").append(ses).append("\""); + s = QString::number(de); + s = s.append(i18n ? CAngleUnit::deg().getUnitName(true) : " "); + s = s.append(QString::number(mi)).append("'").append(ses).append("\""); } else { diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 1e3377403..e70564413 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -240,9 +240,10 @@ public: * \brief Special conversion to QString for sexagesimal degrees. * \param value * \param digits + * \param i18n * \return */ - virtual QString toQStringRounded(double value, int digits) const; + virtual QString toQStringRounded(double value, int digits = -1, bool i18n = false) const; /*! * \brief Radians @@ -477,6 +478,7 @@ public: { static CMassUnit kg("kilogram", "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); return kg; + QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"); } /*! @@ -487,6 +489,7 @@ public: { static CMassUnit g("gram", "g", true, false, 1.0 / 1000.0, CMeasurementPrefix::One(), 0); return g; + QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"); } /*! @@ -497,6 +500,7 @@ public: { static CMassUnit t("tonne", "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); return t; + QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"); } /*! @@ -507,6 +511,7 @@ public: { static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); return lbs; + QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"); } /*! @@ -594,6 +599,7 @@ public: { static CPressureUnit Pa("pascal", "Pa", true); return Pa; + QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"); } /*! @@ -604,6 +610,7 @@ public: { static CPressureUnit hPa("hectopascal", "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); return hPa; + QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"); } /*! @@ -614,6 +621,7 @@ public: { static CPressureUnit psi("pounds per square inch", "psi", false, 6894.8, CMeasurementPrefix::One(), 2); return psi; + QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"); } /*! @@ -624,6 +632,7 @@ public: { static CPressureUnit bar("bar", "bar", false, 1E5); return bar; + QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"); } /*! @@ -879,6 +888,7 @@ public: { static CSpeedUnit ms("meters/second", "m/s", true, false); return ms; + QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"); } /*! @@ -889,6 +899,7 @@ public: { static CSpeedUnit kts("knot", "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); return kts; + QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"); } /*! @@ -899,6 +910,7 @@ public: { static CSpeedUnit NMh("nautical miles/hour", "NM/h", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); return NMh; + QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"); } /*! @@ -907,8 +919,9 @@ public: */ static const CSpeedUnit &ft_s() { - static CSpeedUnit fts("feet/seconds", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CSpeedUnit fts("feet/second", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); return fts; + QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"); } /*! @@ -919,6 +932,7 @@ public: { static CSpeedUnit ftmin("feet/minute", "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); return ftmin; + QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"); } /*! @@ -929,6 +943,7 @@ public: { static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); return kmh; + QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"); } /*! @@ -1015,6 +1030,7 @@ public: { static CTimeUnit s("second", "s", true, true, 1, CMeasurementPrefix::None(), 1); return s; + QT_TRANSLATE_NOOP("CMeasurementUnit", "second"); } /*! @@ -1025,6 +1041,7 @@ public: { static CTimeUnit ms("millisecond", "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); return ms; + QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"); } /*! @@ -1035,6 +1052,7 @@ public: { static CTimeUnit h("hour", "h", false, false, 3600, CMeasurementPrefix::None(), 1); return h; + QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"); } /*! @@ -1045,6 +1063,7 @@ public: { static CTimeUnit min("minute", "min", false, false, 60, CMeasurementPrefix::None(), 2); return min; + QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"); } /*! @@ -1055,6 +1074,7 @@ public: { static CTimeUnit day("day", "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); return day; + QT_TRANSLATE_NOOP("CMeasurementUnit", "day"); } /*! @@ -1138,9 +1158,9 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2("meter/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2("meters/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1); return ms2; - QT_TRANSLATE_NOOP("CMeasurementUnit", "meter/second^2"); + QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"); QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"); } diff --git a/src/blackmisc/readme.txt b/src/blackmisc/readme.txt new file mode 100644 index 000000000..9f0846c5e --- /dev/null +++ b/src/blackmisc/readme.txt @@ -0,0 +1 @@ +I18N: lupdate -noobsolete blackmisc.pro diff --git a/src/blackmisc/translations/blackmisc_i18n_de.qm b/src/blackmisc/translations/blackmisc_i18n_de.qm index cef1adb5b47de2cf7ee5e9737d672a3dcb2d154c..44c59b835b22b511472bbee8433eb92f06d3c50d 100644 GIT binary patch delta 809 zcmZuuOK1~O6g~6F%#hT!O0==9C_-H*8tF>v!q`edi=Y?;L4}aKrq5(%B$@bGXjUS{ zjqOlGl&se z^Jv4gY2eH_pxhwVh;KPEsGQm!=eJa_ zfFusHHHUW(qLCUK6~ar}(y4eNpePA{pW3B7@lU8zJ#9F~q4VIyC(ZJizeJ)iCm1AFx9u0%L^kv#@~Bv4p2QOuUbqHOAIYHPVGqq!!( TreE9K&M{lb8BHaBFmmKKYsk7; delta 228 zcmbOzIEj0LNc{o^1_oy!1_3u9)?#4D+RnhhsLa52Ed@xQVPJPqWnf^gVkpQIVqjo8 z%20gj5Rm@PoV)`>w=!o>JPMTm$+r5%R-k%cw(B5ujKA5f93BDb26ivWO+a~V_V)F4 z3=Axu9A2WEf%*(M4(NViU{GfW;abP>6)4fd^+Os+Gfd}Z4Vwg{AMkZf~D1w8{ExYHWPDsU@jJlVjKxO|E6{ Jp6tjG00194JBk1R diff --git a/src/blackmisc/translations/blackmisc_i18n_de.ts b/src/blackmisc/translations/blackmisc_i18n_de.ts index b72c46b01..b1ddd7165 100644 --- a/src/blackmisc/translations/blackmisc_i18n_de.ts +++ b/src/blackmisc/translations/blackmisc_i18n_de.ts @@ -1,6 +1,21 @@ + + Aviation + + + magnetic + Magnetischer Kurs + missweisend + + + + true + Rechtweisend Kurs (TH) + rechtweisend + + CMeasurementUnit @@ -39,80 +54,175 @@ Statute Meile - + radian Bogenmaß - + degree Grad - + deg ° - + segadecimal degree Segadezimal - + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + millibar - - + + inch of mercury 0C Inch Hg bei 0°C - + Kelvin - + centigrade Grad Celcsius - + C °C - + Fahrenheit Fahrenheit - + F °F - - meter/second^2 + + meters/second + Meter/Sekunde + + + + knot + Knoten + + + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + Fuß/Minute + + + + kilometers/hour + Kilometer/Stunde + + + + second + Sekunde + + + + millisecond + Millisekunde + + + + hour + Stunde + + + + minute + Minute + + + + day + Tag + + + + meters/second^2 Meter/Sekunde² - + m/s^2 - m/s² + m/s² - + ft/s^2 ft/s² - + feet/second^2 - Fuß/Sekunde^2 + Fuß/Sekunde² diff --git a/src/blackmisc/translations/blackmisc_i18n_en.ts b/src/blackmisc/translations/blackmisc_i18n_en.ts index 902c5cd7e..99ff1dfef 100644 --- a/src/blackmisc/translations/blackmisc_i18n_en.ts +++ b/src/blackmisc/translations/blackmisc_i18n_en.ts @@ -1,6 +1,19 @@ + + Aviation + + + magnetic + + + + + true + + + CMeasurementUnit @@ -39,78 +52,173 @@ - + radian - + degree - + deg ° - + segadecimal degree - + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + millibar - - + + inch of mercury 0C - + Kelvin - + centigrade - + C °C - + Fahrenheit - + F °F - - meter/second^2 + + meters/second - - m/s^2 - m/s² + + knot + - + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + + + + + kilometers/hour + + + + + second + + + + + millisecond + + + + + hour + + + + + minute + + + + + day + + + + + meters/second^2 + + + + + m/s^2 + m/s² + + + ft/s^2 ft/s² - + feet/second^2 diff --git a/src/blackmisc/translations/blackmisc_i18n_fr.ts b/src/blackmisc/translations/blackmisc_i18n_fr.ts index 6cee692ea..ca61ab8a9 100644 --- a/src/blackmisc/translations/blackmisc_i18n_fr.ts +++ b/src/blackmisc/translations/blackmisc_i18n_fr.ts @@ -1,12 +1,25 @@ + + Aviation + + + magnetic + + + + + true + + + CMeasurementUnit meter - mètre + mètre @@ -31,7 +44,7 @@ mile - + @@ -39,78 +52,173 @@ - + radian - + degree degré - + deg ° - + segadecimal degree segadecimal - + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + millibar - - + + inch of mercury 0C - + Kelvin - + centigrade - + C °C - + Fahrenheit Fahrenheit - + F °F - - meter/second^2 + + meters/second - + + knot + + + + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + + + + + kilometers/hour + + + + + second + + + + + millisecond + + + + + hour + + + + + minute + + + + + day + + + + + meters/second^2 + + + + m/s^2 m/s² - + ft/s^2 ft/s² - + feet/second^2 From 62591a750fec3d1c5ba8da209da753a6a3f0610a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 28 Jul 2013 03:31:04 +0200 Subject: [PATCH 08/36] Refactoring, renamed: convertToQString (old: stringForConvert) --- src/blackmisc/avaltitude.cpp | 4 ++-- src/blackmisc/avaltitude.h | 2 +- src/blackmisc/avheading.cpp | 4 ++-- src/blackmisc/avheading.h | 2 +- src/blackmisc/aviomodulator.h | 2 +- src/blackmisc/aviotransponder.cpp | 2 +- src/blackmisc/aviotransponder.h | 2 +- src/blackmisc/avtrack.cpp | 4 ++-- src/blackmisc/avtrack.h | 2 +- src/blackmisc/avverticalpositions.cpp | 2 +- src/blackmisc/avverticalpositions.h | 2 +- src/blackmisc/basestreamstringifier.h | 10 +++++----- src/blackmisc/coordinateecef.h | 2 +- src/blackmisc/coordinategeodetic.cpp | 2 +- src/blackmisc/coordinategeodetic.h | 2 +- src/blackmisc/coordinatened.h | 2 +- src/blackmisc/geoearthangle.h | 2 +- src/blackmisc/geolatitude.h | 4 ++-- src/blackmisc/geolongitude.h | 4 ++-- src/blackmisc/mathmatrixbase.cpp | 2 +- src/blackmisc/mathmatrixbase.h | 2 +- src/blackmisc/mathvector3dbase.cpp | 2 +- src/blackmisc/mathvector3dbase.h | 2 +- src/blackmisc/pqbase.h | 4 ++-- src/blackmisc/pqphysicalquantity.h | 2 +- 25 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index db4a7a9f5..3b20ad72d 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -16,9 +16,9 @@ namespace Aviation /* * Own implementation for streaming */ -QString CAltitude::stringForConverter(bool /** i18n **/) const +QString CAltitude::convertToQString(bool /** i18n **/) const { - QString s = CLength::stringForConverter(); + QString s = CLength::convertToQString(); return s.append(this->m_msl ? " MSL" : " AGL"); } diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 4dec1c96f..3ddc1f8f3 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -27,7 +27,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n) const; + virtual QString convertToQString(bool i18n) const; /*! * \brief Stream to DBus << diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index 985bf73ae..1116b13f8 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -16,9 +16,9 @@ namespace Aviation /* * Own implementation for streaming */ -QString CHeading::stringForConverter(bool i18n) const +QString CHeading::convertToQString(bool i18n) const { - QString s = CAngle::stringForConverter(i18n); + QString s = CAngle::convertToQString(i18n); return s.append(this->m_magnetic ? " magnetic" : " true"); } diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 1a3897364..224edd116 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -26,7 +26,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Stream to DBus << diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 00ae1e42e..4985a5822 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -83,7 +83,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const { + virtual QString convertToQString(bool i18n = false) const { QString s(this->getName()); s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3, i18n)); s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3, i18n)); diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index d8ca230ee..431c393ff 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -45,7 +45,7 @@ bool CTransponder::validate(bool strict) const /** * String representation */ -QString CTransponder::stringForConverter(bool /** i18n **/) const +QString CTransponder::convertToQString(bool /** i18n **/) const { QString s = this->getName(); s = s.append(" ").append(this->getTransponderCodeFormatted()).append(" ").append(this->getModeAsString()); diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 477441f53..97621277a 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -95,7 +95,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Stream to DBus << diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 4f9ed363f..341d93a32 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -16,9 +16,9 @@ namespace Aviation /* * Own implementation for streaming */ -QString CTrack::stringForConverter(bool i18n) const +QString CTrack::convertToQString(bool i18n) const { - QString s = CAngle::stringForConverter(i18n); + QString s = CAngle::convertToQString(i18n); return s.append(this->m_magnetic ? " magnetic" : " true"); } diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index e93cc280f..84c2ecffb 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -27,7 +27,7 @@ protected: * \brief Specific stream operation for Track * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Stream to DBus << diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp index cdb93f60e..6b6c4d38d 100644 --- a/src/blackmisc/avverticalpositions.cpp +++ b/src/blackmisc/avverticalpositions.cpp @@ -76,7 +76,7 @@ bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &o /* * String representation for converter */ -QString CAviationVerticalPositions::stringForConverter(bool /** i18n **/) const +QString CAviationVerticalPositions::convertToQString(bool /** i18n **/) const { QString s = QString("Altitude: "). append(this->m_altitude.unitValueRoundedWithUnit()). diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index 0250d2598..ead990609 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -31,7 +31,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Unmarshall from Dbus diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 14e6c8c06..1246b2cee 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -133,7 +133,7 @@ public: */ QString toQString(bool i18n = false) const { - return this->stringForConverter(i18n); + return this->convertToQString(i18n); } protected: @@ -149,7 +149,7 @@ protected: virtual QString stringForStreaming() const { // simplest default implementation requires only one method - return this->stringForConverter(); + return this->convertToQString(); } /*! @@ -157,19 +157,19 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const = 0; + virtual QString convertToQString(bool i18n = false) const = 0; /*! * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &) const {} + virtual void marshallToDbus(QDBusArgument &) const = 0; /*! * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &) {} + virtual void unmarshallFromDbus(const QDBusArgument &) = 0; /*! * \brief Copy assignment operator. diff --git a/src/blackmisc/coordinateecef.h b/src/blackmisc/coordinateecef.h index 0e21b8e20..42695a483 100644 --- a/src/blackmisc/coordinateecef.h +++ b/src/blackmisc/coordinateecef.h @@ -104,7 +104,7 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "ECEF: {x %1, y %2, z %3}"; s = s.arg(QString::number(this->x(), 'f', 6)). diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp index cc6c503e2..363dd370d 100644 --- a/src/blackmisc/coordinategeodetic.cpp +++ b/src/blackmisc/coordinategeodetic.cpp @@ -13,7 +13,7 @@ namespace Geo /* * String for converter */ -QString CCoordinateGeodetic::stringForConverter(bool i18n) const +QString CCoordinateGeodetic::convertToQString(bool i18n) const { QString s = "Geodetic: {%1, %2, %3}"; return s.arg(this->m_latitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_longitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_height.unitValueRoundedWithUnit(i18n)); diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 5f11bb2b3..7af0596c1 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -52,7 +52,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Stream to DBus diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index c620aa83c..00972ec7c 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -28,7 +28,7 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "NED: {N %1, E %2, D %3}"; s = s.arg(QString::number(this->north(), 'f', 6)). diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 7d1b2fc4f..29e93cd1e 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -72,7 +72,7 @@ protected: * \brief String for converter and streaming * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { return this->unitValueRoundedWithUnit(6); } diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index a7187a60f..d4f7ac644 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -19,10 +19,10 @@ protected: /*! * \brief Specific string representation */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "latitude "; - return s.append(CEarthAngle::stringForConverter()); + return s.append(CEarthAngle::convertToQString()); } public: diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 9099d10de..884e3913c 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -16,10 +16,10 @@ protected: /*! * \brief Specific string representation */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "longitude "; - return s.append(CEarthAngle::stringForConverter()); + return s.append(CEarthAngle::convertToQString()); } public: diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 17412a656..b00c1f9de 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -149,7 +149,7 @@ template void CMatrixBase QString CMatrixBase::stringForConverter(bool /** i18n **/) const +template QString CMatrixBase::convertToQString(bool /** i18n **/) const { QString s = "{"; for (int r = 0; r < Rows; r++) diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index 1463e4566..a2090e5c0 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -49,7 +49,7 @@ protected: * \param i18n * \return */ - QString stringForConverter(bool i18n = false) const; + QString convertToQString(bool i18n = false) const; /*! * \brief Stream to DBus diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index fb2a0d8c2..8c07decb3 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -16,7 +16,7 @@ namespace Math /* * Convert to string */ -template QString CVector3DBase::stringForConverter(bool /** i18n **/) const +template QString CVector3DBase::convertToQString(bool /** i18n **/) const { QString s = ("{%1, %2, %3}"); s = s.arg(QString::number(this->m_i, 'f')). diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 90a9ed036..aae74f5f4 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -107,7 +107,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const; + virtual QString convertToQString(bool i18n = false) const; /*! * \brief Unmarshall from Dbus diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index e3aefaf9c..ff1bb2cd5 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -47,7 +47,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool /* i18n */ = false) const + virtual QString convertToQString(bool /* i18n */ = false) const { return this->m_name; } @@ -355,7 +355,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const + virtual QString convertToQString(bool i18n = false) const { return this->getUnitName(i18n); } diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 14d72e494..b09eab05e 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -75,7 +75,7 @@ protected: * \param i18n * \return */ - virtual QString stringForConverter(bool i18n = false) const + virtual QString convertToQString(bool i18n = false) const { return this->unitValueRoundedWithUnit(-1, i18n); } From e6e6dea4cd538dcd8a97ed0c46c9d626e149bc78 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 6 Aug 2013 13:56:15 +0200 Subject: [PATCH 09/36] More DBus tests --- .../BlackMiscTest.Testservice.xml | 9 ++++++++- samples/blackmiscquantities_dbus/main.cpp | 14 +++++++++++++ .../blackmiscquantities_dbus/testservice.cpp | 20 +++++++++++++++++++ .../blackmiscquantities_dbus/testservice.h | 12 +++++++++++ src/blackmisc/pqbase.h | 1 - src/blackmisc/pqphysicalquantity.h | 2 ++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml index fc81aaae8..cdabcbf5a 100644 --- a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -23,7 +23,7 @@ - + @@ -42,5 +42,12 @@ + + + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index 446f24d4e..f43989c1a 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -135,6 +135,20 @@ int main(int argc, char *argv[]) testserviceInterface.receiveTrack(track); qDebug() << "Send track via interface" << track; + CLength len(33, CLengthUnit::m()); + testserviceInterface.receiveLength(len); + qDebug() << "Send length via interface" << len; + + CAltitude alt(33, true, CLengthUnit::m()); + testserviceInterface.receiveLength(alt); + qDebug() << "Send altitude via interface" << alt; + + QVariantList lengths; + lengths << QVariant::fromValue(len); + lengths << QVariant::fromValue(alt); + testserviceInterface.receiveLengths(lengths); + qDebug() << "Send lengths via interface"; + TestserviceTool::sleep(2500); // Math diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp index 52715c063..6d88cf33c 100644 --- a/samples/blackmiscquantities_dbus/testservice.cpp +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -101,4 +101,24 @@ void Testservice::receiveTrack(const BlackMisc::Aviation::CTrack &track) qDebug() << "Pid:" << TestserviceTool::getPid() << "Received track:" << track; } +/* + * Receive a length + */ +void Testservice::receiveLength(const BlackMisc::PhysicalQuantities::CLength &length) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received length:" << length; +} + +/* + * Receive lengths + */ +void Testservice::receiveLengths(const QVariantList &lengths) +{ + BlackMisc::PhysicalQuantities::CLength l; + foreach(QVariant lv, lengths) { + l = lv.value(); + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received in list:" << l; + } +} + } // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h index c31d5364b..d9028b6a4 100644 --- a/samples/blackmiscquantities_dbus/testservice.h +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -106,6 +106,18 @@ public slots: */ void receiveTrack(const BlackMisc::Aviation::CTrack &track); + /*! + * \brief Receive a length + * \param length + */ + void receiveLength(const BlackMisc::PhysicalQuantities::CLength &length); + + /*! + * \brief Receive lengths + * \param length + */ + void receiveLengths(const QVariantList &lengths); + public: static const QString ServiceName; static const QString ServicePath; diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index ff1bb2cd5..cd3ffa643 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -24,7 +24,6 @@ namespace PhysicalQuantities * \brief Typical prefixes (multipliers) such as kilo, mega, hecto. * See here for an overview. * Use the static values such CMeasurementMultiplier::k() as to specify values. - * \author KWB */ class CMeasurementPrefix : public CBaseStreamStringifier { diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index b09eab05e..fb832e952 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -458,8 +458,10 @@ public: { qRegisterMetaType(typeid(MU).name()); qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); qRegisterMetaType(typeid(PQ).name()); qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); } }; From e8b52b33d04bba0b68c63b33e3c4d879a3a6a24e Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 22:23:55 +0100 Subject: [PATCH 10/36] removed CAviationVerticalPositions --- .../blackmiscquantities/samplesaviation.cpp | 4 - samples/blackmiscquantities/samplesaviation.h | 1 - src/blackmisc/avallclasses.h | 1 - src/blackmisc/avverticalpositions.cpp | 143 ------------------ src/blackmisc/avverticalpositions.h | 133 ---------------- 5 files changed, 282 deletions(-) delete mode 100644 src/blackmisc/avverticalpositions.cpp delete mode 100644 src/blackmisc/avverticalpositions.h diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index 8ca2ba9c1..d775dea48 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -22,10 +22,6 @@ int CSamplesAviation::samples() qDebug() << h1; qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1); - CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 1111.0); - CAviationVerticalPositions vp2 = vp1; - qDebug() << vp1 << (vp1 == vp2) << (vp1 != vp2); - CComSystem c1 = CComSystem::getCom1System(125.3); qDebug() << c1; c1.setActiveUnicom(); diff --git a/samples/blackmiscquantities/samplesaviation.h b/samples/blackmiscquantities/samplesaviation.h index 67093c95e..f4ebe94af 100644 --- a/samples/blackmiscquantities/samplesaviation.h +++ b/samples/blackmiscquantities/samplesaviation.h @@ -8,7 +8,6 @@ #include "blackmisc/pqconstants.h" #include "blackmisc/avheading.h" -#include "blackmisc/avverticalpositions.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" diff --git a/src/blackmisc/avallclasses.h b/src/blackmisc/avallclasses.h index a1626c962..bc37c9a3f 100644 --- a/src/blackmisc/avallclasses.h +++ b/src/blackmisc/avallclasses.h @@ -13,6 +13,5 @@ #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" #include "blackmisc/avtrack.h" -#include "blackmisc/avverticalpositions.h" #endif // guard diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp deleted file mode 100644 index 6b6c4d38d..000000000 --- a/src/blackmisc/avverticalpositions.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "avverticalpositions.h" - -using BlackMisc::PhysicalQuantities::CLength; -using BlackMisc::PhysicalQuantities::CLengthUnit; -using BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants; - -namespace BlackMisc -{ -namespace Aviation -{ - -/* - * Constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions() : - m_altitude(CAltitude(0, true, CLengthUnit::ft())), - m_elevation(CPhysicalQuantitiesConstants::Length0ft()), - m_height(CPhysicalQuantitiesConstants::Length0ft()) -{ - // void -} - -/* - * Constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions(const CAltitude &altitude, const CLength &elevation, const CLength &height) : - m_altitude(altitude), m_elevation(elevation), m_height(height) -{ - // void -} - -/* - * Copy constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions(const CAviationVerticalPositions &otherPosition) : - m_altitude(otherPosition.m_altitude), m_elevation(otherPosition.m_elevation), m_height(otherPosition.m_height) -{ - // void -} - -/* - * Assigment - */ -CAviationVerticalPositions &CAviationVerticalPositions::operator =(const CAviationVerticalPositions &otherPositions) -{ - if (this == &otherPositions) return *this; // Same object? - this->m_altitude = otherPositions.m_altitude; - this->m_elevation = otherPositions.m_elevation; - this->m_height = otherPositions.m_height; - return *this; -} - -/* - * Equal operator - */ -bool CAviationVerticalPositions::operator ==(const CAviationVerticalPositions &otherPositions) -{ - return this->m_altitude == otherPositions.m_altitude && - this->m_elevation == otherPositions.m_elevation && - this->m_height == otherPositions.m_height; -} - -/* - * Unequal operator - */ -bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &otherPositions) -{ - return !(*this == otherPositions); -} - -/* - * String representation for converter - */ -QString CAviationVerticalPositions::convertToQString(bool /** i18n **/) const -{ - QString s = QString("Altitude: "). - append(this->m_altitude.unitValueRoundedWithUnit()). - append(" Elevation: "). - append(this->m_elevation.unitValueRoundedWithUnit()). - append(" Height: "). - append(this->m_height.unitValueRoundedWithUnit()); - return s; -} - -/* - * Factory by elevation and altitude - */ -CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationInFt(double altitudeMslFt, double elevationFt) -{ - CAltitude a(altitudeMslFt, true, CLengthUnit::ft()); - CLength e(elevationFt, CLengthUnit::ft()); - CLength h(altitudeMslFt - elevationFt, CLengthUnit::ft()); - return CAviationVerticalPositions(a, e, h); -} - -/* - * Factory by elevation and altitude - */ -CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationInM(double altitudeMslM, double elevationM) -{ - CAltitude a(altitudeMslM, true, CLengthUnit::m()); - CLength e(elevationM, CLengthUnit::m()); - CLength h(altitudeMslM - elevationM, CLengthUnit::m()); - return CAviationVerticalPositions(a, e, h); -} - - -/*! - * \brief Stream to DBus << - * \param argument - */ -void CAviationVerticalPositions::marshallToDbus(QDBusArgument &argument) const { - argument << this->m_altitude; - argument << this->m_elevation; - argument << this->m_height; -} - -/*! - * \brief Stream from DBus >> - * \param argument - */ -void CAviationVerticalPositions::unmarshallFromDbus(const QDBusArgument &argument) { - argument >> this->m_altitude; - argument >> this->m_elevation; - argument >> this->m_height; -} - -/* - * Register metadata - */ -void CAviationVerticalPositions::registerMetadata() -{ - qRegisterMetaType(typeid(CAviationVerticalPositions).name()); - qDBusRegisterMetaType(); -} - -} // namespace -} // namespace diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h deleted file mode 100644 index ead990609..000000000 --- a/src/blackmisc/avverticalpositions.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKMISC_AVVERTICALPOSITION_H -#define BLACKMISC_AVVERTICALPOSITION_H - -#include "blackmisc/avaltitude.h" -#include "blackmisc/pqconstants.h" -#include "blackmisc/basestreamstringifier.h" - -namespace BlackMisc -{ -namespace Aviation -{ - -/*! - * \brief Vertical (Z) positions of an aircraft - */ -class CAviationVerticalPositions : public BlackMisc::CBaseStreamStringifier -{ -private: - BlackMisc::Aviation::CAltitude m_altitude; //!< altitude - BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation - BlackMisc::PhysicalQuantities::CLength m_height; //!< height - -protected: - /*! - * \brief String for converter - * \param i18n - * \return - */ - virtual QString convertToQString(bool i18n = false) const; - - /*! - * \brief Unmarshall from Dbus - * \param argument - */ - virtual void unmarshallFromDbus(const QDBusArgument &argument); - - /*! - * \brief Unmarshall from Dbus - * \param argument - */ - virtual void marshallToDbus(QDBusArgument &argument) const; - -public: - /*! - * \brief Default constructor - */ - CAviationVerticalPositions(); - /*! - * \brief Constructor - * \param altitude - * \param elevation - * \param height - */ - CAviationVerticalPositions(const CAltitude &altitude, const BlackMisc::PhysicalQuantities::CLength &elevation, const BlackMisc::PhysicalQuantities::CLength &height); - /*! - * \brief Copy constructor - * \param otherPosition - */ - CAviationVerticalPositions(const CAviationVerticalPositions &otherPosition); - /*! - * \brief Assignment operator = - * \param otherPositions - * @return - */ - CAviationVerticalPositions &operator =(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Equal operator == - * \param otherPositions - * @return - */ - bool operator ==(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Unequal operator == - * \param otherPositions - * @return - */ - bool operator !=(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Height - * \return - */ - BlackMisc::PhysicalQuantities::CLength getHeight() const - { - return this->m_height; - } - /*! - * \brief Elevation - * \return - */ - BlackMisc::PhysicalQuantities::CLength getElevation() const - { - return this->m_elevation; - } - /*! - * \brief Altitude - * \return - */ - CAltitude getAltitude()const - { - return this->m_altitude; - } - /*! - * \brief Factory getting tupel frome levation and altitude values in ft - * \param altitudeMslFt - * \param elevationFt - * \return - */ - - static CAviationVerticalPositions fromAltitudeAndElevationInFt(double altitudeMslFt, double elevationFt); - /*! - * \brief Factory getting tupel frome levation and altitude values in meters - * \param altitudeMslM - * \param elevationM - * \return - */ - static CAviationVerticalPositions fromAltitudeAndElevationInM(double altitudeMslM, double elevationM); - - /*! - * \brief Register metadata - */ - static void registerMetadata(); -}; - -} // namespace -} // namespace -Q_DECLARE_METATYPE(BlackMisc::Aviation::CAviationVerticalPositions) - -#endif // BLACKMISC_AVVERTICALPOSITION_H From 2c781e8b36f87878b6f31a8ed1982d88b6e9376a Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 22:29:48 +0100 Subject: [PATCH 11/36] style fixes: mostly just things that make my eyes bleed :) --- src/blackmisc/avaltitude.cpp | 23 ++- src/blackmisc/avaltitude.h | 34 ++--- src/blackmisc/avheading.cpp | 19 ++- src/blackmisc/avheading.h | 40 ++--- src/blackmisc/avioadfsystem.h | 78 ++++++---- src/blackmisc/aviobase.h | 19 +-- src/blackmisc/aviocomsystem.h | 152 +++++++++++-------- src/blackmisc/aviomodulator.cpp | 26 ++-- src/blackmisc/aviomodulator.h | 39 ++--- src/blackmisc/avionavsystem.h | 92 +++++++----- src/blackmisc/aviotransponder.cpp | 12 +- src/blackmisc/aviotransponder.h | 71 ++++----- src/blackmisc/avtrack.cpp | 19 ++- src/blackmisc/avtrack.h | 63 +++++--- src/blackmisc/basestreamstringifier.h | 14 +- src/blackmisc/blackmiscfreefunctions.cpp | 21 ++- src/blackmisc/coordinateecef.h | 3 +- src/blackmisc/coordinategeodetic.cpp | 6 +- src/blackmisc/coordinategeodetic.h | 47 +++--- src/blackmisc/coordinatened.h | 43 +++--- src/blackmisc/coordinatetransformation.h | 5 +- src/blackmisc/geoearthangle.h | 50 +++---- src/blackmisc/geolatitude.h | 7 +- src/blackmisc/geolongitude.h | 6 +- src/blackmisc/mathematics.h | 4 +- src/blackmisc/mathmatrix1x3.h | 10 +- src/blackmisc/mathmatrix3x1.h | 10 +- src/blackmisc/mathmatrix3x3.cpp | 13 +- src/blackmisc/mathmatrix3x3.h | 32 ++-- src/blackmisc/mathmatrixbase.cpp | 8 +- src/blackmisc/mathmatrixbase.h | 75 +++++----- src/blackmisc/mathvector3d.h | 5 +- src/blackmisc/mathvector3dbase.cpp | 25 ++-- src/blackmisc/mathvector3dbase.h | 146 +++++++++--------- src/blackmisc/pqacceleration.h | 7 +- src/blackmisc/pqangle.h | 9 +- src/blackmisc/pqbase.cpp | 91 ++++++------ src/blackmisc/pqbase.h | 79 +++++----- src/blackmisc/pqconstants.h | 52 +++---- src/blackmisc/pqfrequency.h | 9 +- src/blackmisc/pqlength.h | 9 +- src/blackmisc/pqmass.h | 7 +- src/blackmisc/pqphysicalquantity.cpp | 125 ++++++++-------- src/blackmisc/pqphysicalquantity.h | 66 ++++---- src/blackmisc/pqpressure.h | 9 +- src/blackmisc/pqspeed.h | 8 +- src/blackmisc/pqtemperature.h | 11 +- src/blackmisc/pqtime.h | 9 +- src/blackmisc/pqunits.cpp | 2 +- src/blackmisc/pqunits.h | 182 +++++++++++------------ 50 files changed, 975 insertions(+), 917 deletions(-) diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index 3b20ad72d..604a654cd 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -16,38 +16,37 @@ namespace Aviation /* * Own implementation for streaming */ -QString CAltitude::convertToQString(bool /** i18n **/) const +QString CAltitude::convertToQString(bool /* i18n */) const { - QString s = CLength::convertToQString(); + QString s = this->CLength::convertToQString(); return s.append(this->m_msl ? " MSL" : " AGL"); } /* * Assigment */ -CAltitude &CAltitude::operator =(const CAltitude &otherAltitude) +CAltitude &CAltitude::operator =(const CAltitude &other) { - // Check for self-assignment! - if (this == &otherAltitude) return *this; - CLength::operator = (otherAltitude); - this->m_msl = otherAltitude.m_msl; - return (*this); + if (this == &other) return *this; + CLength::operator = (other); + this->m_msl = other.m_msl; + return *this; } /* * Equal? */ -bool CAltitude::operator ==(const CAltitude &otherAltitude) +bool CAltitude::operator ==(const CAltitude &other) { - return otherAltitude.m_msl == this->m_msl && CLength::operator ==(otherAltitude); + return other.m_msl == this->m_msl && this->CLength::operator ==(other); } /* * Unequal? */ -bool CAltitude::operator !=(const CAltitude &otherAltitude) +bool CAltitude::operator !=(const CAltitude &other) { - return !((*this) == otherAltitude); + return !((*this) == other); } /* diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 3ddc1f8f3..43379510e 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -33,8 +33,9 @@ protected: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - CLength::marshallToDbus(argument); + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CLength::marshallToDbus(argument); argument << this->m_msl; } @@ -42,13 +43,13 @@ protected: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - CLength::unmarshallFromDbus(argument); + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CLength::unmarshallFromDbus(argument); argument >> this->m_msl; } public: - /*! * \brief Default constructor: 0 Altitude true */ @@ -75,37 +76,34 @@ public: * \param altitude * \param msl */ - CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(), m_msl(msl) - { - BlackMisc::PhysicalQuantities::CLength::operator =(altitude); - } + CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(altitude), m_msl(msl) {} /*! * \brief Copy constructor - * \param otherAltitude + * \param other */ - CAltitude(const CAltitude &otherAltitude) : BlackMisc::PhysicalQuantities::CLength(otherAltitude), m_msl(otherAltitude.m_msl) {} + CAltitude(const CAltitude &other) : BlackMisc::PhysicalQuantities::CLength(other), m_msl(other.m_msl) {} /*! * \brief Assignment operator = - * \param otherAltitude + * \param other * @return */ - CAltitude &operator =(const CAltitude &otherAltitude); + CAltitude &operator =(const CAltitude &other); /*! * \brief Equal operator == - * \param otherAltitude + * \param other * @return */ - bool operator ==(const CAltitude &otherAltitude); + bool operator ==(const CAltitude &other); /*! * \brief Unequal operator == - * \param otherAltitude + * \param other * @return */ - bool operator !=(const CAltitude &otherAltitude); + bool operator !=(const CAltitude &other); /*! * \brief AGL Above ground level? @@ -129,11 +127,11 @@ public: * \brief Register metadata */ static void registerMetadata(); - }; } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Aviation::CAltitude) #endif // guard diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index 1116b13f8..b1b4dd430 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -25,29 +25,28 @@ QString CHeading::convertToQString(bool i18n) const /* * Assigment */ -CHeading& CHeading::operator =(const CHeading &otherHeading) +CHeading& CHeading::operator =(const CHeading &other) { - // Check for self-assignment! - if (this == &otherHeading) return *this; - CAngle::operator = (otherHeading); - this->m_magnetic = otherHeading.m_magnetic; - return (*this); + if (this == &other) return *this; + this->CAngle::operator = (other); + this->m_magnetic = other.m_magnetic; + return *this; } /* * Equal? */ -bool CHeading::operator ==(const CHeading &otherHeading) +bool CHeading::operator ==(const CHeading &other) { - return otherHeading.m_magnetic == this->m_magnetic && CAngle::operator ==(otherHeading); + return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other); } /* * Unequal? */ -bool CHeading::operator !=(const CHeading &otherHeading) +bool CHeading::operator !=(const CHeading &other) { - return !((*this) == otherHeading); + return !((*this) == other); } /*! diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 224edd116..a75dd1c56 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -11,6 +11,7 @@ namespace BlackMisc { namespace Aviation { + /*! * \brief Heading as used in aviation, can be true or magnetic heading * \remarks Intentionally allowing +/- CAngle , and >= / <= CAngle. @@ -32,8 +33,9 @@ protected: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - CAngle::marshallToDbus(argument); + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); argument << this->m_magnetic; } @@ -41,8 +43,9 @@ protected: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - CAngle::unmarshallFromDbus(argument); + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); argument >> this->m_magnetic; } @@ -58,8 +61,8 @@ public: * \param magnetic * \param unit */ - CHeading(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {} + /*! * \brief Constructor * \param value @@ -73,37 +76,34 @@ public: * \param heading * \param magnetic */ - CHeading(CAngle heading, bool magnetic) : CAngle(), m_magnetic(magnetic) - { - CAngle::operator =(heading); - } + CHeading(CAngle heading, bool magnetic) : CAngle(heading), m_magnetic(magnetic) {} /*! * \brief Copy constructor - * \param otherHeading + * \param other */ - CHeading(const CHeading &otherHeading) : CAngle(otherHeading), m_magnetic(otherHeading.m_magnetic) {} + CHeading(const CHeading &other) : CAngle(other), m_magnetic(other.m_magnetic) {} /*! * \brief Assignment operator = - * \param otherHeading + * \param other * @return */ - CHeading &operator =(const CHeading &otherHeading); + CHeading &operator =(const CHeading &other); /*! * \brief Equal operator == - * \param otherHeading + * \param other * @return */ - bool operator ==(const CHeading &otherHeading); + bool operator ==(const CHeading &other); /*! * \brief Unequal operator == - * \param otherHeading + * \param other * @return */ - bool operator !=(const CHeading &otherHeading); + bool operator !=(const CHeading &other); /*! * \brief Magnetic heading? @@ -118,14 +118,14 @@ public: bool isTrueHeading() const { return !this->m_magnetic; } /*! - * \brief Switch heading unit + * \brief Switch angle unit * \param newUnit * \return */ CHeading &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit) { - CAngle::switchUnit(newUnit); - return (*this); + this->CAngle::switchUnit(newUnit); + return *this; } /*! diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index 5cff56b5d..e74914ee5 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -29,6 +29,7 @@ private: double fr = f.valueRounded(PhysicalQuantities::CFrequencyUnit::kHz(), this->m_digits); return fr >= 190.0 && fr <= 1750.0; } + /*! * \brief Constructor * \param validate @@ -53,8 +54,8 @@ protected: { if (this->isDefaultValue()) return true; // special case return - (this->isValidFrequency(this->getFrequencyActive()) && - (this->isValidFrequency(this->getFrequencyStandby()))); + this->isValidFrequency(this->getFrequencyActive()) && + this->isValidFrequency(this->getFrequencyStandby()); } /*! @@ -73,16 +74,19 @@ protected: if (!valid) throw std::range_error("Illegal values in CAdfSystem::validate"); return true; } + public: /*! * Default constructor */ CAdfSystem() : CModulator() {} + /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CAdfSystem(const CAdfSystem &otherSystem) : CModulator(otherSystem) {} + CAdfSystem(const CAdfSystem &other) : CModulator(other) {} + /*! * \brief Constructor * \param name @@ -95,24 +99,27 @@ public: { this->validate(true); } + /*! * \brief Set active frequency * \param frequencyKHz */ void setFrequencyActiveKHz(double frequencyKHz) { - CModulator::setFrequencyActiveKHz(frequencyKHz); + this->CModulator::setFrequencyActiveKHz(frequencyKHz); this->validate(true); } + /*! * \brief Set standby frequency * \param frequencyKHz */ void setFrequencyStandbyKHz(double frequencyKHz) { - CModulator::setFrequencyStandbyKHz(frequencyKHz); + this->CModulator::setFrequencyStandbyKHz(frequencyKHz); this->validate(true); } + /*! * \brief Assigment operator = * \param otherSystem @@ -120,9 +127,10 @@ public: */ CAdfSystem &operator =(const CAdfSystem &otherSystem) { - CModulator::operator =(otherSystem); - return (*this); + this->CModulator::operator =(otherSystem); + return *this; } + /*! * \brief operator == * \param otherSystem @@ -130,8 +138,9 @@ public: */ bool operator ==(const CAdfSystem &otherSystem) const { - return CModulator::operator ==(otherSystem); + return this->CModulator::operator ==(otherSystem); } + /*! * \brief operator == * \param otherSystem @@ -139,42 +148,43 @@ public: */ bool operator !=(const CAdfSystem &otherSystem) const { - return CModulator::operator !=(otherSystem); + return this->CModulator::operator !=(otherSystem); } /*! * Try to get a ADF unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object and false. - * \param adfSystem + * \param[out] o_adfSystem * \param name * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdfSystem(CAdfSystem &o_adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - adfSystem = CAdfSystem(false, name, PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); + o_adfSystem = CAdfSystem(false, name, PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + if (!(s = o_adfSystem.validate(false))) o_adfSystem = CAdfSystem(); // reset to default return s; } /*! * Try to get a ADF unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param adfSystem + * \param[out] o_adfSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdfSystem(CAdfSystem &o_adfSystem, const QString &name, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); + o_adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + if (!(s = o_adfSystem.validate(false))) o_adfSystem = CAdfSystem(); // reset to default return s; } + /*! * \brief ADF1 unit * \param activeFrequencyKHz @@ -185,6 +195,7 @@ public: { return CAdfSystem(CModulator::NameCom1(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief ADF1 unit * \param activeFrequency @@ -195,28 +206,31 @@ public: { return CAdfSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdf1Unit(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdf1Unit(CAdfSystem &o_adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequencyKHz, standbyFrequencyKHz); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom1(), activeFrequencyKHz, standbyFrequencyKHz); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdf1Unit(CAdfSystem &adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf1Unit(CAdfSystem &o_adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } + /*! * \brief ADF2 unit * \param activeFrequencyKHz @@ -227,6 +241,7 @@ public: { return CAdfSystem(CModulator::NameCom2(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief ADF2 unit * \param activeFrequency @@ -237,32 +252,35 @@ public: { return CAdfSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdf2System(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdf2System(CAdfSystem &o_adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequencyKHz, standbyFrequencyKHz); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom2(), activeFrequencyKHz, standbyFrequencyKHz); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdf2System(CAdfSystem &adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf2System(CAdfSystem &o_adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); } }; } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Aviation::CAdfSystem) #endif // BLACKMISC_AVIOADFSYSTEM_H diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index f99c0b583..36f4d335c 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -21,15 +21,13 @@ namespace Aviation */ class CAvionicsBase : public BlackMisc::CBaseStreamStringifier { - protected: - QString m_name; //!< name of the unit /*! * \brief Constructor */ - CAvionicsBase(const QString &name) : CBaseStreamStringifier(), m_name(name) {} + CAvionicsBase(const QString &name) : m_name(name) {} /*! * \brief Are the set values valid / in range @@ -51,20 +49,21 @@ protected: /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator ==(const CAvionicsBase &otherSystem) const + bool operator ==(const CAvionicsBase &other) const { - if (this == &otherSystem) return true; - return this->m_name == otherSystem.m_name; + if (this == &other) return true; + return this->m_name == other.m_name; } /*! * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { + virtual void marshallToDbus(QDBusArgument &argument) const + { argument << this->m_name; } @@ -72,7 +71,8 @@ protected: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { argument >> this->m_name; } @@ -91,6 +91,7 @@ public: return this->m_name; } }; + } // namespace } // namespace diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 9faac94ac..46e4ff6ed 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -24,7 +24,8 @@ private: * \param f * \return */ - bool isValidCivilAviationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const { + bool isValidCivilAviationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const + { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 118.0 && fr <= 136.975; } @@ -34,7 +35,8 @@ private: * \param f * \return */ - bool isValidMilitaryFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const { + bool isValidMilitaryFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const + { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 220.0 && fr <= 399.95; } @@ -49,7 +51,8 @@ private: * */ CComSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): - CModulator(name, activeFrequency, standbyFrequency, digits) { + CModulator(name, activeFrequency, standbyFrequency, digits) + { this->validate(validate); } @@ -58,7 +61,8 @@ protected: * \brief Are the set values valid / in range? * \return */ - bool validValues() const { + bool validValues() const + { if (this->isDefaultValue()) return true; // special case return (this->isValidCivilAviationFrequency(this->getFrequencyActive()) || @@ -71,10 +75,11 @@ protected: * \brief Validate values by assert and exception * \param strict * \throws std::range_error - * \remarks Cannot be virtualsince already used in constructor + * \remarks Cannot be virtual because used in constructor * \return */ - bool validate(bool strict = true) const { + bool validate(bool strict = true) const + { if (this->isDefaultValue()) return true; bool valid = this->validValues(); if (!strict) return valid; @@ -91,9 +96,9 @@ public: /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CComSystem(const CComSystem &otherSystem) : CModulator(otherSystem) {} + CComSystem(const CComSystem &other) : CModulator(other) {} /*! * \brief Constructor @@ -103,7 +108,8 @@ public: * \param digits */ CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): - CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { + CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) + { this->validate(true); } @@ -111,8 +117,9 @@ public: * \brief Set active frequency * \param frequencyMHz */ - void setFrequencyActiveMHz(double frequencyMHz) { - CModulator::setFrequencyActiveMHz(frequencyMHz); + void setFrequencyActiveMHz(double frequencyMHz) + { + this->CModulator::setFrequencyActiveMHz(frequencyMHz); this->validate(true); } @@ -120,15 +127,17 @@ public: * \brief Set standby frequency * \param frequencyMHz */ - void setFrequencyStandbyMHz(double frequencyMHz) { - CModulator::setFrequencyStandbyMHz(frequencyMHz); + void setFrequencyStandbyMHz(double frequencyMHz) + { + this->CModulator::setFrequencyStandbyMHz(frequencyMHz); this->validate(true); } /*! * \brief Set UNICOM frequency as active */ - void setActiveUnicom() { + void setActiveUnicom() + { this->toggleActiveStandby(); this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyUnicom()); } @@ -136,67 +145,74 @@ public: /*! * \brief Set International Air Distress 121.5MHz */ - void setActiveInternationalAirDistress() { + void setActiveInternationalAirDistress() + { this->toggleActiveStandby(); this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress()); } /*! * \brief Assigment operator = - * \param otherSystem + * \param other * \return */ - CComSystem& operator =(const CComSystem &otherSystem) { - CModulator::operator =(otherSystem); - return (*this); + CComSystem& operator =(const CComSystem &other) + { + this->CModulator::operator =(other); + return *this; } /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator ==(const CComSystem &otherSystem) const { - return CModulator::operator ==(otherSystem); + bool operator ==(const CComSystem &other) const + { + return this->CModulator::operator ==(other); } + /*! - * \brief operator == - * \param otherSystem + * \brief operator != + * \param other * \return */ - bool operator !=(const CComSystem &otherSystem) const { - return CModulator::operator !=(otherSystem); + bool operator !=(const CComSystem &other) const + { + return this->CModulator::operator !=(other); } /*! * Try to get a COM unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param comSystem + * \param[out] o_comSystem * \param name * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetComSystem(CComSystem &comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); + static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + o_comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default return s; } /*! * Try to get a COM unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param comSystem + * \param[out] o_comSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetComSystem(CComSystem &comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); + static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + o_comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default return s; } @@ -206,7 +222,8 @@ public: * \param standbyFrequencyMHz * \return */ - static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } @@ -216,28 +233,33 @@ public: * \param standbyFrequency * \return */ - static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom1Unit(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom1Unit(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom1Unit(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + static bool tryGetCom1Unit(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } /*! @@ -246,7 +268,8 @@ public: * \param standbyFrequencyMHz * \return */ - static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } @@ -256,30 +279,33 @@ public: * \param standbyFrequency * \return */ - static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom2System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom2System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); } /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom2System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + static bool tryGetCom2System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); } /*! @@ -288,7 +314,8 @@ public: * \param standbyFrequencyMHz * \return */ - static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom3(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } @@ -298,38 +325,39 @@ public: * \param standbyFrequency * \return */ - static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom3System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom3System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); } /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom3System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); + static bool tryGetCom3System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); } - }; - +} // namespace } // namespace -} // namespace Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem) #endif // include guard diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index ce309642b..94428b640 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -38,33 +38,33 @@ template void CModulator::registerMetadata() /* * Assigment operator = */ -template CModulator& CModulator::operator=(const CModulator &otherModulator) +template CModulator& CModulator::operator=(const CModulator &other) { - if (this == &otherModulator) return *this; // Same object? - this->m_frequencyActive = otherModulator.m_frequencyActive; - this->m_frequencyStandby = otherModulator.m_frequencyStandby; - this->m_digits = otherModulator.m_digits; - this->setName(otherModulator.getName()); + if (this == &other) return *this; + this->m_frequencyActive = other.m_frequencyActive; + this->m_frequencyStandby = other.m_frequencyStandby; + this->m_digits = other.m_digits; + this->setName(other.getName()); return *this; } /* * Equal operator == */ -template bool CModulator::operator ==(const CModulator &otherModulator) const +template bool CModulator::operator ==(const CModulator &other) const { - if (this == &otherModulator) return true; - return (this->getName() == otherModulator.getName() && - this->m_frequencyActive == otherModulator.m_frequencyActive && - this->m_frequencyStandby == otherModulator.m_frequencyStandby); + if (this == &other) return true; + return (this->getName() == other.getName() && + this->m_frequencyActive == other.m_frequencyActive && + this->m_frequencyStandby == other.m_frequencyStandby); } /* * Equal operator != */ -template bool CModulator::operator !=(const CModulator &otherModulator) const +template bool CModulator::operator !=(const CModulator &other) const { - return !(otherModulator == (*this)); + return !(other == (*this)); } // see here for the reason of thess forward instantiations diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 4985a5822..9b6ccf12e 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -11,7 +11,6 @@ namespace BlackMisc { - namespace Aviation { @@ -26,7 +25,8 @@ template class CModulator : public CAvionicsBase * \param uc * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) { + friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) + { // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the @@ -55,7 +55,6 @@ protected: int m_digits; //!< digits used protected: - /*! * \brief Default constructor */ @@ -63,10 +62,10 @@ protected: /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CModulator(const CModulator &otherUnit) : CAvionicsBase(otherUnit.getName()), - m_frequencyActive(otherUnit.m_frequencyActive), m_frequencyStandby(otherUnit.m_frequencyStandby), m_digits(otherUnit.m_digits) {} + CModulator(const CModulator &other) : CAvionicsBase(other.getName()), + m_frequencyActive(other.m_frequencyActive), m_frequencyStandby(other.m_frequencyStandby), m_digits(other.m_digits) {} /*! * \brief Constructor @@ -76,14 +75,15 @@ protected: * \param digits */ CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits) : - CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency), m_digits(digits) { } + CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency), m_digits(digits) {} /*! * \brief String for converter * \param i18n * \return */ - virtual QString convertToQString(bool i18n = false) const { + virtual QString convertToQString(bool i18n = false) const + { QString s(this->getName()); s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3, i18n)); s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3, i18n)); @@ -128,24 +128,25 @@ protected: /*! * \brief Assigment operator = - * \param otherModulator + * \param other * \return */ - CModulator &operator =(const CModulator &otherModulator); + CModulator &operator =(const CModulator &other); /*! * \brief operator == - * \param otherModulator + * \param other * \return */ - bool operator ==(const CModulator &otherModulator) const; + bool operator ==(const CModulator &other) const; /*! * \brief operator != - * \param otherModulator + * \param other * \return */ - bool operator !=(const CModulator &otherModulator) const; + bool operator !=(const CModulator &other) const; + /*! * \brief COM1 * \return @@ -240,8 +241,9 @@ protected: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - CAvionicsBase::marshallToDbus(argument); + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAvionicsBase::marshallToDbus(argument); argument << this->m_frequencyActive; argument << this->m_frequencyStandby; argument << this->m_digits; @@ -251,8 +253,9 @@ protected: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - CAvionicsBase::unmarshallFromDbus(argument); + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAvionicsBase::unmarshallFromDbus(argument); argument >> this->m_frequencyActive; argument >> this->m_frequencyStandby; argument >> this->m_digits; diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index b2d448037..f6ec2026b 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -28,6 +28,7 @@ private: double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 108.0 && fr <= 117.95; } + /*! * \brief Valid military aviation frequency? * \param f @@ -38,6 +39,7 @@ private: double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 960.0 && fr <= 1215.0; // valid TACAN frequency } + /*! * \brief Constructor * \param validate @@ -45,7 +47,6 @@ private: * \param activeFrequency * \param standbyFrequency * \param digits - * */ CNavSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): CModulator(name, activeFrequency, standbyFrequency, digits) @@ -68,11 +69,12 @@ protected: this->isValidMilitaryNavigationFrequency(this->getFrequencyStandby())); return v; } + /*! * \brief Validate values by assert and exception * \param strict * \throws std::range_error - * \remarks Cannot be virtualsince already used in constructor + * \remarks Cannot be virtual because used in constructor * \return */ bool validate(bool strict = true) const @@ -84,16 +86,19 @@ protected: if (!valid) throw std::range_error("Illegal values in CModulator::validate"); return true; } + public: /*! * Default constructor */ CNavSystem() : CModulator() {} + /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CNavSystem(const CNavSystem &otherSystem) : CModulator(otherSystem) {} + CNavSystem(const CNavSystem &other) : CModulator(other) {} + /*! * \brief Constructor * \param name @@ -106,85 +111,92 @@ public: { this->validate(true); } + /*! * \brief Set active frequency * \param frequencyMHz */ void setFrequencyActiveMHz(double frequencyMHz) { - CModulator::setFrequencyActiveMHz(frequencyMHz); + this->CModulator::setFrequencyActiveMHz(frequencyMHz); this->validate(true); } + /*! * \brief Set standby frequency * \param frequencyMHz */ void setFrequencyStandbyMHz(double frequencyMHz) { - CModulator::setFrequencyStandbyMHz(frequencyMHz); + this->CModulator::setFrequencyStandbyMHz(frequencyMHz); this->validate(true); } + /*! * \brief Assigment operator = - * \param otherSystem + * \param other * \return */ - CNavSystem &operator =(const CNavSystem &otherSystem) + CNavSystem &operator =(const CNavSystem &other) { - CModulator::operator =(otherSystem); - return (*this); + this->CModulator::operator =(other); + return *this; } + /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator ==(const CNavSystem &otherSystem) const + bool operator ==(const CNavSystem &other) const { - return CModulator::operator ==(otherSystem); + return this->CModulator::operator ==(other); } + /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator !=(const CNavSystem &otherSystem) const + bool operator !=(const CNavSystem &other) const { - return CModulator::operator !=(otherSystem); + return this->CModulator::operator !=(other); } /*! * Try to get a NAV unit with given name and frequency. Returns true in case an object * has been sucessfully created,otherwise returns a default object. - * \param navSystem + * \param[out] o_navSystem * \param name * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNavSystem(CNavSystem &o_navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - navSystem = CNavSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); + o_navSystem = CNavSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + if (!(s = o_navSystem.validate(false))) o_navSystem = CNavSystem(); // reset to default return s; } + /*! * Try to get a NAV unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param navSystem + * \param[out] o_navSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNavSystem(CNavSystem &o_navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency); + o_navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + if (!(s = o_navSystem.validate(false))) o_navSystem = CNavSystem(); // reset to default return s; } + /*! * \brief NAV1 unit * \param activeFrequencyMHz @@ -195,6 +207,7 @@ public: { return CNavSystem(CModulator::NameNav1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief NAV1 unit * \param activeFrequency @@ -205,28 +218,31 @@ public: { return CNavSystem(CModulator::NameNav1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNav1System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNav1System(CNavSystem &o_navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNav1System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNav1System(CNavSystem &o_navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency); } + /*! * \brief NAV2 unit * \param activeFrequencyMHz @@ -237,6 +253,7 @@ public: { return CNavSystem(CModulator::NameNav2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief NAV2 unit * \param activeFrequency @@ -247,32 +264,35 @@ public: { return CNavSystem(CModulator::NameNav2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNav2System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNav2System(CNavSystem &o_navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNav2System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNav2System(CNavSystem &o_navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency); } }; } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Aviation::CNavSystem) #endif // BLACKMISC_AVIONAVSYSTEM_H diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index 431c393ff..676508e4a 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -45,7 +45,7 @@ bool CTransponder::validate(bool strict) const /** * String representation */ -QString CTransponder::convertToQString(bool /** i18n **/) const +QString CTransponder::convertToQString(bool /* i18n */) const { QString s = this->getName(); s = s.append(" ").append(this->getTransponderCodeFormatted()).append(" ").append(this->getModeAsString()); @@ -103,8 +103,9 @@ QString CTransponder::getTransponderCodeFormatted() const * \brief Stream to DBus << * \param argument */ -void CTransponder::marshallToDbus(QDBusArgument &argument) const { - CAvionicsBase::marshallToDbus(argument); +void CTransponder::marshallToDbus(QDBusArgument &argument) const +{ + this->CAvionicsBase::marshallToDbus(argument); argument << this->m_transponderCode; argument << static_cast(this->m_transponderMode); } @@ -113,8 +114,9 @@ void CTransponder::marshallToDbus(QDBusArgument &argument) const { * \brief Stream from DBus >> * \param argument */ -void CTransponder::unmarshallFromDbus(const QDBusArgument &argument) { - CAvionicsBase::unmarshallFromDbus(argument); +void CTransponder::unmarshallFromDbus(const QDBusArgument &argument) +{ + this->CAvionicsBase::unmarshallFromDbus(argument); qint32 tm; argument >> this->m_transponderCode; argument >> tm; diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 97621277a..e866dfbfc 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -61,7 +61,7 @@ private: { bool ok = false; this->m_transponderCode = transponderCode.toUInt(&ok); - if (!ok)this->m_transponderCode = -1; // will cause assert / exception + if (!ok) this->m_transponderCode = -1; // will cause assert / exception this->validate(validate); } @@ -117,10 +117,10 @@ public: /*! * \brief Copy constructor - * \param otherTransponder + * \param other */ - CTransponder(const CTransponder &otherTransponder) : CAvionicsBase(otherTransponder.getName()), - m_transponderCode(otherTransponder.m_transponderCode), m_transponderMode(otherTransponder.m_transponderMode) {} + CTransponder(const CTransponder &other) : CAvionicsBase(other.getName()), + m_transponderCode(other.m_transponderCode), m_transponderMode(other.m_transponderMode) {} /*! * \brief Constructor @@ -145,7 +145,7 @@ public: { bool ok = false; this->m_transponderCode = transponderCode.toUInt(&ok); - if (!ok)this->m_transponderCode = -1; // will cause assert / exception + if (!ok) this->m_transponderCode = -1; // will cause assert / exception this->validate(true); } @@ -209,7 +209,7 @@ public: } /*! - * \brief Set emergency + * \brief Set VFR */ void setVFR() { @@ -217,7 +217,7 @@ public: } /*! - * \brief Set emergency + * \brief Set IFR */ void setIFR() { @@ -226,71 +226,71 @@ public: /*! * \brief Assigment operator = - * \param otherTransponder + * \param other * \return */ - CTransponder &operator =(const CTransponder &otherTransponder) + CTransponder &operator =(const CTransponder &other) { - CAvionicsBase::operator =(otherTransponder); - this->m_transponderMode = otherTransponder.m_transponderMode; - this->m_transponderCode = otherTransponder.m_transponderCode; - return (*this); + this->CAvionicsBase::operator =(other); + this->m_transponderMode = other.m_transponderMode; + this->m_transponderCode = other.m_transponderCode; + return *this; } /*! * \brief operator == - * \param otherTransponder + * \param other * \return */ - bool operator ==(const CTransponder &otherTransponder) const + bool operator ==(const CTransponder &other) const { return - this->m_transponderCode == otherTransponder.m_transponderCode && - this->m_transponderMode == otherTransponder.m_transponderMode && - CAvionicsBase::operator ==(otherTransponder); + this->m_transponderCode == other.m_transponderCode && + this->m_transponderMode == other.m_transponderMode && + this->CAvionicsBase::operator ==(other); } /*! * \brief operator =! - * \param otherSystem + * \param other * \return */ - bool operator !=(const CTransponder &otherSystem) const + bool operator !=(const CTransponder &other) const { - return !((*this) == otherSystem); + return !((*this) == other); } /*! * Try to get a Transponder unit with given name and code. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param transponder + * \param[out] o_transponder * \param name * \param transponderCode * \param mode * \return */ - static bool tryGetTransponder(CTransponder &transponder, const QString &name, qint32 transponderCode, TransponderMode mode) + static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, qint32 transponderCode, TransponderMode mode) { - transponder = CTransponder(false, name, transponderCode, mode); + o_transponder = CTransponder(false, name, transponderCode, mode); bool s; - if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default return s; } /*! * Try to get a Transponder unit with given name and code. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param transponder + * \param[out] o_transponder * \param name * \param transponderCode * \param mode * \return */ - static bool tryGetTransponder(CTransponder &transponder, const QString &name, const QString &transponderCode, TransponderMode mode) + static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, const QString &transponderCode, TransponderMode mode) { - transponder = CTransponder(false, name, transponderCode, mode); + o_transponder = CTransponder(false, name, transponderCode, mode); bool s; - if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default return s; } @@ -307,26 +307,26 @@ public: /*! * \brief Try to get Transponder unit - * \param transponder + * \param[out] o_transponder * \param transponderCode * \param mode * \return */ - static bool tryGetStandardTransponder(CTransponder &transponder, qint32 transponderCode, TransponderMode mode) + static bool tryGetStandardTransponder(CTransponder &o_transponder, qint32 transponderCode, TransponderMode mode) { - return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); } /*! * \brief Try to get Transponder unit - * \param transponder + * \param[out] o_transponder * \param transponderCode * \param mode * \return */ - static bool tryGetStandardTransponder(CTransponder &transponder, const QString &transponderCode, TransponderMode mode) + static bool tryGetStandardTransponder(CTransponder &o_transponder, const QString &transponderCode, TransponderMode mode) { - return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); } /*! @@ -338,6 +338,7 @@ public: } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder) #endif // BLACKMISC_AVIOTRANSPONDER_H diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 341d93a32..5fe603fc0 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -25,29 +25,28 @@ QString CTrack::convertToQString(bool i18n) const /* * Assigment */ -CTrack& CTrack::operator =(const CTrack &otherTrack) +CTrack& CTrack::operator =(const CTrack &other) { - // Check for self-assignment! - if (this == &otherTrack) return *this; - CAngle::operator = (otherTrack); - this->m_magnetic = otherTrack.m_magnetic; - return (*this); + if (this == &other) return *this; + this->CAngle::operator = (other); + this->m_magnetic = other.m_magnetic; + return *this; } /* * Equal? */ -bool CTrack::operator ==(const CTrack &otherTrack) +bool CTrack::operator ==(const CTrack &other) { - return otherTrack.m_magnetic == this->m_magnetic && CAngle::operator ==(otherTrack); + return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other); } /* * Unequal? */ -bool CTrack::operator !=(const CTrack &otherTrack) +bool CTrack::operator !=(const CTrack &other) { - return !((*this) == otherTrack); + return !((*this) == other); } /*! diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index 84c2ecffb..d9e88dd15 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -7,7 +7,6 @@ #define BLACKMISC_AVTRACK_H #include "blackmisc/pqangle.h" - namespace BlackMisc { namespace Aviation @@ -33,8 +32,9 @@ protected: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - CAngle::marshallToDbus(argument); + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); argument << this->m_magnetic; } @@ -42,8 +42,9 @@ protected: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - CAngle::unmarshallFromDbus(argument); + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); argument >> this->m_magnetic; } @@ -52,6 +53,7 @@ public: * \brief Default constructor: 0 Track magnetic */ CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {} + /*! * \brief Constructor * \param value @@ -59,6 +61,7 @@ public: * \param unit */ CTrack(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} + /*! * \brief Constructor * \param value @@ -66,42 +69,47 @@ public: * \param unit */ CTrack(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} + /*! * \brief Constructor by CAngle * \param track * \param magnetic */ - CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(), m_magnetic(magnetic) { - BlackMisc::PhysicalQuantities::CAngle::operator =(track); - } + CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(track), m_magnetic(magnetic) {} + /*! * \brief Copy constructor - * \param otherTrack + * \param other */ - CTrack(const CTrack &otherTrack) : BlackMisc::PhysicalQuantities::CAngle(otherTrack), m_magnetic(otherTrack.m_magnetic) {} + CTrack(const CTrack &other) : BlackMisc::PhysicalQuantities::CAngle(other), m_magnetic(other.m_magnetic) {} + /*! * \brief Assignment operator = - * \param otherTrack - * @return + * \param other + * \return */ - CTrack &operator =(const CTrack &otherTrack); + CTrack &operator =(const CTrack &other); + /*! * \brief Equal operator == - * \param otherTrack - * @return + * \param other + * \return */ - bool operator ==(const CTrack &otherTrack); + bool operator ==(const CTrack &other); + /*! * \brief Unequal operator == - * \param otherTrack - * @return + * \param other + * \return */ - bool operator !=(const CTrack &otherTrack); + bool operator !=(const CTrack &other); + /*! * \brief Magnetic Track? * \return */ - bool isMagneticTrack() const { + bool isMagneticTrack() const + { return this->m_magnetic; QT_TRANSLATE_NOOP("Aviation", "magnetic"); QT_TRANSLATE_NOOP("Aviation", "true"); @@ -111,10 +119,22 @@ public: * \brief True Track? * \return */ - bool isTrueTrack() const { + bool isTrueTrack() const + { return !this->m_magnetic; } + /*! + * \brief Switch angle unit + * \param newUnit + * \return + */ + CTrack &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit) + { + this->CAngle::switchUnit(newUnit); + return *this; + } + /*! * \brief Register metadata */ @@ -122,7 +142,6 @@ public: }; } // namespace - } // namespace Q_DECLARE_METATYPE(BlackMisc::Aviation::CTrack) diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 1246b2cee..ca216096f 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -17,7 +17,6 @@ namespace BlackMisc { // Virtual operators: http://stackoverflow.com/a/4571634/356726 class CBaseStreamStringifier { - /*! * \brief Stream << overload to be used in debugging messages * \param debug @@ -30,9 +29,6 @@ class CBaseStreamStringifier return debug; } - // msvc2010: friend QDebug &operator<<(QDebug &debug, const CBaseStreamStringifier &uc) - // MinGW: No reference - /*! * \brief Operator << based on text stream * \param textStream @@ -98,7 +94,8 @@ class CBaseStreamStringifier * \param uc * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CBaseStreamStringifier &uc) { + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CBaseStreamStringifier &uc) + { argument.beginStructure(); uc.unmarshallFromDbus(argument); argument.endStructure(); @@ -120,7 +117,6 @@ class CBaseStreamStringifier } public: - /*! * \brief Virtual destructor */ @@ -129,7 +125,6 @@ public: /*! * \brief Cast as QString * \bool i18n - * \remarks operator cast caused too many ambiguity trouble */ QString toQString(bool i18n = false) const { @@ -173,12 +168,11 @@ protected: /*! * \brief Copy assignment operator. - * This is protected in order to forbid slicing an instance of one derived - * class into an instance of a completely unrelated derived class. + * \remark This is protected in order to forbid slicing an instance of one derived + * class into an instance of a completely unrelated derived class. * \return */ CBaseStreamStringifier& operator=(const CBaseStreamStringifier&) { return *this; } - }; } // namespace diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 9d21ea7a4..70020caa3 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -10,17 +10,15 @@ */ void BlackMisc::PhysicalQuantities::registerMetadata() { - { - CAcceleration::registerMetadata(); - CAngle::registerMetadata(); - CFrequency::registerMetadata(); - CLength::registerMetadata(); - CMass::registerMetadata(); - CPressure::registerMetadata(); - CSpeed::registerMetadata(); - CTemperature::registerMetadata(); - CTime::registerMetadata(); - } + CAcceleration::registerMetadata(); + CAngle::registerMetadata(); + CFrequency::registerMetadata(); + CLength::registerMetadata(); + CMass::registerMetadata(); + CPressure::registerMetadata(); + CSpeed::registerMetadata(); + CTemperature::registerMetadata(); + CTime::registerMetadata(); } /* @@ -32,7 +30,6 @@ void BlackMisc::Aviation::registerMetadata() CNavSystem::registerMetadata(); CAdfSystem::registerMetadata(); CAltitude::registerMetadata(); - CAviationVerticalPositions::registerMetadata(); CTransponder::registerMetadata(); CHeading::registerMetadata(); CTrack::registerMetadata(); diff --git a/src/blackmisc/coordinateecef.h b/src/blackmisc/coordinateecef.h index 42695a483..e660b72ef 100644 --- a/src/blackmisc/coordinateecef.h +++ b/src/blackmisc/coordinateecef.h @@ -11,6 +11,7 @@ namespace BlackMisc { namespace Geo { + /*! * \brief Earth centered, earth fixed position */ @@ -112,11 +113,11 @@ protected: arg(QString::number(this->z(), 'f', 6)); return s; } - }; } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateEcef) #endif // guard diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp index 363dd370d..10f64507c 100644 --- a/src/blackmisc/coordinategeodetic.cpp +++ b/src/blackmisc/coordinategeodetic.cpp @@ -22,7 +22,8 @@ QString CCoordinateGeodetic::convertToQString(bool i18n) const /* * Marshall to Dbus */ -void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const { +void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const +{ argument << this->m_latitude; argument << this->m_longitude; argument << this->m_height; @@ -31,7 +32,8 @@ void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const { /* * Unmarshall from Dbus */ -void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument) { +void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument) +{ argument >> this->m_latitude; argument >> this->m_longitude; argument >> this->m_height; diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 7af0596c1..7f7ef9681 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -39,14 +39,12 @@ class ICoordinateGeodetic */ class CCoordinateGeodetic : public CBaseStreamStringifier, public ICoordinateGeodetic { - private: BlackMisc::Geo::CLatitude m_latitude; //!< Latitude BlackMisc::Geo::CLongitude m_longitude; //!< Longitude BlackMisc::PhysicalQuantities::CLength m_height; //!< height protected: - /*! * \brief String for converter * \param i18n @@ -132,7 +130,7 @@ public: { this->m_latitude.switchUnit(unit); this->m_longitude.switchUnit(unit); - return (*this); + return *this; } /*! @@ -143,14 +141,14 @@ public: CCoordinateGeodetic &switchUnit(const BlackMisc::PhysicalQuantities::CLengthUnit &unit) { this->m_height.switchUnit(unit); - return (*this); + return *this; } /*! * \brief Set latitude * \param latitude */ - void setLatitude(CLatitude latitude) + void setLatitude(const CLatitude &latitude) { this->m_latitude = latitude; } @@ -159,7 +157,7 @@ public: * \brief Set longitude * \param longitude */ - void setLongitude(CLongitude longitude) + void setLongitude(const CLongitude &longitude) { this->m_longitude = longitude; } @@ -168,58 +166,57 @@ public: * \brief Set height * \param height */ - void setHeight(BlackMisc::PhysicalQuantities::CLength height) + void setHeight(const BlackMisc::PhysicalQuantities::CLength &height) { this->m_height = height; } /*! * \brief Equal operator == - * \param otherGeodetic + * \param other * \return */ - bool operator ==(const CCoordinateGeodetic &otherGeodetic) const + bool operator ==(const CCoordinateGeodetic &other) const { - if (this == &otherGeodetic) return true; - return this->m_height == otherGeodetic.m_height && - this->m_latitude == otherGeodetic.m_latitude && - this->m_longitude == otherGeodetic.m_longitude; + if (this == &other) return true; + return this->m_height == other.m_height && + this->m_latitude == other.m_latitude && + this->m_longitude == other.m_longitude; } /*! * \brief Unequal operator != - * \param otherGeodetic + * \param other * \return */ - bool operator !=(const CCoordinateGeodetic &otherGeodetic) const + bool operator !=(const CCoordinateGeodetic &other) const { - if (this == &otherGeodetic) return false; - return !((*this) == otherGeodetic); + return !((*this) == other); } /*! * \brief Assigment operator = - * \param otherGeodetic + * \param other * \return */ - CCoordinateGeodetic &operator =(const CCoordinateGeodetic &otherGeodetic) + CCoordinateGeodetic &operator =(const CCoordinateGeodetic &other) { - if (this == &otherGeodetic) return *this; // Same object? - this->m_height = otherGeodetic.m_height; - this->m_latitude = otherGeodetic.m_latitude; - this->m_longitude = otherGeodetic.m_longitude; - return (*this); + if (this == &other) return *this; + this->m_height = other.m_height; + this->m_latitude = other.m_latitude; + this->m_longitude = other.m_longitude; + return *this; } /* * Register metadata */ static void registerMetadata(); - }; } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic) #endif // guard diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index 00972ec7c..57fdd9f85 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -18,7 +18,6 @@ namespace Geo */ class CCoordinateNed : public BlackMisc::Math::CVector3DBase { - private: CCoordinateGeodetic m_referencePosition; //!< geodetic reference position bool m_hasReferencePosition; //!< valid reference position? @@ -70,58 +69,57 @@ public: * \brief Copy constructor * \param otherNed */ - CCoordinateNed(const CCoordinateNed &otherNed) : - CVector3DBase(otherNed), m_referencePosition(otherNed.m_referencePosition), m_hasReferencePosition(otherNed.m_hasReferencePosition) {} + CCoordinateNed(const CCoordinateNed &other) : + CVector3DBase(other), m_referencePosition(other.m_referencePosition), m_hasReferencePosition(other.m_hasReferencePosition) {} /*! * \brief Constructor by math vector * \param vector */ - explicit CCoordinateNed(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {} + explicit CCoordinateNed(const BlackMisc::Math::CVector3D &vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {} /*! * \brief Constructor by math vector and reference position * \param referencePosition * \param vector */ - CCoordinateNed(const CCoordinateGeodetic &referencePosition, const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(referencePosition), m_hasReferencePosition(true) {} + CCoordinateNed(const CCoordinateGeodetic &referencePosition, const BlackMisc::Math::CVector3D &vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(referencePosition), m_hasReferencePosition(true) {} /*! * \brief Equal operator == - * \param otherNed + * \param other * \return */ - bool operator ==(const CCoordinateNed &otherNed) const + bool operator ==(const CCoordinateNed &other) const { - if (this == &otherNed) return true; - return this->m_hasReferencePosition == otherNed.m_hasReferencePosition && - this->m_referencePosition == otherNed.m_referencePosition && - CVector3DBase::operator== (otherNed); + if (this == &other) return true; + return this->m_hasReferencePosition == other.m_hasReferencePosition && + this->m_referencePosition == other.m_referencePosition && + this->CVector3DBase::operator== (other); } /*! * \brief Unequal operator != - * \param otherNed + * \param other * \return */ - bool operator !=(const CCoordinateNed &otherNed) const + bool operator !=(const CCoordinateNed &other) const { - if (this == &otherNed) return false; - return !((*this) == otherNed); + return !((*this) == other); } /*! * \brief Assigment operator = - * \param otherNed + * \param other * \return */ - CCoordinateNed &operator =(const CCoordinateNed &otherNed) + CCoordinateNed &operator =(const CCoordinateNed &other) { - if (this == &otherNed) return *this; // Same object? - CVector3DBase::operator = (otherNed); - this->m_hasReferencePosition = otherNed.m_hasReferencePosition; - this->m_referencePosition = otherNed.m_referencePosition; - return (*this); + if (this == &other) return *this; + this->CVector3DBase::operator = (other); + this->m_hasReferencePosition = other.m_hasReferencePosition; + this->m_referencePosition = other.m_referencePosition; + return *this; } /*! @@ -218,6 +216,7 @@ public: } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateNed) #endif // guard diff --git a/src/blackmisc/coordinatetransformation.h b/src/blackmisc/coordinatetransformation.h index b4e9a62e3..519eb586b 100644 --- a/src/blackmisc/coordinatetransformation.h +++ b/src/blackmisc/coordinatetransformation.h @@ -91,9 +91,9 @@ private: } /*! - * \brief Default constructor, avoid object instantiation + * \brief Default constructor, deleted */ - CCoordinateTransformation() {} + CCoordinateTransformation(); public: /*! @@ -124,7 +124,6 @@ public: * \return */ static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef); - }; } // namespace diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 29e93cd1e..54c74a021 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -22,7 +22,8 @@ template class CEarthAngle : public BlackMisc::PhysicalQuantiti * \param uc * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, LATorLON &uc) { + friend const QDBusArgument &operator>>(const QDBusArgument &argument, LATorLON &uc) + { // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the @@ -53,20 +54,20 @@ protected: * \brief Copy constructor * \param latOrLon */ - CEarthAngle(const LATorLON &latOrLon) : CAngle(latOrLon) { } + CEarthAngle(const LATorLON &latOrLon) : CAngle(latOrLon) {} /*! * \brief Init by double value * \param value * \param unit */ - CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CAngle(value, unit) {} + CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit) {} /*! * \brief Init by double value * \param angle */ - CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle): CAngle(angle) {} + CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle) : CAngle(angle) {} /*! * \brief String for converter and streaming @@ -81,16 +82,18 @@ protected: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { - CAngle::marshallToDbus(argument); + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); } /*! * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { - CAngle::unmarshallFromDbus(argument); + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); } public: @@ -106,7 +109,7 @@ public: */ bool operator==(const LATorLON &latOrLon) const { - return CAngle::operator ==(latOrLon); + return this->CAngle::operator ==(latOrLon); } /*! @@ -116,7 +119,7 @@ public: */ bool operator!=(const LATorLON &latOrLon) const { - return CAngle::operator !=(latOrLon); + return this->CAngle::operator !=(latOrLon); } /*! @@ -126,8 +129,8 @@ public: */ CEarthAngle &operator +=(const CEarthAngle &latOrLon) { - CAngle::operator +=(latOrLon); - return (*this); + this->CAngle::operator +=(latOrLon); + return *this; } /*! @@ -137,8 +140,8 @@ public: */ CEarthAngle &operator -=(const CEarthAngle &latOrLon) { - CAngle::operator -=(latOrLon); - return (*this); + this->CAngle::operator -=(latOrLon); + return *this; } /*! @@ -148,7 +151,7 @@ public: */ bool operator >(const LATorLON &latOrLon) const { - return CAngle::operator >(latOrLon); + return this->CAngle::operator >(latOrLon); } /*! @@ -158,7 +161,7 @@ public: */ bool operator <(const LATorLON &latOrLon) const { - return CAngle::operator >(latOrLon); + return this->CAngle::operator >(latOrLon); } /*! @@ -168,7 +171,7 @@ public: */ bool operator <=(const LATorLON &latOrLon) const { - return CAngle::operator <=(latOrLon); + return this->CAngle::operator <=(latOrLon); } /*! @@ -178,7 +181,7 @@ public: */ bool operator >=(const LATorLON &latOrLon) const { - return CAngle::operator >=(latOrLon); + return this->CAngle::operator >=(latOrLon); } /*! @@ -188,8 +191,8 @@ public: */ CEarthAngle &operator =(const LATorLON &latOrLon) { - CAngle::operator =(latOrLon); - return (*this); + this->CAngle::operator =(latOrLon); + return *this; } /*! @@ -199,8 +202,7 @@ public: */ LATorLON operator +(const LATorLON &latOrLon) const { - LATorLON l(0.0, this->getUnit()); - l += (*this); + LATorLON l(*this); l += latOrLon; return l; } @@ -212,8 +214,7 @@ public: */ LATorLON operator -(const LATorLON &latOrLon) const { - LATorLON l(0.0, this->getUnit()); - l += (*this); + LATorLON l(*this); l -= latOrLon; return l; } @@ -229,7 +230,6 @@ public: * \return */ static LATorLON fromWgs84(const QString &wgsCoordinate); - }; } // namespace diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index d4f7ac644..781a8b599 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -33,9 +33,9 @@ public: /*! * \brief Copy constructor - * \param latitude + * \param other */ - CLatitude(const CLatitude &latitude) : CEarthAngle(latitude) {} + CLatitude(const CLatitude &other) : CEarthAngle(other) {} /*! * \brief Constructor @@ -48,13 +48,12 @@ public: * \param value * \param unit */ - CLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CEarthAngle(value, unit) {} + CLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {} /*! * \brief Virtual destructor */ virtual ~CLatitude() {} - }; } // namespace diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 884e3913c..a851be10c 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -30,9 +30,9 @@ public: /*! * \brief Copy constructor - * \param Longitude + * \param other */ - CLongitude(const CLongitude &Longitude) : CEarthAngle(Longitude) {} + CLongitude(const CLongitude &other) : CEarthAngle(other) {} /*! * \brief Constructor @@ -45,7 +45,7 @@ public: * \param value * \param unit */ - CLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CEarthAngle(value, unit) {} + CLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {} /*! * \brief Virtual destructor diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index e97a72382..f49241513 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -102,9 +102,9 @@ public: private: /*! - * \brief Avoid object init + * \brief Deleted */ - CMath() {} + CMath(); }; } // namespace diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h index 0daeea83b..430307397 100644 --- a/src/blackmisc/mathmatrix1x3.h +++ b/src/blackmisc/mathmatrix1x3.h @@ -21,15 +21,15 @@ class CMatrix1x3 : public CMatrixBase { public: /*! - * \brief Matrix 1x3 + * \brief Constructor */ CMatrix1x3() : CMatrixBase() {} /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix1x3(const CMatrix1x3 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -38,7 +38,7 @@ public: explicit CMatrix1x3(double fillValue) : CMatrixBase(fillValue) {} /*! - * \brief CMatrix 3x1 + * \brief Constructor * \param c1 * \param c2 * \param c3 @@ -52,8 +52,8 @@ public: }; } // namespace - } // namespace + Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix1x3) #endif // guard diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h index e26b82810..81078618a 100644 --- a/src/blackmisc/mathmatrix3x1.h +++ b/src/blackmisc/mathmatrix3x1.h @@ -23,17 +23,17 @@ class CMatrix3x1 : public CMatrixBase public: /*! - * \brief CMatrix 3x1 + * \brief Constructor */ CMatrix3x1() : CMatrixBase() {} /*! - * \brief CMatrix 3x1 + * \brief Constructor * \param r1 * \param r2 * \param r3 */ - CMatrix3x1(qreal r1, qreal r2, qreal r3) : CMatrixBase() + CMatrix3x1(double r1, double r2, double r3) : CMatrixBase() { this->m_matrix(0, 0) = r1; this->m_matrix(1, 0) = r2; @@ -44,7 +44,7 @@ public: * \brief Copy constructor * \param otherMatrix */ - CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix3x1(const CMatrix3x1 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -74,8 +74,8 @@ public: }; } // namespace - } // namespace + Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x1) #endif // guard diff --git a/src/blackmisc/mathmatrix3x3.cpp b/src/blackmisc/mathmatrix3x3.cpp index 7ef0e6905..21185d857 100644 --- a/src/blackmisc/mathmatrix3x3.cpp +++ b/src/blackmisc/mathmatrix3x3.cpp @@ -15,27 +15,25 @@ namespace Math */ double CMatrix3x3::determinant() const { - double determinant = + return this->m_matrix(0, 0) * this->m_matrix(1, 1) * this->m_matrix(2, 2) + this->m_matrix(0, 1) * this->m_matrix(1, 2) * this->m_matrix(2, 0) + this->m_matrix(0, 2) * this->m_matrix(1, 0) * this->m_matrix(2, 1) - this->m_matrix(0, 1) * this->m_matrix(1, 0) * this->m_matrix(2, 2) - this->m_matrix(0, 2) * this->m_matrix(1, 1) * this->m_matrix(2, 0) - this->m_matrix(0, 0) * this->m_matrix(1, 2) * this->m_matrix(2, 1); - - return determinant; } /* * Inverse */ -CMatrix3x3 CMatrix3x3::inverse(bool &invertible) const +CMatrix3x3 CMatrix3x3::inverse(bool &o_invertible) const { CMatrix3x3 inverse; double det; - if (this->allValuesEqual() || (det = determinant()) == 0) + if (this->allValuesEqual() || (det = this->determinant()) == 0) { - invertible = false; + o_invertible = false; inverse.setZero(); return inverse; } @@ -51,7 +49,7 @@ CMatrix3x3 CMatrix3x3::inverse(bool &invertible) const inverse.m_matrix(2, 1) = (- this->m_matrix(0, 0) * this->m_matrix(2, 1) + this->m_matrix(0, 1) * this->m_matrix(2, 0)) * invdet; inverse.m_matrix(2, 2) = (this->m_matrix(0, 0) * this->m_matrix(1, 1) - this->m_matrix(0, 1) * this->m_matrix(1, 0)) * invdet; - invertible = true; + o_invertible = true; return inverse; } @@ -78,5 +76,4 @@ CMatrix3x1 CMatrix3x3::getColumn(int column) const } } // namespace - } // namespace diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index b4da2c090..44e9c5b31 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -27,9 +27,9 @@ public: /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix3x3(const CMatrix3x3 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -72,43 +72,43 @@ public: /*! * \brief Calculate the inverse - * \param invertible + * \param[out] o_isInvertible * \return */ - CMatrix3x3 inverse(bool &invertible) const; + CMatrix3x3 inverse(bool &o_isInvertible) const; /*! * \brief Operator *= - * \param otherMatrix + * \param other * \return */ - CMatrix3x3 &operator *=(const CMatrix3x3 &otherMatrix) + CMatrix3x3 &operator *=(const CMatrix3x3 &other) { - this->m_matrix = this->m_matrix * otherMatrix.m_matrix; - return (*this); + this->m_matrix = this->m_matrix * other.m_matrix; + return *this; } /*! * \brief Operator * - * \param otherMatrix + * \param other * \return */ - CMatrix3x1 operator *(const CMatrix3x1 &otherMatrix) const + CMatrix3x1 operator *(const CMatrix3x1 &other) const { CMatrix3x1 m; - m.m_matrix = this->m_matrix * otherMatrix.m_matrix; + m.m_matrix = this->m_matrix * other.m_matrix; return m; } /*! * \brief Operator * - * \param otherMatrix + * \param other * \return */ - CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const + CMatrix3x3 operator *(const CMatrix3x3 &other) const { CMatrix3x3 m(*this); - m *= otherMatrix; + m *= other; return m; } @@ -144,7 +144,7 @@ public: CMatrix3x3 &operator *=(double factor) { CMatrixBase::operator *=(factor); - return (*this); + return *this; } /*! @@ -175,8 +175,8 @@ public: }; } // namespace - } // namespace + Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x3) #endif // guard diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index b00c1f9de..e2113a91b 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -34,7 +34,6 @@ template void CMatrixBase void CMatrixBase::checkRange(size_t row, size_t column) const { - // no >=0 comparison since unsinged comparison always >=0 bool valid = (row < Rows && column < Columns); Q_ASSERT_X(valid, "getElement()", "Row or column invalid"); if (!valid) throw std::range_error("Row or column invalid"); @@ -149,7 +148,7 @@ template void CMatrixBase QString CMatrixBase::convertToQString(bool /** i18n **/) const +template QString CMatrixBase::convertToQString(bool /* i18n */) const { QString s = "{"; for (int r = 0; r < Rows; r++) @@ -176,7 +175,6 @@ template void CMatrixBase(); } - // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CMatrixBase; @@ -184,8 +182,4 @@ template class CMatrixBase; template class CMatrixBase; } // namespace - } // namespace - -#include "mathmatrixbase.h" - diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index a2090e5c0..7b6897f69 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -55,7 +55,8 @@ protected: * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { + virtual void marshallToDbus(QDBusArgument &argument) const + { const QList l = this->toList(); // there is an issue with the signature of QList, so I use @@ -69,7 +70,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QList list; double v; while(!argument.atEnd()) { @@ -87,9 +89,9 @@ public: /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {} + CMatrixBase(const CMatrixBase &other) : m_matrix(other.m_matrix) {} /*! * \brief Fill with value @@ -119,36 +121,35 @@ public: /*! * \brief Equal operator == - * \param otherMatrix + * \param other * \return */ - bool operator ==(const ImplMatrix &otherMatrix) const + bool operator ==(const ImplMatrix &other) const { - if (this == &otherMatrix) return true; - return this->m_matrix == otherMatrix.m_matrix; + if (this == &other) return true; + return this->m_matrix == other.m_matrix; } /*! * \brief Unequal operator != - * \param otherMatrix + * \param other * \return */ - bool operator !=(const ImplMatrix &otherMatrix) const + bool operator !=(const ImplMatrix &other) const { - if (this == &otherMatrix) return false; - return !((*this) == otherMatrix); + return !((*this) == other); } /*! * \brief Assigment operator = - * \param otherMatrix + * \param other * \return */ - CMatrixBase &operator =(const CMatrixBase &otherMatrix) + CMatrixBase &operator =(const CMatrixBase &other) { - if (this == &otherMatrix) return *this; // Same object? - this->m_matrix = otherMatrix.m_matrix; - return (*this); + if (this == &other) return *this; + this->m_matrix = other.m_matrix; + return *this; } /*! @@ -159,7 +160,7 @@ public: CMatrixBase &operator *=(double factor) { this->m_matrix *= factor; - return (*this); + return *this; } /*! @@ -177,12 +178,12 @@ public: /*! * \brief Operator to support commutative multiplication * \param factor - * \param otherMatrix + * \param other * \return */ - friend ImplMatrix operator *(double factor, const ImplMatrix &otherMatrix) + friend ImplMatrix operator *(double factor, const ImplMatrix &other) { - return otherMatrix * factor; + return other * factor; } /*! @@ -200,7 +201,7 @@ public: CMatrixBase &operator /=(double factor) { this->m_matrix /= factor; - return (*this); + return *this; } /*! @@ -217,47 +218,47 @@ public: /*! * \brief Operator += - * \param otherMatrix + * \param other * \return */ - CMatrixBase &operator +=(const CMatrixBase &otherMatrix) + CMatrixBase &operator +=(const CMatrixBase &other) { - this->m_matrix += otherMatrix.m_matrix; - return (*this); + this->m_matrix += other.m_matrix; + return *this; } /*! * \brief Operator + - * \param otherMatrix + * \param other * \return */ - ImplMatrix operator +(const ImplMatrix &otherMatrix) const + ImplMatrix operator +(const ImplMatrix &other) const { ImplMatrix m = *derived(); - m += otherMatrix; + m += other; return m; } /*! * \brief Operator -= - * \param otherMatrix + * \param other * \return */ - CMatrixBase &operator -=(const CMatrixBase &otherMatrix) + CMatrixBase &operator -=(const CMatrixBase &other) { - this->m_matrix -= otherMatrix.m_matrix; - return (*this); + this->m_matrix -= other.m_matrix; + return *this; } /*! * \brief Operator - - * \param otherMatrix + * \param other * \return */ - ImplMatrix operator -(const ImplMatrix &otherMatrix) const + ImplMatrix operator -(const ImplMatrix &other) const { ImplMatrix m = *derived(); - m -= otherMatrix; + m -= other; return m; } @@ -402,11 +403,9 @@ private: * \throws std::range_error if index out of bounds */ void checkRange(size_t row, size_t column) const; - }; } // namespace - } // namespace #endif // guard diff --git a/src/blackmisc/mathvector3d.h b/src/blackmisc/mathvector3d.h index 26a03cd37..dd8520bd0 100644 --- a/src/blackmisc/mathvector3d.h +++ b/src/blackmisc/mathvector3d.h @@ -35,9 +35,9 @@ public: /*! * \brief Copy constructor - * \param otherVector + * \param other */ - CVector3D(const CVector3D &otherVector) : CVector3DBase(otherVector) {} + CVector3D(const CVector3D &other) : CVector3DBase(other) {} /*! * \brief i @@ -97,6 +97,7 @@ public: } // namespace } // namespace + Q_DECLARE_METATYPE(BlackMisc::Math::CVector3D) #endif // guard diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index 8c07decb3..0e3df39f3 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -16,7 +16,7 @@ namespace Math /* * Convert to string */ -template QString CVector3DBase::convertToQString(bool /** i18n **/) const +template QString CVector3DBase::convertToQString(bool /* i18n */) const { QString s = ("{%1, %2, %3}"); s = s.arg(QString::number(this->m_i, 'f')). @@ -94,21 +94,21 @@ template void CVector3DBase::setElement(size_t ro /* * Cross product */ -template ImplVector CVector3DBase::crossProduct(const ImplVector &otherVector) const +template ImplVector CVector3DBase::crossProduct(const ImplVector &other) const { - ImplVector v(otherVector); - v.m_i = this->m_j * otherVector.m_k - this->m_k * otherVector.m_j; - v.m_j = this->m_k * otherVector.m_i - this->m_i * otherVector.m_k; - v.m_k = this->m_i * otherVector.m_j - this->m_j * otherVector.m_i; + ImplVector v(other); + v.m_i = this->m_j * other.m_k - this->m_k * other.m_j; + v.m_j = this->m_k * other.m_i - this->m_i * other.m_k; + v.m_k = this->m_i * other.m_j - this->m_j * other.m_i; return v; } /* * Cross product */ -template double CVector3DBase::dotProduct(const ImplVector &otherVector) const +template double CVector3DBase::dotProduct(const ImplVector &other) const { - return this->m_i * otherVector.m_i + this->m_j * otherVector.m_j + this->m_k * otherVector.m_k; + return this->m_i * other.m_i + this->m_j * other.m_j + this->m_k * other.m_k; } @@ -117,7 +117,7 @@ template double CVector3DBase::dotProduct(const I */ template void CVector3DBase::matrixMultiplication(const CMatrix3x3 &matrix) { - CMatrix3x1 m = matrix * (this->toMatrix3x1()); + CMatrix3x1 m = matrix * this->toMatrix3x1(); this->m_i = m(0, 0); this->m_j = m(1, 0); this->m_k = m(2, 0); @@ -136,7 +136,8 @@ template CMatrix3x1 CVector3DBase::toMatrix3x1() * \brief Stream to DBus * \param argument */ -template void CVector3DBase::marshallToDbus(QDBusArgument &argument) const { +template void CVector3DBase::marshallToDbus(QDBusArgument &argument) const +{ argument << this->m_i; argument << this->m_j; argument << this->m_k; @@ -146,7 +147,8 @@ template void CVector3DBase::marshallToDbus(QDBus * \brief Stream from DBus * \param argument */ -template void CVector3DBase::unmarshallFromDbus(const QDBusArgument &argument) { +template void CVector3DBase::unmarshallFromDbus(const QDBusArgument &argument) +{ argument >> this->m_i; argument >> this->m_j; argument >> this->m_k; @@ -168,5 +170,4 @@ template class CVector3DBase; template class CVector3DBase; } // namespace - } // namespace diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index aae74f5f4..7bd0fdc0e 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -23,14 +23,14 @@ class CMatrix3x1; // forward declaration */ template class CVector3DBase : public CBaseStreamStringifier { - /*! * \brief Unmarshalling operator >>, DBus to object * \param argument * \param uc * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, ImplVector &uc) { + friend const QDBusArgument &operator>>(const QDBusArgument &argument, ImplVector &uc) + { // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the @@ -71,7 +71,6 @@ private: } protected: - // using own value since Qt QVector3D stores internally as float double m_i; //!< Vector data i double m_j; //!< Vector data j @@ -98,9 +97,9 @@ protected: /*! * \brief Copy constructor - * \param otherVector + * \param other */ - CVector3DBase(const CVector3DBase &otherVector) : m_i(otherVector.m_i), m_j(otherVector.m_j), m_k(otherVector.m_k) {} + CVector3DBase(const CVector3DBase &other) : m_i(other.m_i), m_j(other.m_j), m_k(other.m_k) {} /*! * \brief String for converter @@ -122,7 +121,6 @@ protected: virtual void marshallToDbus(QDBusArgument &argument) const; public: - // getter and setters are implemented in the derived classes // as they have different names (x, i, north) @@ -137,7 +135,7 @@ public: void setZero(); /*! - * \brief Set zeros + * \brief Is zero */ bool isZero() const { @@ -151,7 +149,7 @@ public: bool isZeroEpsilon() const { ImplVector v; - v += (*this); + v += *this; v.round(); return v.isZero(); } @@ -182,124 +180,115 @@ public: */ double operator[](size_t row) const { return this->getElement(row); } - - /*! - * \brief Get row element by () - * \param row - * \return - */ - double operator()(size_t row) const { return this->getElement(row); } - /*! * \brief Equal operator == - * \param otherVector + * \param other * \return */ - bool operator ==(const CVector3DBase &otherVector) const + bool operator ==(const CVector3DBase &other) const { - if (this == &otherVector) return true; - return this->m_i == otherVector.m_i && - this->m_j == otherVector.m_j && - this->m_k == otherVector.m_k; + if (this == &other) return true; + return this->m_i == other.m_i && + this->m_j == other.m_j && + this->m_k == other.m_k; } /*! * \brief Unequal operator != - * \param otherVector + * \param other * \return */ - bool operator !=(const CVector3DBase &otherVector) const + bool operator !=(const CVector3DBase &other) const { - if (this == &otherVector) return false; - return !((*this) == otherVector); + return !((*this) == other); } /*! * \brief Assigment operator = - * \param otherVector + * \param other * \return */ - CVector3DBase &operator =(const CVector3DBase &otherVector) + CVector3DBase &operator =(const CVector3DBase &other) { - if (this == &otherVector) return *this; // Same object? - this->m_i = otherVector.m_i; - this->m_j = otherVector.m_j; - this->m_k = otherVector.m_k; - return (*this); + if (this == &other) return *this; + this->m_i = other.m_i; + this->m_j = other.m_j; + this->m_k = other.m_k; + return *this; } /*! * \brief Operator += - * \param otherVector + * \param other * \return */ - CVector3DBase &operator +=(const CVector3DBase &otherVector) + CVector3DBase &operator +=(const CVector3DBase &other) { - this->m_i += otherVector.m_i; - this->m_j += otherVector.m_j; - this->m_k += otherVector.m_k; - return (*this); + this->m_i += other.m_i; + this->m_j += other.m_j; + this->m_k += other.m_k; + return *this; } /*! * \brief Operator + - * \param otherVector + * \param other * \return */ - ImplVector operator +(const ImplVector &otherVector) const + ImplVector operator +(const ImplVector &other) const { ImplVector v = *derived(); - v += otherVector; + v += other; return v; } /*! * \brief Operator -= - * \param otherVector + * \param other * \return */ - CVector3DBase &operator -=(const CVector3DBase &otherVector) + CVector3DBase &operator -=(const CVector3DBase &other) { - this->m_i -= otherVector.m_i; - this->m_j -= otherVector.m_j; - this->m_k -= otherVector.m_k; - return (*this); + this->m_i -= other.m_i; + this->m_j -= other.m_j; + this->m_k -= other.m_k; + return *this; } /*! * \brief Operator - - * \param otherVector + * \param other * \return */ - ImplVector operator -(const ImplVector &otherVector) const + ImplVector operator -(const ImplVector &other) const { ImplVector v = *derived(); - v -= otherVector; + v -= other; return v; } /*! * \brief Operator *=, just x*x, y*y, z*z neither vector nor dot product (like a matrix produc) - * \param otherVector + * \param other * \return */ - CVector3DBase &operator *=(const CVector3DBase &otherVector) + CVector3DBase &operator *=(const CVector3DBase &other) { - this->m_i *= otherVector.m_i; - this->m_j *= otherVector.m_j; - this->m_k *= otherVector.m_k; - return (*this); + this->m_i *= other.m_i; + this->m_j *= other.m_j; + this->m_k *= other.m_k; + return *this; } /*! * \brief Operator, just x*x, y*y, z*z neither vector nor dot product, (like a matrix produc) - * \param otherVector + * \param other * \return */ - ImplVector operator *(const ImplVector &otherVector) const + ImplVector operator *(const ImplVector &other) const { ImplVector v = *derived(); - v *= otherVector; + v *= other; return v; } @@ -313,7 +302,7 @@ public: this->m_i *= factor; this->m_j *= factor; this->m_k *= factor; - return (*this); + return *this; } /*! @@ -334,9 +323,9 @@ public: * \param otherVector * \return */ - friend ImplVector operator *(double factor, const ImplVector &otherVector) + friend ImplVector operator *(double factor, const ImplVector &other) { - return otherVector * factor; + return other * factor; } /*! @@ -349,7 +338,7 @@ public: this->m_i /= divisor; this->m_j /= divisor; this->m_k /= divisor; - return (*this); + return *this; } /*! @@ -366,42 +355,42 @@ public: /*! * \brief Operator /=, just x/x, y/y, z/z - * \param otherVector + * \param other * \return */ - CVector3DBase &operator /=(const CVector3DBase &otherVector) + CVector3DBase &operator /=(const CVector3DBase &other) { - this->m_i /= otherVector.m_i; - this->m_j /= otherVector.m_j; - this->m_k /= otherVector.m_k; - return (*this); + this->m_i /= other.m_i; + this->m_j /= other.m_j; + this->m_k /= other.m_k; + return *this; } /*! * \brief Operator, just x/x, y/y, z/z - * \param otherVector + * \param other * \return */ - ImplVector operator /(const ImplVector &otherVector) const + ImplVector operator /(const ImplVector &other) const { ImplVector v = *derived(); - v /= otherVector; + v /= other; return v; } /*! * \brief Dot product - * \param otherVector + * \param other * \return */ - double dotProduct(const ImplVector &otherVector) const; + double dotProduct(const ImplVector &other) const; /*! * \brief Cross product - * \param otherVector + * \param other * \return */ - ImplVector crossProduct(const ImplVector &otherVector) const; + ImplVector crossProduct(const ImplVector &other) const; /*! * \brief Matrix * this vector @@ -450,7 +439,7 @@ public: * \brief Rounded vector * \return */ - ImplVector roundedVector() const + ImplVector rounded() const { ImplVector v = *derived(); v.round(); @@ -464,7 +453,6 @@ public: }; } // namespace - } // namespace #endif // guard diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 1a8c4bba4..449c2aec9 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -38,16 +38,17 @@ public: CAcceleration(double value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} /*! - * \brief Copy constructor - * \param acceleration + * \brief Copy constructor by base type + * \param base */ - CAcceleration(const CPhysicalQuantity &acceleration) : CPhysicalQuantity(acceleration) {} + CAcceleration(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} /*! * \brief Virtual destructor */ virtual ~CAcceleration() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 4cd63098a..de0bd6517 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -12,6 +12,7 @@ namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief Physical unit angle (radians, degrees) */ @@ -24,9 +25,9 @@ public: CAngle() : CPhysicalQuantity(0, CAngleUnit::rad(), CAngleUnit::rad()) {} /*! - * \brief Copy constructor + * \brief Copy constructor from base type */ - CAngle(const CAngle &angle) : CPhysicalQuantity(angle) {} + CAngle(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} /*! * \brief Init by int value @@ -51,9 +52,7 @@ public: CAngle(qint32 degrees, qint32 minutes, double seconds) : CPhysicalQuantity( degrees + minutes / 100.0 + seconds / 10000.0, - CAngleUnit::sexagesimalDeg(), CAngleUnit::rad()) { - // void - } + CAngleUnit::sexagesimalDeg(), CAngleUnit::rad()) {} /*! * \brief Virtual destructor diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 774e268df..47a916f98 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -20,65 +20,62 @@ namespace PhysicalQuantities /* * Constructor */ -CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitName, double factor): +CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitName, double factor) : m_name(name), m_prefix(unitName), m_factor(factor) { - // void } /* * Constructor */ -CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &otherMultiplier) : - m_name(otherMultiplier.m_name), m_prefix(otherMultiplier.m_prefix), m_factor(otherMultiplier.m_factor) +CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &other) : + m_name(other.m_name), m_prefix(other.m_prefix), m_factor(other.m_factor) { - // void } /* * Assignment operator */ -CMeasurementPrefix &CMeasurementPrefix::operator=(const CMeasurementPrefix &otherMultiplier) +CMeasurementPrefix &CMeasurementPrefix::operator=(const CMeasurementPrefix &other) { - - if (this == &otherMultiplier) return *this; // Same object? Yes, so skip assignment, and just return *this - this->m_name = otherMultiplier.m_name; - this->m_prefix = otherMultiplier.m_prefix; - this->m_factor = otherMultiplier.m_factor; + if (this == &other) return *this; + this->m_name = other.m_name; + this->m_prefix = other.m_prefix; + this->m_factor = other.m_factor; return *this; } /* * Equal? */ -bool CMeasurementPrefix::operator ==(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator ==(const CMeasurementPrefix &other) const { - if (this == &otherMultiplier) return true; - return this->m_factor == otherMultiplier.m_factor && this->m_name == otherMultiplier.m_name; + if (this == &other) return true; + return this->m_factor == other.m_factor && this->m_name == other.m_name; } /* * Not equal */ -bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const { - return !(*this == otherMultiplier); + return !(*this == other); } /* * Greater? */ -bool CMeasurementPrefix::operator >(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator >(const CMeasurementPrefix &other) const { - return this->m_factor > otherMultiplier.m_factor; + return this->m_factor > other.m_factor; } /* * Less? */ -bool CMeasurementPrefix::operator <(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator <(const CMeasurementPrefix &other) const { - return this->m_factor < otherMultiplier.m_factor; + return this->m_factor < other.m_factor; } // ----------------------------------------------------------------------- @@ -95,57 +92,55 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName, m_conversionFactorToSIConversionUnit(conversionFactorToSI), m_epsilon(epsilon), m_displayDigits(displayDigits), m_multiplier(multiplier), m_fromSiConverter(fromSiConverter), m_toSiConverter(toSiConverter) { - // void } /* * Copy constructor */ -CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &otherUnit): - m_name(otherUnit.m_name), m_unitName(otherUnit.m_unitName), m_type(otherUnit.m_type), m_isSiUnit(otherUnit.m_isSiUnit), - m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit), - m_epsilon(otherUnit.m_epsilon), m_displayDigits(otherUnit.m_displayDigits), m_multiplier(otherUnit.m_multiplier), m_fromSiConverter(otherUnit.m_fromSiConverter), m_toSiConverter(otherUnit.m_toSiConverter) +CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other): + m_name(other.m_name), m_unitName(other.m_unitName), m_type(other.m_type), m_isSiUnit(other.m_isSiUnit), + m_isSiBaseUnit(other.m_isSiBaseUnit), m_conversionFactorToSIConversionUnit(other.m_conversionFactorToSIConversionUnit), + m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_multiplier(other.m_multiplier), m_fromSiConverter(other.m_fromSiConverter), m_toSiConverter(other.m_toSiConverter) { - // void } /* * Assigment operator */ -CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &otherUnit) +CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &other) { - if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this - this->m_name = otherUnit.m_name; - this->m_unitName = otherUnit.m_unitName; - this->m_type = otherUnit.m_type; - this->m_isSiUnit = otherUnit.m_isSiUnit; - this->m_isSiBaseUnit = otherUnit.m_isSiBaseUnit; - this->m_conversionFactorToSIConversionUnit = otherUnit.m_conversionFactorToSIConversionUnit; - this->m_multiplier = otherUnit.m_multiplier; - this->m_displayDigits = otherUnit.m_displayDigits; - this->m_epsilon = otherUnit.m_epsilon; - this->m_fromSiConverter = otherUnit.m_fromSiConverter; - this->m_toSiConverter = otherUnit.m_toSiConverter; + if (this == &other) return *this; // Same object? Yes, so skip assignment, and just return *this + this->m_name = other.m_name; + this->m_unitName = other.m_unitName; + this->m_type = other.m_type; + this->m_isSiUnit = other.m_isSiUnit; + this->m_isSiBaseUnit = other.m_isSiBaseUnit; + this->m_conversionFactorToSIConversionUnit = other.m_conversionFactorToSIConversionUnit; + this->m_multiplier = other.m_multiplier; + this->m_displayDigits = other.m_displayDigits; + this->m_epsilon = other.m_epsilon; + this->m_fromSiConverter = other.m_fromSiConverter; + this->m_toSiConverter = other.m_toSiConverter; return *this; } /* * Equal operator */ -bool CMeasurementUnit::operator ==(const CMeasurementUnit &otherUnit) const +bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const { - if (this == &otherUnit) return true; - if (this->m_type != otherUnit.m_type) return false; - return this->m_multiplier == otherUnit.m_multiplier && this->m_name == otherUnit.m_name - && this->m_isSiUnit == otherUnit.m_isSiUnit; + if (this == &other) return true; + if (this->m_type != other.m_type) return false; + return this->m_multiplier == other.m_multiplier && this->m_name == other.m_name + && this->m_isSiUnit == other.m_isSiUnit; } /* * Unequal operator */ -bool CMeasurementUnit::operator !=(const CMeasurementUnit &otherUnit) const +bool CMeasurementUnit::operator !=(const CMeasurementUnit &other) const { - return !(otherUnit == *this); + return !(other == *this); } /* @@ -153,7 +148,7 @@ bool CMeasurementUnit::operator !=(const CMeasurementUnit &otherUnit) const */ double CMeasurementUnit::conversionToUnit(double value, const CMeasurementUnit &to) const { - if (to == (*this)) return value; + if (to == *this) return value; double siValue = this->convertToSiConversionUnit(value); return to.convertFromSiConversionUnit(siValue); } @@ -179,7 +174,7 @@ double CMeasurementUnit::valueRounded(double value, int digits) const /* * Rounded to QString */ -QString CMeasurementUnit::toQStringRounded(double value, int digits, bool /** i18n **/) const +QString CMeasurementUnit::toQStringRounded(double value, int digits, bool /* i18n */) const { if (digits < 0) digits = this->m_displayDigits; double v = CMath::round(value, digits); diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index cd3ffa643..462fd527c 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -31,6 +31,7 @@ private: QString m_name; //!< name, e.g. "kilo" QString m_prefix; //!< prefix, e.g. "k" for kilo double m_factor; //!< factor, e.g. 1000 for kilo 1/100 for centi + /*! * Constructor by parameters * \brief CMeasurementMultiplier @@ -46,7 +47,7 @@ protected: * \param i18n * \return */ - virtual QString convertToQString(bool /* i18n */ = false) const + virtual QString convertToQString(bool /* i18n */ = false) const { return this->m_name; } @@ -55,7 +56,8 @@ protected: * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { + virtual void marshallToDbus(QDBusArgument &argument) const + { argument << this->m_name; } @@ -63,7 +65,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString name; argument >> name; (*this) = CMeasurementPrefix::fromPrefixName(name); @@ -72,48 +75,44 @@ protected: public: /*! * \brief Copy constructor - * \param otherMultiplier + * \param other */ - CMeasurementPrefix(const CMeasurementPrefix &otherMultiplier); + CMeasurementPrefix(const CMeasurementPrefix &other); /*! * \brief Assigmnet operator = - * \param otherMultiplier + * \param other * \return */ - CMeasurementPrefix &operator =(const CMeasurementPrefix &otherMultiplier); + CMeasurementPrefix &operator =(const CMeasurementPrefix &other); /*! * \brief Equal operator == - * \param otherMultiplier + * \param other * \return */ - bool operator == (const CMeasurementPrefix &otherMultiplier) const; + bool operator == (const CMeasurementPrefix &other) const; /*! * \brief Unequal operator != - * \param otherMultiplier + * \param other * \return */ - bool operator != (const CMeasurementPrefix &otherMultiplier) const; + bool operator != (const CMeasurementPrefix &other) const; /*! * \brief Greater operator > - * \param otherMultiplier + * \param other * \return */ - bool operator > (const CMeasurementPrefix &otherMultiplier) const; + bool operator > (const CMeasurementPrefix &other) const; /*! * \brief Less operator < - * \param otherMultiplier + * \param other * \return */ - bool operator < (const CMeasurementPrefix &otherMultiplier) const; - - /*! - * \brief Cast as double - */ + bool operator < (const CMeasurementPrefix &other) const; /*! * \brief Factor, e.g.1000 for "kilo" @@ -243,7 +242,6 @@ public: return milli; } - /*! * \brief All prefixes * \return @@ -267,9 +265,9 @@ public: * \param prefixName must be valid! * \return */ - static const CMeasurementPrefix &fromPrefixName(const QString &prefixName) { - QList prefixes = CMeasurementPrefix::prefixes(); - // read only, avoid deep copy + static const CMeasurementPrefix &fromPrefixName(const QString &prefixName) + { + const QList &prefixes = CMeasurementPrefix::prefixes(); for (int i = 0; i < prefixes.size(); ++i) { if (prefixes.at(i).getName() == prefixName) return (prefixes.at(i)); } @@ -329,16 +327,16 @@ protected: /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CMeasurementUnit(const CMeasurementUnit &otherUnit); + CMeasurementUnit(const CMeasurementUnit &other); /*! * \brief Assignment operator = - * \param otherUnit + * \param other * \return */ - CMeasurementUnit &operator =(const CMeasurementUnit &otherUnit); + CMeasurementUnit &operator =(const CMeasurementUnit &other); /*! * \brief String for streaming operators is full name @@ -394,7 +392,8 @@ protected: * \brief Stream to DBus * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { + virtual void marshallToDbus(QDBusArgument &argument) const + { argument << this->m_unitName; } @@ -402,7 +401,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &) { + virtual void unmarshallFromDbus(const QDBusArgument &) + { // the concrete implementations will override this default // this is required so I can also stream None (*this) = CMeasurementUnit::None(); @@ -411,17 +411,17 @@ protected: public: /*! * \brief Equal operator == - * \param otherUnit + * \param other * \return */ - bool operator == (const CMeasurementUnit &otherUnit) const; + bool operator == (const CMeasurementUnit &other) const; /*! * \brief Unequal operator != - * \param otherUnit + * \param other * \return */ - bool operator != (const CMeasurementUnit &otherUnit) const; + bool operator != (const CMeasurementUnit &other) const; /*! * \brief Representing an SI unit? Examples: kilometer, meter, hertz @@ -455,7 +455,7 @@ public: * \param i18n * \return */ - QString getName(bool i18n=false) const + QString getName(bool i18n = false) const { return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; } @@ -573,13 +573,13 @@ public: /*! * \brief Is given value <= epsilon? - * \param checkValue + * \param value * \return */ - bool isEpsilon(double checkValue) const + bool isEpsilon(double value) const { - if (checkValue == 0) return true; - return abs(checkValue) <= this->m_epsilon; + if (value == 0) return true; + return abs(value) <= this->m_epsilon; } // -------------------------------------------------------------------- @@ -587,7 +587,7 @@ public: // -------------------------------------------------------------------- /*! - * \brief Unit is not specified + * \brief Dimensionless unit * \return */ static CMeasurementUnit &None() @@ -595,7 +595,6 @@ public: static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); return none; } - }; } // namespace diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index 959ea75e8..173a605ae 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -12,86 +12,76 @@ namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief Physical quantities constants */ class CPhysicalQuantitiesConstants { - public: - /*! - * \brief Temperature absolute Zero in °C - * \return - */ - static const CTemperature& TemperatureAbsoluteZero() { - static CTemperature t(-273.15, CTemperatureUnit::C()); - return t; - } /*! * \brief Tripe point of purified water, 0.01°C * \return */ - static const CTemperature& TemperatureTriplePointOfVSMOW() { + static const CTemperature& TemperatureTriplePointOfVSMOW() + { static CTemperature t(-273.16, CTemperatureUnit::K()); return t; } + /*! * \brief Temperature absolute Zero in °C * \return */ - static const CTemperature& TemperatureAbsoluteZeroC() { + static const CTemperature& TemperatureAbsoluteZeroC() + { static CTemperature t(-273.15, CTemperatureUnit::C()); return t; } + /*! * \brief Standard pressure 1013,25mbar / 29.92inHg * \return */ - static const CPressure& InternationalStandardSeaLevelPressure() { + static const CPressure& InternationalStandardSeaLevelPressure() + { static CPressure p(1013.25, CPressureUnit::hPa()); return p; } - /*! - * \brief 0m - * \return - */ - static const CLength& Length0m() { - static CLength l(0, CLengthUnit::m()); - return l; - } - /*! - * \brief 0ft - * \return - */ - static const CLength& Length0ft() { - static CLength l(0, CLengthUnit::ft()); - return l; - } + /*! * \brief Unicom frequency * \return */ - static const CFrequency& FrequencyUnicom() { + static const CFrequency& FrequencyUnicom() + { static CFrequency f(122.8, CFrequencyUnit::MHz()); return f; } + /*! * \brief Civil aircraft emergency frequency * \return */ - static const CFrequency& FrequencyInternationalAirDistress() { + static const CFrequency& FrequencyInternationalAirDistress() + { static CFrequency f(121.5, CFrequencyUnit::MHz()); return f; } + /*! * \brief Military aircraft emergency frequency * \return */ - static const CFrequency& FrequencyMilitaryAirDistress() { + + static const CFrequency& FrequencyMilitaryAirDistress() + { static CFrequency f(243.0, CFrequencyUnit::MHz()); return f; } }; + } // namespace } // namespace + #endif // guard diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index def61d65d..4501a7461 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -23,27 +23,32 @@ public: * \brief Default constructor */ CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::Hz(), CFrequencyUnit::Hz()) {} + /** - *\brief Copy constructor + *\brief Copy constructor from base type */ - CFrequency(const CFrequency &frequency) : CPhysicalQuantity(frequency) {} + CFrequency(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} + /*! * \brief Init by double value * \param value * \param unit */ CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} + /*! * \brief Virtual destructor */ virtual ~CFrequency() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index a5b914174..6cc339203 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -23,27 +23,32 @@ public: * \brief Default constructor */ CLength() : CPhysicalQuantity(0, CLengthUnit::m(), CLengthUnit::m()) {} + /** - *\brief Copy constructor + *\brief Copy constructor from base type */ - CLength(const CLength &length) : CPhysicalQuantity(length) {} + CLength(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CLength(qint32 value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} + /*! *\brief Init by double value * \param value * \param unit */ CLength(double value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} + /*! * \brief Virtual destructor */ virtual ~CLength() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index 414a2c9a7..76cc070a0 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -38,16 +38,17 @@ public: CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} /*! - * \brief Copy constructor - * \param mass + * \brief Copy constructor from base type + * \param base */ - CMass(const CPhysicalQuantity &mass) : CPhysicalQuantity(mass) {} + CMass(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} /*! * \brief Virtual destructor */ virtual ~CMass() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 72eb72eeb..581cc9025 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -31,11 +31,10 @@ template CPhysicalQuantity::CPhysicalQuantity(doubl /* * Copy constructor */ -template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &otherQuantity) : - m_unitValueD(otherQuantity.m_unitValueD), m_unitValueI(otherQuantity.m_unitValueI), m_convertedSiUnitValueD(otherQuantity.m_convertedSiUnitValueD), - m_isIntegerBaseValue(otherQuantity.m_isIntegerBaseValue), m_unit(otherQuantity.m_unit), m_conversionSiUnit(otherQuantity.m_conversionSiUnit) +template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &other) : + m_unitValueD(other.m_unitValueD), m_unitValueI(other.m_unitValueI), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), + m_isIntegerBaseValue(other.m_isIntegerBaseValue), m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) { - // void } /* @@ -43,40 +42,39 @@ template CPhysicalQuantity::CPhysicalQuantity(const */ template CPhysicalQuantity::~CPhysicalQuantity() { - // void } /* * Equal operator == */ -template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - if (this->m_unit.getType() != otherQuantity.m_unit.getType()) return false; + if (this == &other) return true; + if (this->m_unit.getType() != other.m_unit.getType()) return false; // some special cases for best quality double diff; const double lenient = 1.001; // even diff already has a rounding issue to be avoided bool eq = false; - if (this->m_unit == otherQuantity.m_unit) + if (this->m_unit == other.m_unit) { // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) + if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) { // pure integer comparison, no rounding issues - eq = this->m_unitValueI == otherQuantity.m_unitValueI; + eq = this->m_unitValueI == other.m_unitValueI; } else { // same unit, comparison based on double - diff = qAbs(this->m_unitValueD - otherQuantity.m_unitValueD); + diff = qAbs(this->m_unitValueD - other.m_unitValueD); eq = diff <= (lenient * this->m_unit.getEpsilon()); } } else { // based on SI value - diff = qAbs(this->m_convertedSiUnitValueD - otherQuantity.m_convertedSiUnitValueD); + diff = qAbs(this->m_convertedSiUnitValueD - other.m_convertedSiUnitValueD); eq = diff <= (lenient * this->m_conversionSiUnit.getEpsilon()); } return eq; @@ -85,51 +83,48 @@ template bool CPhysicalQuantity::operator ==(const /* * Not equal */ -template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return false; - return !((*this) == otherQuantity); + return !((*this) == other); } /* * Assignment operator = */ -template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &other) { + if (this == &other) return *this; - // Check for self-assignment! - if (this == &otherQuantity) return *this; // Same object? - - this->m_unitValueI = otherQuantity.m_unitValueI; - this->m_unitValueD = otherQuantity.m_unitValueD; - this->m_convertedSiUnitValueD = otherQuantity.m_convertedSiUnitValueD; - this->m_isIntegerBaseValue = otherQuantity.m_isIntegerBaseValue; - this->m_unit = otherQuantity.m_unit; - this->m_conversionSiUnit = otherQuantity.m_conversionSiUnit; + this->m_unitValueI = other.m_unitValueI; + this->m_unitValueD = other.m_unitValueD; + this->m_convertedSiUnitValueD = other.m_convertedSiUnitValueD; + this->m_isIntegerBaseValue = other.m_isIntegerBaseValue; + this->m_unit = other.m_unit; + this->m_conversionSiUnit = other.m_conversionSiUnit; return *this; } /* * Plus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other) { - if (this->m_unit == otherQuantity.m_unit) + if (this->m_unit == other.m_unit) { // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) + if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) { // pure integer, no rounding issues - this->setUnitValue(otherQuantity.m_unitValueI + this->m_unitValueI); + this->setUnitValue(other.m_unitValueI + this->m_unitValueI); } else { - this->setUnitValue(otherQuantity.m_unitValueD + this->m_unitValueD); + this->setUnitValue(other.m_unitValueD + this->m_unitValueD); } } else { - double v = otherQuantity.value(this->m_unit); + double v = other.value(this->m_unit); this->setUnitValue(v + this->m_unitValueD); } return *this; @@ -138,14 +133,13 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator +(const PQ &otherQuantity) const +template PQ CPhysicalQuantity::operator +(const PQ &other) const { - PQ plus(otherQuantity); - plus += (*this); - return plus; + PQ copy(other); + copy += *this; + return copy; } - /* * Explicit plus */ @@ -165,24 +159,24 @@ template void CPhysicalQuantity::substractUnitValue /* * Minus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other) { - if (this->m_unit == otherQuantity.m_unit) + if (this->m_unit == other.m_unit) { // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) + if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) { // pure integer, no rounding issues - this->setUnitValue(otherQuantity.m_unitValueI - this->m_unitValueI); + this->setUnitValue(other.m_unitValueI - this->m_unitValueI); } else { - this->setUnitValue(otherQuantity.m_unitValueD - this->m_unitValueD); + this->setUnitValue(other.m_unitValueD - this->m_unitValueD); } } else { - double v = otherQuantity.value(this->m_unit); + double v = other.value(this->m_unit); this->setUnitValue(v - this->m_unitValueD); } return *this; @@ -191,11 +185,11 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator -(const PQ &otherQuantity) const +template PQ CPhysicalQuantity::operator -(const PQ &other) const { - PQ minus = *derived(); - minus -= otherQuantity; - return minus; + PQ copy = *derived(); + copy -= other; + return copy; } /* @@ -212,9 +206,9 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator *(double multiply) const { - PQ times = *derived(); - times *= multiply; - return times; + PQ copy = *derived(); + copy *= multiply; + return copy; } /* @@ -231,48 +225,48 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator /(double divide) const { - PQ div = *derived(); - div /= divide; - return div; + PQ copy = *derived(); + copy /= divide; + return copy; } /* * Less operator < */ -template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &other) const { - if ((*this) == otherQuantity) return false; + if ((*this) == other) return false; // == considers epsilon, so we now have a diff > epsilon here - double diff = this->m_convertedSiUnitValueD - otherQuantity.m_convertedSiUnitValueD; + double diff = this->m_convertedSiUnitValueD - other.m_convertedSiUnitValueD; return (diff < 0); } /* * Greater than */ -template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return false; - return otherQuantity < (*this); + if (this == &other) return false; + return other < *this; } /* * Greater / Equal */ -template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - return !(*this < otherQuantity); + if (this == &other) return true; + return !(*this < other); } /* * Less equal */ -template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - return !(*this > otherQuantity); + if (this == &other) return true; + return !(*this > other); } /* @@ -399,7 +393,6 @@ template double CPhysicalQuantity::convertedSiValue return this->m_conversionSiUnit.valueRounded(this->m_convertedSiUnitValueD, digits); } - // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CPhysicalQuantity; diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index fb832e952..18aefe77e 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -19,13 +19,12 @@ namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" */ - template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier { - private: double m_unitValueD; //!< value backed by double qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic @@ -71,7 +70,7 @@ protected: CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit); /*! - * \brief Name as stringification + * \brief Name as string * \param i18n * \return */ @@ -101,9 +100,9 @@ protected: public: /*! * \brief Copy constructor - * \param otherQuantity + * \param other */ - CPhysicalQuantity(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity(const CPhysicalQuantity &other); /*! * \brief Virtual destructor @@ -305,12 +304,12 @@ public: /*! * \brief Operator to support commutative multiplication * \param factor - * \param otherQuantity + * \param other * \return */ - friend PQ operator *(double factor, const PQ &otherQuantity) + friend PQ operator *(double factor, const PQ &other) { - return otherQuantity * factor; + return other * factor; } /*! @@ -322,80 +321,80 @@ public: /*! * \brief Equal operator == - * \param otherQuantity + * \param other * \return */ - bool operator==(const CPhysicalQuantity &otherQuantity) const; + bool operator==(const CPhysicalQuantity &other) const; /*! * \brief Not equal operator != - * \param otherQuantity + * \param other * \return */ - bool operator!=(const CPhysicalQuantity &otherQuantity) const; + bool operator!=(const CPhysicalQuantity &other) const; /*! * \brief Plus operator += - * \param otherQuantity + * \param other * \return */ - CPhysicalQuantity &operator +=(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity &operator +=(const CPhysicalQuantity &other); /*! * \brief Minus operator-= - * \param otherQuantity + * \param other * \return */ - CPhysicalQuantity &operator -=(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity &operator -=(const CPhysicalQuantity &other); /*! * \brief Greater operator > - * \param otherQuantity + * \param other * \return */ - bool operator >(const CPhysicalQuantity &otherQuantity) const; + bool operator >(const CPhysicalQuantity &other) const; /*! * \brief Less operator < - * \param otherQuantity + * \param other * \return */ - bool operator <(const CPhysicalQuantity &otherQuantity) const; + bool operator <(const CPhysicalQuantity &other) const; /*! * \brief Less equal operator <= - * \param otherQuantity + * \param other * \return */ - bool operator <=(const CPhysicalQuantity &otherQuantity) const; + bool operator <=(const CPhysicalQuantity &other) const; /*! * \brief Greater equal operator >= - * \param otherQuantity + * \param other * \return */ - bool operator >=(const CPhysicalQuantity &otherQuantity) const; + bool operator >=(const CPhysicalQuantity &other) const; /*! * \brief Assignment operator = - * \param otherQuantity + * \param other * \return */ - CPhysicalQuantity &operator =(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity &operator =(const CPhysicalQuantity &other); /*! * \brief Plus operator + - * \param otherQuantity + * \param other * \return */ - PQ operator +(const PQ &otherQuantity) const; + PQ operator +(const PQ &other) const; /*! * \brief Minus operator - - * \param otherQuantity + * \param other * \return */ - PQ operator -(const PQ &otherQuantity) const; + PQ operator -(const PQ &other) const; /*! * \brief Quantity value <= epsilon @@ -429,7 +428,8 @@ public: * \brief Stream to DBus << * \param argument */ - virtual void marshallToDbus(QDBusArgument &argument) const { + virtual void marshallToDbus(QDBusArgument &argument) const + { argument << this->m_unitValueD; argument << this->m_unitValueI; argument << this->m_convertedSiUnitValueD; @@ -442,7 +442,8 @@ public: * \brief Stream from DBus >> * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { argument >> this->m_unitValueD; argument >> this->m_unitValueI; argument >> this->m_convertedSiUnitValueD; @@ -463,7 +464,6 @@ public: qDBusRegisterMetaType(); qDBusRegisterMetaType>(); } - }; } // namespace diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index 3cfd5fbdb..660f1451a 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -24,27 +24,32 @@ public: * \brief Default constructor */ CPressure() : CPhysicalQuantity(0, CPressureUnit::Pa(), CPressureUnit::Pa()) {} + /** - *\brief Copy constructor + *\brief Copy constructor from base type */ - CPressure(const CPressure &pressure) : CPhysicalQuantity(pressure) {} + CPressure(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} + /*! *\brief Init by double value * \param value * \param unit */ CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} + /*! * \brief Virtual destructor */ virtual ~CPressure() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index e49dd3f2f..737b2f0d4 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -24,22 +24,26 @@ public: * \brief Default constructor */ CSpeed() : CPhysicalQuantity(0, CSpeedUnit::m_s(), CSpeedUnit::m_s()) {} + /*! - *\brief Copy constructor + *\brief Copy constructor from base type */ - CSpeed(const CSpeed &speed): CPhysicalQuantity(speed) {} + CSpeed(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CSpeed(qint32 value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} + /*! *\brief Init by double value * \param value * \param unit */ CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} + /*! * \brief Destructor */ diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index bec623817..896b313d4 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -23,27 +23,32 @@ public: * \brief Default constructor */ CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::K(), CTemperatureUnit::K()) {} + /** - *\brief Copy constructor + * \brief Copy constructor from base type */ - CTemperature(const CTemperature &temperature) : CPhysicalQuantity(temperature) {} + CTemperature(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CTemperature(qint32 value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} + /*! - *\brief Init by double value + * \brief Init by double value * \param value * \param unit */ CTemperature(double value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} + /*! * \brief Destructor */ virtual ~CTemperature() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 9641e8d45..62e78f115 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -24,27 +24,32 @@ public: * \brief Default constructor */ CTime() : CPhysicalQuantity(0, CTimeUnit::s(), CTimeUnit::s()) {} + /** - *\brief Copy constructor + *\brief Copy constructor from base type */ - CTime(const CPhysicalQuantity &time): CPhysicalQuantity(time) {} + CTime(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} + /*! * \brief Init by int value * \param value * \param unit */ CTime(qint32 value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} + /*! *\brief Init by double value * \param value * \param unit */ CTime(double value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} + /*! * \brief Destructor */ virtual ~CTime() {} }; + } // namespace } // namespace diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 90962792e..5973a3c10 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -82,7 +82,7 @@ QString CAngleUnit::toQStringRounded(double value, int digits, bool i18n) const } else { - s = CMeasurementUnit::toQStringRounded(value, digits); + s = this->CMeasurementUnit::toQStringRounded(value, digits); } return s; } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index e70564413..c11350d76 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -29,7 +29,6 @@ namespace PhysicalQuantities */ class CLengthUnit : public CMeasurementUnit { - private: /*! * \brief Constructor length unit @@ -43,10 +42,7 @@ private: * \param epsilon */ CLengthUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "distance", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) - { - // void - } + CMeasurementUnit(name, unitName, "distance", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} public: /*! @@ -56,12 +52,9 @@ public: /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CLengthUnit(const CLengthUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CLengthUnit(const CLengthUnit &other) : CMeasurementUnit(other) {} /*! * \brief Meter m @@ -74,7 +67,6 @@ public: QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"); } - /*! * \brief Nautical miles NM * \return @@ -97,7 +89,6 @@ public: QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"); } - /*! * \brief Kilometer km * \return @@ -164,9 +155,9 @@ public: * \param unitName must be valid! * \return */ - static const CLengthUnit &fromUnitName(const QString &unitName) { - QList units = CLengthUnit::units(); - // read only, avoid deep copy + static const CLengthUnit &fromUnitName(const QString &unitName) + { + const QList &units = CLengthUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -179,7 +170,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CLengthUnit::fromUnitName(unitName); @@ -207,16 +199,15 @@ private: const CMeasurementPrefix &multiplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9, UnitConverter converterToSi = 0, UnitConverter converterFromSi = 0) : CMeasurementUnit(name, unitName, "angle", isSiUnit, false, conversionFactorToSI, - multiplier, displayDigits, epsilon, converterToSi, converterFromSi) - { - // void - } + multiplier, displayDigits, epsilon, converterToSi, converterFromSi) {} + /*! * \brief Special conversion for sexagesimal degrees * \param value * \return */ static double conversionSexagesimalToSi(const CMeasurementUnit &angleUnit, double value); + /*! * \brief Special conversion for sexagesimal degrees * \param value @@ -226,15 +217,15 @@ private: public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CAngleUnit() : CMeasurementUnit("radian", "rad", "angle", true, false) {} /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CAngleUnit(const CAngleUnit &otherUnit) : CMeasurementUnit(otherUnit) { } + CAngleUnit(const CAngleUnit &other) : CMeasurementUnit(other) {} /*! * \brief Special conversion to QString for sexagesimal degrees. @@ -297,9 +288,9 @@ public: * \param unitName must be valid! * \return */ - static const CAngleUnit &fromUnitName(const QString &unitName) { - QList units = CAngleUnit::units(); - // read only, avoid deep copy + static const CAngleUnit &fromUnitName(const QString &unitName) + { + const QList &units = CAngleUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -312,7 +303,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CAngleUnit::fromUnitName(unitName); @@ -339,20 +331,18 @@ private: */ CFrequencyUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CFrequencyUnit() : CMeasurementUnit("hertz", "Hz", "frequency", true, false) {} /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CFrequencyUnit(const CFrequencyUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CFrequencyUnit(const CFrequencyUnit &other) : CMeasurementUnit(other) {} /*! * \brief Hertz @@ -413,9 +403,9 @@ public: * \param unitName must be valid! * \return */ - static const CFrequencyUnit &fromUnitName(const QString &unitName) { - QList units = CFrequencyUnit::units(); - // read only, avoid deep copy + static const CFrequencyUnit &fromUnitName(const QString &unitName) + { + const QList &units = CFrequencyUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -428,7 +418,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CFrequencyUnit::fromUnitName(unitName); @@ -455,20 +446,18 @@ private: */ CMassUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "mass", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CMassUnit() : CMeasurementUnit("kilogram", "kg", "mass", true, true, 1.0, CMeasurementPrefix::k(), 1) {} /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CMassUnit(const CMassUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CMassUnit(const CMassUnit &other) : CMeasurementUnit(other) {} /*! * \brief Kilogram, SI base unit @@ -533,9 +522,9 @@ public: * \param unitName must be valid! * \return */ - static const CMassUnit &fromUnitName(const QString &unitName) { - QList units = CMassUnit::units(); - // read only, avoid deep copy + static const CMassUnit &fromUnitName(const QString &unitName) + { + const QList &units = CMassUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -548,12 +537,12 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CMassUnit::fromUnitName(unitName); } - }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMassUnit) @@ -576,20 +565,18 @@ private: */ CPressureUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "pressure", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CPressureUnit() : CMeasurementUnit("pascal", "Pa", "pressure", true, false) {} /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CPressureUnit(const CPressureUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CPressureUnit(const CPressureUnit &other) : CMeasurementUnit(other) {} /*! * \brief Pascal @@ -689,9 +676,9 @@ public: * \param unitName must be valid! * \return */ - static const CPressureUnit &fromUnitName(const QString &unitName) { - QList units = CPressureUnit::units(); - // read only, avoid deep copy + static const CPressureUnit &fromUnitName(const QString &unitName) + { + const QList &units = CPressureUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -704,7 +691,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CPressureUnit::fromUnitName(unitName); @@ -719,6 +707,7 @@ class CTemperatureUnit : public CMeasurementUnit { private: double m_conversionOffsetToSi; + private: /*! * Constructor temperature unit @@ -734,6 +723,7 @@ private: */ CTemperatureUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "temperature", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {} + protected: /*! * \brief Convert to SI conversion unit, specific for temperature @@ -751,25 +741,25 @@ protected: public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CTemperatureUnit() : CMeasurementUnit("Kelvin", "K", "temperature", true, true) {} /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CTemperatureUnit(const CTemperatureUnit &otherUnit) : CMeasurementUnit(otherUnit), m_conversionOffsetToSi(otherUnit.m_conversionOffsetToSi) {} + CTemperatureUnit(const CTemperatureUnit &other) : CMeasurementUnit(other), m_conversionOffsetToSi(other.m_conversionOffsetToSi) {} /*! * Assigment operator */ - CTemperatureUnit &operator =(const CTemperatureUnit &otherUnit) + CTemperatureUnit &operator =(const CTemperatureUnit &other) { - if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this - CMeasurementUnit::operator = (otherUnit); - this->m_conversionOffsetToSi = otherUnit.m_conversionOffsetToSi; - return (*this); + if (this == &other) return *this; + CMeasurementUnit::operator = (other); + this->m_conversionOffsetToSi = other.m_conversionOffsetToSi; + return *this; } /*! @@ -825,9 +815,9 @@ public: * \param unitName must be valid! * \return */ - static const CTemperatureUnit &fromUnitName(const QString &unitName) { - QList units = CTemperatureUnit::units(); - // read only, avoid deep copy + static const CTemperatureUnit &fromUnitName(const QString &unitName) + { + const QList &units = CTemperatureUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -840,7 +830,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CTemperatureUnit::fromUnitName(unitName); @@ -868,17 +859,18 @@ private: */ CSpeedUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "speed", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CSpeedUnit() : CMeasurementUnit("meters/second", "m/s", "speed", true, false) {} /*! * Constructor, allows to implement methods in base class - * \param otherUnit + * \param other */ - CSpeedUnit(const CSpeedUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CSpeedUnit(const CSpeedUnit &other) : CMeasurementUnit(other) {} /*! * \brief Meter/second m/s @@ -967,9 +959,9 @@ public: * \param unitName must be valid! * \return */ - static const CSpeedUnit &fromUnitName(const QString &unitName) { - QList units = CSpeedUnit::units(); - // read only, avoid deep copy + static const CSpeedUnit &fromUnitName(const QString &unitName) + { + const QList &units = CSpeedUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -982,7 +974,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CSpeedUnit::fromUnitName(unitName); @@ -1010,17 +1003,18 @@ private: */ CTimeUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ CTimeUnit() : CMeasurementUnit("second", "s", "time", true, true, 1, CMeasurementPrefix::None()) {} /*! * Constructor, allows to implement methods in base class - * \param otherUnit + * \param other */ - CTimeUnit(const CTimeUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CTimeUnit(const CTimeUnit &other) : CMeasurementUnit(other) {} /*! * \brief Second s @@ -1097,9 +1091,9 @@ public: * \param unitName must be valid! * \return */ - static const CTimeUnit &fromUnitName(const QString &unitName) { - QList units = CTimeUnit::units(); - // read only, avoid deep copy + static const CTimeUnit &fromUnitName(const QString &unitName) + { + const QList &units = CTimeUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -1112,7 +1106,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CTimeUnit::fromUnitName(unitName); @@ -1140,17 +1135,18 @@ private: */ CAccelerationUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "acceleration", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ - CAccelerationUnit() : CMeasurementUnit("meter/second²", "m/s^2", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} + CAccelerationUnit() : CMeasurementUnit("meter/second^2", "m/s^2", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} /*! * Constructor, allows to implement methods in base class - * \param otherUnit + * \param other */ - CAccelerationUnit(const CAccelerationUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CAccelerationUnit(const CAccelerationUnit &other) : CMeasurementUnit(other) {} /*! * \brief Meter/second^2 (m/s^2) @@ -1193,9 +1189,9 @@ public: * \param unitName must be valid! * \return */ - static const CAccelerationUnit &fromUnitName(const QString &unitName) { - QList units = CAccelerationUnit::units(); - // read only, avoid deep copy + static const CAccelerationUnit &fromUnitName(const QString &unitName) + { + const QList &units = CAccelerationUnit::units(); for (int i = 0; i < units.size(); ++i) { if (units.at(i).getUnitName() == unitName) return (units.at(i)); } @@ -1208,7 +1204,8 @@ protected: * \brief Stream from DBus * \param argument */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) { + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { QString unitName; argument >> unitName; (*this) = CAccelerationUnit::fromUnitName(unitName); @@ -1216,7 +1213,6 @@ protected: }; Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) - } // namespace } // namespace #endif // guard From 117021aadfc38c82e66ddd993c20457e9f2a2d5b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 22:30:52 +0100 Subject: [PATCH 12/36] fixed copy/paste mistake in CModulator --- src/blackmisc/aviomodulator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 9b6ccf12e..b51686b18 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -203,7 +203,7 @@ protected: */ static const QString &NameNav3() { - static QString n("NAV2"); + static QString n("NAV3"); return n; } From 525756026515f6730c7baa5814e5a9d0749de9e7 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 22:44:01 +0100 Subject: [PATCH 13/36] fixed repeatedly increasing memory usage in units unmarshalling code --- src/blackmisc/pqbase.h | 19 ++++--- src/blackmisc/pqunits.h | 107 +++++++++++++++++++++++++--------------- 2 files changed, 78 insertions(+), 48 deletions(-) diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 462fd527c..78c663189 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -249,14 +249,17 @@ public: static const QList &prefixes() { static QList prefixes; - prefixes.append(CMeasurementPrefix::c()); - prefixes.append(CMeasurementPrefix::G()); - prefixes.append(CMeasurementPrefix::h()); - prefixes.append(CMeasurementPrefix::k()); - prefixes.append(CMeasurementPrefix::M()); - prefixes.append(CMeasurementPrefix::m()); - prefixes.append(CMeasurementPrefix::None()); - prefixes.append(CMeasurementPrefix::One()); + if (prefixes.isEmpty()) + { + prefixes.append(CMeasurementPrefix::c()); + prefixes.append(CMeasurementPrefix::G()); + prefixes.append(CMeasurementPrefix::h()); + prefixes.append(CMeasurementPrefix::k()); + prefixes.append(CMeasurementPrefix::M()); + prefixes.append(CMeasurementPrefix::m()); + prefixes.append(CMeasurementPrefix::None()); + prefixes.append(CMeasurementPrefix::One()); + } return prefixes; } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index c11350d76..b2ff38146 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -140,13 +140,16 @@ public: static const QList &units() { static QList u; - u.append(CLengthUnit::cm()); - u.append(CLengthUnit::ft()); - u.append(CLengthUnit::km()); - u.append(CLengthUnit::m()); - u.append(CLengthUnit::mi()); - u.append(CLengthUnit::miStatute()); - u.append(CLengthUnit::NM()); + if (u.isEmpty()) + { + u.append(CLengthUnit::cm()); + u.append(CLengthUnit::ft()); + u.append(CLengthUnit::km()); + u.append(CLengthUnit::m()); + u.append(CLengthUnit::mi()); + u.append(CLengthUnit::miStatute()); + u.append(CLengthUnit::NM()); + } return u; } @@ -277,9 +280,12 @@ public: static const QList &units() { static QList u; - u.append(CAngleUnit::deg()); - u.append(CAngleUnit::rad()); - u.append(CAngleUnit::sexagesimalDeg()); + if (u.isEmpty()) + { + u.append(CAngleUnit::deg()); + u.append(CAngleUnit::rad()); + u.append(CAngleUnit::sexagesimalDeg()); + } return u; } @@ -391,10 +397,13 @@ public: static const QList &units() { static QList u; - u.append(CFrequencyUnit::GHz()); - u.append(CFrequencyUnit::Hz()); - u.append(CFrequencyUnit::kHz()); - u.append(CFrequencyUnit::MHz()); + if (u.isEmpty()) + { + u.append(CFrequencyUnit::GHz()); + u.append(CFrequencyUnit::Hz()); + u.append(CFrequencyUnit::kHz()); + u.append(CFrequencyUnit::MHz()); + } return u; } @@ -510,10 +519,13 @@ public: static const QList &units() { static QList u; - u.append(CMassUnit::g()); - u.append(CMassUnit::kg()); - u.append(CMassUnit::lb()); - u.append(CMassUnit::t()); + if (u.isEmpty()) + { + u.append(CMassUnit::g()); + u.append(CMassUnit::kg()); + u.append(CMassUnit::lb()); + u.append(CMassUnit::t()); + } return u; } @@ -662,12 +674,15 @@ public: static const QList &units() { static QList u; - u.append(CPressureUnit::bar()); - u.append(CPressureUnit::hPa()); - u.append(CPressureUnit::inHg()); - u.append(CPressureUnit::inHgFL()); - u.append(CPressureUnit::mbar()); - u.append(CPressureUnit::psi()); + if (u.isEmpty()) + { + u.append(CPressureUnit::bar()); + u.append(CPressureUnit::hPa()); + u.append(CPressureUnit::inHg()); + u.append(CPressureUnit::inHgFL()); + u.append(CPressureUnit::mbar()); + u.append(CPressureUnit::psi()); + } return u; } @@ -804,9 +819,12 @@ public: static const QList &units() { static QList u; - u.append(CTemperatureUnit::C()); - u.append(CTemperatureUnit::F()); - u.append(CTemperatureUnit::K()); + if (u.isEmpty()) + { + u.append(CTemperatureUnit::C()); + u.append(CTemperatureUnit::F()); + u.append(CTemperatureUnit::K()); + } return u; } @@ -945,12 +963,15 @@ public: static const QList &units() { static QList u; - u.append(CSpeedUnit::ft_min()); - u.append(CSpeedUnit::ft_s()); - u.append(CSpeedUnit::km_h()); - u.append(CSpeedUnit::kts()); - u.append(CSpeedUnit::m_s()); - u.append(CSpeedUnit::NM_h()); + if (u.isEmpty()) + { + u.append(CSpeedUnit::ft_min()); + u.append(CSpeedUnit::ft_s()); + u.append(CSpeedUnit::km_h()); + u.append(CSpeedUnit::kts()); + u.append(CSpeedUnit::m_s()); + u.append(CSpeedUnit::NM_h()); + } return u; } @@ -1078,11 +1099,14 @@ public: static const QList &units() { static QList u; - u.append(CTimeUnit::d()); - u.append(CTimeUnit::h()); - u.append(CTimeUnit::min()); - u.append(CTimeUnit::ms()); - u.append(CTimeUnit::s()); + if (u.isEmpty()) + { + u.append(CTimeUnit::d()); + u.append(CTimeUnit::h()); + u.append(CTimeUnit::min()); + u.append(CTimeUnit::ms()); + u.append(CTimeUnit::s()); + } return u; } @@ -1179,8 +1203,11 @@ public: static const QList &units() { static QList u; - u.append(CAccelerationUnit::ft_s2()); - u.append(CAccelerationUnit::m_s2()); + if (u.isEmpty()) + { + u.append(CAccelerationUnit::ft_s2()); + u.append(CAccelerationUnit::m_s2()); + } return u; } From 1c1aa4cad317ba9c54ea3d5db0dbab915dbe71a3 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 22:47:19 +0100 Subject: [PATCH 14/36] moved Q_DECLARE_METATYPE outside of namespace --- src/blackmisc/pqunits.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index b2ff38146..05354f4ab 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -180,7 +180,6 @@ protected: (*this) = CLengthUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit) /*! * \brief Specialized class for angles (degrees, radian). @@ -316,7 +315,6 @@ protected: (*this) = CAngleUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit) /*! * \brief Specialized class for frequency (hertz, mega hertz, kilo hertz). @@ -434,7 +432,6 @@ protected: (*this) = CFrequencyUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit) /*! * \brief Specialized class for mass units (kg, lbs). @@ -556,7 +553,6 @@ protected: (*this) = CMassUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMassUnit) /*! * \brief Specialized class for pressure (psi, hPa, bar). @@ -713,7 +709,6 @@ protected: (*this) = CPressureUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit) /*! * \brief Specialized class for temperatur units (kelvin, centidegree). @@ -855,7 +850,6 @@ protected: (*this) = CTemperatureUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit) /*! * \brief Specialized class for speed units (m/s, ft/s, NM/h). @@ -1002,7 +996,6 @@ protected: (*this) = CSpeedUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) /*! * \brief Specialized class for time units (ms, hour, min). @@ -1137,7 +1130,6 @@ protected: (*this) = CTimeUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) /*! * \brief Specialized class for acceleration units (m/s2, ft/s2). @@ -1238,8 +1230,18 @@ protected: (*this) = CAccelerationUnit::fromUnitName(unitName); } }; -Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMassUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) + #endif // guard From d4279a8c2838559ff762ca16cca495677fd2c238 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 14 Aug 2013 18:03:51 +0100 Subject: [PATCH 15/36] move QT_TRANSLATE_NOOP to suppress GCC warnings --- src/blackmisc/pqunits.h | 124 +++++++++++++--------------------------- 1 file changed, 41 insertions(+), 83 deletions(-) diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 05354f4ab..c20c0771e 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -62,9 +62,8 @@ public: */ static const CLengthUnit &m() { - static CLengthUnit m("meter", "m", true, true); + static CLengthUnit m(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"), "m", true, true); return m; - QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"); } /*! @@ -73,9 +72,8 @@ public: */ static const CLengthUnit &NM() { - static CLengthUnit NM("nautical mile", "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); + static CLengthUnit NM(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"), "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); return NM; - QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"); } /*! @@ -84,9 +82,8 @@ public: */ static const CLengthUnit &ft() { - static CLengthUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CLengthUnit ft(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"), "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); return ft; - QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"); } /*! @@ -95,9 +92,8 @@ public: */ static const CLengthUnit &km() { - static CLengthUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); + static CLengthUnit km(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"), "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); return km; - QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"); } /*! @@ -106,9 +102,8 @@ public: */ static const CLengthUnit &cm() { - static CLengthUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); + static CLengthUnit cm(QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"), "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); return cm; - QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"); } /*! @@ -117,9 +112,8 @@ public: */ static const CLengthUnit &mi() { - static CLengthUnit mi("mile", "mi", false, false, 1609.344, CMeasurementPrefix::None(), 3); + static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"), "mi", false, false, 1609.344, CMeasurementPrefix::None(), 3); return mi; - QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"); } /*! @@ -128,9 +122,8 @@ public: */ static const CLengthUnit &miStatute() { - static CLengthUnit mi("mile(statute)", "mi(statute)", false, false, 1609.3472, CMeasurementPrefix::None(), 3); + static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile(statute)"), "mi(statute)", false, false, 1609.3472, CMeasurementPrefix::None(), 3); return mi; - QT_TRANSLATE_NOOP("CMeasurementUnit", "mile(statute)"); } /*! @@ -244,9 +237,8 @@ public: */ static const CAngleUnit &rad() { - static CAngleUnit rad("radian", "rad", true); + static CAngleUnit rad(QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"), "rad", true); return rad; - QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"); } /*! @@ -255,10 +247,8 @@ public: */ static const CAngleUnit °() { - static CAngleUnit deg("degree", "deg", false, M_PI / 180); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"), QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"), false, M_PI / 180); return deg; - QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"); - QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"); } /*! @@ -267,9 +257,8 @@ public: */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg("segadecimal degree", "segd", false, M_PI / 180, + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "segadecimal degree"), "segd", false, M_PI / 180, CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; - QT_TRANSLATE_NOOP("CMeasurementUnit", "segadecimal degree"); } /*! @@ -354,7 +343,7 @@ public: */ static const CFrequencyUnit &Hz() { - static CFrequencyUnit Hz("hertz", "Hz", true); + static CFrequencyUnit Hz(QT_TRANSLATE_NOOP("CMeasurementUnit", "hertz"), "Hz", true); return Hz; } @@ -364,7 +353,7 @@ public: */ static const CFrequencyUnit &kHz() { - static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1); + static CFrequencyUnit kHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilohertz"), "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1); return kHz; } @@ -374,7 +363,7 @@ public: */ static const CFrequencyUnit &MHz() { - static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); + static CFrequencyUnit MHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "megahertz"), "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); return MHz; } @@ -384,7 +373,7 @@ public: */ static const CFrequencyUnit &GHz() { - static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); + static CFrequencyUnit GHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "gigahertz"), "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); return GHz; } @@ -471,9 +460,8 @@ public: */ static const CMassUnit &kg() { - static CMassUnit kg("kilogram", "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); + static CMassUnit kg(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"), "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); return kg; - QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"); } /*! @@ -482,9 +470,8 @@ public: */ static const CMassUnit &g() { - static CMassUnit g("gram", "g", true, false, 1.0 / 1000.0, CMeasurementPrefix::One(), 0); + static CMassUnit g(QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"), "g", true, false, 1.0 / 1000.0, CMeasurementPrefix::One(), 0); return g; - QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"); } /*! @@ -493,9 +480,8 @@ public: */ static const CMassUnit &t() { - static CMassUnit t("tonne", "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); + static CMassUnit t(QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"), "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); return t; - QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"); } /*! @@ -504,9 +490,8 @@ public: */ static const CMassUnit &lb() { - static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); + static CMassUnit lbs(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"), "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); return lbs; - QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"); } /*! @@ -592,9 +577,8 @@ public: */ static const CPressureUnit &Pa() { - static CPressureUnit Pa("pascal", "Pa", true); + static CPressureUnit Pa(QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"), "Pa", true); return Pa; - QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"); } /*! @@ -603,9 +587,8 @@ public: */ static const CPressureUnit &hPa() { - static CPressureUnit hPa("hectopascal", "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); + static CPressureUnit hPa(QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"), "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); return hPa; - QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"); } /*! @@ -614,9 +597,8 @@ public: */ static const CPressureUnit &psi() { - static CPressureUnit psi("pounds per square inch", "psi", false, 6894.8, CMeasurementPrefix::One(), 2); + static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"), "psi", false, 6894.8, CMeasurementPrefix::One(), 2); return psi; - QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"); } /*! @@ -625,9 +607,8 @@ public: */ static const CPressureUnit &bar() { - static CPressureUnit bar("bar", "bar", false, 1E5); + static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", false, 1E5); return bar; - QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"); } /*! @@ -636,9 +617,8 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar("millibar", "bar", false, 1E2); + static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"), "bar", false, 1E2); return bar; - QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"); } /*! @@ -647,9 +627,8 @@ public: */ static const CPressureUnit &inHg() { - static CPressureUnit inhg("inch of mercury 0C", "inHg", false, 3386.389); + static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"), "inHg", false, 3386.389); return inhg; - QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"); } /*! @@ -658,9 +637,8 @@ public: */ static const CPressureUnit &inHgFL() { - static CPressureUnit inhg("inch of mercury", "inHg", false, 3386.5307486631); + static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", false, 3386.5307486631); return inhg; - QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"); } /*! @@ -778,9 +756,8 @@ public: */ static const CTemperatureUnit &K() { - static CTemperatureUnit K("Kelvin", "K", true, true); + static CTemperatureUnit K(QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"), "K", true, true); return K; - QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"); } /*! @@ -789,10 +766,8 @@ public: */ static const CTemperatureUnit &C() { - static CTemperatureUnit C("centigrade", "C", false, false, 1.0, 273.15); + static CTemperatureUnit C(QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"), QT_TRANSLATE_NOOP("CMeasurementUnit", "C"), false, false, 1.0, 273.15); return C; - QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"); - QT_TRANSLATE_NOOP("CMeasurementUnit", "C"); } /*! @@ -801,10 +776,8 @@ public: */ static const CTemperatureUnit &F() { - static CTemperatureUnit F("Fahrenheit", "F", false, false, 5.0 / 9.0, 459.67); + static CTemperatureUnit F(QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"), QT_TRANSLATE_NOOP("CMeasurementUnit", "F"), false, false, 5.0 / 9.0, 459.67); return F; - QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"); - QT_TRANSLATE_NOOP("CMeasurementUnit", "F"); } /*! @@ -890,9 +863,8 @@ public: */ static const CSpeedUnit &m_s() { - static CSpeedUnit ms("meters/second", "m/s", true, false); + static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"), "m/s", true, false); return ms; - QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"); } /*! @@ -901,9 +873,8 @@ public: */ static const CSpeedUnit &kts() { - static CSpeedUnit kts("knot", "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit kts(QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"), "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); return kts; - QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"); } /*! @@ -912,9 +883,8 @@ public: */ static const CSpeedUnit &NM_h() { - static CSpeedUnit NMh("nautical miles/hour", "NM/h", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"), "NM/h", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); return NMh; - QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"); } /*! @@ -923,9 +893,8 @@ public: */ static const CSpeedUnit &ft_s() { - static CSpeedUnit fts("feet/second", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"), "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); return fts; - QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"); } /*! @@ -934,9 +903,8 @@ public: */ static const CSpeedUnit &ft_min() { - static CSpeedUnit ftmin("feet/minute", "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); + static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"), "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); return ftmin; - QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"); } /*! @@ -945,9 +913,8 @@ public: */ static const CSpeedUnit &km_h() { - static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); + static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"), "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); return kmh; - QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"); } /*! @@ -1036,9 +1003,8 @@ public: */ static const CTimeUnit &s() { - static CTimeUnit s("second", "s", true, true, 1, CMeasurementPrefix::None(), 1); + static CTimeUnit s(QT_TRANSLATE_NOOP("CMeasurementUnit", "second"), "s", true, true, 1, CMeasurementPrefix::None(), 1); return s; - QT_TRANSLATE_NOOP("CMeasurementUnit", "second"); } /*! @@ -1047,9 +1013,8 @@ public: */ static const CTimeUnit &ms() { - static CTimeUnit ms("millisecond", "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); + static CTimeUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"), "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); return ms; - QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"); } /*! @@ -1058,9 +1023,8 @@ public: */ static const CTimeUnit &h() { - static CTimeUnit h("hour", "h", false, false, 3600, CMeasurementPrefix::None(), 1); + static CTimeUnit h(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"), "h", false, false, 3600, CMeasurementPrefix::None(), 1); return h; - QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"); } /*! @@ -1069,9 +1033,8 @@ public: */ static const CTimeUnit &min() { - static CTimeUnit min("minute", "min", false, false, 60, CMeasurementPrefix::None(), 2); + static CTimeUnit min(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", false, false, 60, CMeasurementPrefix::None(), 2); return min; - QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"); } /*! @@ -1080,9 +1043,8 @@ public: */ static const CTimeUnit &d() { - static CTimeUnit day("day", "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); + static CTimeUnit day(QT_TRANSLATE_NOOP("CMeasurementUnit", "day"), "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); return day; - QT_TRANSLATE_NOOP("CMeasurementUnit", "day"); } /*! @@ -1170,10 +1132,8 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2("meters/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), true, false, 1, CMeasurementPrefix::None(), 1); return ms2; - QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"); - QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"); } /*! @@ -1182,10 +1142,8 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2("feet/seconds²", "ft/s^2", true, false, 3.28084, CMeasurementPrefix::m(), 0); + static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), true, false, 3.28084, CMeasurementPrefix::m(), 0); return fts2; - QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"); - QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"); } /*! From a6756f204349837195f4067cc2423c6363fa4ebf Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 13 Aug 2013 23:21:12 +0100 Subject: [PATCH 16/36] suppress/fix a few more GCC and MSVC warnings and errors --- samples/blackmiscquantities_dbus/testservicetool.h | 2 ++ samples/com_client/client.cpp | 2 +- src/blackbox/dialog_connect.cpp | 6 ++++-- src/blackmisc/avioadfsystem.h | 1 + src/blackmisc/avtrack.h | 4 ++-- src/blackmisc/mathmatrixbase.cpp | 1 + src/blackmisc/pqphysicalquantity.h | 5 +++-- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/samples/blackmiscquantities_dbus/testservicetool.h b/samples/blackmiscquantities_dbus/testservicetool.h index 125db190e..5d5f2a2c4 100644 --- a/samples/blackmiscquantities_dbus/testservicetool.h +++ b/samples/blackmiscquantities_dbus/testservicetool.h @@ -5,7 +5,9 @@ #include #ifdef Q_OS_WIN // for qdatetime, see here http://qt-project.org/forums/viewthread/22133 +#ifndef NOMINMAX #define NOMINMAX +#endif #include // for Sleep #endif diff --git a/samples/com_client/client.cpp b/samples/com_client/client.cpp index 4fdb3e1aa..4f1eb8a1c 100644 --- a/samples/com_client/client.cpp +++ b/samples/com_client/client.cpp @@ -19,7 +19,7 @@ Client::~Client() { } -void Client::onError(QAbstractSocket::SocketError error, QString message) +void Client::onError(QAbstractSocket::SocketError /* error */, QString message) { bAppWarning << "Socket error!"; } diff --git a/src/blackbox/dialog_connect.cpp b/src/blackbox/dialog_connect.cpp index 956288dd4..802430a48 100644 --- a/src/blackbox/dialog_connect.cpp +++ b/src/blackbox/dialog_connect.cpp @@ -13,8 +13,10 @@ using namespace BlackMisc; CDialogConnect::CDialogConnect(QWidget *parent) : - QDialog(parent), m_hasComConnection(false), - ui(new Ui::CDialogConnect), comclient(IContext::getInstance()) + QDialog(parent), + ui(new Ui::CDialogConnect), + comclient(IContext::getInstance()), + m_hasComConnection(false) { ui->setupUi(this); diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index e74914ee5..8a65aa16f 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -7,6 +7,7 @@ #define BLACKMISC_AVIOADFSYSTEM_H #include "blackmisc/aviomodulator.h" +#include namespace BlackMisc { diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index d9e88dd15..e31135998 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -111,8 +111,8 @@ public: bool isMagneticTrack() const { return this->m_magnetic; - QT_TRANSLATE_NOOP("Aviation", "magnetic"); - QT_TRANSLATE_NOOP("Aviation", "true"); + (void)QT_TRANSLATE_NOOP("Aviation", "magnetic"); + (void)QT_TRANSLATE_NOOP("Aviation", "true"); } /*! diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index e2113a91b..6d6d5819a 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -5,6 +5,7 @@ #include "blackmisc/mathmatrix3x3.h" #include "blackmisc/mathmatrix3x1.h" +#include namespace BlackMisc { diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 18aefe77e..18fa3c275 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace BlackMisc { @@ -459,10 +460,10 @@ public: { qRegisterMetaType(typeid(MU).name()); qDBusRegisterMetaType(); - qDBusRegisterMetaType>(); + qDBusRegisterMetaType >(); qRegisterMetaType(typeid(PQ).name()); qDBusRegisterMetaType(); - qDBusRegisterMetaType>(); + qDBusRegisterMetaType >(); } }; From 586be27502c4580d31bab32a4b8b3bdd586ed3da Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 14 Aug 2013 03:28:19 +0100 Subject: [PATCH 17/36] update unit tests --- tests/blackmisc/testaviation.cpp | 10 ---------- tests/blackmisc/testaviation.h | 5 ----- tests/blackmisc/testgeo.cpp | 2 +- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index 4652a9100..7bec3cda6 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -44,16 +44,6 @@ void CTestAviation::headingBasics() QVERIFY2(h2.unitValueToDouble() == 360, "Value shall be 360"); } -/* - * Vertical positions - */ -void CTestAviation::verticalPosition() -{ - CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0); - CAviationVerticalPositions vp2 = vp1; - QVERIFY2(vp1 == vp2, "Values shall be equal"); -} - /* * COM and NAV units */ diff --git a/tests/blackmisc/testaviation.h b/tests/blackmisc/testaviation.h index 45ffbd2f0..b3c153ee1 100644 --- a/tests/blackmisc/testaviation.h +++ b/tests/blackmisc/testaviation.h @@ -8,7 +8,6 @@ #include "blackmisc/pqconstants.h" #include "blackmisc/avheading.h" -#include "blackmisc/avverticalpositions.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" @@ -36,10 +35,6 @@ private slots: * \brief Basic unit tests for physical units */ void headingBasics(); - /*! - * \brief Vertical positions - */ - void verticalPosition(); /*! * \brief COM and NAV units */ diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp index 6ea4cc34d..211bd098c 100644 --- a/tests/blackmisc/testgeo.cpp +++ b/tests/blackmisc/testgeo.cpp @@ -28,7 +28,7 @@ void CTestGeo::geoBasics() CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec); // check against rounded reconvert - QVERIFY2(mediumEcefVec.roundedVector() == ecefReconvert.roundedVector(), "Reconverted geo vector should be equal"); + QVERIFY2(mediumEcefVec.rounded() == ecefReconvert.rounded(), "Reconverted geo vector should be equal"); } } // namespace From baa0ac147e70020d4933bb0a4a8f7b4a5e7caa40 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 14 Aug 2013 03:29:03 +0100 Subject: [PATCH 18/36] remove integer quantities --- src/blackmisc/pqacceleration.h | 7 --- src/blackmisc/pqangle.h | 7 --- src/blackmisc/pqfrequency.h | 7 --- src/blackmisc/pqlength.h | 7 --- src/blackmisc/pqmass.h | 7 --- src/blackmisc/pqphysicalquantity.cpp | 65 +++------------------- src/blackmisc/pqphysicalquantity.h | 40 ------------- src/blackmisc/pqpressure.h | 7 --- src/blackmisc/pqspeed.h | 7 --- src/blackmisc/pqtemperature.h | 7 --- src/blackmisc/pqtime.h | 7 --- tests/blackmisc/testphysicalquantities.cpp | 7 +-- 12 files changed, 10 insertions(+), 165 deletions(-) diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 449c2aec9..0461f8b3f 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -23,13 +23,6 @@ public: */ CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::m_s2(), CAccelerationUnit::m_s2()) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAcceleration(qint32 value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index de0bd6517..1dc37a270 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -29,13 +29,6 @@ public: */ CAngle(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAngle(qint32 value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 4501a7461..7d106204a 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -29,13 +29,6 @@ public: */ CFrequency(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index 6cc339203..fe24480b0 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -29,13 +29,6 @@ public: */ CLength(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CLength(qint32 value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index 76cc070a0..266b54929 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -23,13 +23,6 @@ public: */ CMass() : CPhysicalQuantity(0, CMassUnit::kg(), CMassUnit::kg()) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CMass(qint32 value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 581cc9025..63b7ba8b3 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -10,15 +10,6 @@ namespace BlackMisc namespace PhysicalQuantities { -/* - * Constructor by integer - */ -template CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit) : - m_unit(unit), m_conversionSiUnit(siConversionUnit) -{ - this->setUnitValue(baseValue); -} - /* * Constructor by double */ @@ -32,8 +23,8 @@ template CPhysicalQuantity::CPhysicalQuantity(doubl * Copy constructor */ template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &other) : - m_unitValueD(other.m_unitValueD), m_unitValueI(other.m_unitValueI), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), - m_isIntegerBaseValue(other.m_isIntegerBaseValue), m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) + m_unitValueD(other.m_unitValueD), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), + m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) { } @@ -58,18 +49,9 @@ template bool CPhysicalQuantity::operator ==(const bool eq = false; if (this->m_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer comparison, no rounding issues - eq = this->m_unitValueI == other.m_unitValueI; - } - else - { - // same unit, comparison based on double - diff = qAbs(this->m_unitValueD - other.m_unitValueD); - eq = diff <= (lenient * this->m_unit.getEpsilon()); - } + // same unit, comparison based on double + diff = qAbs(this->m_unitValueD - other.m_unitValueD); + eq = diff <= (lenient * this->m_unit.getEpsilon()); } else { @@ -95,10 +77,8 @@ template CPhysicalQuantity& CPhysicalQuantitym_unitValueI = other.m_unitValueI; this->m_unitValueD = other.m_unitValueD; this->m_convertedSiUnitValueD = other.m_convertedSiUnitValueD; - this->m_isIntegerBaseValue = other.m_isIntegerBaseValue; this->m_unit = other.m_unit; this->m_conversionSiUnit = other.m_conversionSiUnit; return *this; @@ -111,16 +91,7 @@ template CPhysicalQuantity &CPhysicalQuantitym_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(other.m_unitValueI + this->m_unitValueI); - } - else - { - this->setUnitValue(other.m_unitValueD + this->m_unitValueD); - } + this->setUnitValue(other.m_unitValueD + this->m_unitValueD); } else { @@ -163,16 +134,7 @@ template CPhysicalQuantity &CPhysicalQuantitym_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(other.m_unitValueI - this->m_unitValueI); - } - else - { - this->setUnitValue(other.m_unitValueD - this->m_unitValueD); - } + this->setUnitValue(other.m_unitValueD - this->m_unitValueD); } else { @@ -283,25 +245,12 @@ template PQ &CPhysicalQuantity::switchUnit(const MU return *derived(); } -/* - * Init by integer - */ -template void CPhysicalQuantity::setUnitValue(qint32 baseValue) -{ - this->m_unitValueI = baseValue; - this->m_unitValueD = double(baseValue); - this->m_isIntegerBaseValue = true; - this->setConversionSiUnitValue(); -} - /* * Init by double */ template void CPhysicalQuantity::setUnitValue(double baseValue) { this->m_unitValueD = baseValue; - this->m_unitValueI = qRound(baseValue); - this->m_isIntegerBaseValue = false; this->setConversionSiUnitValue(); } diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 18fa3c275..586755265 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -28,9 +28,7 @@ template class CPhysicalQuantity : public BlackMisc::CBaseS { private: double m_unitValueD; //!< value backed by double - qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic double m_convertedSiUnitValueD; //!< SI unit value - bool m_isIntegerBaseValue; //!< flag integer? / double? /*! * \brief Easy access to derived class (CRTP template parameter) @@ -54,14 +52,6 @@ protected: MU m_unit; //!< unit MU m_conversionSiUnit; //!< corresponding SI base unit - /*! - * \brief Constructor by integer - * \param baseValue - * \param unit - * \param siConversionUnit - */ - CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit); - /*! * \brief Constructor with double * \param baseValue @@ -80,12 +70,6 @@ protected: return this->unitValueRoundedWithUnit(-1, i18n); } - /*! - * \brief Init by integer - * \param baseValue - */ - void setUnitValue(qint32 baseValue); - /*! * \brief Init by double * \param baseValue @@ -186,15 +170,6 @@ public: */ QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; - /*! - * \brief Value as int - * \return - */ - qint32 unitValueToInteger() const - { - return this->m_unitValueI; - } - /*! * \brief Value as double * \return @@ -235,16 +210,6 @@ public: return this->m_convertedSiUnitValueD; } - /*! - * \brief SI value as integer - * \return - */ - qint32 convertedSiValueToInteger() const - { - return static_cast( - BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); - } - /*! * \brief Rounded SI value by n digits * \param digits @@ -403,7 +368,6 @@ public: */ bool isZeroEpsilon() const { - if (this->m_isIntegerBaseValue) return this->m_unitValueI == 0; return this->m_unit.isEpsilon(this->m_unitValueD); } @@ -432,9 +396,7 @@ public: virtual void marshallToDbus(QDBusArgument &argument) const { argument << this->m_unitValueD; - argument << this->m_unitValueI; argument << this->m_convertedSiUnitValueD; - argument << this->m_isIntegerBaseValue; argument << this->m_unit; argument << this->m_conversionSiUnit; } @@ -446,9 +408,7 @@ public: virtual void unmarshallFromDbus(const QDBusArgument &argument) { argument >> this->m_unitValueD; - argument >> this->m_unitValueI; argument >> this->m_convertedSiUnitValueD; - argument >> this->m_isIntegerBaseValue; argument >> this->m_unit; argument >> this->m_conversionSiUnit; } diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index 660f1451a..80d57f96c 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -30,13 +30,6 @@ public: */ CPressure(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index 737b2f0d4..f5ecf2e72 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -30,13 +30,6 @@ public: */ CSpeed(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CSpeed(qint32 value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index 896b313d4..4553493fd 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -29,13 +29,6 @@ public: */ CTemperature(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CTemperature(qint32 value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 62e78f115..16bbf9fe4 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -30,13 +30,6 @@ public: */ CTime(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CTime(qint32 value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} - /*! *\brief Init by double value * \param value diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 6dabc06cb..9b9202b3e 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -97,7 +97,6 @@ void CTestPhysicalQuantities::angleTests() CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 a2.switchUnit(CAngleUnit::deg()); - QVERIFY2(a2.unitValueToInteger() == 270, qPrintable(QString("1.5Pi should be 270deg, not %1 deg").arg(a2.unitValueToInteger()))); QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor()))); QVERIFY2(a3.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); } @@ -108,9 +107,9 @@ void CTestPhysicalQuantities::angleTests() void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); - CMass w2(w1.unitValueToInteger(), CMassUnit::kg()); + CMass w2(w1.unitValueToDouble(), CMassUnit::kg()); w2.switchUnit(CMassUnit::t()); - QVERIFY2(w2.unitValueToInteger() == 1, "1tonne shall be 1000kg"); + QVERIFY2(w2.unitValueToDouble() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); QVERIFY2(w2.unitValueToDoubleRounded(2) == 2204.62, "1tonne shall be 2204pounds"); QVERIFY2(w1 == w2, "Masses shall be equal"); @@ -154,7 +153,7 @@ void CTestPhysicalQuantities::temperatureTests() void CTestPhysicalQuantities::timeTests() { CTime t1(1, CTimeUnit::h()); - QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s"); + QVERIFY2(t1.convertedSiValueToDouble() == 3600, "1hour shall be 3600s"); } /* From 5d4fcc8d40ec44d68f73cbae3e7e55e63254953b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 18 Aug 2013 17:29:37 +0100 Subject: [PATCH 19/36] resolved pressure constants 1013.2hPa != 29.92inHg --- src/blackmisc/pqconstants.h | 24 ++++++++++++++++++++-- src/blackmisc/pqunits.h | 13 +----------- tests/blackmisc/testphysicalquantities.cpp | 4 +--- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index 173a605ae..d2a7ce937 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -40,15 +40,35 @@ public: } /*! - * \brief Standard pressure 1013,25mbar / 29.92inHg + * \brief International Standard Atmosphere pressure at mean sea level, 1013.25hPa * \return */ - static const CPressure& InternationalStandardSeaLevelPressure() + static const CPressure& ISASeaLevelPressure() { static CPressure p(1013.25, CPressureUnit::hPa()); return p; } + /*! + * \brief ICAO standard pressure datum for flight levels, 1013.2hPa + * \return + */ + static const CPressure& ICAOFlightLevelPressure() + { + static CPressure p(1013.2, CPressureUnit::hPa()); + return p; + } + + /*! + * \brief Standard pressure datum for flight levels in USA, Canada, parts of Latin America, 29.92inHg + * \return + */ + static const CPressure& USFlightLevelPressure() + { + static CPressure p(29.92, CPressureUnit::inHg()); + return p; + } + /*! * \brief Unicom frequency * \return diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index c20c0771e..a6c355580 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -627,17 +627,7 @@ public: */ static const CPressureUnit &inHg() { - static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury 0C"), "inHg", false, 3386.389); - return inhg; - } - - /*! - * \brief Inch of mercury for flight level 29,92inHg = 1013,25mbar = 1013,25hPa - * \return - */ - static const CPressureUnit &inHgFL() - { - static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", false, 3386.5307486631); + static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", false, 3386.389); return inhg; } @@ -653,7 +643,6 @@ public: u.append(CPressureUnit::bar()); u.append(CPressureUnit::hPa()); u.append(CPressureUnit::inHg()); - u.append(CPressureUnit::inHgFL()); u.append(CPressureUnit::mbar()); u.append(CPressureUnit::psi()); } diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 9b9202b3e..2a918a458 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -122,13 +122,11 @@ void CTestPhysicalQuantities::pressureTests() { CPressure p1(1013.25, CPressureUnit::hPa()); CPressure p2(29.92, CPressureUnit::inHg()); - CPressure p3(29.92, CPressureUnit::inHgFL()); CPressure p4(p1); p4.switchUnit(CPressureUnit::mbar()); // does not match exactly QVERIFY2(p1 != p2, "Standard pressure test little difference"); - QVERIFY2(p1 == p3, "Standard pressure test matching"); QVERIFY2(p1.unitValueToDouble() == p4.unitValueToDouble(), "mbar/hPa test"); } @@ -195,7 +193,7 @@ void CTestPhysicalQuantities::memoryTests() */ void CTestPhysicalQuantities::basicArithmetic() { - CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure(); + CPressure p1 = CPhysicalQuantitiesConstants::ISASeaLevelPressure(); CPressure p2(p1); p2 *= 2.0; CPressure p3 = p1 + p1; From c8114c2d850debcd4d048dad61b5131a4b525ddb Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 18 Aug 2013 23:13:56 +0100 Subject: [PATCH 20/36] Remove switchUnit() from CHeading and CTrack; they already inherit switchUnit() from CPhysicalQuantity --- src/blackmisc/avheading.h | 11 ----------- src/blackmisc/avtrack.h | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index a75dd1c56..83d678da6 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -117,17 +117,6 @@ public: */ bool isTrueHeading() const { return !this->m_magnetic; } - /*! - * \brief Switch angle unit - * \param newUnit - * \return - */ - CHeading &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit) - { - this->CAngle::switchUnit(newUnit); - return *this; - } - /*! * \brief Register metadata */ diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index e31135998..6eca3ecf8 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -124,17 +124,6 @@ public: return !this->m_magnetic; } - /*! - * \brief Switch angle unit - * \param newUnit - * \return - */ - CTrack &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit) - { - this->CAngle::switchUnit(newUnit); - return *this; - } - /*! * \brief Register metadata */ From a8036f1ce55d22dc403f2ec357ea1db37f203c98 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 18 Aug 2013 23:15:33 +0100 Subject: [PATCH 21/36] in geodetic coordinates, latitude(), longitude(), and height() return by reference to const instead of by value --- src/blackmisc/coordinategeodetic.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 7f7ef9681..6883db106 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -25,13 +25,13 @@ class ICoordinateGeodetic * \brief Latitude * \return */ - virtual CLatitude latitude() const = 0; + virtual const CLatitude &latitude() const = 0; /*! * \brief Longitude * \return */ - virtual CLongitude longitude() const = 0; + virtual const CLongitude &longitude() const = 0; }; /*! @@ -98,7 +98,7 @@ public: * \brief Latitude * \return */ - CLatitude latitude() const + const CLatitude &latitude() const { return this->m_latitude; } @@ -107,7 +107,7 @@ public: * \brief Longitude * \return */ - CLongitude longitude() const + const CLongitude &longitude() const { return this->m_longitude; } @@ -116,7 +116,7 @@ public: * \brief Height * \return */ - BlackMisc::PhysicalQuantities::CLength height() const + const BlackMisc::PhysicalQuantities::CLength &height() const { return this->m_height; } From da8ba9aac3c3cd40b512e558a78c1ead38b5ab5b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 18 Aug 2013 23:40:52 +0100 Subject: [PATCH 22/36] First major wave of PQ refactoring, including but not limited to: * Default unit is more clearly stated in one place, not restated in many different places, and is not always the SI unit * Converter strategy pattern in CMeasurementUnit, covering linear, affine, and different kinds of sexagesimal units * General reorganization of CMeasurementUnit construction and CPhysicalQuantity methods, not removing any behvaiour * Move duplicated method unitFromSymbol from derived classes into base class CMeasurementUnit * For DBus, CPhysicalQuantity marshals both in its own unit and in the default unit --- .../samplesphysicalquantities.cpp | 15 +- samples/blackmiscquantities_dbus/main.cpp | 4 +- src/blackmisc/aviomodulator.h | 4 +- src/blackmisc/coordinategeodetic.cpp | 2 +- src/blackmisc/coordinatetransformation.cpp | 2 +- src/blackmisc/geoearthangle.h | 2 +- src/blackmisc/mathematics.h | 21 + src/blackmisc/pqacceleration.h | 4 +- src/blackmisc/pqangle.h | 24 +- src/blackmisc/pqbase.cpp | 110 ++- src/blackmisc/pqbase.h | 380 ++++++----- src/blackmisc/pqconstants.h | 10 + src/blackmisc/pqfrequency.h | 4 +- src/blackmisc/pqlength.h | 4 +- src/blackmisc/pqmass.h | 4 +- src/blackmisc/pqphysicalquantity.cpp | 166 +---- src/blackmisc/pqphysicalquantity.h | 208 ++---- src/blackmisc/pqpressure.h | 4 +- src/blackmisc/pqspeed.h | 4 +- src/blackmisc/pqtemperature.h | 4 +- src/blackmisc/pqtime.h | 4 +- src/blackmisc/pqunits.cpp | 111 ++-- src/blackmisc/pqunits.h | 624 +++++++++--------- tests/blackmisc/testaviation.cpp | 4 +- tests/blackmisc/testgeo.cpp | 2 +- tests/blackmisc/testphysicalquantities.cpp | 45 +- 26 files changed, 809 insertions(+), 957 deletions(-) diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index ca451855b..322eaa450 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -57,7 +57,7 @@ int CSamplesPhysicalQuantities::samples() CSpeed s2 = CSpeed(1000, CSpeedUnit::ft_min()); CSpeed s3 = CSpeed(s2); s3.switchUnit(CSpeedUnit::m_s()); - qDebug() << s1 << s1.convertedSiValueRoundedWithUnit() << s1.valueRoundedWithUnit(CSpeedUnit::NM_h()); + qDebug() << s1 << s1.valueRoundedWithUnit(CSpeedUnit::defaultUnit()) << s1.valueRoundedWithUnit(CSpeedUnit::NM_h()); qDebug() << s2 << s3; CAngle a1(180, CAngleUnit::deg()); @@ -72,7 +72,7 @@ int CSamplesPhysicalQuantities::samples() a2 = a1 + a1; a2.switchUnit(CAngleUnit::deg()); - qDebug() << a1.unitValueRoundedWithUnit() << a1.piFactor(); + qDebug() << a1.valueRoundedWithUnit() << a1.piFactor(); qDebug() << a2; a3.switchUnit(CAngleUnit::sexagesimalDeg()); a4.switchUnit(CAngleUnit::deg()); @@ -89,8 +89,8 @@ int CSamplesPhysicalQuantities::samples() CTemperature t1; CTemperature t2(20, CTemperatureUnit::C()); CTemperature t3(1, CTemperatureUnit::F()); - qDebug() << t1 << t2 << t2.convertedSiValueRoundedWithUnit(true); - qDebug() << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1 ,true) << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << "I18N/UTF"; + qDebug() << t1 << t2 << t2.valueRoundedWithUnit(CTemperatureUnit::defaultUnit(), -1, true); + qDebug() << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1, true) << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << "I18N/UTF"; // some logging with CLogMessage // bDebug << p1; @@ -108,10 +108,13 @@ int CSamplesPhysicalQuantities::samples() CTime ti1(1, CTimeUnit::h()); CTime ti2(ti1); ti2.switchUnit(CTimeUnit::ms()); - qDebug() << ti1 << ti2; + CTime ti3(1.0101, CTimeUnit::hms()); + CTime ti4(1.15, CTimeUnit::hrmin()); + CTime ti5(1.30, CTimeUnit::minsec()); + qDebug() << ti1 << ti2 << ti3 << ti4 << ti5; CAcceleration ac1(10, CAccelerationUnit::m_s2()); - qDebug() << ac1 << ac1.unitValueRoundedWithUnit(-1, true) << "I18N/UTF"; + qDebug() << ac1 << ac1.valueRoundedWithUnit(-1, true) << "I18N/UTF"; // bye qDebug() << "-----------------------------------------------"; diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index f43989c1a..e88fea442 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) qDebug() << "Send speed via interface" << speed; TestserviceTool::sleep(2500); speed.switchUnit(CSpeedUnit::km_h()); - speed.addUnitValue(1.0); + speed.addValueSameUnit(1.0); // Aviation CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom()); @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) testserviceInterface.receiveVariant(qv); testserviceInterface.receiveAltitude(al); qDebug() << "Send altitude via interface" << al; - al.addUnitValue(1); + al.addValueSameUnit(1); CTransponder transponder("transponder", 7000, CTransponder::ModeC); testserviceInterface.receiveTransponder(transponder); diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index b51686b18..3d6ca3a5a 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -85,8 +85,8 @@ protected: virtual QString convertToQString(bool i18n = false) const { QString s(this->getName()); - s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3, i18n)); - s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3, i18n)); + s.append(" Active: ").append(this->m_frequencyActive.valueRoundedWithUnit(3, i18n)); + s.append(" Standby: ").append(this->m_frequencyStandby.valueRoundedWithUnit(3, i18n)); return s; } diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp index 10f64507c..b1d675b33 100644 --- a/src/blackmisc/coordinategeodetic.cpp +++ b/src/blackmisc/coordinategeodetic.cpp @@ -16,7 +16,7 @@ namespace Geo QString CCoordinateGeodetic::convertToQString(bool i18n) const { QString s = "Geodetic: {%1, %2, %3}"; - return s.arg(this->m_latitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_longitude.unitValueRoundedWithUnit(6, i18n)).arg(this->m_height.unitValueRoundedWithUnit(i18n)); + return s.arg(this->m_latitude.valueRoundedWithUnit(6, i18n)).arg(this->m_longitude.valueRoundedWithUnit(6, i18n)).arg(this->m_height.valueRoundedWithUnit(i18n)); } /* diff --git a/src/blackmisc/coordinatetransformation.cpp b/src/blackmisc/coordinatetransformation.cpp index a79483ce9..28c70fbc4 100644 --- a/src/blackmisc/coordinatetransformation.cpp +++ b/src/blackmisc/coordinatetransformation.cpp @@ -80,7 +80,7 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo double clambda = cos(lambdaRad); - double h = geo.height().convertedSiValueToDouble(); + double h = geo.height().value(CLengthUnit::m()); double x = (n + h) * cphi; double y = x * slambda; x *= clambda; diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 54c74a021..ccb707659 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -75,7 +75,7 @@ protected: */ virtual QString convertToQString() const { - return this->unitValueRoundedWithUnit(6); + return this->valueRoundedWithUnit(6); } /*! diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index f49241513..fa0eeada8 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -6,6 +6,7 @@ #ifndef BLACKMISC_MATHEMATICS_H #define BLACKMISC_MATHEMATICS_H #include +#include namespace BlackMisc { @@ -70,6 +71,26 @@ public: */ static double roundEpsilon(double value, double epsilon); + /*! + * \brief Nearest integer not greater in magnitude than value, correcting for epsilon + * \param value + * \param epsilon + */ + static inline double trunc(double value, double epsilon = 1e-10) + { + return value < 0 ? ceil(value - epsilon) : floor(value + epsilon); + } + + /*! + * \brief Fractional part of value + * \param value + */ + static inline double fract(double value) + { + double unused; + return modf(value, &unused); + } + /*! * \brief PI * \return diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 0461f8b3f..6d7c7718e 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -21,14 +21,14 @@ public: /*! * \brief Default constructor */ - CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::m_s2(), CAccelerationUnit::m_s2()) {} + CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::defaultUnit()) {} /*! * \brief Init by double value * \param value * \param unit */ - CAcceleration(double value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} + CAcceleration(double value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Copy constructor by base type diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 1dc37a270..9453f63c6 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -22,7 +22,7 @@ public: /*! * \brief Default constructor */ - CAngle() : CPhysicalQuantity(0, CAngleUnit::rad(), CAngleUnit::rad()) {} + CAngle() : CPhysicalQuantity(0, CAngleUnit::defaultUnit()) {} /*! * \brief Copy constructor from base type @@ -34,18 +34,30 @@ public: * \param value * \param unit */ - CAngle(double value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} + CAngle(double value, const CAngleUnit &unit): CPhysicalQuantity(value, unit) {} /*! - * \brief Intir as sexagesimal degrees + * \brief Init as sexagesimal degrees, minutes, seconds + * The sign of all parameters must be the same, either all positive or all negative. * \param degrees * \param minutes * \param seconds */ - CAngle(qint32 degrees, qint32 minutes, double seconds) : + CAngle(int degrees, int minutes, double seconds) : CPhysicalQuantity( degrees + minutes / 100.0 + seconds / 10000.0, - CAngleUnit::sexagesimalDeg(), CAngleUnit::rad()) {} + CAngleUnit::sexagesimalDeg()) {} + + /*! + * \brief Init as sexagesimal degrees, minutes + * The sign of both parameters must be the same, either both positive or both negative. + * \param degrees + * \param minutes + */ + CAngle(int degrees, double minutes) : + CPhysicalQuantity( + degrees + minutes / 100.0, + CAngleUnit::sexagesimalDegMin()) {} /*! * \brief Virtual destructor @@ -58,7 +70,7 @@ public: */ double piFactor() const { - return BlackMisc::Math::CMath::round(this->convertedSiValueToDouble() / BlackMisc::Math::CMath::PI() , 6); + return BlackMisc::Math::CMath::round(this->value(CAngleUnit::rad()) / BlackMisc::Math::CMath::PI() , 6); } /*! diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 47a916f98..982ddaf0e 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -14,14 +14,14 @@ namespace PhysicalQuantities { // ----------------------------------------------------------------------- -// --- Mulitplier -------------------------------------------------------- +// --- Prefix ------------------------------------------------------------ // ----------------------------------------------------------------------- /* * Constructor */ -CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitName, double factor) : - m_name(name), m_prefix(unitName), m_factor(factor) +CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &symbol, double factor) : + m_name(name), m_symbol(symbol), m_factor(factor) { } @@ -29,7 +29,7 @@ CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitN * Constructor */ CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &other) : - m_name(other.m_name), m_prefix(other.m_prefix), m_factor(other.m_factor) + m_name(other.m_name), m_symbol(other.m_symbol), m_factor(other.m_factor) { } @@ -40,7 +40,7 @@ CMeasurementPrefix &CMeasurementPrefix::operator=(const CMeasurementPrefix &othe { if (this == &other) return *this; this->m_name = other.m_name; - this->m_prefix = other.m_prefix; + this->m_symbol= other.m_symbol; this->m_factor = other.m_factor; return *this; } @@ -62,22 +62,6 @@ bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const return !(*this == other); } -/* - * Greater? - */ -bool CMeasurementPrefix::operator >(const CMeasurementPrefix &other) const -{ - return this->m_factor > other.m_factor; -} - -/* - * Less? - */ -bool CMeasurementPrefix::operator <(const CMeasurementPrefix &other) const -{ - return this->m_factor < other.m_factor; -} - // ----------------------------------------------------------------------- // --- Measurement unit -------------------------------------------------- // ----------------------------------------------------------------------- @@ -85,22 +69,40 @@ bool CMeasurementPrefix::operator <(const CMeasurementPrefix &other) const /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName, const QString &type, bool isSIUnit, bool isSIBaseUnit, - double conversionFactorToSI, const CMeasurementPrefix &multiplier, qint32 displayDigits, double epsilon, - UnitConverter toSiConverter, UnitConverter fromSiConverter): - m_name(name), m_unitName(unitName), m_type(type), m_isSiUnit(isSIUnit), m_isSiBaseUnit(isSIBaseUnit), - m_conversionFactorToSIConversionUnit(conversionFactorToSI), - m_epsilon(epsilon), m_displayDigits(displayDigits), m_multiplier(multiplier), m_fromSiConverter(fromSiConverter), m_toSiConverter(toSiConverter) +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, qint32 displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new LinearConverter(factor)) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, qint32 displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new AffineConverter(factor, offset)) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, qint32 displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(converter) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, qint32 displayDigits, double epsilon) : + m_name(base.m_name), m_symbol(base.m_symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(prefix), m_converter(base.m_converter->clone(prefix)) { } /* * Copy constructor */ -CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other): - m_name(other.m_name), m_unitName(other.m_unitName), m_type(other.m_type), m_isSiUnit(other.m_isSiUnit), - m_isSiBaseUnit(other.m_isSiBaseUnit), m_conversionFactorToSIConversionUnit(other.m_conversionFactorToSIConversionUnit), - m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_multiplier(other.m_multiplier), m_fromSiConverter(other.m_fromSiConverter), m_toSiConverter(other.m_toSiConverter) +CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) : + m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_prefix(other.m_prefix), m_converter(other.m_converter) { } @@ -111,16 +113,11 @@ CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &other) { if (this == &other) return *this; // Same object? Yes, so skip assignment, and just return *this this->m_name = other.m_name; - this->m_unitName = other.m_unitName; - this->m_type = other.m_type; - this->m_isSiUnit = other.m_isSiUnit; - this->m_isSiBaseUnit = other.m_isSiBaseUnit; - this->m_conversionFactorToSIConversionUnit = other.m_conversionFactorToSIConversionUnit; - this->m_multiplier = other.m_multiplier; + this->m_symbol = other.m_symbol; + this->m_prefix = other.m_prefix; this->m_displayDigits = other.m_displayDigits; this->m_epsilon = other.m_epsilon; - this->m_fromSiConverter = other.m_fromSiConverter; - this->m_toSiConverter = other.m_toSiConverter; + this->m_converter = other.m_converter; return *this; } @@ -130,9 +127,7 @@ CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &other) bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const { if (this == &other) return true; - if (this->m_type != other.m_type) return false; - return this->m_multiplier == other.m_multiplier && this->m_name == other.m_name - && this->m_isSiUnit == other.m_isSiUnit; + return this->m_prefix == other.m_prefix && this->m_name == other.m_name; } /* @@ -144,28 +139,29 @@ bool CMeasurementUnit::operator !=(const CMeasurementUnit &other) const } /* - * Conversion factor from unit x to y + * Conversion */ -double CMeasurementUnit::conversionToUnit(double value, const CMeasurementUnit &to) const +double CMeasurementUnit::convertFrom(double value, const CMeasurementUnit &unit) const { - if (to == *this) return value; - double siValue = this->convertToSiConversionUnit(value); - return to.convertFromSiConversionUnit(siValue); + Q_ASSERT(this->m_converter); + Q_ASSERT(unit.m_converter); + if (this->m_converter == unit.m_converter) return value; + return this->m_converter->fromDefault(unit.m_converter->toDefault(value)); } /* * Value to QString with unit, e.g. "5.00m" * @return */ -QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits, bool i18n) const +QString CMeasurementUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { - return this->toQStringRounded(value, digits).append(this->getUnitName(i18n)); + return this->makeRoundedQString(value, digits).append(this->getSymbol(i18n)); } /* * Value rounded */ -double CMeasurementUnit::valueRounded(double value, int digits) const +double CMeasurementUnit::roundValue(double value, int digits) const { if (digits < 0) digits = this->m_displayDigits; return CMath::round(value, digits); @@ -174,7 +170,7 @@ double CMeasurementUnit::valueRounded(double value, int digits) const /* * Rounded to QString */ -QString CMeasurementUnit::toQStringRounded(double value, int digits, bool /* i18n */) const +QString CMeasurementUnit::makeRoundedQString(double value, int digits, bool /* i18n */) const { if (digits < 0) digits = this->m_displayDigits; double v = CMath::round(value, digits); @@ -182,17 +178,5 @@ QString CMeasurementUnit::toQStringRounded(double value, int digits, bool /* i18 return s; } -/* - * Epsilon rounding - */ -double CMeasurementUnit::epsilonUpRounding(double value) const -{ - // Rounds a little up in order to avoid fractions - double eps = value > 0 ? this->m_epsilon : -1.0 * this->m_epsilon; - double v = floor((value + eps) / this->m_epsilon); - v *= this->m_epsilon; - return v; -} - } // namespace } // namespace diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 78c663189..4bee55a0a 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -8,12 +8,14 @@ #include "blackmisc/basestreamstringifier.h" #include "blackmisc/debug.h" +#include "blackmisc/mathematics.h" #include #include #include #include #include - +#include +#include namespace BlackMisc { @@ -23,13 +25,13 @@ namespace PhysicalQuantities /*! * \brief Typical prefixes (multipliers) such as kilo, mega, hecto. * See here for an overview. - * Use the static values such CMeasurementMultiplier::k() as to specify values. + * Use the static values such as CMeasurementPrefix::k() to specify values. */ class CMeasurementPrefix : public CBaseStreamStringifier { private: QString m_name; //!< name, e.g. "kilo" - QString m_prefix; //!< prefix, e.g. "k" for kilo + QString m_symbol; //!< prefix, e.g. "k" for kilo double m_factor; //!< factor, e.g. 1000 for kilo 1/100 for centi /*! @@ -39,11 +41,11 @@ private: * \param prefixName * \param factor */ - CMeasurementPrefix(const QString &name, const QString &prefixName, double factor); + CMeasurementPrefix(const QString &name, const QString &symbol, double factor); protected: /*! - * \brief Name as stringification + * \brief Name as string * \param i18n * \return */ @@ -100,20 +102,6 @@ public: */ bool operator != (const CMeasurementPrefix &other) const; - /*! - * \brief Greater operator > - * \param other - * \return - */ - bool operator > (const CMeasurementPrefix &other) const; - - /*! - * \brief Less operator < - * \param other - * \return - */ - bool operator < (const CMeasurementPrefix &other) const; - /*! * \brief Factor, e.g.1000 for "kilo" * \return @@ -136,26 +124,18 @@ public: * \brief Name, e.g. "kilo" * \return */ - QString getName() const + QString getName(bool i18n = false) const { - return this->m_name; + return i18n ? QCoreApplication::translate("CMeasurementPrefix", this->m_name.toStdString().c_str()) : this->m_name; } /*! * \brief Prefix, e.g. "k" for "kilo" * \return */ - QString getPrefix() const + QString getSymbol(bool i18n = false) const { - return this->m_prefix; - } - - /*! - * \brief Operator as double - */ - operator double() const - { - return this->m_factor; + return i18n ? QCoreApplication::translate("CMeasurementPrefix", this->m_symbol.toStdString().c_str()) : this->m_symbol; } // --- static units, always use these for initialization @@ -178,7 +158,7 @@ public: */ static const CMeasurementPrefix &One() { - static CMeasurementPrefix one("one", "", 1.0); + static CMeasurementPrefix one(QT_TR_NOOP("one"), "", 1.0); return one; } @@ -188,7 +168,7 @@ public: */ static const CMeasurementPrefix &M() { - static CMeasurementPrefix mega("mega", "M", 1E6); + static CMeasurementPrefix mega(QT_TR_NOOP("mega"), "M", 1E6); return mega; } @@ -198,7 +178,7 @@ public: */ static const CMeasurementPrefix &k() { - static CMeasurementPrefix kilo("kilo", "k", 1000.0); + static CMeasurementPrefix kilo(QT_TR_NOOP("kilo"), "k", 1000.0); return kilo; } @@ -208,7 +188,7 @@ public: */ static const CMeasurementPrefix &G() { - static CMeasurementPrefix giga("giga", "G", 1E9); + static CMeasurementPrefix giga(QT_TR_NOOP("giga"), "G", 1E9); return giga; } @@ -218,7 +198,7 @@ public: */ static const CMeasurementPrefix &h() { - static CMeasurementPrefix hecto("hecto", "h", 100.0); + static CMeasurementPrefix hecto(QT_TR_NOOP("hecto"), "h", 100.0); return hecto; } @@ -228,7 +208,7 @@ public: */ static const CMeasurementPrefix &c() { - static CMeasurementPrefix centi("centi", "c", 0.01); + static CMeasurementPrefix centi(QT_TR_NOOP("centi"), "c", 0.01); return centi; } @@ -238,7 +218,7 @@ public: */ static const CMeasurementPrefix &m() { - static CMeasurementPrefix milli("milli", "m", 1E-03); + static CMeasurementPrefix milli(QT_TR_NOOP("milli"), "m", 1E-03); return milli; } @@ -287,46 +267,171 @@ public: /*! * \brief Base class for all units, such as meter, hertz. */ -class CMeasurementUnit: public CBaseStreamStringifier +class CMeasurementUnit : public CBaseStreamStringifier { protected: /*! - * \brief Points to an individual converter method - * Conversion as perobject, as required for CAnglewith sexagesimal conversion + * Abstract strategy pattern that encapsulates a unit conversion strategy. */ - typedef double(*UnitConverter)(const CMeasurementUnit &, double); + class Converter : public QSharedData + { + public: + /*! + * Virtual destructor. + */ + virtual ~Converter() {} + /*! + * Convert from this unit to default unit. + * \param factor + * \return + */ + virtual double toDefault(double factor) const = 0; + /*! + * Convert from default unit to this unit. + * \param factor + * \return + */ + virtual double fromDefault(double factor) const = 0; + /*! + * Make a copy of this object with a different prefix. + * \param prefix + * \return + */ + virtual Converter *clone(const CMeasurementPrefix &prefix) const = 0; + }; + + /*! + * Concrete strategy pattern for converting unit with linear conversion. + */ + class LinearConverter : public Converter + { + double m_factor; + public: + /*! + * Constructor + * \param factor + */ + LinearConverter(double factor) : m_factor(factor) {} + virtual double toDefault(double factor) const { return factor * m_factor; } + virtual double fromDefault(double factor) const { return factor / m_factor; } + virtual Converter *clone(const CMeasurementPrefix &prefix) const { auto ret = new LinearConverter(*this); ret->m_factor *= prefix.getFactor(); return ret; } + }; + + /*! + * Concrete strategy pattern for converting unit with affine conversion. + */ + class AffineConverter : public Converter + { + double m_factor; + double m_offset; + public: + /*! + * Constructor + * \param factor + * \param offset + */ + AffineConverter(double factor, double offset) : m_factor(factor), m_offset(offset) {} + virtual double toDefault(double factor) const { return (factor - m_offset) * m_factor; } + virtual double fromDefault(double factor) const { return factor / m_factor + m_offset; } + virtual Converter *clone(const CMeasurementPrefix &prefix) const { auto ret = new AffineConverter(*this); ret->m_factor *= prefix.getFactor(); return ret; } + }; + + /*! + * Concrete strategy pattern for converting unit with subdivision conversion. + */ + template + class SubdivisionConverter : public Converter + { + double m_factor; + public: + /*! + * Constructor + */ + SubdivisionConverter(double factor = 1) : m_factor(factor) {} + virtual double toDefault(double factor) const { using BlackMisc::Math::CMath; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Den; + ret += factor / Num; + return ret * m_factor; } + virtual double fromDefault(double factor) const { using BlackMisc::Math::CMath; + factor /= m_factor; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Num; + return ret += factor / Den; } + virtual Converter *clone(const CMeasurementPrefix &) const { qFatal("Not implemented"); return 0; } + }; + + /*! + * Concrete strategy pattern for converting unit with subdivision conversion. + */ + template + class SubdivisionConverter2 : public Converter + { + double m_factor; + public: + /*! + * Constructor + */ + SubdivisionConverter2(double factor = 1) : m_factor(factor) {} + virtual double toDefault(double factor) const { using BlackMisc::Math::CMath; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Den1; + ret += CMath::trunc(factor) / Num1; factor = CMath::fract(factor) * Den2; + ret += factor / (Num1 * Num2); + return ret * m_factor; } + virtual double fromDefault(double factor) const { using BlackMisc::Math::CMath; + factor /= m_factor; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Num1; + ret += CMath::trunc(factor) / Den1; factor = CMath::fract(factor) * Num2; + return ret += factor / (Den1 * Den2); } + virtual Converter *clone(const CMeasurementPrefix &) const { qFatal("Not implemented"); return 0; } + }; private: QString m_name; //!< name, e.g. "meter" - QString m_unitName; //!< unit name, e.g. "m" - QString m_type; //!< type,such as distance. Somehow redundant, but simplifies unit comparisons - bool m_isSiUnit; //!< is this a SI unit? - bool m_isSiBaseUnit; //!< SI base unit? - double m_conversionFactorToSIConversionUnit; //!< factor to convert to SI, set to 0 if not applicable (rare cases, e.g. temperature) + QString m_symbol; //!< unit name, e.g. "m" double m_epsilon; //!< values with differences below epsilon are the equal int m_displayDigits; //!< standard rounding for string conversions - CMeasurementPrefix m_multiplier; //!< multiplier (kilo, Mega) - UnitConverter m_fromSiConverter; //! allows an arbitrary conversion method as per object (e.g. angle, sexagesimal) - UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object (e.g. angle, sexagesimal) + CMeasurementPrefix m_prefix; //!< multiplier (kilo, Mega) + QSharedDataPointer m_converter; //!< strategy pattern allows an arbitrary conversion method as per object protected: /*! - * Constructor by parameter + * Construct a unit with linear conversion * \param name - * \param unitName - * \param type - * \param isSiUnit - * \param isSiBaseUnit - * \param conversionFactorToSI - * \param multiplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon - * \param toSiConverter - * \param fromSiConverter */ - CMeasurementUnit(const QString &name, const QString &unitName, const QString &type, bool isSiUnit, bool isSiBaseUnit, double conversionFactorToSI = 1, - const CMeasurementPrefix &multiplier = CMeasurementPrefix::None(), qint32 displayDigits = 2, - double epsilon = 1E-10, UnitConverter toSiConverter = 0, UnitConverter fromSiConverter = 0); + CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon); + + /*! + * Construct a unit with affine conversion + * \param name + * \param symbol + * \param factor + * \param offset + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon); + + /*! + * Construct a unit with custom conversion + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon); + + /*! + * Construct from base unit and prefix + * \param base + * \param prefix + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10); /*! * \brief Copy constructor @@ -357,38 +462,7 @@ protected: */ virtual QString convertToQString(bool i18n = false) const { - return this->getUnitName(i18n); - } - - /*! - * \brief Conversion factor to SI conversion unit - * \return - */ - double getConversionFactorToSI() const - { - return this->m_conversionFactorToSIConversionUnit; - } - - /*! - * Given value to conversion SI conversion unit (e.g. meter, hertz). - * Standard implementaion is simply factor based. - * \param value - * \return - */ - virtual double conversionToSiConversionUnit(double value) const - { - return value * this->m_conversionFactorToSIConversionUnit; - } - - /*! - * \brief Value from SI conversion unit to this unit. - * Standard implementation is simply factor based. - * \param value - * \return - */ - virtual double conversionFromSiConversionUnit(double value) const - { - return value / this->m_conversionFactorToSIConversionUnit; + return this->getSymbol(i18n); } /*! @@ -397,7 +471,7 @@ protected: */ virtual void marshallToDbus(QDBusArgument &argument) const { - argument << this->m_unitName; + argument << this->m_symbol; } /*! @@ -411,6 +485,22 @@ protected: (*this) = CMeasurementUnit::None(); } + /*! + * \brief Unit from symbol + * \param symbol must be a valid unit symbol (without i18n) or empty string (empty means default unit) + * \return + */ + template static const U &unitFromSymbol(const QString &symbol) + { + if (symbol.isEmpty()) return U::defaultUnit(); + const QList &units = U::allUnits(); + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getSymbol() == symbol) return units.at(i); + } + qFatal("Illegal unit name"); + return U::defaultUnit(); // just suppress "not all control paths return a value" + } + public: /*! * \brief Equal operator == @@ -426,33 +516,6 @@ public: */ bool operator != (const CMeasurementUnit &other) const; - /*! - * \brief Representing an SI unit? Examples: kilometer, meter, hertz - * \return - */ - bool isSiUnit() const - { - return this->m_isSiUnit; - } - - /*! - * \brief Representing an base SI unit? Examples: second, meter - * \return - */ - bool isSiBaseUnit() const - { - return this->m_isSiUnit; - } - - /*! - * \brief Representing an SI base unit? Example: meter - * \return - */ - bool isUnprefixedSiUnit() const - { - return this->m_isSiUnit && this->m_multiplier.getFactor() == 1; - } - /*! * \brief Name such as "meter" * \param i18n @@ -460,7 +523,8 @@ public: */ QString getName(bool i18n = false) const { - return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; + QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; + return this->m_prefix.getName(i18n) + base; } /*! @@ -468,41 +532,19 @@ public: * \param i18n * \return */ - QString getUnitName(bool i18n = false) const + QString getSymbol(bool i18n = false) const { - return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_unitName.toStdString().c_str()) : this->m_unitName; + QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol; + return this->m_prefix.getSymbol(i18n) + base; } /*! - * \brief Type such as "distance", "frequency" - * \return - */ - QString getType() const - { - return this->m_type; - } - - /*! - * Given value to conversion SI conversion unit (e.g. meter, hertz). - * Standard implementation is simply factor based. + * \brief Rounded value * \param value + * \param digits * \return */ - double convertToSiConversionUnit(double value) const - { - return (this->m_toSiConverter) ? this->m_toSiConverter((*this), value) : this->conversionToSiConversionUnit(value); - } - - /*! - * Value from SI conversion unit to this unit. - * Standard implementation is simply factor based. - * \param value - * \return - */ - double convertFromSiConversionUnit(double value) const - { - return (this->m_fromSiConverter) ? this->m_fromSiConverter((*this), value) : this->conversionFromSiConversionUnit(value); - } + double roundValue(double value, int digits = -1) const; /*! * Rounded string utility method, virtual so units can have @@ -512,15 +554,7 @@ public: * \param i18n * \return */ - virtual QString toQStringRounded(double value, int digits = -1, bool i18n = false) const; - - /*! - * \brief Rounded value - * \param value - * \param digits - * \return - */ - double valueRounded(double value, int digits = -1) const; + virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; /*! * \brief Value rounded with unit, e.g. "5.00m", "30kHz" @@ -529,7 +563,7 @@ public: * \param i18n * \return */ - virtual QString valueRoundedWithUnit(double value, int digits = -1, bool i18n = false) const; + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Threshold for rounding @@ -544,7 +578,7 @@ public: * \brief getDisplayDigits * \return */ - qint32 getDisplayDigits() const + int getDisplayDigits() const { return this->m_displayDigits; } @@ -553,26 +587,16 @@ public: * \brief Multiplier such as "kilo" * \return */ - CMeasurementPrefix getMultiplier() const + CMeasurementPrefix getPrefix() const { - return this->m_multiplier; + return this->m_prefix; } /*! - * \brief Factor to convert to given unit - * \param value - * \param to - * \return + * Convert from other unit to this unit. + * \param */ - double conversionToUnit(double value, const CMeasurementUnit &to) const; - - /*! - * Epsilon rounding. In some conversion rouding is required to avoid - * periodical numbers. - * \param value - * \return - */ - double epsilonUpRounding(double value) const; + double convertFrom(double value, const CMeasurementUnit &unit) const; /*! * \brief Is given value <= epsilon? @@ -595,7 +619,7 @@ public: */ static CMeasurementUnit &None() { - static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); + static CMeasurementUnit none("none", "", 0.0, 0, 0); return none; } }; diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index d2a7ce937..fa67d9a4e 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -69,6 +69,16 @@ public: return p; } + /*! + * \brief Standard pressure datum for flight levels expressed in mmHg, such as in Russia, 760mmHg + * \return + */ + static const CPressure& RuFlightLevelPressure() + { + static CPressure p(760, CPressureUnit::mmHg()); + return p; + } + /*! * \brief Unicom frequency * \return diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 7d106204a..96b790d95 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -22,7 +22,7 @@ public: /*! * \brief Default constructor */ - CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::Hz(), CFrequencyUnit::Hz()) {} + CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::defaultUnit()) {} /** *\brief Copy constructor from base type @@ -34,7 +34,7 @@ public: * \param value * \param unit */ - CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} + CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Virtual destructor diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index fe24480b0..559b7f172 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -22,7 +22,7 @@ public: /*! * \brief Default constructor */ - CLength() : CPhysicalQuantity(0, CLengthUnit::m(), CLengthUnit::m()) {} + CLength() : CPhysicalQuantity(0, CLengthUnit::defaultUnit()) {} /** *\brief Copy constructor from base type @@ -34,7 +34,7 @@ public: * \param value * \param unit */ - CLength(double value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} + CLength(double value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Virtual destructor diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index 266b54929..9b949b78b 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -21,14 +21,14 @@ public: /*! * \brief Default constructor */ - CMass() : CPhysicalQuantity(0, CMassUnit::kg(), CMassUnit::kg()) {} + CMass() : CPhysicalQuantity(0, CMassUnit::defaultUnit()) {} /*! * \brief Init by double value * \param value * \param unit */ - CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} + CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Copy constructor from base type diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 63b7ba8b3..945c0aa68 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -13,25 +13,16 @@ namespace PhysicalQuantities /* * Constructor by double */ -template CPhysicalQuantity::CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit) : - m_unit(unit), m_conversionSiUnit(siConversionUnit) +template CPhysicalQuantity::CPhysicalQuantity(double value, const MU &unit) : + m_value(value), m_unit(unit) { - this->setUnitValue(baseValue); } /* * Copy constructor */ template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &other) : - m_unitValueD(other.m_unitValueD), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), - m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) -{ -} - -/* - * Destructor - */ -template CPhysicalQuantity::~CPhysicalQuantity() + m_value(other.m_value), m_unit(other.m_unit) { } @@ -41,25 +32,8 @@ template CPhysicalQuantity::~CPhysicalQuantity() template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &other) const { if (this == &other) return true; - if (this->m_unit.getType() != other.m_unit.getType()) return false; - - // some special cases for best quality - double diff; - const double lenient = 1.001; // even diff already has a rounding issue to be avoided - bool eq = false; - if (this->m_unit == other.m_unit) - { - // same unit, comparison based on double - diff = qAbs(this->m_unitValueD - other.m_unitValueD); - eq = diff <= (lenient * this->m_unit.getEpsilon()); - } - else - { - // based on SI value - diff = qAbs(this->m_convertedSiUnitValueD - other.m_convertedSiUnitValueD); - eq = diff <= (lenient * this->m_conversionSiUnit.getEpsilon()); - } - return eq; + double diff = abs(this->m_value - other.value(this->m_unit)); + return diff <= this->m_unit.getEpsilon(); } /* @@ -77,10 +51,8 @@ template CPhysicalQuantity& CPhysicalQuantitym_unitValueD = other.m_unitValueD; - this->m_convertedSiUnitValueD = other.m_convertedSiUnitValueD; + this->m_value = other.m_value; this->m_unit = other.m_unit; - this->m_conversionSiUnit = other.m_conversionSiUnit; return *this; } @@ -89,15 +61,7 @@ template CPhysicalQuantity& CPhysicalQuantity CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other) { - if (this->m_unit == other.m_unit) - { - this->setUnitValue(other.m_unitValueD + this->m_unitValueD); - } - else - { - double v = other.value(this->m_unit); - this->setUnitValue(v + this->m_unitValueD); - } + this->m_value += other.value(this->m_unit); return *this; } @@ -114,17 +78,17 @@ template PQ CPhysicalQuantity::operator +(const PQ /* * Explicit plus */ -template void CPhysicalQuantity::addUnitValue(double value) +template void CPhysicalQuantity::addValueSameUnit(double value) { - this->setUnitValue(this->m_unitValueD + value); + this->m_value += value; } /* * Explicit minus */ -template void CPhysicalQuantity::substractUnitValue(double value) +template void CPhysicalQuantity::substractValueSameUnit(double value) { - this->setUnitValue(this->m_unitValueD - value); + this->m_value -= value; } /* @@ -132,15 +96,7 @@ template void CPhysicalQuantity::substractUnitValue */ template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other) { - if (this->m_unit == other.m_unit) - { - this->setUnitValue(other.m_unitValueD - this->m_unitValueD); - } - else - { - double v = other.value(this->m_unit); - this->setUnitValue(v - this->m_unitValueD); - } + this->m_value -= other.value(this->m_unit); return *this; } @@ -157,38 +113,38 @@ template PQ CPhysicalQuantity::operator -(const PQ /* * Multiply operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator *=(double multiply) +template CPhysicalQuantity &CPhysicalQuantity::operator *=(double factor) { - this->setUnitValue(this->m_unitValueD * multiply); + this->m_value *= factor; return *this; } /* * Multiply operator */ -template PQ CPhysicalQuantity::operator *(double multiply) const +template PQ CPhysicalQuantity::operator *(double factor) const { PQ copy = *derived(); - copy *= multiply; + copy *= factor; return copy; } /* * Divide operator /= */ -template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divide) +template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divisor) { - this->setUnitValue(this->m_unitValueD / divide); + this->m_value /= divisor; return *this; } /* * Divide operator / */ -template PQ CPhysicalQuantity::operator /(double divide) const +template PQ CPhysicalQuantity::operator /(double divisor) const { PQ copy = *derived(); - copy /= divide; + copy /= divisor; return copy; } @@ -199,9 +155,7 @@ template bool CPhysicalQuantity::operator <(const C { if ((*this) == other) return false; - // == considers epsilon, so we now have a diff > epsilon here - double diff = this->m_convertedSiUnitValueD - other.m_convertedSiUnitValueD; - return (diff < 0); + return (this->m_value < other.value(this->m_unit)); } /* @@ -238,9 +192,8 @@ template PQ &CPhysicalQuantity::switchUnit(const MU { if (this->m_unit != newUnit) { - double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit); + this->m_value = newUnit.convertFrom(this->m_value, this->m_unit); this->m_unit = newUnit; - this->setUnitValue(cf); } return *derived(); } @@ -248,60 +201,9 @@ template PQ &CPhysicalQuantity::switchUnit(const MU /* * Init by double */ -template void CPhysicalQuantity::setUnitValue(double baseValue) +template void CPhysicalQuantity::setValueSameUnit(double baseValue) { - this->m_unitValueD = baseValue; - this->setConversionSiUnitValue(); -} - -/* - * Set SI value - */ -template void CPhysicalQuantity::setConversionSiUnitValue() -{ - double si = this->m_unit.convertToSiConversionUnit(this->m_unitValueD); - this->m_convertedSiUnitValueD = si; -} - -/* - * Round - */ -template double CPhysicalQuantity::unitValueToDoubleRounded(int digits) const -{ - return this->m_unit.valueRounded(this->m_unitValueD, digits); -} - -/* - * Rounded value to QString - */ -template QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const -{ - return this->m_unit.toQStringRounded(this->m_unitValueD, digits); -} - -/* - * Rounded with unit - */ -template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits, bool i18n) const -{ - return this->m_unit.valueRoundedWithUnit(this->m_unitValueD, digits, i18n); -} - -/* - * Rounded SI value to QString - */ -template QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const -{ - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->m_conversionSiUnit.toQStringRounded(this->m_convertedSiUnitValueD, digits); -} - -/* - * SI base unit value with unit - */ -template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits, bool i18n) const -{ - return this->m_conversionSiUnit.valueRoundedWithUnit(this->m_convertedSiUnitValueD, digits, i18n); + this->m_value = baseValue; } /* @@ -309,9 +211,7 @@ template QString CPhysicalQuantity::convertedSiValu */ template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const { - if (unit == this->m_unit) return this->unitValueRoundedWithUnit(digits, i18n); - if (unit == this->m_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits, i18n); - return unit.valueRoundedWithUnit(this->value(unit), digits, i18n); + return unit.makeRoundedQStringWithUnit(this->value(unit), digits, i18n); } /* @@ -319,7 +219,7 @@ template QString CPhysicalQuantity::valueRoundedWit */ template double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const { - return unit.valueRounded(this->value(unit), digits); + return unit.roundValue(this->value(unit), digits); } /* @@ -327,19 +227,7 @@ template double CPhysicalQuantity::valueRounded(con */ template double CPhysicalQuantity::value(const MU &unit) const { - if (unit == this->m_unit) return this->m_unitValueD; - if (unit == this->m_conversionSiUnit) return this->m_convertedSiUnitValueD; - double v = unit.convertFromSiConversionUnit(this->m_convertedSiUnitValueD); - return v; -} - -/* - * Round utility method - */ -template double CPhysicalQuantity::convertedSiValueToDoubleRounded(int digits) const -{ - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->m_conversionSiUnit.valueRounded(this->m_convertedSiUnitValueD, digits); + return unit.convertFrom(this->m_value, this->m_unit); } // see here for the reason of thess forward instantiations diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 586755265..20ac9b10f 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -27,8 +27,13 @@ namespace PhysicalQuantities template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier { private: - double m_unitValueD; //!< value backed by double - double m_convertedSiUnitValueD; //!< SI unit value + double m_value; //!< numeric part + MU m_unit; //!< unit part + + /*! + * Which subclass of CMeasurementUnit does this quantity use? + */ + typedef MU UnitClass; /*! * \brief Easy access to derived class (CRTP template parameter) @@ -49,16 +54,25 @@ private: } protected: - MU m_unit; //!< unit - MU m_conversionSiUnit; //!< corresponding SI base unit - /*! * \brief Constructor with double - * \param baseValue + * \param value * \param unit - * \param siConversionUnit */ - CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit); + CPhysicalQuantity(double value, const MU &unit); + + /*! + * \brief Copy constructor + * \param other + */ + CPhysicalQuantity(const CPhysicalQuantity &other); + + /*! + * \brief Assignment operator = + * \param other + * \return + */ + CPhysicalQuantity &operator =(const CPhysicalQuantity &other); /*! * \brief Name as string @@ -67,32 +81,20 @@ protected: */ virtual QString convertToQString(bool i18n = false) const { - return this->unitValueRoundedWithUnit(-1, i18n); + return this->valueRoundedWithUnit(this->getUnit(), -1, i18n); } /*! - * \brief Init by double - * \param baseValue + * \brief Change value without changing unit + * \param value */ - - void setUnitValue(double baseValue); - - /*! - * \brief Set the SI value - */ - void setConversionSiUnitValue(); + void setValueSameUnit(double value); public: - /*! - * \brief Copy constructor - * \param other - */ - CPhysicalQuantity(const CPhysicalQuantity &other); - /*! * \brief Virtual destructor */ - virtual ~CPhysicalQuantity(); + virtual ~CPhysicalQuantity() {} /*! * \brief Unit of the distance @@ -104,48 +106,12 @@ public: } /*! - * \brief Conversion SI unit - * \return - */ - MU getConversionSiUnit() const - { - return this->m_conversionSiUnit; - } - - /*! - * \brief Switch unit, e.g. feet to meter + * \brief Change unit, and convert value to maintain the same quantity * \param newUnit * \return */ PQ &switchUnit(const MU &newUnit); - /*! - * \brief Value in SI base unit? Meter is an SI base unit, hertz not! - * \return - */ - bool isSiBaseUnit() const - { - return this->m_unit.isSiBaseUnit(); - } - - /*! - * \brief Value in SI unit? Hertz is an derived SI unit, NM not! - * \return - */ - bool isSiUnit() const - { - return this->m_unit.isSiUnit(); - } - - /*! - * \brief Value in unprefixed SI unit? Meter is a unprefixed, kilometer a prefixed SI Unit - * \return - */ - bool isUnprefixedSiUnit() const - { - return this->m_unit.isUnprefixedSiUnit(); - } - /*! * \brief Value in given unit * \param unit @@ -154,7 +120,16 @@ public: double value(const MU &unit) const; /*! - * \brief Rounded value in unit + * \brief Value in current unit + * \return + */ + double value() const + { + return this->m_value; + } + + /*! + * \brief Rounded value in given unit * \param unit * \param digits * \return @@ -162,7 +137,17 @@ public: double valueRounded(const MU &unit, int digits = -1) const; /*! - * \brief Value to QString with unit, e.g. "5.00m" + * \brief Rounded value in current unit + * \param digits + * \return + */ + double valueRounded(int digits = -1) const + { + return this->valueRounded(this->m_unit, digits); + } + + /*! + * \brief Value to QString with the given unit, e.g. "5.00m" * \param unit * \param digits * \param i18n @@ -171,80 +156,27 @@ public: QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; /*! - * \brief Value as double - * \return - */ - double unitValueToDouble() const - { - return this->m_unitValueD; - } - - /*! - * \brief Value to QString with unit, e.g. "5.00m" + * \brief Value to QString with the current unit, e.g. "5.00m" * \param digits * \param i18n * \return */ - QString unitValueRoundedWithUnit(int digits = -1, bool i18n = false) const; - - /*! - * \brief Rounded value by n digits - * \param digits - * \return - */ - double unitValueToDoubleRounded(int digits = -1) const; - - /*! - * \brief Rounded value by n digits - * \param digits if no value is provided, unit rounding is taken - * \return - */ - QString unitValueToQStringRounded(int digits = -1) const; - - /*! - * \brief Conversion SI value as double - * \return - */ - double convertedSiValueToDouble() const + QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const { - return this->m_convertedSiUnitValueD; + return this->valueRoundedWithUnit(this->m_unit, digits, i18n); } /*! - * \brief Rounded SI value by n digits - * \param digits - * \return - */ - double convertedSiValueToDoubleRounded(int digits = -1) const; - - /*! - * \brief Rounded value by n digits - * \param digits if no value is provided, unit rounding is taken - * \return - */ - QString convertedSiValueToQStringRounded(int digits = -1) const; - - /*! - * \brief SI Base unit value rounded - * \param digits - * \param i18n - * \return - */ - QString convertedSiValueRoundedWithUnit(int digits = -1, bool i18n = false) const; - - /*! - * \brief Add to the unit value. - * \remarks Since overloading the + operator with double did lead to unintended conversions, as explicit method + * \brief Add to the value in the current unit. * \param value */ - void addUnitValue(double value); + void addValueSameUnit(double value); /*! - * \brief Substract to the unit value. - * \remarks Since overloading the - operator with double did lead to unintended conversions, as explicit method + * \brief Substract from the value in the current unit. * \param value */ - void substractUnitValue(double value); + void substractValueSameUnit(double value); /*! * \brief Multiply operator *= @@ -341,13 +273,6 @@ public: */ bool operator >=(const CPhysicalQuantity &other) const; - /*! - * \brief Assignment operator = - * \param other - * \return - */ - CPhysicalQuantity &operator =(const CPhysicalQuantity &other); - /*! * \brief Plus operator + * \param other @@ -368,25 +293,25 @@ public: */ bool isZeroEpsilon() const { - return this->m_unit.isEpsilon(this->m_unitValueD); + return this->m_unit.isEpsilon(this->m_value); } /*! * \brief Value >= 0 epsilon considered * \return */ - bool isGreaterOrEqualZeroEpsilon() const + bool isNonNegativeEpsilon() const { - return this->isZeroEpsilon() || this->m_unitValueD > 0; + return this->isZeroEpsilon() || this->m_value > 0; } /*! * \brief Value <= 0 epsilon considered * \return */ - bool isLessOrEqualZeroEpsilon() const + bool isNonPositiveEpsilon() const { - return this->isZeroEpsilon() || this->m_unitValueD < 0; + return this->isZeroEpsilon() || this->m_value < 0; } /*! @@ -395,10 +320,9 @@ public: */ virtual void marshallToDbus(QDBusArgument &argument) const { - argument << this->m_unitValueD; - argument << this->m_convertedSiUnitValueD; + argument << this->value(UnitClass::defaultUnit()); + argument << this->m_value; argument << this->m_unit; - argument << this->m_conversionSiUnit; } /*! @@ -407,10 +331,10 @@ public: */ virtual void unmarshallFromDbus(const QDBusArgument &argument) { - argument >> this->m_unitValueD; - argument >> this->m_convertedSiUnitValueD; + double ignore; + argument >> ignore; + argument >> this->m_value; argument >> this->m_unit; - argument >> this->m_conversionSiUnit; } /*! diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index 80d57f96c..38d08778f 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -23,7 +23,7 @@ public: /*! * \brief Default constructor */ - CPressure() : CPhysicalQuantity(0, CPressureUnit::Pa(), CPressureUnit::Pa()) {} + CPressure() : CPhysicalQuantity(0, CPressureUnit::defaultUnit()) {} /** *\brief Copy constructor from base type @@ -35,7 +35,7 @@ public: * \param value * \param unit */ - CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} + CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Virtual destructor diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index f5ecf2e72..889916f42 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -23,7 +23,7 @@ public: /*! * \brief Default constructor */ - CSpeed() : CPhysicalQuantity(0, CSpeedUnit::m_s(), CSpeedUnit::m_s()) {} + CSpeed() : CPhysicalQuantity(0, CSpeedUnit::defaultUnit()) {} /*! *\brief Copy constructor from base type @@ -35,7 +35,7 @@ public: * \param value * \param unit */ - CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} + CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Destructor diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index 4553493fd..e8697e509 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -22,7 +22,7 @@ public: /*! * \brief Default constructor */ - CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::K(), CTemperatureUnit::K()) {} + CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::defaultUnit()) {} /** * \brief Copy constructor from base type @@ -34,7 +34,7 @@ public: * \param value * \param unit */ - CTemperature(double value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} + CTemperature(double value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit) {} /*! * \brief Destructor diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 16bbf9fe4..060585c70 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -23,7 +23,7 @@ public: /*! * \brief Default constructor */ - CTime() : CPhysicalQuantity(0, CTimeUnit::s(), CTimeUnit::s()) {} + CTime() : CPhysicalQuantity(0, CTimeUnit::defaultUnit()) {} /** *\brief Copy constructor from base type @@ -35,7 +35,7 @@ public: * \param value * \param unit */ - CTime(double value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} + CTime(double value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Destructor diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 5973a3c10..f7de957aa 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -10,79 +10,74 @@ namespace BlackMisc namespace PhysicalQuantities { -/* - * Convert to SI - */ -double CTemperatureUnit::conversionToSiConversionUnit(double value) const -{ - double v = value + this->m_conversionOffsetToSi; - v *= this->getConversionFactorToSI(); - return v; -} +using BlackMisc::Math::CMath; /* - * Convert from SI + * Rounded to QString */ -double CTemperatureUnit::conversionFromSiConversionUnit(double value) const +QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) const { - double v = value / this->getConversionFactorToSI(); - v -= this->m_conversionOffsetToSi; - return v; -} - -/* - * Convert from SI - */ -double CAngleUnit::conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit, double value) -{ - // using rounding here, since fractions can lead to ugly sexagesimal conversion - // e.g. 185.499999 gives 185 29' 59.9999" - value = angleUnit.epsilonUpRounding(value * 180 / M_PI); // degree - double v = floor(value); - double c = value - v; - double mr = c * 60.0; - double m = floor(mr); // minutes - double s = (mr - m) * 60; // seconds + rest fraction - v = (v + (m / 100) + (s / 10000)); - return v; -} - -/* - * Convert to SI - */ -double CAngleUnit::conversionSexagesimalToSi(const CMeasurementUnit &, double value) -{ - double v = floor(value); // degrees - double c = value - v; - c = c * 100.0; - double m = floor(c); - c = c - m; - m /= 60.0; // minutes back to decimals - double s = c / 36.0; // seconds back to decimals - v = v + m + s; - return v / 180.0 * M_PI; + if (digits < 0) digits = this->getDisplayDigits(); + QString s; + if ((*this) == CAngleUnit::sexagesimalDeg()) + { + double de = CMath::trunc(value); + double mi = CMath::trunc((value - de) * 100.0); + double se = CMath::trunc((value - de - mi / 100.0) * 1000000) / 100.0; + const char *fmt = value < 0 ? "-%L1 %L2'%L3\"" : "%L1 %L2'%L3\""; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', 0, '0').arg(fabs(se), 2, 'f', digits, '0'); + } + else if ((*this) == CAngleUnit::sexagesimalDegMin()) + { + double de = CMath::trunc(value); + double mi = CMath::trunc((value - de) * 100.0); + const char *fmt = value < 0 ? "-%L1 %L2'" : "%L1 %L2'"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', digits, '0'); + } + else + { + s = this->CMeasurementUnit::makeRoundedQString(value, digits, i18n); + } + return s; } /* * Rounded to QString */ -QString CAngleUnit::toQStringRounded(double value, int digits, bool i18n) const +QString CTimeUnit::makeRoundedQString(double value, int digits, bool i18n) const { + if (digits < 0) digits = this->getDisplayDigits(); QString s; - if ((*this) == CAngleUnit::sexagesimalDeg()) + if ((*this) == CTimeUnit::hms()) { - // special formatting for sexagesimal degrees - double de = floor(value); - double mi = floor((value - de) * 100.0); - double se = floor((value - de - mi / 100.0) * 1000000) / 100.0; - QString ses = QLocale::system().toString(se, 'f', 2); - s = QString::number(de); - s = s.append(i18n ? CAngleUnit::deg().getUnitName(true) : " "); - s = s.append(QString::number(mi)).append("'").append(ses).append("\""); + double hr = CMath::trunc(value); + double mi = CMath::trunc((value - hr) * 100.0); + double se = CMath::trunc((value - hr - mi / 100.0) * 1000000) / 100.0; + const char *fmt = value < 0 ? "-%L1h%L2m%L3s" : "%L1h%L2m%L3s"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(hr), 0, 'f', 0).arg(fabs(mi), 2, 'f', 0, '0').arg(fabs(se), 2, 'f', digits, '0'); + } + else if ((*this) == CTimeUnit::hrmin()) + { + double hr = CMath::trunc(value); + double mi = CMath::trunc((value - hr) * 100.0); + const char *fmt = value < 0 ? "-%L1h%L2m" : "%L1h%L2m"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(hr), 0, 'f', 0).arg(fabs(mi), 2, 'f', digits, '0'); + } + else if ((*this) == CTimeUnit::minsec()) + { + double mi = CMath::trunc(value); + double se = CMath::trunc((value - mi) * 100.0); + const char *fmt = value < 0 ? "-%L2m%L3s" : "%L2m%L3s"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(mi), 0, 'f', 0).arg(fabs(se), 2, 'f', digits, '0'); } else { - s = this->CMeasurementUnit::toQStringRounded(value, digits); + s = this->CMeasurementUnit::makeRoundedQString(value, digits, i18n); } return s; } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index a6c355580..b461fdda6 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -33,22 +33,29 @@ private: /*! * \brief Constructor length unit * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CLengthUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "distance", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CLengthUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Constructor length unit + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CLengthUnit(const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(base, prefix, displayDigits, epsilon) {} public: /*! - * Default constructor, we do not want this, but required for Qt Metasystem + * Default constructor, required for Qt Metasystem */ - CLengthUnit() : CMeasurementUnit("meter", "m", "distance", true, true) {} + CLengthUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor @@ -56,13 +63,19 @@ public: */ CLengthUnit(const CLengthUnit &other) : CMeasurementUnit(other) {} + /*! + * \brief Default unit + * \return + */ + static const CLengthUnit &defaultUnit() { return m(); } + /*! * \brief Meter m * \return */ static const CLengthUnit &m() { - static CLengthUnit m(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"), "m", true, true); + static CLengthUnit m(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"), "m", 1); return m; } @@ -72,7 +85,7 @@ public: */ static const CLengthUnit &NM() { - static CLengthUnit NM(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"), "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); + static CLengthUnit NM(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"), "NM", 1000.0 * 1.85200, 3); return NM; } @@ -82,7 +95,7 @@ public: */ static const CLengthUnit &ft() { - static CLengthUnit ft(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"), "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CLengthUnit ft(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"), "ft", 0.3048, 0); return ft; } @@ -92,7 +105,7 @@ public: */ static const CLengthUnit &km() { - static CLengthUnit km(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"), "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); + static CLengthUnit km(CMeasurementPrefix::k(), m(), 3); return km; } @@ -102,7 +115,7 @@ public: */ static const CLengthUnit &cm() { - static CLengthUnit cm(QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"), "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); + static CLengthUnit cm(CMeasurementPrefix::c(), m(), 1); return cm; } @@ -112,7 +125,7 @@ public: */ static const CLengthUnit &mi() { - static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"), "mi", false, false, 1609.344, CMeasurementPrefix::None(), 3); + static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"), "mi", 1609.344, 3); return mi; } @@ -120,17 +133,17 @@ public: * \brief Statute mile * \return */ - static const CLengthUnit &miStatute() + static const CLengthUnit &SM() { - static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile(statute)"), "mi(statute)", false, false, 1609.3472, CMeasurementPrefix::None(), 3); - return mi; + static CLengthUnit sm(QT_TRANSLATE_NOOP("CMeasurementUnit", "statute miles"), "SM", 1609.3472, 3); + return sm; } /*! * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -140,27 +153,12 @@ public: u.append(CLengthUnit::km()); u.append(CLengthUnit::m()); u.append(CLengthUnit::mi()); - u.append(CLengthUnit::miStatute()); + u.append(CLengthUnit::SM()); u.append(CLengthUnit::NM()); } return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CLengthUnit &fromUnitName(const QString &unitName) - { - const QList &units = CLengthUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CLengthUnit::m(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -170,7 +168,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CLengthUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -183,38 +181,30 @@ private: /*! * \brief Constructor angle units: Radian, degree * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param multiplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CAngleUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, - const CMeasurementPrefix &multiplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, - double epsilon = 1E-9, UnitConverter converterToSi = 0, UnitConverter converterFromSi = 0) : - CMeasurementUnit(name, unitName, "angle", isSiUnit, false, conversionFactorToSI, - multiplier, displayDigits, epsilon, converterToSi, converterFromSi) {} + CAngleUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} /*! - * \brief Special conversion for sexagesimal degrees - * \param value - * \return + * \brief Constructor angle units: Sexagesimal + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon */ - static double conversionSexagesimalToSi(const CMeasurementUnit &angleUnit, double value); - - /*! - * \brief Special conversion for sexagesimal degrees - * \param value - * \return - */ - static double conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit, double value); + CAngleUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, converter, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CAngleUnit() : CMeasurementUnit("radian", "rad", "angle", true, false) {} + CAngleUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor @@ -223,13 +213,19 @@ public: CAngleUnit(const CAngleUnit &other) : CMeasurementUnit(other) {} /*! - * \brief Special conversion to QString for sexagesimal degrees. + * \brief Default unit + * \return + */ + static const CAngleUnit &defaultUnit() { return deg(); } + + /*! + * \brief Override for sexagesimal degrees. * \param value * \param digits * \param i18n * \return */ - virtual QString toQStringRounded(double value, int digits = -1, bool i18n = false) const; + virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; /*! * \brief Radians @@ -237,7 +233,7 @@ public: */ static const CAngleUnit &rad() { - static CAngleUnit rad(QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"), "rad", true); + static CAngleUnit rad(QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"), "rad", 180.0 / M_PI); return rad; } @@ -247,25 +243,39 @@ public: */ static const CAngleUnit °() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"), QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"), false, M_PI / 180); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"), QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"), 1); return deg; } /*! - * \brief Sexagesimal degree (degree, minute, seconds) + * \brief Sexagesimal degree (degrees, minutes, seconds, decimal seconds) * \return */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "segadecimal degree"), "segd", false, M_PI / 180, - CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degrees minutes seconds"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 0); + return deg; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'%L3\""); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1 %L2'%L3\""); + } + + /*! + * \brief Sexagesimal degree (degrees, minutes, decimal minutes) + * \return + */ + static const CAngleUnit &sexagesimalDegMin() + { + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degrees minutes"), "MinDec", new SubdivisionConverter<60, 100>, 2); + return deg; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2'"); } /*! * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -273,25 +283,11 @@ public: u.append(CAngleUnit::deg()); u.append(CAngleUnit::rad()); u.append(CAngleUnit::sexagesimalDeg()); + u.append(CAngleUnit::sexagesimalDegMin()); } return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CAngleUnit &fromUnitName(const QString &unitName) - { - const QList &units = CAngleUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CAngleUnit::rad(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -301,7 +297,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CAngleUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -312,24 +308,31 @@ class CFrequencyUnit : public CMeasurementUnit { private: /*! - * Constructor - * \brief CFrequencyUnit + * Constructor frequency unit * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CFrequencyUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CFrequencyUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * Constructor frequency unit + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CFrequencyUnit(const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(base, prefix, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CFrequencyUnit() : CMeasurementUnit("hertz", "Hz", "frequency", true, false) {} + CFrequencyUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor @@ -337,13 +340,19 @@ public: */ CFrequencyUnit(const CFrequencyUnit &other) : CMeasurementUnit(other) {} + /*! + * \brief Default unit + * \return + */ + static const CFrequencyUnit &defaultUnit() { return Hz(); } + /*! * \brief Hertz * \return */ static const CFrequencyUnit &Hz() { - static CFrequencyUnit Hz(QT_TRANSLATE_NOOP("CMeasurementUnit", "hertz"), "Hz", true); + static CFrequencyUnit Hz(QT_TRANSLATE_NOOP("CMeasurementUnit", "hertz"), "Hz", 1); return Hz; } @@ -353,7 +362,7 @@ public: */ static const CFrequencyUnit &kHz() { - static CFrequencyUnit kHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilohertz"), "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1); + static CFrequencyUnit kHz(CMeasurementPrefix::k(), Hz(), 1); return kHz; } @@ -363,7 +372,7 @@ public: */ static const CFrequencyUnit &MHz() { - static CFrequencyUnit MHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "megahertz"), "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); + static CFrequencyUnit MHz(CMeasurementPrefix::M(), Hz(), 2); return MHz; } @@ -373,7 +382,7 @@ public: */ static const CFrequencyUnit &GHz() { - static CFrequencyUnit GHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "gigahertz"), "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); + static CFrequencyUnit GHz(CMeasurementPrefix::G(), Hz(), 2); return GHz; } @@ -381,7 +390,7 @@ public: * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -394,21 +403,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CFrequencyUnit &fromUnitName(const QString &unitName) - { - const QList &units = CFrequencyUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CFrequencyUnit::Hz(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -418,7 +412,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CFrequencyUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -431,22 +425,29 @@ private: /*! * \brief Constructor mass units * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CMassUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "mass", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CMassUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Constructor mass units + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CMassUnit(const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(base, prefix, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CMassUnit() : CMeasurementUnit("kilogram", "kg", "mass", true, true, 1.0, CMeasurementPrefix::k(), 1) {} + CMassUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor @@ -454,13 +455,19 @@ public: */ CMassUnit(const CMassUnit &other) : CMeasurementUnit(other) {} + /*! + * \brief Default unit + * \return + */ + static const CMassUnit &defaultUnit() { return kg(); } + /*! * \brief Kilogram, SI base unit * \return */ static const CMassUnit &kg() { - static CMassUnit kg(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"), "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); + static CMassUnit kg(CMeasurementPrefix::k(), g(), 1); return kg; } @@ -470,7 +477,7 @@ public: */ static const CMassUnit &g() { - static CMassUnit g(QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"), "g", true, false, 1.0 / 1000.0, CMeasurementPrefix::One(), 0); + static CMassUnit g(QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"), "g", 0.001, 0); return g; } @@ -480,7 +487,7 @@ public: */ static const CMassUnit &t() { - static CMassUnit t(QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"), "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); + static CMassUnit t(QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"), "t", 1000.0, 3); return t; } @@ -490,7 +497,7 @@ public: */ static const CMassUnit &lb() { - static CMassUnit lbs(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"), "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); + static CMassUnit lbs(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"), "lb", 0.45359237, 1); return lbs; } @@ -498,7 +505,7 @@ public: * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -511,21 +518,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CMassUnit &fromUnitName(const QString &unitName) - { - const QList &units = CMassUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CMassUnit::kg(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -535,7 +527,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CMassUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -546,24 +538,31 @@ class CPressureUnit : public CMeasurementUnit { private: /*! - * Constructor - * \brief Pressure unit + * \brief Pressure unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CPressureUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "pressure", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CPressureUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Pressure unit constructor + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CPressureUnit(const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(base, prefix, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CPressureUnit() : CMeasurementUnit("pascal", "Pa", "pressure", true, false) {} + CPressureUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor @@ -571,13 +570,19 @@ public: */ CPressureUnit(const CPressureUnit &other) : CMeasurementUnit(other) {} + /*! + * \brief Default unit + * \return + */ + static const CPressureUnit &defaultUnit() { return hPa(); } + /*! * \brief Pascal * \return */ static const CPressureUnit &Pa() { - static CPressureUnit Pa(QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"), "Pa", true); + static CPressureUnit Pa(QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"), "Pa", 0.01); return Pa; } @@ -587,7 +592,7 @@ public: */ static const CPressureUnit &hPa() { - static CPressureUnit hPa(QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"), "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); + static CPressureUnit hPa(CMeasurementPrefix::h(), Pa()); return hPa; } @@ -597,7 +602,7 @@ public: */ static const CPressureUnit &psi() { - static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"), "psi", false, 6894.8, CMeasurementPrefix::One(), 2); + static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"), "psi", 68.948, 2); return psi; } @@ -607,7 +612,7 @@ public: */ static const CPressureUnit &bar() { - static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", false, 1E5); + static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", 1000, 1, 1E5); return bar; } @@ -617,7 +622,7 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"), "bar", false, 1E2); + static CPressureUnit bar(CMeasurementPrefix::m(), bar(), 1, 1E2); return bar; } @@ -627,15 +632,25 @@ public: */ static const CPressureUnit &inHg() { - static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", false, 3386.389); + static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", 33.86389); return inhg; } + /*! + * \brief Millimeter of mercury + * \return + */ + static const CPressureUnit &mmHg() + { + static CPressureUnit mmhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "millimeter of mercury"), "mmHg", 860.142806); + return mmhg; + } + /*! * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -643,27 +658,13 @@ public: u.append(CPressureUnit::bar()); u.append(CPressureUnit::hPa()); u.append(CPressureUnit::inHg()); + u.append(CPressureUnit::mmHg()); u.append(CPressureUnit::mbar()); u.append(CPressureUnit::psi()); } return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CPressureUnit &fromUnitName(const QString &unitName) - { - const QList &units = CPressureUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CPressureUnit::Pa(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -673,7 +674,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CPressureUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -682,62 +683,36 @@ protected: */ class CTemperatureUnit : public CMeasurementUnit { -private: - double m_conversionOffsetToSi; - private: /*! * Constructor temperature unit * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param temperatureOffsetToSI - * \param mulitplier + * \param symbol + * \param factor + * \param offset * \param displayDigits * \param epsilon */ - CTemperatureUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "temperature", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {} - -protected: - /*! - * \brief Convert to SI conversion unit, specific for temperature - * \param value - * \return - */ - virtual double conversionToSiConversionUnit(double value) const; - - /*! - * \brief Convert from SI conversion unit, specific for temperature - * \param value - * \return - */ - virtual double conversionFromSiConversionUnit(double value) const; + CTemperatureUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, offset, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CTemperatureUnit() : CMeasurementUnit("Kelvin", "K", "temperature", true, true) {} + CTemperatureUnit() : CMeasurementUnit(defaultUnit()) {} /*! * \brief Copy constructor * \param other */ - CTemperatureUnit(const CTemperatureUnit &other) : CMeasurementUnit(other), m_conversionOffsetToSi(other.m_conversionOffsetToSi) {} + CTemperatureUnit(const CTemperatureUnit &other) : CMeasurementUnit(other) {} /*! - * Assigment operator + * \brief Default unit + * \return */ - CTemperatureUnit &operator =(const CTemperatureUnit &other) - { - if (this == &other) return *this; - CMeasurementUnit::operator = (other); - this->m_conversionOffsetToSi = other.m_conversionOffsetToSi; - return *this; - } + static const CTemperatureUnit &defaultUnit() { return C(); } /*! * \brief Kelvin @@ -745,7 +720,7 @@ public: */ static const CTemperatureUnit &K() { - static CTemperatureUnit K(QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"), "K", true, true); + static CTemperatureUnit K(QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"), "K", 1, 273.15); return K; } @@ -755,7 +730,7 @@ public: */ static const CTemperatureUnit &C() { - static CTemperatureUnit C(QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"), QT_TRANSLATE_NOOP("CMeasurementUnit", "C"), false, false, 1.0, 273.15); + static CTemperatureUnit C(QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"), QT_TRANSLATE_NOOP("CMeasurementUnit", "C"), 1, 0); return C; } @@ -765,7 +740,7 @@ public: */ static const CTemperatureUnit &F() { - static CTemperatureUnit F(QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"), QT_TRANSLATE_NOOP("CMeasurementUnit", "F"), false, false, 5.0 / 9.0, 459.67); + static CTemperatureUnit F(QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"), QT_TRANSLATE_NOOP("CMeasurementUnit", "F"), 5.0 / 9.0, 32); return F; } @@ -773,7 +748,7 @@ public: * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -785,21 +760,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CTemperatureUnit &fromUnitName(const QString &unitName) - { - const QList &units = CTemperatureUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CTemperatureUnit::K(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -809,7 +769,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CTemperatureUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -820,25 +780,21 @@ class CSpeedUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Speed unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CSpeedUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "speed", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CSpeedUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CSpeedUnit() : CMeasurementUnit("meters/second", "m/s", "speed", true, false) {} + CSpeedUnit() : CMeasurementUnit(defaultUnit()) {} /*! * Constructor, allows to implement methods in base class @@ -846,13 +802,19 @@ public: */ CSpeedUnit(const CSpeedUnit &other) : CMeasurementUnit(other) {} + /*! + * Default unit + * \return + */ + static const CSpeedUnit &defaultUnit() { return m_s(); } + /*! * \brief Meter/second m/s * \return */ static const CSpeedUnit &m_s() { - static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"), "m/s", true, false); + static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"), "m/s", 1); return ms; } @@ -862,7 +824,7 @@ public: */ static const CSpeedUnit &kts() { - static CSpeedUnit kts(QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"), "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit kts(QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"), "kts", 1852.0 / 3600.0, 1); return kts; } @@ -872,7 +834,7 @@ public: */ static const CSpeedUnit &NM_h() { - static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"), "NM/h", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"), "NM/h", 1852.0 / 3600.0, 1); return NMh; } @@ -882,7 +844,7 @@ public: */ static const CSpeedUnit &ft_s() { - static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"), "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"), "ft/s", 0.3048, 0); return fts; } @@ -892,7 +854,7 @@ public: */ static const CSpeedUnit &ft_min() { - static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"), "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); + static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"), "ft/min", 0.3048 / 60.0, 0); return ftmin; } @@ -902,7 +864,7 @@ public: */ static const CSpeedUnit &km_h() { - static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"), "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); + static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"), "km/h", 1.0 / 3.6, 1); return kmh; } @@ -910,7 +872,7 @@ public: * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -925,21 +887,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CSpeedUnit &fromUnitName(const QString &unitName) - { - const QList &units = CSpeedUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CSpeedUnit::m_s(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -949,7 +896,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CSpeedUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -960,25 +907,42 @@ class CTimeUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Time unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CTimeUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CTimeUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Time unit constructor + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CTimeUnit(const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + + /*! + * \brief Time unit constructor + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon + */ + CTimeUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, converter, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CTimeUnit() : CMeasurementUnit("second", "s", "time", true, true, 1, CMeasurementPrefix::None()) {} + CTimeUnit() : CMeasurementUnit(defaultUnit()) {} /*! * Constructor, allows to implement methods in base class @@ -986,13 +950,28 @@ public: */ CTimeUnit(const CTimeUnit &other) : CMeasurementUnit(other) {} + /*! + * Default unit + * \return + */ + static const CTimeUnit &defaultUnit() { return s(); } + + /*! + * \brief Override for subdivisional units. + * \param value + * \param digits + * \param i18n + * \return + */ + virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; + /*! * \brief Second s * \return */ static const CTimeUnit &s() { - static CTimeUnit s(QT_TRANSLATE_NOOP("CMeasurementUnit", "second"), "s", true, true, 1, CMeasurementPrefix::None(), 1); + static CTimeUnit s(QT_TRANSLATE_NOOP("CMeasurementUnit", "second"), "s", 1, 1); return s; } @@ -1002,7 +981,7 @@ public: */ static const CTimeUnit &ms() { - static CTimeUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"), "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); + static CTimeUnit ms(CMeasurementPrefix::m(), s(), 0); return ms; } @@ -1012,7 +991,7 @@ public: */ static const CTimeUnit &h() { - static CTimeUnit h(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"), "h", false, false, 3600, CMeasurementPrefix::None(), 1); + static CTimeUnit h(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"), "h", 3600, 1); return h; } @@ -1022,7 +1001,7 @@ public: */ static const CTimeUnit &min() { - static CTimeUnit min(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", false, false, 60, CMeasurementPrefix::None(), 2); + static CTimeUnit min(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", 60, 2); return min; } @@ -1032,15 +1011,48 @@ public: */ static const CTimeUnit &d() { - static CTimeUnit day(QT_TRANSLATE_NOOP("CMeasurementUnit", "day"), "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); + static CTimeUnit day(QT_TRANSLATE_NOOP("CMeasurementUnit", "day"), "d", 3600 * 24, 1); return day; } + /*! + * \brief Hours, minutes, seconds + */ + static const CTimeUnit &hms() + { + static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hours minutes seconds"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 0); + return hms; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m%L3s"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1h%L2m%L3s"); + } + + /*! + * \brief Hours, minutes + */ + static const CTimeUnit &hrmin() + { + static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hours minutes"), "hm", new SubdivisionConverter<60, 100>(3600), 1); + return hrmin; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1h%L2m"); + } + + /*! + * \brief Minutes, seconds + */ + static const CTimeUnit &minsec() + { + static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minutes seconds"), "minsec", new SubdivisionConverter<60, 100>(60), 0); + return minsec; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1m%L2s"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1m%L2s"); + } + /*! * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -1054,21 +1066,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CTimeUnit &fromUnitName(const QString &unitName) - { - const QList &units = CTimeUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CTimeUnit::s(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -1078,7 +1075,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CTimeUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -1089,39 +1086,41 @@ class CAccelerationUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Acceleration unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CAccelerationUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "acceleration", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CAccelerationUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} public: /*! * Default constructor, required for Qt Metasystem */ - CAccelerationUnit() : CMeasurementUnit("meter/second^2", "m/s^2", "acceleration", true, false, 1, CMeasurementPrefix::None(), 1) {} + CAccelerationUnit() : CMeasurementUnit(defaultUnit()) {} /*! - * Constructor, allows to implement methods in base class + * Copy constructor * \param other */ CAccelerationUnit(const CAccelerationUnit &other) : CMeasurementUnit(other) {} + /*! + * Default unit + * \return + */ + static const CAccelerationUnit &defaultUnit() { return m_s2(); } + /*! * \brief Meter/second^2 (m/s^2) * \return */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), 1, 1); return ms2; } @@ -1131,7 +1130,7 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), true, false, 3.28084, CMeasurementPrefix::m(), 0); + static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), 3.28084, 0); return fts2; } @@ -1139,7 +1138,7 @@ public: * \brief All units * \return */ - static const QList &units() + static const QList &allUnits() { static QList u; if (u.isEmpty()) @@ -1150,21 +1149,6 @@ public: return u; } - /*! - * \brief Unit from name - * \param unitName must be valid! - * \return - */ - static const CAccelerationUnit &fromUnitName(const QString &unitName) - { - const QList &units = CAccelerationUnit::units(); - for (int i = 0; i < units.size(); ++i) { - if (units.at(i).getUnitName() == unitName) return (units.at(i)); - } - qFatal("Illegal unit name"); - return CAccelerationUnit::m_s2(); // just suppress "not all control paths return a value" - } - protected: /*! * \brief Stream from DBus @@ -1174,7 +1158,7 @@ protected: { QString unitName; argument >> unitName; - (*this) = CAccelerationUnit::fromUnitName(unitName); + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index 7bec3cda6..1956ea577 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -37,11 +37,11 @@ void CTestAviation::headingBasics() QVERIFY2(h4 == h1, "Values shall be equal"); h1 -= h1; - QVERIFY2(h1.unitValueToDouble() == 0, "Value shall be 0"); + QVERIFY2(h1.value() == 0, "Value shall be 0"); // h4 = h1 + h2; does not work, because misleading h2 += h2; // add just angle - QVERIFY2(h2.unitValueToDouble() == 360, "Value shall be 360"); + QVERIFY2(h2.value() == 360, "Value shall be 360"); } /* diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp index 211bd098c..8c5b5b21b 100644 --- a/tests/blackmisc/testgeo.cpp +++ b/tests/blackmisc/testgeo.cpp @@ -14,7 +14,7 @@ void CTestGeo::geoBasics() CLatitude lati(10, CAngleUnit::deg()); QVERIFY2(lati * 2 == lati + lati, "Latitude addition should be equal"); lati += CLatitude(20, CAngleUnit::deg()); - QVERIFY2(lati.unitValueToDoubleRounded() == 30.0, "Latitude should be 30 degrees"); + QVERIFY2(lati.valueRounded() == 30.0, "Latitude should be 30 degrees"); double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest CCoordinateGeodetic startGeoVec(lat, lon, h); diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 2a918a458..a958046de 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -15,8 +15,6 @@ namespace BlackMiscTest */ void CTestPhysicalQuantities::unitsBasics() { - QVERIFY2(CMeasurementPrefix::k() > CMeasurementPrefix::h(), "kilo > hecto"); - // some tests on units CLengthUnit du1 = CLengthUnit::m(); // Copy CLengthUnit du2 = CLengthUnit::m(); // Copy @@ -25,7 +23,6 @@ void CTestPhysicalQuantities::unitsBasics() du2 = CLengthUnit::m(); // Copy QVERIFY2(du1 == du2, "Compare by value 2"); QVERIFY2(CLengthUnit::m() == CLengthUnit::m(), "Compare by value"); - QVERIFY2(CMeasurementPrefix::h() < CMeasurementPrefix::M(), "hecto < mega"); CFrequencyUnit fu1 = CFrequencyUnit::Hz(); QVERIFY2(fu1 != du1, "Hz must not be meter"); @@ -54,12 +51,12 @@ void CTestPhysicalQuantities::lengthBasics() // epsilon tests d1 = d2; // both in same unit - d1.addUnitValue(d1.getUnit().getEpsilon()); // this should be still the same + d1.addValueSameUnit(d1.getUnit().getEpsilon() / 2.0); // this should be still the same QVERIFY2(d1 == d2, "Epsilon: 100cm + epsilon shall be 100cm"); QVERIFY2(!(d1 != d2), "Epsilon: 100cm + epsilon shall be still 100cm"); QVERIFY2(!(d1 > d2), "d1 shall not be greater"); - d1.addUnitValue(d1.getUnit().getEpsilon()); // now over epsilon threshold + d1.addValueSameUnit(d1.getUnit().getEpsilon()); // now over epsilon threshold QVERIFY2(d1 != d2, "Epsilon exceeded: 100 cm + 2 epsilon shall not be 100cm"); QVERIFY2(d1 > d2, "d1 shall be greater"); } @@ -82,8 +79,8 @@ void CTestPhysicalQuantities::frequencyTests() { CFrequency f1(1, CFrequencyUnit::MHz()); QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz"); - QVERIFY2(f1.unitValueToDouble() == 1 , "1MHz"); - QVERIFY2(f1.convertedSiValueToDouble() == 1000000 , "1E6 Hz"); + QVERIFY2(f1.value() == 1 , "1MHz"); + QVERIFY2(f1.value(CFrequencyUnit::defaultUnit()) == 1000000 , "1E6 Hz"); CFrequency f2(CMeasurementPrefix::M().toDouble(), CFrequencyUnit::Hz()) ; // 1 Megahertz QVERIFY2(f1 == f2 , "MHz is 1E6 Hz"); } @@ -96,9 +93,13 @@ void CTestPhysicalQuantities::angleTests() CAngle a1(180, CAngleUnit::deg()); CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 + CAngle a4(35.436, CAngleUnit::sexagesimalDegMin()); // 35.72666 + CAngle a5(-60.3015, CAngleUnit::sexagesimalDeg()); // negative angles = west longitude or south latitude a2.switchUnit(CAngleUnit::deg()); QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor()))); QVERIFY2(a3.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); + QVERIFY2(a4.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); + QVERIFY2(a5.valueRounded(CAngleUnit::deg(), 4) == -60.5042, "Expecting -60.5042"); } /* @@ -107,11 +108,11 @@ void CTestPhysicalQuantities::angleTests() void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); - CMass w2(w1.unitValueToDouble(), CMassUnit::kg()); + CMass w2(w1.value(), CMassUnit::kg()); w2.switchUnit(CMassUnit::t()); - QVERIFY2(w2.unitValueToDouble() == 1, "1tonne shall be 1000kg"); + QVERIFY2(w2.value() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); - QVERIFY2(w2.unitValueToDoubleRounded(2) == 2204.62, "1tonne shall be 2204pounds"); + QVERIFY2(w2.valueRounded(2) == 2204.62, "1tonne shall be 2204pounds"); QVERIFY2(w1 == w2, "Masses shall be equal"); } @@ -127,7 +128,7 @@ void CTestPhysicalQuantities::pressureTests() // does not match exactly QVERIFY2(p1 != p2, "Standard pressure test little difference"); - QVERIFY2(p1.unitValueToDouble() == p4.unitValueToDouble(), "mbar/hPa test"); + QVERIFY2(p1.value() == p4.value(), "mbar/hPa test"); } /* @@ -139,19 +140,25 @@ void CTestPhysicalQuantities::temperatureTests() CTemperature t2(1, CTemperatureUnit::F()); // 1F CTemperature t3(220.15, CTemperatureUnit::F()); CTemperature t4(10, CTemperatureUnit::F()); - QVERIFY2(t1.convertedSiValueToDoubleRounded() == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.convertedSiValueToDoubleRounded()))); + QVERIFY2(t1.valueRounded(CTemperatureUnit::K()) == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.valueRounded(CTemperatureUnit::K())))); QVERIFY2(t2.valueRounded(CTemperatureUnit::C()) == -17.22, qPrintable(QString("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C())))); QVERIFY2(t3.valueRounded(CTemperatureUnit::C()) == 104.53, qPrintable(QString("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C())))); QVERIFY2(t4.valueRounded(CTemperatureUnit::K()) == 260.93, qPrintable(QString("10F shall be 260.93K, not %1 K").arg(t4.valueRounded(CTemperatureUnit::K())))); } /* - * Temperature tests + * Time tests */ void CTestPhysicalQuantities::timeTests() { CTime t1(1, CTimeUnit::h()); - QVERIFY2(t1.convertedSiValueToDouble() == 3600, "1hour shall be 3600s"); + CTime t2(1.5, CTimeUnit::h()); + CTime t3(1.25, CTimeUnit::min()); + CTime t4(1.0101, CTimeUnit::hms()); + QVERIFY2(t1.value(CTimeUnit::defaultUnit()) == 3600, "1hour shall be 3600s"); + QVERIFY2(t2.value(CTimeUnit::hrmin()) == 1.30, "1.5hour shall be 1h30m"); + QVERIFY2(t3.value(CTimeUnit::minsec()) == 1.15, "1.25min shall be 1m15s"); + QVERIFY2(t4.value(CTimeUnit::s()) == 3661, "1h01m01s shall be 3661s"); } /* @@ -160,13 +167,13 @@ void CTestPhysicalQuantities::timeTests() void CTestPhysicalQuantities::accelerationTests() { CLength oneMeter(1, CLengthUnit::m()); - double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).unitValueToDouble(); + double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).value(); CAcceleration a1(10.0, CAccelerationUnit::m_s2()); CAcceleration a2(a1); a1.switchUnit(CAccelerationUnit::ft_s2()); QVERIFY2(a1 == a2, "Accelerations should be similar"); - QVERIFY2(BlackMisc::Math::CMath::round(a1.unitValueToDouble() * ftFactor, 6) == a2.unitValueToDoubleRounded(6), + QVERIFY2(BlackMisc::Math::CMath::round(a1.value() * ftFactor, 6) == a2.valueRounded(6), "Numerical values should be equal"); } @@ -177,13 +184,13 @@ void CTestPhysicalQuantities::memoryTests() { CLength *c = new CLength(100, CLengthUnit::m()); c->switchUnit(CLengthUnit::NM()); - QVERIFY2(c->getUnit() == CLengthUnit::NM() && c->getConversionSiUnit() == CLengthUnit::m(), + QVERIFY2(c->getUnit() == CLengthUnit::NM() && CLengthUnit::defaultUnit() == CLengthUnit::m(), "Testing distance units failed"); delete c; CAngle *a = new CAngle(100, CAngleUnit::rad()); a->switchUnit(CAngleUnit::deg()); - QVERIFY2(a->getUnit() == CAngleUnit::deg() && c->getConversionSiUnit() == CAngleUnit::rad(), + QVERIFY2(a->getUnit() == CAngleUnit::deg() && CAngleUnit::defaultUnit() == CAngleUnit::deg(), "Testing angle units failed"); delete a; } @@ -201,7 +208,7 @@ void CTestPhysicalQuantities::basicArithmetic() p3 /= 2.0; QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)"); p3 = p3 - p3; - QVERIFY2(p3.unitValueToDouble() == 0, "Value needs to be zero"); + QVERIFY2(p3.value() == 0, "Value needs to be zero"); p3 = CPressure(1013, CPressureUnit::hPa()); QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed"); } From a6f89ce9eaf626940b320d31dd5b73cafdec9c76 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 18 Aug 2013 23:47:29 +0100 Subject: [PATCH 23/36] renamed CBaseStreamStringifier to CStreamable --- src/blackmisc/aviobase.h | 4 +-- src/blackmisc/aviomodulator.h | 6 ++-- src/blackmisc/coordinategeodetic.h | 2 +- src/blackmisc/geoearthangle.h | 6 ++-- src/blackmisc/mathmatrixbase.h | 4 +-- src/blackmisc/mathvector3dbase.h | 10 +++--- src/blackmisc/pqbase.h | 6 ++-- src/blackmisc/pqphysicalquantity.h | 2 +- .../{basestreamstringifier.h => streamable.h} | 31 ++++++++++--------- 9 files changed, 36 insertions(+), 35 deletions(-) rename src/blackmisc/{basestreamstringifier.h => streamable.h} (79%) diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index 36f4d335c..fa77b57d3 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -7,7 +7,7 @@ #define BLACKMISC_AVIOBASE_H // QtGlobal is required for asserts -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/pqconstants.h" #include @@ -19,7 +19,7 @@ namespace Aviation /*! * \brief Base class for avionics */ -class CAvionicsBase : public BlackMisc::CBaseStreamStringifier +class CAvionicsBase : public BlackMisc::CStreamable { protected: QString m_name; //!< name of the unit diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 3d6ca3a5a..ab7485c43 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -30,8 +30,8 @@ template class CModulator : public CAvionicsBase // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the - // CBaseStreamStringifier signature should be used - CBaseStreamStringifier &sf = uc; + // CStreamable signature should be used + CStreamable &sf = uc; return argument >> sf; } @@ -43,7 +43,7 @@ template class CModulator : public CAvionicsBase */ friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO &uc) { - const CBaseStreamStringifier &sf = uc; + const CStreamable &sf = uc; return argument << sf; } diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 6883db106..3ec776e86 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -37,7 +37,7 @@ class ICoordinateGeodetic /*! * \brief Geodetic coordinate */ -class CCoordinateGeodetic : public CBaseStreamStringifier, public ICoordinateGeodetic +class CCoordinateGeodetic : public CStreamable, public ICoordinateGeodetic { private: BlackMisc::Geo::CLatitude m_latitude; //!< Latitude diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index ccb707659..4c76aad70 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -27,8 +27,8 @@ template class CEarthAngle : public BlackMisc::PhysicalQuantiti // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the - // CBaseStreamStringifier signature should be used - CBaseStreamStringifier &sf = uc; + // CStreamable signature should be used + CStreamable &sf = uc; return argument >> sf; } @@ -40,7 +40,7 @@ template class CEarthAngle : public BlackMisc::PhysicalQuantiti */ friend QDBusArgument &operator<<(QDBusArgument &argument, const LATorLON &uc) { - const CBaseStreamStringifier &sf = uc; + const CStreamable &sf = uc; return argument << sf; } diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index 7b6897f69..ca11bb417 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -6,7 +6,7 @@ #ifndef BLACKMISC_MATHMATRIXBASE_H #define BLACKMISC_MATHMATRIXBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/mathvector3dbase.h" #include #include @@ -19,7 +19,7 @@ namespace Math /*! * \brief Base functionality of a matrix */ -template class CMatrixBase : public BlackMisc::CBaseStreamStringifier +template class CMatrixBase : public BlackMisc::CStreamable { private: /*! diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 7bd0fdc0e..b5c9e1ea8 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -6,7 +6,7 @@ #ifndef BLACKMISC_MATHVECTOR3DBASE_H #define BLACKMISC_MATHVECTOR3DBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/mathematics.h" namespace BlackMisc @@ -21,7 +21,7 @@ class CMatrix3x1; // forward declaration /*! * \brief 3D vector base (x, y, z) */ -template class CVector3DBase : public CBaseStreamStringifier +template class CVector3DBase : public CStreamable { /*! * \brief Unmarshalling operator >>, DBus to object @@ -34,8 +34,8 @@ template class CVector3DBase : public CBaseStreamStringifier // If I do not have the method here, DBus metasystem tries to stream against // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) // Once someone solves this, this methods should go and the - // CBaseStreamStringifier signature should be used - CBaseStreamStringifier &sf = uc; + // CStreamable signature should be used + CStreamable &sf = uc; return argument >> sf; } @@ -47,7 +47,7 @@ template class CVector3DBase : public CBaseStreamStringifier */ friend QDBusArgument &operator<<(QDBusArgument &argument, const ImplVector &uc) { - const CBaseStreamStringifier &sf = uc; + const CStreamable &sf = uc; return argument << sf; } diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 4bee55a0a..0576109ad 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -6,7 +6,7 @@ #ifndef BLACKMISC_PQBASE_H #define BLACKMISC_PQBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/debug.h" #include "blackmisc/mathematics.h" #include @@ -27,7 +27,7 @@ namespace PhysicalQuantities * See here for an overview. * Use the static values such as CMeasurementPrefix::k() to specify values. */ -class CMeasurementPrefix : public CBaseStreamStringifier +class CMeasurementPrefix : public CStreamable { private: QString m_name; //!< name, e.g. "kilo" @@ -267,7 +267,7 @@ public: /*! * \brief Base class for all units, such as meter, hertz. */ -class CMeasurementUnit : public CBaseStreamStringifier +class CMeasurementUnit : public CStreamable { protected: /*! diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 20ac9b10f..acdc6794e 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -24,7 +24,7 @@ namespace PhysicalQuantities /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" */ -template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier +template class CPhysicalQuantity : public BlackMisc::CStreamable { private: double m_value; //!< numeric part diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/streamable.h similarity index 79% rename from src/blackmisc/basestreamstringifier.h rename to src/blackmisc/streamable.h index ca216096f..8e5394cf7 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/streamable.h @@ -1,5 +1,5 @@ -#ifndef BLACKMISC_BASESTREAMSTRINGIFIER_H -#define BLACKMISC_BASESTREAMSTRINGIFIER_H +#ifndef BLACKMISC_STREAMABLE_H +#define BLACKMISC_STREAMABLE_H #include "blackmisc/debug.h" #include @@ -12,10 +12,11 @@ namespace BlackMisc { /*! - * \brief Provides "to QString" and stream operators + * \brief Base class for streamable value objects. + * Public non-virtual interface with protected virtual implementation. */ // Virtual operators: http://stackoverflow.com/a/4571634/356726 -class CBaseStreamStringifier +class CStreamable { /*! * \brief Stream << overload to be used in debugging messages @@ -23,7 +24,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend QDebug operator<<(QDebug debug, const CBaseStreamStringifier &uc) + friend QDebug operator<<(QDebug debug, const CStreamable &uc) { debug << uc.stringForStreaming(); return debug; @@ -35,7 +36,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend QTextStream &operator<<(QTextStream &textStream, const CBaseStreamStringifier &uc) + friend QTextStream &operator<<(QTextStream &textStream, const CStreamable &uc) { textStream << uc.stringForStreaming(); return textStream; @@ -47,7 +48,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend QNoDebug operator<<(QNoDebug nodebug, const CBaseStreamStringifier & /* uc */) + friend QNoDebug operator<<(QNoDebug nodebug, const CStreamable & /* uc */) { return nodebug; } @@ -58,7 +59,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend QDataStream &operator<<(QDataStream &stream, const CBaseStreamStringifier &uc) + friend QDataStream &operator<<(QDataStream &stream, const CStreamable &uc) { stream << uc.stringForStreaming(); return stream; @@ -70,7 +71,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend CLogMessage operator<<(CLogMessage log, const CBaseStreamStringifier &uc) + friend CLogMessage operator<<(CLogMessage log, const CStreamable &uc) { log << uc.stringForStreaming(); return log; @@ -82,7 +83,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend std::ostream &operator<<(std::ostream &ostr, const CBaseStreamStringifier &uc) + friend std::ostream &operator<<(std::ostream &ostr, const CStreamable &uc) { ostr << uc.stringForStreaming().toStdString(); return ostr; @@ -94,7 +95,7 @@ class CBaseStreamStringifier * \param uc * \return */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, CBaseStreamStringifier &uc) + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CStreamable &uc) { argument.beginStructure(); uc.unmarshallFromDbus(argument); @@ -108,7 +109,7 @@ class CBaseStreamStringifier * \param pq * \return */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const CBaseStreamStringifier &uc) + friend QDBusArgument &operator<<(QDBusArgument &argument, const CStreamable &uc) { argument.beginStructure(); uc.marshallToDbus(argument); @@ -120,7 +121,7 @@ public: /*! * \brief Virtual destructor */ - virtual ~CBaseStreamStringifier() {} + virtual ~CStreamable() {} /*! * \brief Cast as QString @@ -135,7 +136,7 @@ protected: /*! * \brief Default constructor */ - CBaseStreamStringifier() {} + CStreamable() {} /*! * \brief String for streaming operators @@ -172,7 +173,7 @@ protected: * class into an instance of a completely unrelated derived class. * \return */ - CBaseStreamStringifier& operator=(const CBaseStreamStringifier&) { return *this; } + CStreamable& operator=(const CStreamable&) { return *this; } }; } // namespace From 21ca361bc101559e1fd1ffa920fa5801f9b70195 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 03:21:12 +0100 Subject: [PATCH 24/36] removed operator= and copy ctor from classes where they only duplicated the behaviour of the default implementations that C++ generates automatically --- src/blackmisc/avaltitude.cpp | 11 ------- src/blackmisc/avaltitude.h | 13 --------- src/blackmisc/avheading.cpp | 11 ------- src/blackmisc/avheading.h | 13 --------- src/blackmisc/avioadfsystem.h | 11 ------- src/blackmisc/aviocomsystem.h | 11 ------- src/blackmisc/aviomodulator.cpp | 13 --------- src/blackmisc/aviomodulator.h | 7 ----- src/blackmisc/avionavsystem.h | 11 ------- src/blackmisc/aviotransponder.h | 13 --------- src/blackmisc/avtrack.cpp | 11 ------- src/blackmisc/avtrack.h | 13 --------- src/blackmisc/coordinategeodetic.h | 14 --------- src/blackmisc/coordinatened.h | 14 --------- src/blackmisc/geoearthangle.h | 17 ----------- src/blackmisc/geolatitude.h | 6 ---- src/blackmisc/geolongitude.h | 6 ---- src/blackmisc/mathmatrixbase.h | 12 -------- src/blackmisc/mathvector3dbase.h | 14 --------- src/blackmisc/pqangle.h | 5 ---- src/blackmisc/pqbase.cpp | 43 ---------------------------- src/blackmisc/pqbase.h | 23 ++------------- src/blackmisc/pqfrequency.h | 5 ---- src/blackmisc/pqlength.h | 5 ---- src/blackmisc/pqmass.h | 6 ---- src/blackmisc/pqphysicalquantity.cpp | 20 ------------- src/blackmisc/pqphysicalquantity.h | 13 --------- src/blackmisc/pqpressure.h | 5 ---- src/blackmisc/pqspeed.h | 5 ---- src/blackmisc/pqtemperature.h | 5 ---- src/blackmisc/pqtime.h | 5 ---- src/blackmisc/streamable.h | 8 ------ 32 files changed, 2 insertions(+), 367 deletions(-) diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index 604a654cd..d2b1619b7 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -22,17 +22,6 @@ QString CAltitude::convertToQString(bool /* i18n */) const return s.append(this->m_msl ? " MSL" : " AGL"); } -/* - * Assigment - */ -CAltitude &CAltitude::operator =(const CAltitude &other) -{ - if (this == &other) return *this; - CLength::operator = (other); - this->m_msl = other.m_msl; - return *this; -} - /* * Equal? */ diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 43379510e..572b5da1b 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -78,19 +78,6 @@ public: */ CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(altitude), m_msl(msl) {} - /*! - * \brief Copy constructor - * \param other - */ - CAltitude(const CAltitude &other) : BlackMisc::PhysicalQuantities::CLength(other), m_msl(other.m_msl) {} - - /*! - * \brief Assignment operator = - * \param other - * @return - */ - CAltitude &operator =(const CAltitude &other); - /*! * \brief Equal operator == * \param other diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index b1b4dd430..b02f7d939 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -22,17 +22,6 @@ QString CHeading::convertToQString(bool i18n) const return s.append(this->m_magnetic ? " magnetic" : " true"); } -/* - * Assigment - */ -CHeading& CHeading::operator =(const CHeading &other) -{ - if (this == &other) return *this; - this->CAngle::operator = (other); - this->m_magnetic = other.m_magnetic; - return *this; -} - /* * Equal? */ diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 83d678da6..124c895ec 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -78,19 +78,6 @@ public: */ CHeading(CAngle heading, bool magnetic) : CAngle(heading), m_magnetic(magnetic) {} - /*! - * \brief Copy constructor - * \param other - */ - CHeading(const CHeading &other) : CAngle(other), m_magnetic(other.m_magnetic) {} - - /*! - * \brief Assignment operator = - * \param other - * @return - */ - CHeading &operator =(const CHeading &other); - /*! * \brief Equal operator == * \param other diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index 8a65aa16f..6dc056e82 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -121,17 +121,6 @@ public: this->validate(true); } - /*! - * \brief Assigment operator = - * \param otherSystem - * \return - */ - CAdfSystem &operator =(const CAdfSystem &otherSystem) - { - this->CModulator::operator =(otherSystem); - return *this; - } - /*! * \brief operator == * \param otherSystem diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 46e4ff6ed..ab10eab81 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -151,17 +151,6 @@ public: this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress()); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CComSystem& operator =(const CComSystem &other) - { - this->CModulator::operator =(other); - return *this; - } - /*! * \brief operator == * \param other diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index 94428b640..c7de9a2df 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -35,19 +35,6 @@ template void CModulator::registerMetadata() qDBusRegisterMetaType(); } -/* - * Assigment operator = - */ -template CModulator& CModulator::operator=(const CModulator &other) -{ - if (this == &other) return *this; - this->m_frequencyActive = other.m_frequencyActive; - this->m_frequencyStandby = other.m_frequencyStandby; - this->m_digits = other.m_digits; - this->setName(other.getName()); - return *this; -} - /* * Equal operator == */ diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index ab7485c43..f8280bf18 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -126,13 +126,6 @@ protected: this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CModulator &operator =(const CModulator &other); - /*! * \brief operator == * \param other diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index f6ec2026b..188a42502 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -132,17 +132,6 @@ public: this->validate(true); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CNavSystem &operator =(const CNavSystem &other) - { - this->CModulator::operator =(other); - return *this; - } - /*! * \brief operator == * \param other diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index e866dfbfc..3d09cb1cc 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -224,19 +224,6 @@ public: this->m_transponderCode = 2000; } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CTransponder &operator =(const CTransponder &other) - { - this->CAvionicsBase::operator =(other); - this->m_transponderMode = other.m_transponderMode; - this->m_transponderCode = other.m_transponderCode; - return *this; - } - /*! * \brief operator == * \param other diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 5fe603fc0..b3a16a450 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -22,17 +22,6 @@ QString CTrack::convertToQString(bool i18n) const return s.append(this->m_magnetic ? " magnetic" : " true"); } -/* - * Assigment - */ -CTrack& CTrack::operator =(const CTrack &other) -{ - if (this == &other) return *this; - this->CAngle::operator = (other); - this->m_magnetic = other.m_magnetic; - return *this; -} - /* * Equal? */ diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index 6eca3ecf8..d202b4e38 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -77,19 +77,6 @@ public: */ CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(track), m_magnetic(magnetic) {} - /*! - * \brief Copy constructor - * \param other - */ - CTrack(const CTrack &other) : BlackMisc::PhysicalQuantities::CAngle(other), m_magnetic(other.m_magnetic) {} - - /*! - * \brief Assignment operator = - * \param other - * \return - */ - CTrack &operator =(const CTrack &other); - /*! * \brief Equal operator == * \param other diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 3ec776e86..864acff1c 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -194,20 +194,6 @@ public: return !((*this) == other); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CCoordinateGeodetic &operator =(const CCoordinateGeodetic &other) - { - if (this == &other) return *this; - this->m_height = other.m_height; - this->m_latitude = other.m_latitude; - this->m_longitude = other.m_longitude; - return *this; - } - /* * Register metadata */ diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index 57fdd9f85..78c40638e 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -108,20 +108,6 @@ public: return !((*this) == other); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CCoordinateNed &operator =(const CCoordinateNed &other) - { - if (this == &other) return *this; - this->CVector3DBase::operator = (other); - this->m_hasReferencePosition = other.m_hasReferencePosition; - this->m_referencePosition = other.m_referencePosition; - return *this; - } - /*! * \brief Corresponding reference position * \return diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 4c76aad70..8cb2835ed 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -50,12 +50,6 @@ protected: */ CEarthAngle() : CAngle(0.0, BlackMisc::PhysicalQuantities::CAngleUnit::deg()) {} - /*! - * \brief Copy constructor - * \param latOrLon - */ - CEarthAngle(const LATorLON &latOrLon) : CAngle(latOrLon) {} - /*! * \brief Init by double value * \param value @@ -184,17 +178,6 @@ public: return this->CAngle::operator >=(latOrLon); } - /*! - * \brief Assignment operator = - * \param latOrLon - * \return - */ - CEarthAngle &operator =(const LATorLON &latOrLon) - { - this->CAngle::operator =(latOrLon); - return *this; - } - /*! * \brief Plus operator + * \param latOrLon diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 781a8b599..5f5fd66a1 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -31,12 +31,6 @@ public: */ CLatitude() : CEarthAngle() {} - /*! - * \brief Copy constructor - * \param other - */ - CLatitude(const CLatitude &other) : CEarthAngle(other) {} - /*! * \brief Constructor * \param angle diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index a851be10c..8ab0e9e8a 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -28,12 +28,6 @@ public: */ CLongitude() : CEarthAngle() {} - /*! - * \brief Copy constructor - * \param other - */ - CLongitude(const CLongitude &other) : CEarthAngle(other) {} - /*! * \brief Constructor * \param angle diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index ca11bb417..de8d3b5d3 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -140,18 +140,6 @@ public: return !((*this) == other); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CMatrixBase &operator =(const CMatrixBase &other) - { - if (this == &other) return *this; - this->m_matrix = other.m_matrix; - return *this; - } - /*! * \brief Operator *= * \param factor diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index b5c9e1ea8..dac6f3e8d 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -203,20 +203,6 @@ public: return !((*this) == other); } - /*! - * \brief Assigment operator = - * \param other - * \return - */ - CVector3DBase &operator =(const CVector3DBase &other) - { - if (this == &other) return *this; - this->m_i = other.m_i; - this->m_j = other.m_j; - this->m_k = other.m_k; - return *this; - } - /*! * \brief Operator += * \param other diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 9453f63c6..c8209d8cd 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -24,11 +24,6 @@ public: */ CAngle() : CPhysicalQuantity(0, CAngleUnit::defaultUnit()) {} - /*! - * \brief Copy constructor from base type - */ - CAngle(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 982ddaf0e..8ea33df57 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -17,34 +17,6 @@ namespace PhysicalQuantities // --- Prefix ------------------------------------------------------------ // ----------------------------------------------------------------------- -/* - * Constructor - */ -CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &symbol, double factor) : - m_name(name), m_symbol(symbol), m_factor(factor) -{ -} - -/* - * Constructor - */ -CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &other) : - m_name(other.m_name), m_symbol(other.m_symbol), m_factor(other.m_factor) -{ -} - -/* - * Assignment operator - */ -CMeasurementPrefix &CMeasurementPrefix::operator=(const CMeasurementPrefix &other) -{ - if (this == &other) return *this; - this->m_name = other.m_name; - this->m_symbol= other.m_symbol; - this->m_factor = other.m_factor; - return *this; -} - /* * Equal? */ @@ -106,21 +78,6 @@ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) : { } -/* - * Assigment operator - */ -CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &other) -{ - if (this == &other) return *this; // Same object? Yes, so skip assignment, and just return *this - this->m_name = other.m_name; - this->m_symbol = other.m_symbol; - this->m_prefix = other.m_prefix; - this->m_displayDigits = other.m_displayDigits; - this->m_epsilon = other.m_epsilon; - this->m_converter = other.m_converter; - return *this; -} - /* * Equal operator */ diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 0576109ad..f7fb27a3b 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -41,7 +41,8 @@ private: * \param prefixName * \param factor */ - CMeasurementPrefix(const QString &name, const QString &symbol, double factor); + CMeasurementPrefix(const QString &name, const QString &symbol, double factor) : + m_name(name), m_symbol(symbol), m_factor(factor) {} protected: /*! @@ -75,19 +76,6 @@ protected: } public: - /*! - * \brief Copy constructor - * \param other - */ - CMeasurementPrefix(const CMeasurementPrefix &other); - - /*! - * \brief Assigmnet operator = - * \param other - * \return - */ - CMeasurementPrefix &operator =(const CMeasurementPrefix &other); - /*! * \brief Equal operator == * \param other @@ -439,13 +427,6 @@ protected: */ CMeasurementUnit(const CMeasurementUnit &other); - /*! - * \brief Assignment operator = - * \param other - * \return - */ - CMeasurementUnit &operator =(const CMeasurementUnit &other); - /*! * \brief String for streaming operators is full name * \return diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 96b790d95..d86a89f76 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -24,11 +24,6 @@ public: */ CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::defaultUnit()) {} - /** - *\brief Copy constructor from base type - */ - CFrequency(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index 559b7f172..15cecf3ef 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -24,11 +24,6 @@ public: */ CLength() : CPhysicalQuantity(0, CLengthUnit::defaultUnit()) {} - /** - *\brief Copy constructor from base type - */ - CLength(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index 9b949b78b..00483b3b1 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -30,12 +30,6 @@ public: */ CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit) {} - /*! - * \brief Copy constructor from base type - * \param base - */ - CMass(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! * \brief Virtual destructor */ diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 945c0aa68..b83c3ce29 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -18,14 +18,6 @@ template CPhysicalQuantity::CPhysicalQuantity(doubl { } -/* - * Copy constructor - */ -template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &other) : - m_value(other.m_value), m_unit(other.m_unit) -{ -} - /* * Equal operator == */ @@ -44,18 +36,6 @@ template bool CPhysicalQuantity::operator !=(const return !((*this) == other); } -/* - * Assignment operator = - */ -template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &other) -{ - if (this == &other) return *this; - - this->m_value = other.m_value; - this->m_unit = other.m_unit; - return *this; -} - /* * Plus operator */ diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index acdc6794e..ce3c80786 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -61,19 +61,6 @@ protected: */ CPhysicalQuantity(double value, const MU &unit); - /*! - * \brief Copy constructor - * \param other - */ - CPhysicalQuantity(const CPhysicalQuantity &other); - - /*! - * \brief Assignment operator = - * \param other - * \return - */ - CPhysicalQuantity &operator =(const CPhysicalQuantity &other); - /*! * \brief Name as string * \param i18n diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index 38d08778f..febb338b1 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -25,11 +25,6 @@ public: */ CPressure() : CPhysicalQuantity(0, CPressureUnit::defaultUnit()) {} - /** - *\brief Copy constructor from base type - */ - CPressure(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index 889916f42..a783b4b9c 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -25,11 +25,6 @@ public: */ CSpeed() : CPhysicalQuantity(0, CSpeedUnit::defaultUnit()) {} - /*! - *\brief Copy constructor from base type - */ - CSpeed(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index e8697e509..a94540967 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -24,11 +24,6 @@ public: */ CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::defaultUnit()) {} - /** - * \brief Copy constructor from base type - */ - CTemperature(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 060585c70..8ecd81fc7 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -25,11 +25,6 @@ public: */ CTime() : CPhysicalQuantity(0, CTimeUnit::defaultUnit()) {} - /** - *\brief Copy constructor from base type - */ - CTime(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/streamable.h b/src/blackmisc/streamable.h index 8e5394cf7..8ad890010 100644 --- a/src/blackmisc/streamable.h +++ b/src/blackmisc/streamable.h @@ -166,14 +166,6 @@ protected: * \param argument */ virtual void unmarshallFromDbus(const QDBusArgument &) = 0; - - /*! - * \brief Copy assignment operator. - * \remark This is protected in order to forbid slicing an instance of one derived - * class into an instance of a completely unrelated derived class. - * \return - */ - CStreamable& operator=(const CStreamable&) { return *this; } }; } // namespace From f9f35f27d588cd1b40aaadc10b9d56c9c6c6b33c Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 14:28:55 +0100 Subject: [PATCH 25/36] make construct-from-CAngle constructors explicit in CLatitude and CLongitude to make it harder to convert between incompatible CAngle subclasses --- src/blackmisc/geolatitude.h | 2 +- src/blackmisc/geolongitude.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 5f5fd66a1..82fb40285 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -35,7 +35,7 @@ public: * \brief Constructor * \param angle */ - CLatitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} + explicit CLatitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} /*! * \brief Init by double value diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 8ab0e9e8a..64880ef51 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -32,7 +32,7 @@ public: * \brief Constructor * \param angle */ - CLongitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} + explicit CLongitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} /*! * \brief Init by double value From 5f267e8245845ebab47eed84130f4b72969156df Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 17:44:33 +0100 Subject: [PATCH 26/36] minor regularization of vectors and matrices --- .../samplesvectormatrix.cpp | 4 +- src/blackmisc/mathmatrix1x3.h | 2 +- src/blackmisc/mathmatrix3x1.h | 4 +- src/blackmisc/mathmatrix3x3.cpp | 4 +- src/blackmisc/mathmatrix3x3.h | 52 ++++++------- src/blackmisc/mathmatrixbase.cpp | 32 +------- src/blackmisc/mathmatrixbase.h | 24 +----- src/blackmisc/mathvector3dbase.cpp | 49 +++++------- src/blackmisc/mathvector3dbase.h | 78 ++++--------------- 9 files changed, 72 insertions(+), 177 deletions(-) diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp index c39d4507c..2423da9a0 100644 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp +++ b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp @@ -10,13 +10,11 @@ int BlackMiscTest::CSamplesVectorMatrix::samples() CVector3D v1; CVector3D v2(1, 2, 3); qDebug() << v1 << "value:" << v2[2] << v2.length(); - v2 *= v2; // v2 * v2 - qDebug() << v2 << 2 * v1 << v1 *v1; + qDebug() << v2 << (2 * v1); CMatrix3x3 m; CMatrix3x3 mr = m; qDebug() << m << mr; - mr.setRandom(); bool im; CMatrix3x3 mi = mr.inverse(im); CMatrix3x3 mid = mr * mi; diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h index 430307397..fede41204 100644 --- a/src/blackmisc/mathmatrix1x3.h +++ b/src/blackmisc/mathmatrix1x3.h @@ -15,7 +15,7 @@ namespace Math { /*! - * \brief 3D matrix + * \brief Matrix 1x3 */ class CMatrix1x3 : public CMatrixBase { diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h index 81078618a..b28bbc979 100644 --- a/src/blackmisc/mathmatrix3x1.h +++ b/src/blackmisc/mathmatrix3x1.h @@ -14,12 +14,14 @@ namespace BlackMisc namespace Math { +class CMatrix3x3; + /*! * \brief Matrix 3x1 */ class CMatrix3x1 : public CMatrixBase { - friend class CMatrix3x3; // for matrix multiplicaion to access m_matrix + friend class CMatrix3x3; public: /*! diff --git a/src/blackmisc/mathmatrix3x3.cpp b/src/blackmisc/mathmatrix3x3.cpp index 21185d857..fed2ad73f 100644 --- a/src/blackmisc/mathmatrix3x3.cpp +++ b/src/blackmisc/mathmatrix3x3.cpp @@ -30,8 +30,8 @@ double CMatrix3x3::determinant() const CMatrix3x3 CMatrix3x3::inverse(bool &o_invertible) const { CMatrix3x3 inverse; - double det; - if (this->allValuesEqual() || (det = this->determinant()) == 0) + double det = this->determinant(); + if (det == 0) { o_invertible = false; inverse.setZero(); diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index 44e9c5b31..f21a1d7be 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -87,6 +87,17 @@ public: this->m_matrix = this->m_matrix * other.m_matrix; return *this; } + /*! + * \brief Operator * + * \param other + * \return + */ + CMatrix3x3 operator *(const CMatrix3x3 &other) const + { + CMatrix3x3 m(*this); + m *= other; + return m; + } /*! * \brief Operator * @@ -101,27 +112,24 @@ public: } /*! - * \brief Operator * - * \param other - * \return - */ - CMatrix3x3 operator *(const CMatrix3x3 &other) const - { - CMatrix3x3 m(*this); - m *= other; - return m; - } - - /*! - * \brief Multiply vector with this 3x3 matrix + * \brief Multiply this matrix with vector * \param vector * \return */ CVector3D operator *(const CVector3D &vector) const { - CVector3D v(vector); - v.matrixMultiplication(*this); - return v; + return ((*this) * CMatrix3x1(vector.toMatrix3x1())).toVector3D(); + } + + /*! + * \brief Multiply with factor + * \param factor + * \return + */ + CMatrix3x3 &operator *=(double factor) + { + this->CMatrixBase::operator *=(factor); + return *this; } /*! @@ -136,17 +144,6 @@ public: return m; } - /*! - * \brief Multiply with factor - * \param factor - * \return - */ - CMatrix3x3 &operator *=(double factor) - { - CMatrixBase::operator *=(factor); - return *this; - } - /*! * \brief Transposed matrix * \return @@ -171,7 +168,6 @@ public: * \return */ CMatrix1x3 getRow(int row) const; - }; } // namespace diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 6d6d5819a..d0a7b01b8 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -40,20 +40,6 @@ template void CMatrixBase void CMatrixBase::setRandom() -{ - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - this->m_matrix(r, c) = (qrand() % 101); // 0...100 - } - } -} - /* * All values zero? */ @@ -87,7 +73,7 @@ template void CMatrixBase const QList CMatrixBase::toList() const +template QList CMatrixBase::toList() const { QList list; for (int r = 0; r < Rows; r++) @@ -116,22 +102,6 @@ template void CMatrixBase bool CMatrixBase::allValuesEqual() const -{ - double v = this->getElement(0, 0); - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - if (this->m_matrix(r, c) != v) return false; - } - } - return true; -} - /* * Round all values */ diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index de8d3b5d3..48a9e310b 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -111,7 +111,7 @@ public: * \brief List of values * \return */ - const QList toList() const; + QList toList() const; /*! * \brief List of values @@ -164,7 +164,7 @@ public: } /*! - * \brief Operator to support commutative multiplication + * \brief Operator to support commutative scalar multiplication * \param factor * \param other * \return @@ -174,13 +174,6 @@ public: return other * factor; } - /*! - * \brief Multiply with 3D vector operator * - * \param matrix - * \return - */ - template ImplVector operator*(const ImplVector matrix) const; - /*! * \brief Operator /= * \param factor @@ -279,11 +272,6 @@ public: this->m_matrix.setToIdentity(); } - /*! - * \brief Fills the matrix with random elements - */ - void setRandom(); - /*! * \brief All values to zero */ @@ -312,13 +300,7 @@ public: } /*! - * \brief All values equal, if so matirx is not invertible - * \return - */ - bool allValuesEqual() const; - - /*! - * \brief Set a dedicated value + * \brief Set all elements the same * \param value */ void fill(double value) { this->m_matrix.fill(value); } diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index 0e3df39f3..6484e6ae9 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -43,29 +43,31 @@ template void CVector3DBase::fill(double value) this->m_k = value; } +/* + * Element (return by reference) + */ +template double &CVector3DBase::getElement(size_t row) +{ + switch (row) + { + case 0: + return this->m_i; + case 1: + return this->m_j; + case 2: + return this->m_k; + default: + Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector"); + throw std::range_error("Detected invalid index in 3D vector"); + } +} + /* * Element */ template double CVector3DBase::getElement(size_t row) const { - double d; - switch (row) - { - case 0: - d = this->m_i; - break; - case 1: - d = this->m_j; - break; - case 2: - d = this->m_k; - break; - default: - Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector"); - throw std::range_error("Detected invalid index in 3D vector"); - break; - } - return d; + return const_cast*>(this)->getElement(row); } /* @@ -112,17 +114,6 @@ template double CVector3DBase::dotProduct(const I } -/* - * Multiply with matrix - */ -template void CVector3DBase::matrixMultiplication(const CMatrix3x3 &matrix) -{ - CMatrix3x1 m = matrix * this->toMatrix3x1(); - this->m_i = m(0, 0); - this->m_j = m(1, 0); - this->m_k = m(2, 0); -} - /* * Convert to matrix */ diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index dac6f3e8d..0d40cf8df 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -14,9 +14,7 @@ namespace BlackMisc namespace Math { -class CMatrix3x3; // forward declaration -class CMatrix3x1; // forward declaration - +class CMatrix3x1; /*! * \brief 3D vector base (x, y, z) @@ -101,6 +99,13 @@ protected: */ CVector3DBase(const CVector3DBase &other) : m_i(other.m_i), m_j(other.m_j), m_k(other.m_k) {} + /*! + * \brief Get element + * \param row + * \return Mutable reference + */ + double &getElement(size_t row); + /*! * \brief String for converter * \param i18n @@ -155,7 +160,8 @@ public: } /*! - * \brief Set zeros + * \brief Set all elements the same + * \param value */ void fill(double value); @@ -180,6 +186,13 @@ public: */ double operator[](size_t row) const { return this->getElement(row); } + /*! + * \brief Operator [] + * \param row + * \return Mutable reference + */ + double &operator[](size_t row) { return this->getElement(row); } + /*! * \brief Equal operator == * \param other @@ -253,31 +266,6 @@ public: return v; } - /*! - * \brief Operator *=, just x*x, y*y, z*z neither vector nor dot product (like a matrix produc) - * \param other - * \return - */ - CVector3DBase &operator *=(const CVector3DBase &other) - { - this->m_i *= other.m_i; - this->m_j *= other.m_j; - this->m_k *= other.m_k; - return *this; - } - - /*! - * \brief Operator, just x*x, y*y, z*z neither vector nor dot product, (like a matrix produc) - * \param other - * \return - */ - ImplVector operator *(const ImplVector &other) const - { - ImplVector v = *derived(); - v *= other; - return v; - } - /*! * \brief Multiply with scalar * \param factor @@ -339,31 +327,6 @@ public: return v; } - /*! - * \brief Operator /=, just x/x, y/y, z/z - * \param other - * \return - */ - CVector3DBase &operator /=(const CVector3DBase &other) - { - this->m_i /= other.m_i; - this->m_j /= other.m_j; - this->m_k /= other.m_k; - return *this; - } - - /*! - * \brief Operator, just x/x, y/y, z/z - * \param other - * \return - */ - ImplVector operator /(const ImplVector &other) const - { - ImplVector v = *derived(); - v /= other; - return v; - } - /*! * \brief Dot product * \param other @@ -378,13 +341,6 @@ public: */ ImplVector crossProduct(const ImplVector &other) const; - /*! - * \brief Matrix * this vector - * \param matrix - * \return - */ - void matrixMultiplication(const CMatrix3x3 &matrix); - /*! * \brief Reciprocal value * \return From cec9de5cc5845686f36aed0036ec5037138266df Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 18:11:54 +0100 Subject: [PATCH 27/36] use enums instead of bools to distinguish true/magnetic headings and tracks and MSL/AGL altitudes --- .../blackmiscquantities/samplesaviation.cpp | 4 +- samples/blackmiscquantities_dbus/main.cpp | 6 +-- samples/interpolator/main.cpp | 4 +- src/blackcore/interpolator.cpp | 4 +- src/blackcore/multiplayer.cpp | 2 +- src/blackmisc/avaltitude.cpp | 4 +- src/blackmisc/avaltitude.h | 46 +++++++++++------- src/blackmisc/avheading.cpp | 4 +- src/blackmisc/avheading.h | 46 +++++++++++------- src/blackmisc/avtrack.cpp | 4 +- src/blackmisc/avtrack.h | 48 +++++++++++-------- tests/blackmisc/testaviation.cpp | 6 +-- 12 files changed, 104 insertions(+), 74 deletions(-) diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index d775dea48..a29f30791 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -16,8 +16,8 @@ namespace BlackMiscTest */ int CSamplesAviation::samples() { - CHeading h1(180, true, CAngleUnit::deg()); - CHeading h2(180, false, CAngleUnit::deg()); + CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg()); + CHeading h2(180, CHeading::True, CAngleUnit::deg()); qDebug() << h1; qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1); diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp index e88fea442..6e571e3da 100644 --- a/samples/blackmiscquantities_dbus/main.cpp +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection, &a); CSpeed speed(200, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); - CAltitude al(1000, true, CLengthUnit::ft()); + CAltitude al(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft()); while (true) { QDBusMessage m = QDBusMessage::createSignal( @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) testserviceInterface.receiveTransponder(transponder); qDebug() << "Send transponder via interface" << transponder; - CTrack track(123.45, true, CAngleUnit::deg()); + CTrack track(123.45, CTrack::Magnetic, CAngleUnit::deg()); testserviceInterface.receiveTrack(track); qDebug() << "Send track via interface" << track; @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) testserviceInterface.receiveLength(len); qDebug() << "Send length via interface" << len; - CAltitude alt(33, true, CLengthUnit::m()); + CAltitude alt(33, CAltitude::MeanSeaLevel, CLengthUnit::m()); testserviceInterface.receiveLength(alt); qDebug() << "Send altitude via interface" << alt; diff --git a/samples/interpolator/main.cpp b/samples/interpolator/main.cpp index a5baa7f1f..92c4b3bfa 100644 --- a/samples/interpolator/main.cpp +++ b/samples/interpolator/main.cpp @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) CSpeed speed(20, CSpeedUnit::kts()); CCoordinateNed ned; - ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, false, CAngleUnit::deg()), zeroAngle, zeroAngle); + ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle); cout << "Interpolator NED 1: " << ned << endl; - ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, false, CAngleUnit::deg()), zeroAngle, zeroAngle); + ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle); cout << "Interpolator NED 2: " << ned << endl; double duration = timer.nsecsElapsed(); diff --git a/src/blackcore/interpolator.cpp b/src/blackcore/interpolator.cpp index 6c12e9b79..4329d9c35 100644 --- a/src/blackcore/interpolator.cpp +++ b/src/blackcore/interpolator.cpp @@ -67,7 +67,7 @@ CCoordinateNed CInterpolator::pushUpdate(const CCoordinateGeodetic &pos, const C m_state_end->timestamp = m_time.elapsed(); m_state_end->position = CCoordinateTransformation::toEcef(pos); - m_state_end->orientation.heading = CHeading(normalizeRadians(heading), false); + m_state_end->orientation.heading = CHeading(normalizeRadians(heading), CHeading::True); m_state_end->orientation.pitch = normalizeRadians(pitch); m_state_end->orientation.bank = normalizeRadians(bank); m_state_end->groundspeed = groundSpeed; @@ -131,7 +131,7 @@ bool CInterpolator::stateNow(TPlaneState *state) // Plane Orientation double vEast = state->velNED.east(); double vNorth = state->velNED.north(); - state->orientation.heading = CHeading(atan2(vNorth, vEast), false, CAngleUnit::rad()); + state->orientation.heading = CHeading(atan2(vNorth, vEast), CHeading::True, CAngleUnit::rad()); return true; } diff --git a/src/blackcore/multiplayer.cpp b/src/blackcore/multiplayer.cpp index 2a7da6c9d..017e59390 100644 --- a/src/blackcore/multiplayer.cpp +++ b/src/blackcore/multiplayer.cpp @@ -82,7 +82,7 @@ void CMultiPlayer::onPositionUpdate(const FSD::FSD_MSG_Plane_Position *plane_pos plane->addPosition(position, CSpeed(plane_position->Speed(), CSpeedUnit::kts()), - CHeading((qint32)pitchBankHeading.hdg, false, CAngleUnit::deg()), + CHeading((qint32)pitchBankHeading.hdg, CHeading::True, CAngleUnit::deg()), CAngle((qint32)pitchBankHeading.pitch, CAngleUnit::deg()), CAngle((qint32)pitchBankHeading.bank, CAngleUnit::deg())); diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index d2b1619b7..d0b7becb8 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -19,7 +19,7 @@ namespace Aviation QString CAltitude::convertToQString(bool /* i18n */) const { QString s = this->CLength::convertToQString(); - return s.append(this->m_msl ? " MSL" : " AGL"); + return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL"); } /* @@ -27,7 +27,7 @@ QString CAltitude::convertToQString(bool /* i18n */) const */ bool CAltitude::operator ==(const CAltitude &other) { - return other.m_msl == this->m_msl && this->CLength::operator ==(other); + return other.m_datum == this->m_datum && this->CLength::operator ==(other); } /* diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 572b5da1b..cf74a0311 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -18,8 +18,18 @@ namespace Aviation */ class CAltitude : public BlackMisc::PhysicalQuantities::CLength { +public: + /*! + * Enum type to distinguish between MSL and AGL + */ + enum ReferenceDatum + { + MeanSeaLevel = 0, //!< MSL + AboveGround = 1, //!< AGL + }; + private: - bool m_msl; //!< MSL or AGL? + ReferenceDatum m_datum; //!< MSL or AGL? protected: /*! @@ -36,7 +46,7 @@ protected: virtual void marshallToDbus(QDBusArgument &argument) const { this->CLength::marshallToDbus(argument); - argument << this->m_msl; + argument << qint32(this->m_datum); } /*! @@ -46,37 +56,31 @@ protected: virtual void unmarshallFromDbus(const QDBusArgument &argument) { this->CLength::unmarshallFromDbus(argument); - argument >> this->m_msl; + qint32 datum; + argument >> datum; + this->m_datum = static_cast(datum); } public: /*! * \brief Default constructor: 0 Altitude true */ - CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_msl(true) {} + CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel) {} /*! * \brief Constructor * \param value - * \param msl MSL or AGL? + * \param datum MSL or AGL? * \param unit */ - CAltitude(double value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_msl(msl) {} - - /*! - * \brief Constructor - * \param value - * \param msl MSL or AGL? - * \param unit - */ - CAltitude(int value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : CLength(value, unit), m_msl(msl) {} + CAltitude(double value, ReferenceDatum datum, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_datum(datum) {} /*! * \brief Constructor by CLength * \param altitude - * \param msl + * \param datum */ - CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(altitude), m_msl(msl) {} + CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, ReferenceDatum datum) : BlackMisc::PhysicalQuantities::CLength(altitude), m_datum(datum) {} /*! * \brief Equal operator == @@ -98,7 +102,7 @@ public: */ bool isAboveGroundLevel() const { - return !this->m_msl; + return AboveGround == this->m_datum; } /*! @@ -107,9 +111,15 @@ public: */ bool isMeanSeaLevel() const { - return this->m_msl; + return MeanSeaLevel == this->m_datum; } + /*! + * \brief Get reference datum (MSL or AGL) + * \return + */ + ReferenceDatum getReferenceDatum() const { return m_datum; } + /*! * \brief Register metadata */ diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index b02f7d939..ffaddbbd9 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -19,7 +19,7 @@ namespace Aviation QString CHeading::convertToQString(bool i18n) const { QString s = CAngle::convertToQString(i18n); - return s.append(this->m_magnetic ? " magnetic" : " true"); + return s.append(this->isMagneticHeading() ? " magnetic" : " true"); } /* @@ -27,7 +27,7 @@ QString CHeading::convertToQString(bool i18n) const */ bool CHeading::operator ==(const CHeading &other) { - return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other); + return other.m_north == this->m_north && this->CAngle::operator ==(other); } /* diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 124c895ec..e187143ff 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -18,8 +18,18 @@ namespace Aviation */ class CHeading : public BlackMisc::PhysicalQuantities::CAngle { +public: + /*! + * Enum type to distinguish between true north and magnetic north + */ + enum ReferenceNorth + { + Magnetic = 0, //!< magnetic north + True = 1, //!< true north + }; + private: - bool m_magnetic; //!< magnetic or true heading? + ReferenceNorth m_north; //!< magnetic or true? protected: /*! @@ -36,7 +46,7 @@ protected: virtual void marshallToDbus(QDBusArgument &argument) const { this->CAngle::marshallToDbus(argument); - argument << this->m_magnetic; + argument << qint32(this->m_north); } /*! @@ -46,37 +56,31 @@ protected: virtual void unmarshallFromDbus(const QDBusArgument &argument) { this->CAngle::unmarshallFromDbus(argument); - argument >> this->m_magnetic; + qint32 north; + argument >> north; + this->m_north = static_cast(north); } public: /*! * \brief Default constructor: 0 heading true */ - CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {} + CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {} /*! * \brief Constructor * \param value - * \param magnetic + * \param north * \param unit */ - CHeading(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {} - - /*! - * \brief Constructor - * \param value - * \param magnetic - * \param unit - */ - CHeading(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {} + CHeading(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_north(north) {} /*! * \brief Constructor by CAngle - * \param heading + * \param north * \param magnetic */ - CHeading(CAngle heading, bool magnetic) : CAngle(heading), m_magnetic(magnetic) {} + CHeading(CAngle heading, ReferenceNorth north) : CAngle(heading), m_north(north) {} /*! * \brief Equal operator == @@ -96,13 +100,19 @@ public: * \brief Magnetic heading? * \return */ - bool isMagneticHeading() const { return this->m_magnetic; } + bool isMagneticHeading() const { return Magnetic == this->m_north; } /*! * \brief True heading? * \return */ - bool isTrueHeading() const { return !this->m_magnetic; } + bool isTrueHeading() const { return True == this->m_north; } + + /*! + * \brief Get reference north (magnetic or true) + * \return + */ + ReferenceNorth getReferenceNorth() const { return m_north; } /*! * \brief Register metadata diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index b3a16a450..0569216f1 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -19,7 +19,7 @@ namespace Aviation QString CTrack::convertToQString(bool i18n) const { QString s = CAngle::convertToQString(i18n); - return s.append(this->m_magnetic ? " magnetic" : " true"); + return s.append(this->isMagneticTrack() ? " magnetic" : " true"); } /* @@ -27,7 +27,7 @@ QString CTrack::convertToQString(bool i18n) const */ bool CTrack::operator ==(const CTrack &other) { - return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other); + return other.m_north == this->m_north && this->CAngle::operator ==(other); } /* diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index d202b4e38..3600f71ba 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -18,8 +18,18 @@ namespace Aviation */ class CTrack : public BlackMisc::PhysicalQuantities::CAngle { +public: + /*! + * Enum type to distinguish between true north and magnetic north + */ + enum ReferenceNorth + { + Magnetic = 0, //!< magnetic north + True = 1, //!< true north + }; + private: - bool m_magnetic; //!< magnetic or true Track? + ReferenceNorth m_north; //!< magnetic or true? protected: /*! @@ -35,7 +45,7 @@ protected: virtual void marshallToDbus(QDBusArgument &argument) const { this->CAngle::marshallToDbus(argument); - argument << this->m_magnetic; + argument << qint32(this->m_north); } /*! @@ -45,37 +55,31 @@ protected: virtual void unmarshallFromDbus(const QDBusArgument &argument) { this->CAngle::unmarshallFromDbus(argument); - argument >> this->m_magnetic; + qint32 north; + argument >> north; + this->m_north = static_cast(north); } public: /*! * \brief Default constructor: 0 Track magnetic */ - CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {} + CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {} /*! * \brief Constructor * \param value - * \param magnetic + * \param north * \param unit */ - CTrack(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} - - /*! - * \brief Constructor - * \param value - * \param magnetic - * \param unit - */ - CTrack(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} + CTrack(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_north(north) {} /*! * \brief Constructor by CAngle * \param track - * \param magnetic + * \param north */ - CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(track), m_magnetic(magnetic) {} + CTrack(BlackMisc::PhysicalQuantities::CAngle track, ReferenceNorth north) : BlackMisc::PhysicalQuantities::CAngle(track), m_north(north) {} /*! * \brief Equal operator == @@ -97,9 +101,8 @@ public: */ bool isMagneticTrack() const { - return this->m_magnetic; + return Magnetic == this->m_north; (void)QT_TRANSLATE_NOOP("Aviation", "magnetic"); - (void)QT_TRANSLATE_NOOP("Aviation", "true"); } /*! @@ -108,9 +111,16 @@ public: */ bool isTrueTrack() const { - return !this->m_magnetic; + return True == this->m_north; + (void)QT_TRANSLATE_NOOP("Aviation", "true"); } + /*! + * \brief Get reference north (magnetic or true) + * \return + */ + ReferenceNorth getReferenceNorth() const { return m_north; } + /*! * \brief Register metadata */ diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index 1956ea577..191c5bac6 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -24,9 +24,9 @@ CTestAviation::CTestAviation(QObject *parent): QObject(parent) */ void CTestAviation::headingBasics() { - CHeading h1(180, true, CAngleUnit::deg()); - CHeading h2(180, false, CAngleUnit::deg()); - CHeading h3(181, true, CAngleUnit::deg()); + CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg()); + CHeading h2(180, CHeading::True, CAngleUnit::deg()); + CHeading h3(181, CHeading::Magnetic, CAngleUnit::deg()); CAngle a1(200, CAngleUnit::deg()); CHeading h4; h4 = h1; From 3cb9a783d27e36594d9359d9bfb6a35c3aeb48a2 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 18:18:30 +0100 Subject: [PATCH 28/36] just something I missed earlier - no need to use qint32 here --- src/blackmisc/pqbase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 8ea33df57..8b50086fe 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -41,7 +41,7 @@ bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, qint32 displayDigits, double epsilon) : +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon) : m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new LinearConverter(factor)) { } @@ -49,7 +49,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, qint32 displayDigits, double epsilon) : +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon) : m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new AffineConverter(factor, offset)) { } @@ -57,7 +57,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, qint32 displayDigits, double epsilon) : +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon) : m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(converter) { } @@ -65,7 +65,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, C /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, qint32 displayDigits, double epsilon) : +CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) : m_name(base.m_name), m_symbol(base.m_symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(prefix), m_converter(base.m_converter->clone(prefix)) { } From 3567dace6f1a87431b2fe68b26c9aa6c61be2988 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 18:25:39 +0100 Subject: [PATCH 29/36] fixed mistakenly big epsilons --- src/blackmisc/pqunits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index b461fdda6..16b38d48f 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -612,7 +612,7 @@ public: */ static const CPressureUnit &bar() { - static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", 1000, 1, 1E5); + static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", 1000, 1); return bar; } @@ -622,7 +622,7 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar(CMeasurementPrefix::m(), bar(), 1, 1E2); + static CPressureUnit bar(CMeasurementPrefix::m(), bar(), 1); return bar; } From 9b239f12aaa5b3e418336ffe9fa939477399a194 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 19 Aug 2013 18:46:37 +0100 Subject: [PATCH 30/36] fixes for MinGW, including adding CONFIG += c++11 in all qmake project files --- samples/blackmiscquantities/sample_quantities_avionics.pro | 2 +- .../sample_quantities_avionics_dbus.pro | 2 +- samples/blackmiscvectorgeo/sample_vector_geo.pro | 2 +- samples/com_client/sample_com_client.pro | 2 +- samples/com_server/sample_com_server.pro | 2 +- samples/config/sample_config.pro | 1 + samples/interpolator/sample_interpolator.pro | 2 +- samples/logging/sample_logging.pro | 2 +- samples/plugin/sample_plugin.pro | 2 +- samples/pluginmgr/sample_pluginmgr.pro | 2 +- src/blackbox/blackbox.pro | 1 + src/blackcore/blackcore.pro | 2 +- src/blackd/blackd.pro | 1 + src/blackmisc/blackmisc.pro | 2 +- src/blackmisc/pqunits.h | 4 ++-- src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro | 2 +- src/driver/fs9/driver_fs9.pro | 2 +- src/driver/fsx/driver_fsx.pro | 2 +- src/driver/xplane/driver_xplane.pro | 2 +- tests/blackcore/test_blackcore.pro | 2 +- tests/blackmisc/test_blackmisc.pro | 2 +- 21 files changed, 22 insertions(+), 19 deletions(-) diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index dd34fafb5..698e25923 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -3,7 +3,7 @@ QT += core dbus TARGET = sample_quantities_avionics TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src/blackmisc diff --git a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro index afabcc8a9..ae5acc6c6 100644 --- a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro +++ b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro @@ -3,7 +3,7 @@ QT += core dbus TARGET = sample_quantities_avionics_dbus TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle # Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, diff --git a/samples/blackmiscvectorgeo/sample_vector_geo.pro b/samples/blackmiscvectorgeo/sample_vector_geo.pro index 134fc28fe..0dc821635 100644 --- a/samples/blackmiscvectorgeo/sample_vector_geo.pro +++ b/samples/blackmiscvectorgeo/sample_vector_geo.pro @@ -1,7 +1,7 @@ QT += core dbus TARGET = sample_vector_geo -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index 61b68e378..ba2388745 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -3,7 +3,7 @@ QT -= gui TARGET = com_client -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index e6d61c03d..68c6521e8 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = com_server TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index 801d9f071..f6a151727 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -3,6 +3,7 @@ QT -= gui TARGET = sample_config TEMPLATE = app +CONFIG += c++11 DEPENDPATH += . ../../src INCLUDEPATH += . ../../src diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 97ede3805..2f2cc4972 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -1,7 +1,7 @@ QT += core dbus TARGET = sample_interpolator -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/logging/sample_logging.pro b/samples/logging/sample_logging.pro index b262a6322..e5194585f 100644 --- a/samples/logging/sample_logging.pro +++ b/samples/logging/sample_logging.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = sample_logging TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro index e0e3f7291..7aeb4abb3 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -3,7 +3,7 @@ QT -= gui TARGET = sample_plugin TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin c++11 DEPENDPATH += . ../../src INCLUDEPATH += . ../../src diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro index 11700db9a..c5758be6b 100644 --- a/samples/pluginmgr/sample_pluginmgr.pro +++ b/samples/pluginmgr/sample_pluginmgr.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = sample_pluginmgr TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index 9587feccc..d6b26bb9c 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -6,6 +6,7 @@ INCLUDEPATH += . .. TARGET = blackbox TEMPLATE = app +CONFIG += c++11 SOURCES += *.cpp HEADERS += *.h diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 98361abb9..bd22f107c 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -3,7 +3,7 @@ QT += network dbus TARGET = blackcore TEMPLATE = lib -CONFIG += staticlib +CONFIG += staticlib c++11 INCLUDEPATH += .. DEPENDPATH += . .. diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 7ac44a843..6eaf7dc04 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -5,6 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = blackd TEMPLATE = app +CONFIG += c++11 DEPENDPATH += . .. INCLUDEPATH += .. diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 22a1e863c..071684d66 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -2,7 +2,7 @@ QT += network dbus TARGET = blackmisc TEMPLATE = lib -CONFIG += staticlib +CONFIG += staticlib c++11 INCLUDEPATH += .. # DEPENDPATH += . .. // BlackMisc should be independent diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 16b38d48f..040e942be 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -622,8 +622,8 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar(CMeasurementPrefix::m(), bar(), 1); - return bar; + static CPressureUnit mbar(CMeasurementPrefix::m(), bar(), 1); + return mbar; } /*! diff --git a/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro index 099fcf4d6..164fa3cf9 100644 --- a/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro +++ b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro @@ -3,7 +3,7 @@ QT += core dbus TARGET = blackmisc_cpp2xml TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin c++11 DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src diff --git a/src/driver/fs9/driver_fs9.pro b/src/driver/fs9/driver_fs9.pro index 236b65797..ed91f1d0a 100644 --- a/src/driver/fs9/driver_fs9.pro +++ b/src/driver/fs9/driver_fs9.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_fs9 TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/src/driver/fsx/driver_fsx.pro b/src/driver/fsx/driver_fsx.pro index 81ecfc425..98f2cfdc8 100644 --- a/src/driver/fsx/driver_fsx.pro +++ b/src/driver/fsx/driver_fsx.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_fsx TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/src/driver/xplane/driver_xplane.pro b/src/driver/xplane/driver_xplane.pro index 7116b9cf8..21a93cfe0 100644 --- a/src/driver/xplane/driver_xplane.pro +++ b/src/driver/xplane/driver_xplane.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_xplane TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/tests/blackcore/test_blackcore.pro b/tests/blackcore/test_blackcore.pro index a64285298..1a681b773 100644 --- a/tests/blackcore/test_blackcore.pro +++ b/tests/blackcore/test_blackcore.pro @@ -3,7 +3,7 @@ QT += core testlib dbus TARGET = test_blackcore TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index d9e8ae911..11fb266df 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -3,7 +3,7 @@ QT += core testlib dbus TARGET = test_blackmisc TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src From e8736cf31d514a7381823558e2896f6b0f2222f4 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 22 Aug 2013 18:32:15 +0100 Subject: [PATCH 31/36] unit names singular not plural --- src/blackmisc/pqunits.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 040e942be..da29b84b2 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -135,7 +135,7 @@ public: */ static const CLengthUnit &SM() { - static CLengthUnit sm(QT_TRANSLATE_NOOP("CMeasurementUnit", "statute miles"), "SM", 1609.3472, 3); + static CLengthUnit sm(QT_TRANSLATE_NOOP("CMeasurementUnit", "statute mile"), "SM", 1609.3472, 3); return sm; } @@ -253,7 +253,7 @@ public: */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degrees minutes seconds"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 0); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute, second"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 0); return deg; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'%L3\""); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1 %L2'%L3\""); @@ -265,7 +265,7 @@ public: */ static const CAngleUnit &sexagesimalDegMin() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degrees minutes"), "MinDec", new SubdivisionConverter<60, 100>, 2); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute"), "MinDec", new SubdivisionConverter<60, 100>, 2); return deg; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2'"); @@ -602,7 +602,7 @@ public: */ static const CPressureUnit &psi() { - static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pounds per square inch"), "psi", 68.948, 2); + static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound per square inch"), "psi", 68.948, 2); return psi; } @@ -814,7 +814,7 @@ public: */ static const CSpeedUnit &m_s() { - static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second"), "m/s", 1); + static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter per second"), "m/s", 1); return ms; } @@ -834,7 +834,7 @@ public: */ static const CSpeedUnit &NM_h() { - static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical miles/hour"), "NM/h", 1852.0 / 3600.0, 1); + static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile per hour"), "NM/h", 1852.0 / 3600.0, 1); return NMh; } @@ -844,7 +844,7 @@ public: */ static const CSpeedUnit &ft_s() { - static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second"), "ft/s", 0.3048, 0); + static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per second"), "ft/s", 0.3048, 0); return fts; } @@ -854,7 +854,7 @@ public: */ static const CSpeedUnit &ft_min() { - static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/minute"), "ft/min", 0.3048 / 60.0, 0); + static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per minute"), "ft/min", 0.3048 / 60.0, 0); return ftmin; } @@ -864,7 +864,7 @@ public: */ static const CSpeedUnit &km_h() { - static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometers/hour"), "km/h", 1.0 / 3.6, 1); + static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer per hour"), "km/h", 1.0 / 3.6, 1); return kmh; } @@ -1020,7 +1020,7 @@ public: */ static const CTimeUnit &hms() { - static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hours minutes seconds"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 0); + static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute, second"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 0); return hms; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m%L3s"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1h%L2m%L3s"); @@ -1031,7 +1031,7 @@ public: */ static const CTimeUnit &hrmin() { - static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hours minutes"), "hm", new SubdivisionConverter<60, 100>(3600), 1); + static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute"), "hm", new SubdivisionConverter<60, 100>(3600), 1); return hrmin; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1h%L2m"); @@ -1042,7 +1042,7 @@ public: */ static const CTimeUnit &minsec() { - static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minutes seconds"), "minsec", new SubdivisionConverter<60, 100>(60), 0); + static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute, second"), "minsec", new SubdivisionConverter<60, 100>(60), 0); return minsec; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1m%L2s"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1m%L2s"); @@ -1120,7 +1120,7 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meters/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), 1, 1); + static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter per second per second"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), 1, 1); return ms2; } @@ -1130,7 +1130,7 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "feet/second^2"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), 3.28084, 0); + static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per second per second"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), 3.28084, 0); return fts2; } From 669af6b691fb44af9268ea8eb36e4ca3bf8e2655 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 22 Aug 2013 19:44:19 +0100 Subject: [PATCH 32/36] give prefixed units their own names and symbols instead of concatenating prefix and base unit --- src/blackmisc/pqbase.cpp | 14 ++++++------ src/blackmisc/pqbase.h | 18 +++------------ src/blackmisc/pqunits.h | 48 ++++++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 8b50086fe..f7e9f47f0 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -42,7 +42,7 @@ bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const * Constructor */ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon) : - m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new LinearConverter(factor)) + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new LinearConverter(factor)) { } @@ -50,7 +50,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d * Constructor */ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon) : - m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(new AffineConverter(factor, offset)) + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new AffineConverter(factor, offset)) { } @@ -58,15 +58,15 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, d * Constructor */ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon) : - m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(CMeasurementPrefix::One()), m_converter(converter) + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(converter) { } /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) : - m_name(base.m_name), m_symbol(base.m_symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_prefix(prefix), m_converter(base.m_converter->clone(prefix)) +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(base.m_converter->clone(prefix)) { } @@ -74,7 +74,7 @@ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &base, const CMeasurem * Copy constructor */ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) : - m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_prefix(other.m_prefix), m_converter(other.m_converter) + m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_converter(other.m_converter) { } @@ -84,7 +84,7 @@ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) : bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const { if (this == &other) return true; - return this->m_prefix == other.m_prefix && this->m_name == other.m_name; + return this->m_name == other.m_name; } /* diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index f7fb27a3b..c66127013 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -377,7 +377,6 @@ private: QString m_symbol; //!< unit name, e.g. "m" double m_epsilon; //!< values with differences below epsilon are the equal int m_displayDigits; //!< standard rounding for string conversions - CMeasurementPrefix m_prefix; //!< multiplier (kilo, Mega) QSharedDataPointer m_converter; //!< strategy pattern allows an arbitrary conversion method as per object protected: @@ -419,7 +418,7 @@ protected: * \param displayDigits * \param epsilon */ - CMeasurementUnit(const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10); + CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10); /*! * \brief Copy constructor @@ -504,8 +503,7 @@ public: */ QString getName(bool i18n = false) const { - QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; - return this->m_prefix.getName(i18n) + base; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; } /*! @@ -515,8 +513,7 @@ public: */ QString getSymbol(bool i18n = false) const { - QString base = i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol; - return this->m_prefix.getSymbol(i18n) + base; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol; } /*! @@ -564,15 +561,6 @@ public: return this->m_displayDigits; } - /*! - * \brief Multiplier such as "kilo" - * \return - */ - CMeasurementPrefix getPrefix() const - { - return this->m_prefix; - } - /*! * Convert from other unit to this unit. * \param diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index da29b84b2..21170d00f 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -43,13 +43,15 @@ private: /*! * \brief Constructor length unit + * \param name + * \param symbol * \param prefix * \param base * \param displayDigits * \param epsilon */ - CLengthUnit(const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + CLengthUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} public: /*! @@ -105,7 +107,7 @@ public: */ static const CLengthUnit &km() { - static CLengthUnit km(CMeasurementPrefix::k(), m(), 3); + static CLengthUnit km(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"), "km", CMeasurementPrefix::k(), m(), 3); return km; } @@ -115,7 +117,7 @@ public: */ static const CLengthUnit &cm() { - static CLengthUnit cm(CMeasurementPrefix::c(), m(), 1); + static CLengthUnit cm(QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"), "cm", CMeasurementPrefix::c(), m(), 1); return cm; } @@ -320,13 +322,15 @@ private: /*! * Constructor frequency unit + * \param name + * \param symbol * \param prefix * \param base * \param displayDigits * \param epsilon */ - CFrequencyUnit(const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + CFrequencyUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} public: /*! @@ -362,7 +366,7 @@ public: */ static const CFrequencyUnit &kHz() { - static CFrequencyUnit kHz(CMeasurementPrefix::k(), Hz(), 1); + static CFrequencyUnit kHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilohertz"), "kHz", CMeasurementPrefix::k(), Hz(), 1); return kHz; } @@ -372,7 +376,7 @@ public: */ static const CFrequencyUnit &MHz() { - static CFrequencyUnit MHz(CMeasurementPrefix::M(), Hz(), 2); + static CFrequencyUnit MHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "megahertz"), "MHz", CMeasurementPrefix::M(), Hz(), 2); return MHz; } @@ -382,7 +386,7 @@ public: */ static const CFrequencyUnit &GHz() { - static CFrequencyUnit GHz(CMeasurementPrefix::G(), Hz(), 2); + static CFrequencyUnit GHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "gigahertz"), "GHz", CMeasurementPrefix::G(), Hz(), 2); return GHz; } @@ -435,13 +439,15 @@ private: /*! * \brief Constructor mass units + * \param name + * \param symbol * \param prefix * \param base * \param displayDigits * \param epsilon */ - CMassUnit(const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + CMassUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} public: /*! @@ -467,7 +473,7 @@ public: */ static const CMassUnit &kg() { - static CMassUnit kg(CMeasurementPrefix::k(), g(), 1); + static CMassUnit kg(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"), "kg", CMeasurementPrefix::k(), g(), 1); return kg; } @@ -550,13 +556,15 @@ private: /*! * \brief Pressure unit constructor + * \param name + * \param symbol * \param prefix * \param base * \param displayDigits * \param epsilon */ - CPressureUnit(const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + CPressureUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} public: /*! @@ -592,7 +600,7 @@ public: */ static const CPressureUnit &hPa() { - static CPressureUnit hPa(CMeasurementPrefix::h(), Pa()); + static CPressureUnit hPa(QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"), "hPa", CMeasurementPrefix::h(), Pa()); return hPa; } @@ -622,7 +630,7 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit mbar(CMeasurementPrefix::m(), bar(), 1); + static CPressureUnit mbar(QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"), "mbar", CMeasurementPrefix::m(), bar(), 1); return mbar; } @@ -919,13 +927,15 @@ private: /*! * \brief Time unit constructor + * \param name + * \param symbol * \param prefix * \param base * \param displayDigits * \param epsilon */ - CTimeUnit(const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(base, prefix, displayDigits, epsilon) {} + CTimeUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} /*! * \brief Time unit constructor @@ -981,7 +991,7 @@ public: */ static const CTimeUnit &ms() { - static CTimeUnit ms(CMeasurementPrefix::m(), s(), 0); + static CTimeUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"), "ms", CMeasurementPrefix::m(), s(), 0); return ms; } From 74452599bfeda51b7782947568c0cbfa82c88319 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 22 Aug 2013 19:59:41 +0100 Subject: [PATCH 33/36] disambiguate metric tonne (1,000kg) and US ton (2,000lb) --- .../samplesphysicalquantities.cpp | 2 +- src/blackmisc/pqunits.h | 17 ++++++++++++++--- tests/blackmisc/testphysicalquantities.cpp | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index 322eaa450..bc9c87344 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -78,7 +78,7 @@ int CSamplesPhysicalQuantities::samples() a4.switchUnit(CAngleUnit::deg()); qDebug() << a3 << a4; - CMass w1(1, CMassUnit::t()); + CMass w1(1, CMassUnit::tonne()); CMass w2(w1); w2.switchUnit(CMassUnit::lb()); qDebug() << w1 << w1.valueRoundedWithUnit(CMassUnit::kg()) << w2; diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 21170d00f..fbaa662a0 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -488,15 +488,25 @@ public: } /*! - * \brief Tonne, aka metric tonne (1000kg) + * \brief Tonne, aka metric ton (1000kg) * \return */ - static const CMassUnit &t() + static const CMassUnit &tonne() { static CMassUnit t(QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"), "t", 1000.0, 3); return t; } + /*! + * \brief Short ton (2000lb) used in the United States + * \return + */ + static const CMassUnit &shortTon() + { + static CMassUnit ton(QT_TRANSLATE_NOOP("CMeasurementUnit", "short ton"), "ton", 907.18474, 3); + return ton; + } + /*! * \brief Pound, aka mass pound * \return @@ -519,7 +529,8 @@ public: u.append(CMassUnit::g()); u.append(CMassUnit::kg()); u.append(CMassUnit::lb()); - u.append(CMassUnit::t()); + u.append(CMassUnit::tonne()); + u.append(CMassUnit::shortTon()); } return u; } diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index a958046de..b082256d7 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -109,7 +109,7 @@ void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); CMass w2(w1.value(), CMassUnit::kg()); - w2.switchUnit(CMassUnit::t()); + w2.switchUnit(CMassUnit::tonne()); QVERIFY2(w2.value() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); QVERIFY2(w2.valueRounded(2) == 2204.62, "1tonne shall be 2204pounds"); From ea4d0dedbb0912271617512b1d013b4c76a26cda Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 22 Aug 2013 20:08:53 +0100 Subject: [PATCH 34/36] removed escaped double-quote character from i18n string --- src/blackmisc/pqunits.cpp | 4 ++-- src/blackmisc/pqunits.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index f7de957aa..4f738c154 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -24,7 +24,7 @@ QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) cons double de = CMath::trunc(value); double mi = CMath::trunc((value - de) * 100.0); double se = CMath::trunc((value - de - mi / 100.0) * 1000000) / 100.0; - const char *fmt = value < 0 ? "-%L1 %L2'%L3\"" : "%L1 %L2'%L3\""; + const char *fmt = value < 0 ? "-%L1 %L2 %L3" : "%L1 %L2 %L3"; s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', 0, '0').arg(fabs(se), 2, 'f', digits, '0'); } @@ -32,7 +32,7 @@ QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) cons { double de = CMath::trunc(value); double mi = CMath::trunc((value - de) * 100.0); - const char *fmt = value < 0 ? "-%L1 %L2'" : "%L1 %L2'"; + const char *fmt = value < 0 ? "-%L1 %L2" : "%L1 %L2"; s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', digits, '0'); } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index fbaa662a0..d66e9388e 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -257,8 +257,8 @@ public: { static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute, second"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 0); return deg; - (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'%L3\""); - (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1 %L2'%L3\""); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2 %L3"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2 %L3"); } /*! @@ -269,8 +269,8 @@ public: { static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute"), "MinDec", new SubdivisionConverter<60, 100>, 2); return deg; - (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2'"); - (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2'"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2"); } /*! From 7117545fd6a33c86abf0adf8a3c817cb6bbb787b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 26 Aug 2013 21:15:59 +0100 Subject: [PATCH 35/36] Operator function templates, using std::enable_if to match only classes derived from CStreamable, for streaming to/from QtDBusArgument, avoiding the unrelated operator function template for streaming Container defined by Qt, by being a better match in overload resolution. --- src/blackmisc/aviomodulator.h | 28 ---------------------------- src/blackmisc/geoearthangle.h | 28 ---------------------------- src/blackmisc/mathvector3dbase.h | 28 ---------------------------- src/blackmisc/streamable.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 84 deletions(-) diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index f8280bf18..3a39ee661 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -19,34 +19,6 @@ namespace Aviation */ template class CModulator : public CAvionicsBase { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - private: BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency BlackMisc::PhysicalQuantities::CFrequency m_frequencyStandby; //!< standby frequency diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 8cb2835ed..7491af0de 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -16,34 +16,6 @@ namespace Geo */ template class CEarthAngle : public BlackMisc::PhysicalQuantities::CAngle { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, LATorLON &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const LATorLON &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - protected: /*! * \brief Default constructor diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 0d40cf8df..bd0bec9d7 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -21,34 +21,6 @@ class CMatrix3x1; */ template class CVector3DBase : public CStreamable { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, ImplVector &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const ImplVector &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - private: /*! * \brief Easy access to derived class (CRTP template parameter) diff --git a/src/blackmisc/streamable.h b/src/blackmisc/streamable.h index 8ad890010..76f3881d6 100644 --- a/src/blackmisc/streamable.h +++ b/src/blackmisc/streamable.h @@ -168,6 +168,34 @@ protected: virtual void unmarshallFromDbus(const QDBusArgument &) = 0; }; +/*! + * Non-member non-friend operator for streaming T objects to QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type const& +operator>>(const QDBusArgument &argument, T &uc) +{ + return argument >> static_cast(uc); +} + +/*! + * Non-member non-friend operator for streaming T objects from QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type& +operator<<(QDBusArgument &argument, T &uc) +{ + return argument << static_cast(uc); +} + } // namespace #endif // guard From 611f1ecaeb7e57a752a817fa64bb9925fb5cb54e Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 28 Aug 2013 20:42:31 +0100 Subject: [PATCH 36/36] consistent stringification of sexagesimal angle and time values with and without units --- src/blackmisc/pqunits.cpp | 18 ++++++++++++++---- src/blackmisc/pqunits.h | 14 +++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 4f738c154..e03e8f00b 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -15,12 +15,14 @@ using BlackMisc::Math::CMath; /* * Rounded to QString */ -QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) const +QString CAngleUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { if (digits < 0) digits = this->getDisplayDigits(); QString s; if ((*this) == CAngleUnit::sexagesimalDeg()) { + digits -= 4; + Q_ASSERT(digits >= 0); double de = CMath::trunc(value); double mi = CMath::trunc((value - de) * 100.0); double se = CMath::trunc((value - de - mi / 100.0) * 1000000) / 100.0; @@ -30,6 +32,8 @@ QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) cons } else if ((*this) == CAngleUnit::sexagesimalDegMin()) { + digits -= 2; + Q_ASSERT(digits >= 0); double de = CMath::trunc(value); double mi = CMath::trunc((value - de) * 100.0); const char *fmt = value < 0 ? "-%L1 %L2" : "%L1 %L2"; @@ -38,7 +42,7 @@ QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) cons } else { - s = this->CMeasurementUnit::makeRoundedQString(value, digits, i18n); + s = this->CMeasurementUnit::makeRoundedQStringWithUnit(value, digits, i18n); } return s; } @@ -46,12 +50,14 @@ QString CAngleUnit::makeRoundedQString(double value, int digits, bool i18n) cons /* * Rounded to QString */ -QString CTimeUnit::makeRoundedQString(double value, int digits, bool i18n) const +QString CTimeUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { if (digits < 0) digits = this->getDisplayDigits(); QString s; if ((*this) == CTimeUnit::hms()) { + digits -= 4; + Q_ASSERT(digits >= 0); double hr = CMath::trunc(value); double mi = CMath::trunc((value - hr) * 100.0); double se = CMath::trunc((value - hr - mi / 100.0) * 1000000) / 100.0; @@ -61,6 +67,8 @@ QString CTimeUnit::makeRoundedQString(double value, int digits, bool i18n) const } else if ((*this) == CTimeUnit::hrmin()) { + digits -= 2; + Q_ASSERT(digits >= 0); double hr = CMath::trunc(value); double mi = CMath::trunc((value - hr) * 100.0); const char *fmt = value < 0 ? "-%L1h%L2m" : "%L1h%L2m"; @@ -69,6 +77,8 @@ QString CTimeUnit::makeRoundedQString(double value, int digits, bool i18n) const } else if ((*this) == CTimeUnit::minsec()) { + digits -= 2; + Q_ASSERT(digits >= 0); double mi = CMath::trunc(value); double se = CMath::trunc((value - mi) * 100.0); const char *fmt = value < 0 ? "-%L2m%L3s" : "%L2m%L3s"; @@ -77,7 +87,7 @@ QString CTimeUnit::makeRoundedQString(double value, int digits, bool i18n) const } else { - s = this->CMeasurementUnit::makeRoundedQString(value, digits, i18n); + s = this->CMeasurementUnit::makeRoundedQStringWithUnit(value, digits, i18n); } return s; } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index d66e9388e..d94f8db96 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -227,7 +227,7 @@ public: * \param i18n * \return */ - virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Radians @@ -255,7 +255,7 @@ public: */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute, second"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 0); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute, second"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 4); return deg; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2 %L3"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2 %L3"); @@ -267,7 +267,7 @@ public: */ static const CAngleUnit &sexagesimalDegMin() { - static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute"), "MinDec", new SubdivisionConverter<60, 100>, 2); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute"), "MinDec", new SubdivisionConverter<60, 100>, 4); return deg; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2"); @@ -984,7 +984,7 @@ public: * \param i18n * \return */ - virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Second s @@ -1041,7 +1041,7 @@ public: */ static const CTimeUnit &hms() { - static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute, second"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 0); + static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute, second"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 4); return hms; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m%L3s"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1h%L2m%L3s"); @@ -1052,7 +1052,7 @@ public: */ static const CTimeUnit &hrmin() { - static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute"), "hm", new SubdivisionConverter<60, 100>(3600), 1); + static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute"), "hm", new SubdivisionConverter<60, 100>(3600), 3); return hrmin; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1h%L2m"); @@ -1063,7 +1063,7 @@ public: */ static const CTimeUnit &minsec() { - static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute, second"), "minsec", new SubdivisionConverter<60, 100>(60), 0); + static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute, second"), "minsec", new SubdivisionConverter<60, 100>(60), 2); return minsec; (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1m%L2s"); (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1m%L2s");