mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-15 03:45:41 +08:00
DBus enabling of base classes plus sample for testing / show how to use them. Also qdbuscpp2xml plugin for blackmisc classes.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -81,4 +81,5 @@ Thumbs.db
|
||||
desktop.ini
|
||||
|
||||
# Editors temporary files
|
||||
*~
|
||||
*~
|
||||
/client.pro.user.2.7pre1
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 +=
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="blackmisctest.testservice">
|
||||
<signal name="sendStringMessage">
|
||||
<arg name="message" type="s" direction="out"/>
|
||||
</signal>
|
||||
<method name="receiveStringMessage">
|
||||
<arg name="message" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="receiveVariant">
|
||||
<arg name="variant" type="v" direction="in"/>
|
||||
</method>
|
||||
<method name="receiveSpeed">
|
||||
<arg name="speed" type="(didb(s)(s))" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::PhysicalQuantities::CSpeed"/>
|
||||
</method>
|
||||
<method name="receiveComUnit">
|
||||
<arg name="comUnit" type="((didb(s)(s))(didb(s)(s))i)" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::Aviation::CComSystem"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
114
samples/blackmiscquantities_dbus/main.cpp
Normal file
114
samples/blackmiscquantities_dbus/main.cpp
Normal file
@@ -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 <QDBusMetaType>
|
||||
#include <QtDBus/qdbusabstractinterface.h>
|
||||
#include <QtDBus/qdbusconnection.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#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();
|
||||
}
|
||||
9
samples/blackmiscquantities_dbus/readme.txt
Normal file
9
samples/blackmiscquantities_dbus/readme.txt
Normal file
@@ -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
|
||||
@@ -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
|
||||
56
samples/blackmiscquantities_dbus/testservice.cpp
Normal file
56
samples/blackmiscquantities_dbus/testservice.cpp
Normal file
@@ -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
|
||||
89
samples/blackmiscquantities_dbus/testservice.h
Normal file
89
samples/blackmiscquantities_dbus/testservice.h
Normal file
@@ -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 <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDBusVariant>
|
||||
#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
|
||||
32
samples/blackmiscquantities_dbus/testservicetool.cpp
Normal file
32
samples/blackmiscquantities_dbus/testservicetool.cpp
Normal file
@@ -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
|
||||
53
samples/blackmiscquantities_dbus/testservicetool.h
Normal file
53
samples/blackmiscquantities_dbus/testservicetool.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef BLACKMISCTEST_TESTSERVICETOOL_H
|
||||
#define BLACKMISCTEST_TESTSERVICETOOL_H
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#ifdef Q_OS_WIN
|
||||
// for qdatetime, see here http://qt-project.org/forums/viewthread/22133
|
||||
#define NOMINMAX
|
||||
#include <windows.h> // 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
|
||||
@@ -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
|
||||
|
||||
12
samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp
Normal file
12
samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "sampleplugin.h"
|
||||
|
||||
|
||||
void CXmlSamplePlugin::registerMetaTypes()
|
||||
{
|
||||
qRegisterMetaType<BlackMiscTest::Dummy>("BlackMiscTest::Dummy");
|
||||
qDBusRegisterMetaType<BlackMiscTest::Dummy>();
|
||||
|
||||
qRegisterMetaType<BlackMiscTest::DummyNoQ>("BlackMiscTest::DummyNoQ");
|
||||
qDBusRegisterMetaType<BlackMiscTest::DummyNoQ>();
|
||||
|
||||
}
|
||||
21
samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h
Normal file
21
samples/blackmiscquantities_dbus_xmlplugin/sampleplugin.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef SAMPLEPLUGIN_H
|
||||
#define SAMPLEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDBusMetaType>
|
||||
#include <QMetaType>
|
||||
#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
|
||||
@@ -1,4 +1,4 @@
|
||||
QT += core
|
||||
QT += core dbus
|
||||
|
||||
TARGET = sample_vector_geo
|
||||
CONFIG += console
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
QT += core
|
||||
QT += core dbus
|
||||
|
||||
TARGET = sample_interpolator
|
||||
CONFIG += console
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# GUI is required for the matrix classes
|
||||
QT += network
|
||||
QT += network dbus
|
||||
|
||||
TARGET = blackcore
|
||||
TEMPLATE = lib
|
||||
|
||||
18
src/blackmisc/avallclasses.h
Normal file
18
src/blackmisc/avallclasses.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -320,5 +320,6 @@ public:
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem)
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -25,17 +25,6 @@ template <class AVIO> void CModulator<AVIO>::toggleActiveStandby()
|
||||
this->m_frequencyStandby = a;
|
||||
}
|
||||
|
||||
/*
|
||||
* String representation
|
||||
*/
|
||||
template <class AVIO> QString CModulator<AVIO>::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 =
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#ifndef BLACKMISC_AVIOMODULATORUNIT_H
|
||||
#define BLACKMISC_AVIOMODULATORUNIT_H
|
||||
|
||||
#include <QDBusArgument>
|
||||
#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<AVIO>(typeid(AVIO).name());
|
||||
qDBusRegisterMetaType<AVIO>();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -273,5 +273,6 @@ public:
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CNavSystem)
|
||||
|
||||
#endif // BLACKMISC_AVIONAVSYSTEM_H
|
||||
|
||||
@@ -315,5 +315,6 @@ public:
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder)
|
||||
|
||||
#endif // BLACKMISC_AVIOTRANSPONDER_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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
43
src/blackmisc/blackmiscfreefunctions.cpp
Normal file
43
src/blackmisc/blackmiscfreefunctions.cpp
Normal file
@@ -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();
|
||||
}
|
||||
44
src/blackmisc/blackmiscfreefunctions.h
Normal file
44
src/blackmisc/blackmiscfreefunctions.h
Normal file
@@ -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
|
||||
@@ -16,6 +16,7 @@ namespace Geo
|
||||
{
|
||||
|
||||
/*!
|
||||
* Latitude and longitude interface
|
||||
* \brief Interface for geodetic ccordinates
|
||||
*/
|
||||
class ICoordinateGeodetic
|
||||
|
||||
@@ -51,4 +51,6 @@ public:
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAcceleration)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -69,4 +69,6 @@ public:
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngle)
|
||||
|
||||
#endif // BLACKMISC_PQANGLE_H
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
|
||||
#include "blackmisc/basestreamstringifier.h"
|
||||
#include "blackmisc/debug.h"
|
||||
#include <QDBusArgument>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -46,4 +46,7 @@ public:
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequency)
|
||||
|
||||
#endif // BLACKMISC_PQFREQUENCY_H
|
||||
|
||||
@@ -46,4 +46,7 @@ public:
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLength)
|
||||
|
||||
#endif // BLACKMISC_PQLENGTH_H
|
||||
|
||||
@@ -51,4 +51,6 @@ public:
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMass)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackmisc/pqbase.h"
|
||||
#include "blackmisc/pqunits.h"
|
||||
#include "blackmisc/debug.h"
|
||||
#include <QDBusMetaType>
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
#include <QLocale>
|
||||
@@ -21,8 +22,10 @@ namespace PhysicalQuantities
|
||||
/*!
|
||||
* \brief A physical quantity such as "5m", "20s", "1500ft/s"
|
||||
*/
|
||||
|
||||
template <class MU, class PQ> 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<qint32>(
|
||||
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<MU>(typeid(MU).name());
|
||||
qDBusRegisterMetaType<MU>();
|
||||
qRegisterMetaType<PQ>(typeid(PQ).name());
|
||||
qDBusRegisterMetaType<PQ>();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -47,4 +47,7 @@ public:
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressure)
|
||||
|
||||
#endif // BLACKMISC_PQPRESSURE_H
|
||||
|
||||
@@ -18,15 +18,16 @@ namespace PhysicalQuantities
|
||||
*/
|
||||
class CSpeed : public CPhysicalQuantity<CSpeedUnit, CSpeed>
|
||||
{
|
||||
|
||||
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
|
||||
|
||||
@@ -46,4 +46,7 @@ public:
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperature)
|
||||
|
||||
#endif // BLACKMISC_CTEMPERATURE_H
|
||||
|
||||
@@ -48,4 +48,6 @@ public:
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTime)
|
||||
|
||||
#endif // BLACKMISC_PQTIME_H
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
#define BLACKMISC_PQUNITS_H
|
||||
|
||||
#include "blackmisc/pqbase.h"
|
||||
#include <QDBusArgument>
|
||||
#include <QList>
|
||||
#include <QtCore/qmath.h>
|
||||
|
||||
|
||||
//
|
||||
// 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<CLengthUnit> &units()
|
||||
{
|
||||
static QList<CLengthUnit> 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<CLengthUnit> 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<CAngleUnit> &units()
|
||||
{
|
||||
static QList<CAngleUnit> 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<CAngleUnit> 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<CFrequencyUnit> &units()
|
||||
{
|
||||
static QList<CFrequencyUnit> 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<CFrequencyUnit> 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<CMassUnit> &units()
|
||||
{
|
||||
static QList<CMassUnit> 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<CMassUnit> 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<CPressureUnit> &units()
|
||||
{
|
||||
static QList<CPressureUnit> 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<CPressureUnit> 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<CTemperatureUnit> &units()
|
||||
{
|
||||
static QList<CTemperatureUnit> 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<CTemperatureUnit> 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<CSpeedUnit> &units()
|
||||
{
|
||||
static QList<CSpeedUnit> 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<CSpeedUnit> 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<CTimeUnit> &units()
|
||||
{
|
||||
static QList<CTimeUnit> 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<CTimeUnit> 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<CAccelerationUnit> &units()
|
||||
{
|
||||
static QList<CAccelerationUnit> 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<CAccelerationUnit> 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
|
||||
|
||||
19
src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro
Normal file
19
src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro
Normal file
@@ -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
|
||||
15
src/blackmisc_cpp2xml/blackmiscplugin.cpp
Normal file
15
src/blackmisc_cpp2xml/blackmiscplugin.cpp
Normal file
@@ -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();
|
||||
}
|
||||
28
src/blackmisc_cpp2xml/blackmiscplugin.h
Normal file
28
src/blackmisc_cpp2xml/blackmiscplugin.h
Normal file
@@ -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 <QDBusMetaType>
|
||||
#include <QMetaType>
|
||||
|
||||
/*!
|
||||
* \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
|
||||
@@ -1,4 +1,4 @@
|
||||
QT += core testlib
|
||||
QT += core testlib dbus
|
||||
|
||||
TARGET = test_blackcore
|
||||
TEMPLATE = app
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
QT += core testlib
|
||||
QT += core testlib dbus
|
||||
|
||||
TARGET = test_blackmisc
|
||||
TEMPLATE = app
|
||||
|
||||
Reference in New Issue
Block a user