tell views to update when a device changes state

This commit is contained in:
Kevin Matz 2023-04-14 13:17:37 -04:00
parent 75598b4359
commit 8b5da1d1ca
2 changed files with 12 additions and 0 deletions

View File

@ -8,6 +8,12 @@ WidgetModel::WidgetModel(QObject *parent)
}
WidgetModel::~WidgetModel() {
for(auto &wdgt: widgets_)
disconnect(wdgt.get(), nullptr, this, nullptr);
}
QVariant WidgetModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
@ -127,5 +133,10 @@ void WidgetModel::rescanPorts()
beginInsertRows(QModelIndex(), widgets_.size(), widgets_.size()+newWidgets.size()-1);
widgets_.append(newWidgets);
endInsertRows();
for(auto &wdgt: newWidgets)
connect(wdgt.get(), &DmxWidget::connectedChanged, this, [this](){
// refresh the whole view. Could be optimized by looking for this widget in the rows.
emit dataChanged(createIndex(0,0), createIndex(rowCount(),columnCount()));
});
}
}

View File

@ -9,6 +9,7 @@ class WidgetModel : public QAbstractItemModel
public:
explicit WidgetModel(QObject *parent = nullptr);
virtual ~WidgetModel();
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;