Commit e273648e authored by Richard Lin's avatar Richard Lin
Browse files

Complete: instrument cluster

parent 6306f597
......@@ -30,6 +30,7 @@
moc_*.cpp
qrc_*.cpp
ui_*.h
*build*
Makefile*
*-build-*
*.qmlc
......
......@@ -13,7 +13,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp \
contentsupplier.cpp
scenemanager.cpp \
sceneinfo.cpp
RESOURCES += qml.qrc
......@@ -29,6 +30,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
contentsupplier.h
scenemanager.h \
sceneinfo.h
include(../Interface/Interface.pri)
#include "contentsupplier.h"
ContentSupplier::ContentSupplier(QObject *parent) : QObject(parent)
{
}
#ifndef CONTENTSUPPLIER_H
#define CONTENTSUPPLIER_H
#include <QObject>
class ContentSupplier : public QObject
{
Q_OBJECT
Q_PROPERTY(QPixmap bg READ bg NOTIFY bgChanged)
public:
explicit ContentSupplier(QObject *parent = nullptr);
signals:
public slots:
private:
QMap<QString, iDriver*> _drivers;
QList<QThread*> _threads;
QList<DriverInfo> _supportedDriversInfo;
QList<QPluginLoader*> _supportedDriversLoader;
};
#endif // CONTENTSUPPLIER_H
#include <QGuiApplication>
#include <QQmlContext>
#include <QQmlApplicationEngine>
#include "contentsupplier.h"
#include "scenemanager.h"
int main(int argc, char *argv[])
{
......@@ -9,10 +9,10 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
ContentSupplier* cs = new ContentSupplier();
SceneManager* cm = new SceneManager();
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("contentSupplier", QVariant::fromValue(cs));
engine.rootContext()->setContextProperty("sceneManager", QVariant::fromValue(cm));
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
......
......@@ -3,60 +3,54 @@ import QtQuick.Window 2.2
import QtQuick.VirtualKeyboard 2.1
Window {
id: root
visible: true
width: 640
height: 480
title: qsTr("Hello World")
id: root
MouseArea {
color: "grey"
Loader {
id: content
anchors.fill: parent
onClicked: {
console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"'))
}
}
TextEdit {
id: textEdit
text: qsTr("Enter some text...")
verticalAlignment: Text.AlignVCenter
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 20
Rectangle {
anchors.fill: parent
anchors.margins: -10
color: "transparent"
border.width: 1
Item {
id: s
property int sceneNumber: 0
property int sceneCounts: 0
Connections {
target: sceneManager
onSceneListChanged: {
s.sceneCounts = sceneManager.sceneList.size();
s.sceneNumber = 0
}
}
function selectScene(number) {
if (number < 0 || number > s.sceneCounts) return;
s.sceneNumber = number;
content.setSource( sceneManager.sceneList.at(number).entryPath );
}
}
InputPanel {
id: inputPanel
z: 99
ListView {
id: sceneSelector
x: 0
y: root.height
width: root.width
states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: root.height - inputPanel.height
}
}
transitions: Transition {
from: ""
to: "visible"
reversible: true
ParallelAnimation {
NumberAnimation {
properties: "y"
duration: 250
easing.type: Easing.InOutQuad
}
y: 0
width: parent.width / 3
height: parent.height / 1.5
model: sceneManager.sceneList
delegate: Rectangle {
width: sceneSelector.width
height: sceneSelector.height / 3
Text {
text: sceneManager.sceneList[index].name
}
}
}
}
#include "sceneinfo.h"
#include <QDebug>
SceneInfo::SceneInfo(QObject *parent) : QObject(parent), _pSnapShot(nullptr) {
}
SceneInfo::~SceneInfo(void) {
unload();
}
bool SceneInfo::loadFile(const QString& filePath) {
if (QLibrary::isLibrary(filePath)) {
QPluginLoader* newLoader = new QPluginLoader(filePath);
const QJsonObject meta = newLoader->metaData();
if (meta["MetaData"]["type"].toString(QString()) == QString("scenePlugin") &&
meta["MetaData"]["version"].toInt(0) > 0 &&
meta["MetaData"]["name"].toString(QString()) != _name) {
iPlugin *plugin = qobject_cast<iPlugin*>(newLoader->instance());
if (plugin) {
//success
unload();
_version = meta["MetaData"]["version"].toInt(0);
_name = meta["MetaData"]["name"].toString(QString());
_entryPath = meta["MetaData"]["entryPath"].toString(QString());
_pLoader = newLoader;
_pSnapShot = plugin->snapShot();
plugin->deleteLater();
return true;
}
}
newLoader->deleteLater();
}
//failed
return false;
}
void SceneInfo::unload(void) {
if (!_pLoader) {
_pLoader->deleteLater();
_pLoader = nullptr;
}
_version = 0;
_name = QString();
_entryPath = QString();
_pSnapShot.clear();
}
QPluginLoader* SceneInfo::loader(void) {
return _pLoader;
}
QSharedPointer<QImage> SceneInfo::snapShot(void) {
return _pSnapShot;
}
#ifndef SCENEINFO_H
#define SCENEINFO_H
#include <QObject>
#include <QPluginLoader>
#include "iplugin.h"
class SceneInfo: public QObject
{
Q_OBJECT
Q_PROPERTY(QString name MEMBER _name)
Q_PROPERTY(int version MEMBER _version)
Q_PROPERTY(QString entryPath MEMBER _entryPath)
public:
explicit SceneInfo(QObject *parent = nullptr);
virtual ~SceneInfo(void);
bool loadFile(const QString& filePath);
void unload(void);
QPluginLoader* loader(void);
QSharedPointer<QImage> snapShot(void);
private:
QString _name;
int _version;
QString _entryPath;
QSharedPointer<QImage> _pSnapShot;
QPluginLoader* _pLoader;
};
#endif // SCENEINFO_H
#include "scenemanager.h"
#include "sceneinfo.h"
sceneManager::sceneManager(QObject *parent) : QObject(parent)
{
#include <QGuiApplication>
#include <QDir>
SceneManager::SceneManager(QObject *parent) : QObject(parent) {
_sceneInit();
_loadScene();
}
SceneManager::~SceneManager() {
}
QList<QObject*> SceneManager::sceneList(void) {
QList<QObject* > ret;
foreach (SceneInfo* s, _pSceneInfo) {
ret << qobject_cast<QObject*>(s);
}
return ret;
}
void SceneManager::_sceneInit(void){
QList<SceneInfo*> _pSceneInfo;
foreach (SceneInfo* d, _pSceneInfo) {
d->deleteLater();
_pSceneInfo.removeOne(d);
}
}
void SceneManager::_loadScene(void) {
QDir _pluginsDir = QDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
if (_pluginsDir.dirName().toLower() == "debug" || _pluginsDir.dirName().toLower() == "release")
_pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (_pluginsDir.dirName() == "MacOS") {
_pluginsDir.cdUp();
_pluginsDir.cdUp();
_pluginsDir.cdUp();
}
#endif
_pluginsDir.cd("Scenes");
foreach (QString fileName, _pluginsDir.entryList(QDir::Files)) {
SceneInfo* newScene = new SceneInfo();
bool ret = newScene->loadFile(_pluginsDir.absoluteFilePath(fileName));
if (ret) {
_pSceneInfo.append(newScene);
emit sceneListChanged();
} else {
newScene->deleteLater();
}
}
}
......@@ -3,15 +3,26 @@
#include <QObject>
class sceneManager : public QObject
class SceneInfo;
class SceneManager : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<QObject*> sceneList READ sceneList NOTIFY sceneListChanged)
public:
explicit sceneManager(QObject *parent = nullptr);
explicit SceneManager(QObject *parent = nullptr);
virtual ~SceneManager();
signals:
void sceneListChanged(void);
public slots:
QList<QObject*> sceneList(void);
private:
void _sceneInit(void);
void _loadScene(void);
QList<SceneInfo*> _pSceneInfo;
};
#endif // SCENEMANAGER_H
\ No newline at end of file
#endif // SCENEMANAGER_H
#ifndef IDRIVER_H
#define IDRIVER_H
#include <QObject>
#include <QImage>
#include <QSharedPointer>
class iPlugin : public QObject
{
......@@ -11,11 +13,9 @@ public:
virtual ~iPlugin(){}
public slots:
QString property(const QString& name) const=0;
QImage snapShot(void) const=0;
virtual void initialRes(void)=0;
virtual void cleanUpRes(void)=0;
virtual QSharedPointer<QImage> snapShot(void) const=0;
};
Q_DECLARE_INTERFACE(iPlugin, "iPlugin_iid")
......
TEMPLATE = subdirs
SUBDIRS += Archermind
SUBDIRS += Triton
#SUBDIRS += ArchermindScene
SUBDIRS += TritonScene
QT+= network widgets
TEMPLATE = lib
CONFIG += plugin
TARGET = $$qtLibraryTarget(TritonScene)
DESTDIR = ../../ScenePlugin
CONFIG += c++11
INCLUDEPATH += $$PWD\
HEADERS += \
$$PWD/udpdatabaseprotocoldriver.h
SOURCES += \
$$PWD/udpdatabaseprotocoldriver.cpp
#interface:
include(../../Interface/Interface.pri)
#ifndef UDPDATABASEPROTOCOLDRIVER_H
#define UDPDATABASEPROTOCOLDRIVER_H
#include <QObject>
#include <QTimer>
#include <QtNetwork>
#include <QtNetwork/QUdpSocket>
#include "iplugin.h"
class QUdpSocket;
class QHostAddress;
class UdpDatabaseProtocolDriverUI;
class UdpDatabaseProtocolDriver : public iDriver
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.csic711.appServer.drivers.udpdatabaseProtocol" FILE "udpdatabaseProtocol.json")
Q_INTERFACES(iDriver)
public:
/*!
* 构造函数
* 功能描述:
* 1、初始化参数
* 2、进入停止状态
*/
explicit UdpDatabaseProtocolDriver(QObject *parent = 0);
~UdpDatabaseProtocolDriver();
public slots:
DriverInfo driverInfo()const override;
void save(iLoadSaveProcessor* processor) override;
void load(iLoadSaveProcessor* processor) override;
int start() override;
int stop() override;
int restart() override;
int state() override{ return _state; }
QList<int> availableRWStrategy(void)const override;
QList<int> availableRWStrategy(const QString& addr)const override;
bool isAddressCorrect(const QString& addr)const override;
QString addressErrorString(const QString& addr)const override;
int setRelatedTagAddresses(const QList<TagAddress *>& relatedTagAddresses) override;
void showUI(bool show=true, QWidget* parent=0) override;
public slots:
/*!
* 设置组播的Address和Port
* 返回数值:0:成功 -1:失败
* 功能描述:
* 1、如果是组播的地址则成功,否则失败
*/
int setUdpDatabaseAddress(const QHostAddress& hostaddr, qint16 hostport,qint16 localport);
/*!
* 设置组播的网卡接口
* 返回数值:0:成功 -1:失败
* 功能描述:
* 1、如果是组播的网卡接口则成功,否则失败
*/
int setNetworkInterface(const QNetworkInterface& networkInterface);
/*!
* 设置站号-csic711定制
* 返回数值:0:成功 -1:失败
* 功能描述:
* 站号范围:1-255
*/
int setSMDERIMStation(qint16 station);
QString udpdatabaseAddress(void)const;
int udpdatabasePort(void)const;
QNetworkInterface& networkInterface(void);
signals:
void msgEventString(const QString& msg);
//accept per udp package
void dataReceived();
//emit per accepted tag
void dataAccepted();
private slots:
void _processPendingDatagrams();
void _setState(enum_states state);
void _watchDogTimeOver();
bool _getTime(QDateTime& t, int year, int month, int day, int hour, int minute, int second, int millisecond = 0);
void _scheduleProcess();
private:
/*!
* For sorting
* instead of operator<() to compare the TagInfo*
*/
static bool compareTagAddress(const TagAddress* t1, const TagAddress* t2);
QUdpSocket * _pUdpSocket;
QHostAddress _udpdatabaseAddress;
QHostAddress _hostAddress;
QNetworkInterface _networkInterface;
UdpDatabaseProtocolDriverUI * _pUI;
int _port;
quint16 _hostPort;
char _stationID;
enum_states _state;
QTimer *_pWatchDogTimer;
QList<TagAddress*> _relatedTags;
QTimer* _scheduleTimer;//UDP发送定时器
};
#endif // UDPDATABASEPROTOCOLDRIVER_H
<!DOCTYPE RCC>
<RCC version="1.0"/>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment