model directly from the DMX::Universe
This commit is contained in:
parent
91128ca9f3
commit
1563e620b9
|
@ -19,7 +19,7 @@ UniverseWindow::UniverseWindow(QWidget *parent, QSacnUniverse *universe)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
auto model = new UniverseModel(this, universe);
|
auto model = new UniverseModel(this, universe->get());
|
||||||
ui->tableView->setModel(model);
|
ui->tableView->setModel(model);
|
||||||
|
|
||||||
// update the status bar whenever the universe refreshes
|
// update the status bar whenever the universe refreshes
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param universe
|
* @param universe
|
||||||
*/
|
*/
|
||||||
UniverseModel::UniverseModel(QObject *parent, QSacnUniverse *universe)
|
UniverseModel::UniverseModel(QObject *parent, std::shared_ptr<DMX::Universe> universe)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
, universe_(universe)
|
, universe_(universe)
|
||||||
, data_mode_(Decimal)
|
, data_mode_(Decimal)
|
||||||
|
@ -18,9 +18,8 @@ UniverseModel::UniverseModel(QObject *parent, QSacnUniverse *universe)
|
||||||
if (!universe_)
|
if (!universe_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connect(universe_, &QSacnUniverse::dataChanged,
|
data_change_token = universe_->onDataChange([this] (DMX::Universe*) {
|
||||||
this, [this](){
|
emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
|
||||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,10 +196,9 @@ Qt::ItemFlags UniverseModel::flags(const QModelIndex &index) const
|
||||||
* @brief UniverseModel::setDataMode
|
* @brief UniverseModel::setDataMode
|
||||||
* @param mode
|
* @param mode
|
||||||
*/
|
*/
|
||||||
void UniverseModel::setDataMode(const QString mode)
|
void UniverseModel::setDataMode(const UniverseModel::data_modes mode)
|
||||||
{
|
{
|
||||||
auto metaEnum = QMetaEnum::fromType<data_modes>();
|
data_mode_ = mode;
|
||||||
data_mode_ = static_cast<data_modes>(metaEnum.keyToValue(mode.toLocal8Bit()));
|
|
||||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include "qsacn_global.h"
|
#include <universe.h>
|
||||||
#include "qsacnuniverse.h"
|
|
||||||
|
|
||||||
class QT_EXPORT UniverseModel
|
class UniverseModel
|
||||||
: public QAbstractTableModel
|
: public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UniverseModel(QObject *parent = nullptr,
|
explicit UniverseModel(QObject *parent = nullptr,
|
||||||
QSacnUniverse *universe = nullptr);
|
std::shared_ptr<DMX::Universe> universe = nullptr);
|
||||||
// Model overrides:
|
// Model overrides:
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const override;
|
int role = Qt::DisplayRole) const override;
|
||||||
|
@ -32,9 +31,11 @@ public:
|
||||||
data_modes dataMode();
|
data_modes dataMode();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDataMode(const QString mode);
|
void setDataMode(const UniverseModel::data_modes mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSacnUniverse* universe_;
|
std::shared_ptr<DMX::Universe> universe_;
|
||||||
data_modes data_mode_;
|
data_modes data_mode_;
|
||||||
|
|
||||||
|
std::shared_ptr<void> data_change_token;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user