drop models from library
This commit is contained in:
parent
d021366fc8
commit
0090fa5706
|
@ -1,4 +1,4 @@
|
|||
project(QsACNNode VERSION 0.1 LANGUAGES CXX)
|
||||
project(QsACN VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
|
@ -17,12 +17,10 @@ target_sources(${PROJECT_NAME}
|
|||
PUBLIC
|
||||
qsacnnode.h
|
||||
qsacnuniverse.h
|
||||
universemodel.h
|
||||
PRIVATE
|
||||
qsacnnode_global.h
|
||||
qsacnnode.cpp
|
||||
qsacnuniverse.cpp
|
||||
universemodel.cpp
|
||||
qsacn_global.h
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "qsacnnode.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMetaEnum>
|
||||
#include <QNetworkDatagram>
|
||||
#include <QNetworkInterface>
|
||||
|
||||
|
@ -46,11 +47,13 @@ void QSacnNode::subscribe(const uint16_t num)
|
|||
{
|
||||
if (Receiver::universe(num)) // already subscribed
|
||||
return;
|
||||
if (num != sACN::E131_DISCOVERY_UNIVERSE) {
|
||||
qDebug() << "Subscribing to universe" << QString::number(num);
|
||||
Receiver::subscribe(num);
|
||||
rx_universes_.insert(num, new QSacnUniverse(this, Receiver::universe(num)));
|
||||
}
|
||||
if (num != sACN::E131_DISCOVERY_UNIVERSE)
|
||||
{
|
||||
qDebug() << "Subscribing to universe" << QString::number(num);
|
||||
Receiver::subscribe(num);
|
||||
rx_universes.emplace(num, new QSacnUniverse(this, Receiver::universe(num)));
|
||||
emit subscribing(rx_universes.value(num));
|
||||
}
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
joinMulticastGroup(IPv4MulticastAddress(num), iface);
|
||||
for (QNetworkInterface &iface : QNetworkInterface::allInterfaces())
|
||||
|
@ -71,7 +74,8 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
|||
|
||||
if (Receiver::universe(num)) {
|
||||
qDebug() << "Unsubscribing from universe " << QString::number(num);
|
||||
delete rx_universes_.take(num);
|
||||
emit unsubscribing(rx_universes.value(num));
|
||||
rx_universes.take(num)->deleteLater();
|
||||
Receiver::unsubscribe(num);
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +91,8 @@ void QSacnNode::create(const uint16_t num)
|
|||
return;
|
||||
|
||||
Source::create(num);
|
||||
tx_universes_.insert(num, new QSacnUniverse(this, Source::universe(num)));
|
||||
tx_universes.emplace(num, new QSacnUniverse(this, Source::universe(num)));
|
||||
emit creating(tx_universes.value(num));
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,9 +103,10 @@ void QSacnNode::create(const uint16_t num)
|
|||
void QSacnNode::terminate(const uint16_t num)
|
||||
{
|
||||
if (Source::universe(num)) {
|
||||
qDebug() << "terminating universe " << QString::number(num);
|
||||
delete tx_universes_.take(num);
|
||||
qDebug() << "Terminating universe " << QString::number(num);
|
||||
Source::terminate(num);
|
||||
emit terminating(tx_universes.value(num));
|
||||
tx_universes.take(num)->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,6 +130,11 @@ void QSacnNode::udpReceive()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief QSacnNode::rlpSend
|
||||
* @param stream
|
||||
* @param ip
|
||||
*/
|
||||
void QSacnNode::rlpSend(const ACN::PDU::Stream stream,
|
||||
const ACN::SDT::UDP::ipAddress& ip)
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include "qsacn_global.h"
|
||||
#include "qsacnuniverse.h"
|
||||
#include "sacn/node.h"
|
||||
#include "sdt/udp.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QHostAddress>
|
||||
|
@ -26,25 +26,26 @@ public:
|
|||
// rlp component
|
||||
void rlpSend(const ACN::PDU::Stream, const ACN::SDT::UDP::ipAddress&) override;
|
||||
|
||||
// reciever
|
||||
QSacnUniverse * universe(const uint16_t u) {return rx_universes_.value(u); }
|
||||
void subscribe(const uint16_t universe = 1) override;
|
||||
void unsubscribe(const uint16_t) override;
|
||||
QSacnUniverse * universe(const uint16_t u) { return rx_universes.value(u); }
|
||||
QSacnUniverse * source(const uint16_t u) { return tx_universes.value(u); }
|
||||
|
||||
// source
|
||||
QSacnUniverse * source(const uint16_t u) {return tx_universes_.value(u); }
|
||||
public slots:
|
||||
void subscribe(const uint16_t) override;
|
||||
void unsubscribe(const uint16_t) override;
|
||||
void create(const uint16_t) override;
|
||||
void terminate(const uint16_t) override;
|
||||
|
||||
signals:
|
||||
void foundUniverse(
|
||||
std::shared_ptr<sACN::EXTENDED::DISCOVERY::discoveredUniverse>);
|
||||
void subscribing(QSacnUniverse*);
|
||||
void unsubscribing(QSacnUniverse*);
|
||||
void creating(QSacnUniverse*);
|
||||
void terminating(QSacnUniverse*);
|
||||
|
||||
private:
|
||||
void udpReceive();
|
||||
|
||||
QHash<uint16_t, QSacnUniverse*> rx_universes_;
|
||||
QHash<uint16_t, QSacnUniverse*> tx_universes_;
|
||||
QHash<uint16_t, QSacnUniverse*> rx_universes;
|
||||
QHash<uint16_t, QSacnUniverse*> tx_universes;
|
||||
|
||||
public:
|
||||
/// \cite sACN 9.3.1 Allocation of IPv4 Multicast Addresses
|
||||
|
|
|
@ -20,7 +20,10 @@ QSacnUniverse::QSacnUniverse(QObject *parent, sACN::Universe *universe)
|
|||
*/
|
||||
const QString QSacnUniverse::description() const
|
||||
{
|
||||
return QString::fromUtf8(universe_->provenance()->source_name.c_str());
|
||||
auto metadata = universe_->provenance();
|
||||
if (!metadata)
|
||||
return QString();
|
||||
return QString::fromUtf8(metadata->source_name.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +33,10 @@ const QString QSacnUniverse::description() const
|
|||
*/
|
||||
uint16_t QSacnUniverse::number() const
|
||||
{
|
||||
return universe_->provenance()->universe;
|
||||
auto metadata = universe_->provenance();
|
||||
if (!metadata)
|
||||
return 0;
|
||||
return metadata->universe;
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +46,10 @@ uint16_t QSacnUniverse::number() const
|
|||
*/
|
||||
uint8_t QSacnUniverse::priority() const
|
||||
{
|
||||
return universe_->provenance()->priority;
|
||||
auto metadata = universe_->provenance();
|
||||
if (!metadata)
|
||||
return 0;
|
||||
return metadata->priority;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include "qsacn_global.h"
|
||||
#include "sacn/universe.h"
|
||||
|
||||
/**
|
||||
|
@ -45,3 +45,4 @@ protected:
|
|||
private:
|
||||
sACN::Universe *universe_;
|
||||
};
|
||||
Q_DECLARE_METATYPE(QSacnUniverse*)
|
||||
|
|
|
@ -1,240 +0,0 @@
|
|||
#include "universemodel.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include <QChar>
|
||||
#include <QMetaEnum>
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::UniverseModel
|
||||
* @param parent
|
||||
*/
|
||||
UniverseModel::UniverseModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::headerData
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant UniverseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
return section + 1;
|
||||
|
||||
if (orientation == Qt::Vertical)
|
||||
return section * 10;
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::rowCount
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int UniverseModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return 52;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::columnCount
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int UniverseModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::data
|
||||
* @param index
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant UniverseModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (!universe_)
|
||||
return QVariant();
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
int slot = (index.row() * 10) + (index.column() + 1);
|
||||
if (slot == 0)
|
||||
return QVariant();
|
||||
if (slot > 512)
|
||||
return QVariant();
|
||||
switch (data_mode_) {
|
||||
case Decimal:
|
||||
return universe_->slot(slot);
|
||||
case Hex:
|
||||
return QString("%1")
|
||||
.arg(universe_->slot(slot), 2, 16, QChar('0'))
|
||||
.toUpper();
|
||||
case Percent:
|
||||
return QString("%1%").arg((universe_->slot(slot) / 255.0F) * 100,
|
||||
0, 'f', 0, '0');
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
case Qt::FontRole:
|
||||
return QFont("monospace");
|
||||
case Qt::TextAlignmentRole:
|
||||
return int(Qt::AlignCenter | Qt::AlignVCenter);
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
int slot = (index.row() * 10) + (index.column() + 1);
|
||||
if (slot > universe_->activeSlots() - 1)
|
||||
return QBrush(Qt::gray);
|
||||
return QVariant();
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::setData
|
||||
* @param index
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool UniverseModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
int role)
|
||||
{
|
||||
if (data(index, role) == value)
|
||||
return false;
|
||||
|
||||
uint16_t slot = (index.row() * 10) + (index.column() + 1);
|
||||
uint8_t data;
|
||||
|
||||
switch (data_mode_) {
|
||||
case Decimal:
|
||||
{
|
||||
if (!value.canConvert<uint>())
|
||||
return false;
|
||||
uint d = value.toUInt();
|
||||
if (d > 255)
|
||||
return false;
|
||||
data = d;
|
||||
}
|
||||
break;
|
||||
case Hex:
|
||||
{
|
||||
if (!value.canConvert<QString>())
|
||||
return false;
|
||||
bool ok;
|
||||
uint d = value.toString().toInt(&ok, 16);
|
||||
if (!ok)
|
||||
return false;
|
||||
if (d > 255)
|
||||
return false;
|
||||
data = d;
|
||||
}
|
||||
break;
|
||||
case Percent:
|
||||
{
|
||||
if (!value.canConvert<double>())
|
||||
return false;
|
||||
int d = 255 * (value.toDouble() / 100);
|
||||
if (d < 0 || d > 255)
|
||||
return false;
|
||||
data = d;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
universe_->setValue(slot, data);
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::flags
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
Qt::ItemFlags UniverseModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
if (!universe_)
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
int slot = (index.row() * 10) + (index.column() + 1);
|
||||
|
||||
if (slot == 0)
|
||||
return Qt::NoItemFlags;
|
||||
if (slot > 512)
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
auto f = QAbstractItemModel::flags(index);
|
||||
|
||||
if (universe_->isEditable())
|
||||
f |= Qt::ItemIsEditable;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::universeRefreshed
|
||||
*/
|
||||
void UniverseModel::universeRefreshed() {
|
||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||
emit recievedUpdate(universe_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::setDataMode
|
||||
* @param mode
|
||||
*/
|
||||
void UniverseModel::setDataMode(const QString mode)
|
||||
{
|
||||
auto&& metaEnum = QMetaEnum::fromType<data_modes>();
|
||||
data_mode_ = static_cast<data_modes>(metaEnum.keyToValue(mode.toLocal8Bit()));
|
||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::setUniverse
|
||||
* @param universe
|
||||
*/
|
||||
void UniverseModel::setUniverse(QSacnUniverse *universe)
|
||||
{
|
||||
if (universe_)
|
||||
disconnect(universe_, 0, this, 0);
|
||||
universe_ = universe;
|
||||
connect(universe_, &QSacnUniverse::changed,
|
||||
this, &UniverseModel::universeRefreshed);
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include <QAbstractTableModel>
|
||||
#include "qsacnuniverse.h"
|
||||
|
||||
class QT_EXPORT UniverseModel
|
||||
: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum data_modes {
|
||||
Decimal,
|
||||
Hex,
|
||||
Percent
|
||||
};
|
||||
Q_ENUM(data_modes)
|
||||
|
||||
explicit UniverseModel(QObject *parent = nullptr);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
// Data source:
|
||||
void setUniverse(QSacnUniverse *universe);
|
||||
QSacnUniverse * universe() const { return universe_; }
|
||||
data_modes dataMode() { return data_mode_; }
|
||||
|
||||
signals:
|
||||
void recievedUpdate(const QSacnUniverse*);
|
||||
|
||||
public slots:
|
||||
void universeRefreshed();
|
||||
void setDataMode(const QString mode);
|
||||
|
||||
private:
|
||||
QSacnUniverse * universe_ = nullptr;
|
||||
data_modes data_mode_ = Decimal;
|
||||
};
|
Loading…
Reference in New Issue