Add time to the sensor list widget, also broadcast and recive the time of a sensor
This commit is contained in:
@ -88,7 +88,7 @@ uint8_t Actor::getTriggerValue()
|
|||||||
|
|
||||||
void Actor::onValueChanged(uint8_t value)
|
void Actor::onValueChanged(uint8_t value)
|
||||||
{
|
{
|
||||||
|
(void)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
||||||
|
@ -41,20 +41,23 @@ void BroadCast::sendJson(const QJsonObject& json)
|
|||||||
|
|
||||||
void BroadCast::sendSensors()
|
void BroadCast::sendSensors()
|
||||||
{
|
{
|
||||||
if(iodevice_)for(auto& sensor: *globalSensors.getSensors())
|
if(iodevice_)
|
||||||
{
|
{
|
||||||
|
for(auto& sensor: *globalSensors.getSensors())
|
||||||
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
|
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCast::requestSensors()
|
void BroadCast::requestSensors()
|
||||||
{
|
{
|
||||||
if(iodevice_)iodevice_->write("bcst: GETSENSORS\n");
|
if(iodevice_)
|
||||||
|
iodevice_->write("bcst: GETSENSORS\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCast::requestJson()
|
void BroadCast::requestJson()
|
||||||
{
|
{
|
||||||
if(iodevice_)iodevice_->write("bcst: GETJSN\n");
|
if(iodevice_)
|
||||||
|
iodevice_->write("bcst: GETJSN\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCast::decodeMaster(const QByteArray& buffer)
|
void BroadCast::decodeMaster(const QByteArray& buffer)
|
||||||
|
17
src/main.cpp
17
src/main.cpp
@ -4,6 +4,9 @@
|
|||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
//Currently pipewire support is disabled
|
||||||
|
//#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
#include <QtSerialPort/QtSerialPort>
|
#include <QtSerialPort/QtSerialPort>
|
||||||
@ -11,18 +14,9 @@
|
|||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "actors/alarmtime.h"
|
|
||||||
#include "microcontroller.h"
|
#include "microcontroller.h"
|
||||||
#include "ui/mainwindow.h"
|
#include "ui/mainwindow.h"
|
||||||
#include "sensors/speakersensor.h"
|
|
||||||
#include "sensors/sunsensor.h"
|
|
||||||
#include "sensors/ocupancysensor.h"
|
|
||||||
#include "alarmactions.h"
|
|
||||||
#include "sensors/sensor.h"
|
|
||||||
#include "items/itemstore.h"
|
#include "items/itemstore.h"
|
||||||
#include "items/auxitem.h"
|
|
||||||
#include "items/rgbitem.h"
|
|
||||||
#include "items/poweritem.h"
|
|
||||||
#include "mainobject.h"
|
#include "mainobject.h"
|
||||||
|
|
||||||
|
|
||||||
@ -32,6 +26,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
//pw_init(&argc, &argv);
|
||||||
|
|
||||||
//set info
|
//set info
|
||||||
QCoreApplication::setOrganizationName("UVOS");
|
QCoreApplication::setOrganizationName("UVOS");
|
||||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||||
@ -128,7 +124,8 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||||
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
|
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
|
||||||
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
||||||
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
if(!mainObject.micro.connected())
|
||||||
|
w.changeHeaderLableText("No io debug only!");
|
||||||
|
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
|||||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
|
||||||
sunSensorSource.run();
|
sunSensorSource.run();
|
||||||
|
//pwHandler.startLoop();
|
||||||
|
|
||||||
//connect item store
|
//connect item store
|
||||||
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
||||||
@ -35,14 +36,17 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
|||||||
items.addItem(auxItem);
|
items.addItem(auxItem);
|
||||||
MessageItem::broadCast = &broadCast;
|
MessageItem::broadCast = &broadCast;
|
||||||
|
|
||||||
|
|
||||||
Relay::setMicrocontroller(µ);
|
Relay::setMicrocontroller(µ);
|
||||||
|
|
||||||
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
||||||
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||||
if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
if(master)
|
||||||
|
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
||||||
|
|
||||||
if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
|
if(master)
|
||||||
|
{
|
||||||
|
load(getJsonObjectFromDisk(settingsPath, &noSave));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
broadCast.requestJson();
|
broadCast.requestJson();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "items/poweritem.h"
|
#include "items/poweritem.h"
|
||||||
#include "iomuliplexer.h"
|
#include "iomuliplexer.h"
|
||||||
#include "broadcast.h"
|
#include "broadcast.h"
|
||||||
|
//#include "pipewire.h"
|
||||||
|
|
||||||
class MainObject : public QObject
|
class MainObject : public QObject
|
||||||
{
|
{
|
||||||
@ -49,6 +50,7 @@ public:
|
|||||||
Microcontroller micro;
|
Microcontroller micro;
|
||||||
BroadCast broadCast;
|
BroadCast broadCast;
|
||||||
|
|
||||||
|
|
||||||
const QString settingsPath;
|
const QString settingsPath;
|
||||||
|
|
||||||
//sensors
|
//sensors
|
||||||
@ -62,6 +64,8 @@ public:
|
|||||||
std::shared_ptr<RgbItem> rgbItem;
|
std::shared_ptr<RgbItem> rgbItem;
|
||||||
std::shared_ptr<AuxItem> auxItem;
|
std::shared_ptr<AuxItem> auxItem;
|
||||||
|
|
||||||
|
//PipeWireHandler pwHandler;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
|
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
|
||||||
|
72
src/pipewire.cpp
Normal file
72
src/pipewire.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "pipewire.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
static const struct pw_registry_events registry_events = {
|
||||||
|
.version = PW_VERSION_REGISTRY_EVENTS,
|
||||||
|
.global = &PipeWireHandler::registryEventHandler,
|
||||||
|
.global_remove = nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
PipeWireHandler::PipeWireHandler()
|
||||||
|
{
|
||||||
|
loop = pw_thread_loop_new("SHinterface", nullptr);
|
||||||
|
if(!loop)
|
||||||
|
throw std::runtime_error("Could not create pipewire main loop");
|
||||||
|
|
||||||
|
context = pw_context_new(pw_thread_loop_get_loop(loop), nullptr, 0);
|
||||||
|
if(!context)
|
||||||
|
throw std::runtime_error("Could not create pipewire context");
|
||||||
|
|
||||||
|
core = pw_context_connect(context, NULL, 0);
|
||||||
|
if(!core)
|
||||||
|
throw std::runtime_error("Could not connect to pipewire");
|
||||||
|
|
||||||
|
registry = pw_core_get_registry(core, PW_VERSION_REGISTRY, 0);
|
||||||
|
if(!registry)
|
||||||
|
throw std::runtime_error("Could not get pipewire registry");
|
||||||
|
|
||||||
|
spa_zero(registryListener);
|
||||||
|
pw_registry_add_listener(registry, ®istryListener, ®istry_events, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PipeWireHandler::startLoop()
|
||||||
|
{
|
||||||
|
if(!loop || !context || !core || !registry)
|
||||||
|
return false;
|
||||||
|
int ret = pw_thread_loop_start(loop);
|
||||||
|
return ret == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pw_registry* PipeWireHandler::getRegistry()
|
||||||
|
{
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipeWireHandler::registryEventHandler(void *data, uint32_t id,
|
||||||
|
uint32_t permissions, const char *type, uint32_t version,
|
||||||
|
const struct spa_dict *props)
|
||||||
|
{
|
||||||
|
(void)permissions;
|
||||||
|
(void)version;
|
||||||
|
|
||||||
|
PipeWireHandler* handler = static_cast<PipeWireHandler*>(data);
|
||||||
|
|
||||||
|
if(std::string(type) == PW_TYPE_INTERFACE_Node)
|
||||||
|
{
|
||||||
|
const struct spa_dict_item *item = spa_dict_lookup_item(props, "node.name");
|
||||||
|
if(item)
|
||||||
|
{
|
||||||
|
qDebug()<<"got new pipewire node:"<<id<<"name:"<<item->value;
|
||||||
|
handler->nodeAdded({id, item->value});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PipeWireHandler::~PipeWireHandler()
|
||||||
|
{
|
||||||
|
pw_core_disconnect(core);
|
||||||
|
pw_context_destroy(context);
|
||||||
|
pw_thread_loop_stop(loop);
|
||||||
|
}
|
||||||
|
|
56
src/pipewire.h
Normal file
56
src/pipewire.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pipewire/context.h>
|
||||||
|
#include <pipewire/core.h>
|
||||||
|
#include <pipewire/pipewire.h>
|
||||||
|
#include <QObject>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class PipeWireHandler: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct PwNode
|
||||||
|
{
|
||||||
|
uint32_t id;
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct pw_thread_loop* loop;
|
||||||
|
struct pw_context* context;
|
||||||
|
struct pw_core* core;
|
||||||
|
struct pw_registry* registry;
|
||||||
|
struct spa_hook registryListener;
|
||||||
|
|
||||||
|
void write(const char * const buffer, const size_t length);
|
||||||
|
void write(const QByteArray& buffer);
|
||||||
|
|
||||||
|
void decode(QByteArray buffer);
|
||||||
|
void decodeMaster(const QByteArray& buffer);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static void registryEventHandler(void *data, uint32_t id,
|
||||||
|
uint32_t permissions, const char *type, uint32_t version,
|
||||||
|
const struct spa_dict *props);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void nodeAdded(PwNode node);
|
||||||
|
void nodeRemoved(PwNode node);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
PipeWireHandler();
|
||||||
|
PipeWireHandler(const PipeWireHandler&) = delete;
|
||||||
|
PipeWireHandler operator=(const PipeWireHandler&) = delete;
|
||||||
|
bool startLoop();
|
||||||
|
struct pw_registry* getRegistry();
|
||||||
|
|
||||||
|
~PipeWireHandler();
|
||||||
|
};
|
||||||
|
|
74
src/sensors/pipewiresensor.cpp
Normal file
74
src/sensors/pipewiresensor.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include "pipewiresensor.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
static const struct pw_node_events node_events = {
|
||||||
|
.version = PW_VERSION_NODE_EVENTS,
|
||||||
|
.info = &PipeWireSensorSource::nodeEventHandler,
|
||||||
|
.param = nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
PipeWireSensorSource::PipeWireSensorSource(PipeWireHandler* handler, const std::string& nodeName, uint8_t id, QObject *parent)
|
||||||
|
: QObject{parent}, handler_(handler), nodeName_(nodeName), id_(id)
|
||||||
|
{
|
||||||
|
connect(handler_, &PipeWireHandler::nodeAdded, this, &PipeWireSensorSource::nodeAdded);
|
||||||
|
connect(&timer, &QTimer::timeout, this, &PipeWireSensorSource::offTimeout);
|
||||||
|
timer.setSingleShot(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipeWireSensorSource::offTimeout()
|
||||||
|
{
|
||||||
|
if(state == false)
|
||||||
|
return;
|
||||||
|
state = false;
|
||||||
|
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, id_, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipeWireSensorSource::nodeEventHandler(void* data, const struct pw_node_info *info)
|
||||||
|
{
|
||||||
|
PipeWireSensorSource* source = static_cast<PipeWireSensorSource*>(data);
|
||||||
|
|
||||||
|
if(info->state == source->prevState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
source->prevState = info->state;
|
||||||
|
|
||||||
|
switch (info->state)
|
||||||
|
{
|
||||||
|
case PW_NODE_STATE_ERROR:
|
||||||
|
case PW_NODE_STATE_CREATING:
|
||||||
|
source->state = false;
|
||||||
|
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, 0));
|
||||||
|
break;
|
||||||
|
case PW_NODE_STATE_SUSPENDED:
|
||||||
|
case PW_NODE_STATE_IDLE:
|
||||||
|
if(source->state == true)
|
||||||
|
source->timer.start(10000);
|
||||||
|
break;
|
||||||
|
case PW_NODE_STATE_RUNNING:
|
||||||
|
if(source->state == false)
|
||||||
|
{
|
||||||
|
source->state = true;
|
||||||
|
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, source->state));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipeWireSensorSource::nodeAdded(PipeWireHandler::PwNode node)
|
||||||
|
{
|
||||||
|
if(node.name == nodeName_)
|
||||||
|
{
|
||||||
|
|
||||||
|
sinkNode = static_cast<struct pw_node*>(pw_registry_bind(handler_->getRegistry(), node.id, PW_TYPE_INTERFACE_Node, PW_VERSION_CLIENT, 0));
|
||||||
|
if(sinkNode)
|
||||||
|
{
|
||||||
|
qDebug()<<"Failed to register to required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pw_node_add_listener(sinkNode, &sinkListener, &node_events, this);
|
||||||
|
qDebug()<<"Found required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
40
src/sensors/pipewiresensor.h
Normal file
40
src/sensors/pipewiresensor.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef PIPEWIRESENSOR_H
|
||||||
|
#define PIPEWIRESENSOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <string>
|
||||||
|
#include <pipewire/core.h>
|
||||||
|
#include <pipewire/pipewire.h>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "sensor.h"
|
||||||
|
#include "../pipewire.h"
|
||||||
|
|
||||||
|
class PipeWireSensorSource : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
PipeWireHandler* handler_;
|
||||||
|
std::string nodeName_;
|
||||||
|
struct pw_node* sinkNode = nullptr;
|
||||||
|
struct spa_hook sinkListener;
|
||||||
|
pw_node_state prevState = PW_NODE_STATE_SUSPENDED;
|
||||||
|
QTimer timer;
|
||||||
|
uint8_t id_;
|
||||||
|
bool state = false;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void offTimeout();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PipeWireSensorSource(PipeWireHandler* handler, const std::string& nodeName, uint8_t id, QObject *parent = nullptr);
|
||||||
|
static void nodeEventHandler(void* data, const struct pw_node_info *info);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void stateChanged(Sensor sensor);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void nodeAdded(PipeWireHandler::PwNode node);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PIPEWIRESENSOR_H
|
@ -34,7 +34,8 @@ public:
|
|||||||
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
if(nameIn == "") generateName();
|
if(nameIn == "")
|
||||||
|
generateName();
|
||||||
}
|
}
|
||||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
|
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
|
||||||
{
|
{
|
||||||
@ -58,15 +59,23 @@ public:
|
|||||||
if(bufferList.size() >= 7)
|
if(bufferList.size() >= 7)
|
||||||
{
|
{
|
||||||
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
|
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
|
||||||
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
|
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE)
|
||||||
|
sensor.field = sensor.field/10;
|
||||||
|
|
||||||
|
if(bufferList.size() >= 9)
|
||||||
|
sensor.lastSeen = QDateTime::fromSecsSinceEpoch(bufferList[8].toLongLong());
|
||||||
return sensor;
|
return sensor;
|
||||||
}
|
}
|
||||||
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
else
|
||||||
|
{
|
||||||
|
return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QString toString()
|
QString toString()
|
||||||
{
|
{
|
||||||
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
|
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
|
||||||
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field);
|
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field) +
|
||||||
|
" TIME: " + QString::number(lastSeen.toSecsSinceEpoch());
|
||||||
}
|
}
|
||||||
inline void generateName()
|
inline void generateName()
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ void ItemSettingsDialog::addActor()
|
|||||||
|
|
||||||
void ItemSettingsDialog::removeActor()
|
void ItemSettingsDialog::removeActor()
|
||||||
{
|
{
|
||||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
||||||
{
|
{
|
||||||
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
||||||
loadActorList();
|
loadActorList();
|
||||||
@ -153,7 +153,7 @@ void ItemSettingsDialog::removeActor()
|
|||||||
|
|
||||||
void ItemSettingsDialog::editActor()
|
void ItemSettingsDialog::editActor()
|
||||||
{
|
{
|
||||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
||||||
{
|
{
|
||||||
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ void ItemSettingsDialog::editActor()
|
|||||||
dialog->show();
|
dialog->show();
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i)
|
for(int i = 0; i < ui->tableWidget->rowCount() && i < static_cast<size_t>(item_->getActors().size()); ++i)
|
||||||
{
|
{
|
||||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||||
|
@ -54,6 +54,8 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
|||||||
|
|
||||||
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
||||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
||||||
|
|
||||||
|
ui->splitter->setStretchFactor(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -42,8 +42,16 @@
|
|||||||
<property name="autoFillBackground">
|
<property name="autoFillBackground">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
<item>
|
<item>
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="childrenCollapsible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_serialRecive">
|
<widget class="QLabel" name="label_serialRecive">
|
||||||
@ -78,6 +86,18 @@
|
|||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="SensorListWidget" name="sensorListView">
|
<widget class="SensorListWidget" name="sensorListView">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>300</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::NoSelection</enum>
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -135,8 +155,8 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</widget>
|
||||||
<item>
|
<widget class="QWidget" name="">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
@ -214,6 +234,8 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent),
|
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent),
|
||||||
showHidden_(showHidden)
|
showHidden_(showHidden)
|
||||||
{
|
{
|
||||||
setColumnCount(2);
|
setColumnCount(3);
|
||||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
|
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
|
||||||
setAutoScroll(true);
|
setAutoScroll(true);
|
||||||
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
sensorsChanged(std::vector<Sensor>());
|
||||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
verticalHeader()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden,
|
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden,
|
||||||
@ -28,8 +28,11 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
|
|||||||
clear();
|
clear();
|
||||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
||||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||||
|
setHorizontalHeaderItem(2, new QTableWidgetItem("Time"));
|
||||||
size_t listLen = 0;
|
size_t listLen = 0;
|
||||||
for(size_t i = 0; i < sensors.size(); ++i) if(showHidden_ || !sensors[i].hidden) ++listLen;
|
for(size_t i = 0; i < sensors.size(); ++i)
|
||||||
|
if(showHidden_ || !sensors[i].hidden)
|
||||||
|
++listLen;
|
||||||
setRowCount(static_cast<int>(listLen));
|
setRowCount(static_cast<int>(listLen));
|
||||||
size_t row = 0;
|
size_t row = 0;
|
||||||
for(size_t i = 0; i < sensors.size(); ++i)
|
for(size_t i = 0; i < sensors.size(); ++i)
|
||||||
@ -42,20 +45,25 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
|
|||||||
|
|
||||||
if(sensors[i].type == Sensor::TYPE_DOOR)
|
if(sensors[i].type == Sensor::TYPE_DOOR)
|
||||||
{
|
{
|
||||||
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Open\"");
|
if(static_cast<bool>(sensors[i].field))
|
||||||
|
itemString.append("\"Open\"");
|
||||||
else itemString.append("\"Closed\"");
|
else itemString.append("\"Closed\"");
|
||||||
}
|
}
|
||||||
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
|
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
|
||||||
{
|
{
|
||||||
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Playing\"");
|
if(static_cast<bool>(sensors[i].field))
|
||||||
|
itemString.append("\"Playing\"");
|
||||||
else itemString.append("\"Silent\"");
|
else itemString.append("\"Silent\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : "")));
|
setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : "")));
|
||||||
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
|
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
|
||||||
|
setItem(static_cast<int>(row), 2, new QTableWidgetItem(sensors[i].lastSeen.time().toString("hh:mm")));
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sortItems(0, Qt::AscendingOrder);
|
||||||
|
resizeColumnsToContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorListWidget::setShowHidden(const bool showHidden)
|
void SensorListWidget::setShowHidden(const bool showHidden)
|
||||||
|
Reference in New Issue
Block a user