feat: integrate ui with data api
Much of this was ai generated.
This commit is contained in:
+22
-17
@@ -2,8 +2,16 @@
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
NetworkStreamModel::NetworkStreamModel(Data *data, QObject *parent) : QAbstractItemModel(parent), m_data(data)
|
||||
NetworkStreamModel::NetworkStreamModel(Store *store, QObject *parent) : QAbstractItemModel(parent), m_store(store)
|
||||
{
|
||||
connect(m_store, &Store::networksChanged, this, [this]() {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
});
|
||||
connect(m_store, &Store::streamsChanged, this, [this]() {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
});
|
||||
}
|
||||
|
||||
QModelIndex NetworkStreamModel::index(int row, int column, const QModelIndex &parent) const
|
||||
@@ -59,7 +67,7 @@ int NetworkStreamModel::rowCount(const QModelIndex &parent) const
|
||||
if (!parent.isValid())
|
||||
{
|
||||
// Root level - return number of networks
|
||||
return m_data->networkCount();
|
||||
return m_store->networkCount();
|
||||
}
|
||||
|
||||
quintptr id = parent.internalId();
|
||||
@@ -69,10 +77,9 @@ int NetworkStreamModel::rowCount(const QModelIndex &parent) const
|
||||
if (networkIndex == 0xFFFFFFFF)
|
||||
{
|
||||
int actualNetworkIndex = static_cast<int>(id & 0xFFFFFFFF);
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_data->networks().size())
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_store->networks().size())
|
||||
{
|
||||
const QString &networkId = m_data->networks().at(actualNetworkIndex).id;
|
||||
return m_data->streamCount(networkId);
|
||||
return static_cast<int>(m_store->networks().at(actualNetworkIndex).streams.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +109,9 @@ QVariant NetworkStreamModel::data(const QModelIndex &index, int role) const
|
||||
if (role == Qt::DisplayRole && index.column() == 0)
|
||||
{
|
||||
int actualNetworkIndex = static_cast<int>(id & 0xFFFFFFFF);
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_data->networks().size())
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_store->networks().size())
|
||||
{
|
||||
return m_data->networks().at(actualNetworkIndex).name.toUpper();
|
||||
return m_store->networks().at(actualNetworkIndex).name.toUpper();
|
||||
}
|
||||
}
|
||||
// Networks don't show unseen count in column 1
|
||||
@@ -114,12 +121,11 @@ QVariant NetworkStreamModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// This is a stream item
|
||||
int streamIndex = static_cast<int>(id & 0xFFFFFFFF);
|
||||
if (networkIndex >= 0 && networkIndex < m_data->networks().size())
|
||||
if (networkIndex >= 0 && networkIndex < m_store->networks().size())
|
||||
{
|
||||
const QString &networkId = m_data->networks().at(networkIndex).id;
|
||||
const QList<Stream> &streams = m_data->streamsForNetwork(networkId);
|
||||
const auto &streams = m_store->networks().at(networkIndex).streams;
|
||||
|
||||
if (streamIndex >= 0 && streamIndex < streams.size())
|
||||
if (streamIndex >= 0 && streamIndex < static_cast<int>(streams.size()))
|
||||
{
|
||||
const Stream &stream = streams.at(streamIndex);
|
||||
|
||||
@@ -174,12 +180,11 @@ QString NetworkStreamModel::streamIdFromIndex(const QModelIndex &index) const
|
||||
if (networkIndex != 0xFFFFFFFF)
|
||||
{
|
||||
int streamIndex = static_cast<int>(id & 0xFFFFFFFF);
|
||||
if (networkIndex >= 0 && networkIndex < m_data->networks().size())
|
||||
if (networkIndex >= 0 && networkIndex < m_store->networks().size())
|
||||
{
|
||||
const QString &networkId = m_data->networks().at(networkIndex).id;
|
||||
const QList<Stream> &streams = m_data->streamsForNetwork(networkId);
|
||||
const auto &streams = m_store->networks().at(networkIndex).streams;
|
||||
|
||||
if (streamIndex >= 0 && streamIndex < streams.size())
|
||||
if (streamIndex >= 0 && streamIndex < static_cast<int>(streams.size()))
|
||||
{
|
||||
return streams.at(streamIndex).id;
|
||||
}
|
||||
@@ -203,9 +208,9 @@ QString NetworkStreamModel::networkIdFromIndex(const QModelIndex &index) const
|
||||
if (networkIndex == 0xFFFFFFFF)
|
||||
{
|
||||
int actualNetworkIndex = static_cast<int>(id & 0xFFFFFFFF);
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_data->networks().size())
|
||||
if (actualNetworkIndex >= 0 && actualNetworkIndex < m_store->networks().size())
|
||||
{
|
||||
return m_data->networks().at(actualNetworkIndex).id;
|
||||
return m_store->networks().at(actualNetworkIndex).id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user