diff --git a/example/sACN Explorer/universewindow.cpp b/example/sACN Explorer/universewindow.cpp index 62894d8..450b7a3 100644 --- a/example/sACN Explorer/universewindow.cpp +++ b/example/sACN Explorer/universewindow.cpp @@ -19,7 +19,7 @@ UniverseWindow::UniverseWindow(QWidget *parent, QSacnUniverse *universe) { ui->setupUi(this); - auto model = new UniverseModel(this, universe); + auto model = new UniverseModel(this, universe->get()); ui->tableView->setModel(model); // update the status bar whenever the universe refreshes diff --git a/platform/qt/sacn/universemodel.cpp b/platform/qt/sacn/universemodel.cpp index 9e58301..3083b5a 100644 --- a/platform/qt/sacn/universemodel.cpp +++ b/platform/qt/sacn/universemodel.cpp @@ -10,7 +10,7 @@ * @param parent * @param universe */ -UniverseModel::UniverseModel(QObject *parent, QSacnUniverse *universe) +UniverseModel::UniverseModel(QObject *parent, std::shared_ptr universe) : QAbstractTableModel(parent) , universe_(universe) , data_mode_(Decimal) @@ -18,9 +18,8 @@ UniverseModel::UniverseModel(QObject *parent, QSacnUniverse *universe) if (!universe_) return; - connect(universe_, &QSacnUniverse::dataChanged, - this, [this](){ - emit dataChanged(index(0,0), index(rowCount(), columnCount())); + data_change_token = universe_->onDataChange([this] (DMX::Universe*) { + emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount())); }); } @@ -197,10 +196,9 @@ Qt::ItemFlags UniverseModel::flags(const QModelIndex &index) const * @brief UniverseModel::setDataMode * @param mode */ -void UniverseModel::setDataMode(const QString mode) +void UniverseModel::setDataMode(const UniverseModel::data_modes mode) { - auto metaEnum = QMetaEnum::fromType(); - data_mode_ = static_cast(metaEnum.keyToValue(mode.toLocal8Bit())); + data_mode_ = mode; emit dataChanged(index(0,0), index(rowCount(), columnCount())); } diff --git a/platform/qt/sacn/universemodel.h b/platform/qt/sacn/universemodel.h index 024151d..f0b11c0 100644 --- a/platform/qt/sacn/universemodel.h +++ b/platform/qt/sacn/universemodel.h @@ -1,16 +1,15 @@ #pragma once #include -#include "qsacn_global.h" -#include "qsacnuniverse.h" +#include -class QT_EXPORT UniverseModel +class UniverseModel : public QAbstractTableModel { Q_OBJECT public: explicit UniverseModel(QObject *parent = nullptr, - QSacnUniverse *universe = nullptr); + std::shared_ptr universe = nullptr); // Model overrides: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; @@ -32,9 +31,11 @@ public: data_modes dataMode(); public slots: - void setDataMode(const QString mode); + void setDataMode(const UniverseModel::data_modes mode); private: - QSacnUniverse* universe_; + std::shared_ptr universe_; data_modes data_mode_; + + std::shared_ptr data_change_token; };