initial universe data table model
This commit is contained in:
parent
96fa743548
commit
4ce12e250d
|
@ -11,6 +11,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
|||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
|
||||
endif()
|
||||
set(CMAKE_AUTOUIC OFF)
|
||||
set(CMAKE_AUTOMOC OFF)
|
||||
set(CMAKE_AUTORCC OFF)
|
||||
|
||||
set(SOURCE_FILES
|
||||
acn/acn.h
|
||||
|
|
|
@ -20,7 +20,9 @@ add_library(${PROJECT_NAME} STATIC
|
|||
qsacnnode_global.h
|
||||
qsacnnode.cpp
|
||||
qsacnnode.h
|
||||
qsacnuniversewrapper.h
|
||||
qsacnuniverse.h
|
||||
universemodel.h
|
||||
universemodel.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Network ESTA)
|
||||
|
|
|
@ -10,6 +10,8 @@ QSacnNode::QSacnNode(QObject *parent, QUuid cid)
|
|||
, QUdpSocket(parent)
|
||||
, multiverse_(new MultiverseModel(this))
|
||||
{
|
||||
fctn_ = "libESTA QSacnNode";
|
||||
|
||||
bind(QHostAddress::AnyIPv4, ACN_SDT_MULTICAST_PORT);
|
||||
|
||||
connect(this, &QUdpSocket::readyRead,
|
||||
|
@ -27,7 +29,7 @@ void QSacnNode::subscribe(const uint16_t num)
|
|||
if (num != SACN::E131_DISCOVERY_UNIVERSE) {
|
||||
qDebug() << "Subscribing to universe" << QString::number(num);
|
||||
Receiver::subscribe(num);
|
||||
wrappers_.insert(num, new QSacnUniverseWrapper(this, Receiver::universe(num)));
|
||||
universes_.insert(num, new QSacnUniverse(this, Receiver::universe(num)));
|
||||
}
|
||||
joinMulticastGroup(IPv4MulticastAddress(num));
|
||||
}
|
||||
|
@ -38,7 +40,7 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
|||
leaveMulticastGroup(IPv4MulticastAddress(num));
|
||||
if (Receiver::universe(num)) {
|
||||
qDebug() << "Unsubscribing from universe " << QString::number(num);
|
||||
delete wrappers_.take(num);
|
||||
delete universes_.take(num);
|
||||
Receiver::unsubscribe(num);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +49,6 @@ void QSacnNode::unsubscribe(const uint16_t num)
|
|||
void QSacnNode::UdpPayloadReceiver()
|
||||
{
|
||||
while (hasPendingDatagrams()) {
|
||||
qDebug() << "processing UDP datagram...";
|
||||
QNetworkDatagram datagram = receiveDatagram();
|
||||
// Expecting IANA registered Session Data Transport traffic
|
||||
if (datagram.destinationPort() != ACN_SDT_MULTICAST_PORT)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef QSACNNODE_H
|
||||
#define QSACNNODE_H
|
||||
#pragma once
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include "qsacnuniversewrapper.h"
|
||||
#include "../../sacn/node.h"
|
||||
|
||||
#include <QHash>
|
||||
|
@ -36,6 +34,9 @@ class QT_EXPORT QSacnNode
|
|||
|
||||
public:
|
||||
explicit QSacnNode(QObject *parent = nullptr, QUuid = QUuid::createUuid());
|
||||
QSacnUniverse * universe(const uint16_t u) {return universes_.value(u); }
|
||||
|
||||
// reciever
|
||||
virtual void subscribe(const uint16_t universe = 1);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
|
||||
|
@ -46,8 +47,7 @@ private:
|
|||
void UdpPayloadReceiver();
|
||||
void emitFound(std::shared_ptr<EXTENDED::DISCOVERY::DiscoveredUniverse>);
|
||||
|
||||
QHash<uint16_t, QSacnUniverseWrapper*> wrappers_;
|
||||
QHash<uint16_t, QSacnUniverse*> universes_;
|
||||
};
|
||||
|
||||
} // namespace SACN
|
||||
#endif // QSACNNODE_H
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef QSACNUNIVERSEWRAPPER_H
|
||||
#define QSACNUNIVERSEWRAPPER_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QTime>
|
||||
|
@ -7,25 +6,31 @@
|
|||
|
||||
#include "../../sacn/universe.h"
|
||||
|
||||
namespace SACN {
|
||||
|
||||
class QSacnUniverseWrapper
|
||||
/**
|
||||
* @brief The QSacnUniverse class
|
||||
*/
|
||||
class QSacnUniverse
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
friend DMX::Universe; // permit callback to access the private notifier
|
||||
explicit QSacnUniverseWrapper(QObject *parent = nullptr,
|
||||
Universe *universe = nullptr)
|
||||
explicit QSacnUniverse(QObject *parent = nullptr,
|
||||
SACN::Universe *universe = nullptr)
|
||||
: QObject(parent)
|
||||
, universe_(universe)
|
||||
, refreshTimer_(new QTimer(this))
|
||||
, lastRecieved_(QTime())
|
||||
{
|
||||
universe_->onData(std::bind(&QSacnUniverseWrapper::dataChangedNotifier,
|
||||
universe_->onData(std::bind(&QSacnUniverse::dataChangedNotifier,
|
||||
this, std::placeholders::_1));
|
||||
};
|
||||
|
||||
uint8_t value(const u_int16_t slot)
|
||||
{
|
||||
return universe_->slot(slot);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setDescription(std::string desc)
|
||||
{
|
||||
|
@ -70,6 +75,3 @@ private:
|
|||
QTimer *refreshTimer_;
|
||||
QTime lastRecieved_;
|
||||
};
|
||||
|
||||
} // SACN namespace
|
||||
#endif // QSACNUNIVERSEWRAPPER_H
|
|
@ -0,0 +1,158 @@
|
|||
#include "universemodel.h"
|
||||
|
||||
/**
|
||||
* @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();
|
||||
return universe_->value(slot);
|
||||
break;
|
||||
}
|
||||
case Qt::TextAlignmentRole:
|
||||
return int(Qt::AlignCenter | Qt::AlignVCenter);
|
||||
break;
|
||||
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) {
|
||||
// FIXME: Implement me!
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
return QAbstractItemModel::flags(index);// | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief UniverseModel::universeRefreshed
|
||||
*/
|
||||
void UniverseModel::universeRefreshed() {
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include "qsacnuniverse.h"
|
||||
|
||||
class UniverseModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
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;
|
||||
|
||||
void setUniverse(QSacnUniverse *universe);
|
||||
|
||||
public slots:
|
||||
void universeRefreshed();
|
||||
|
||||
private:
|
||||
QSacnUniverse * universe_ = nullptr;
|
||||
};
|
Loading…
Reference in New Issue