feat: show fake data network, stream, and particles data

This commit is contained in:
talksik
2026-01-28 08:26:30 -08:00
parent 5b271ab623
commit dfcd366f9d
11 changed files with 750 additions and 74 deletions
+71 -1
View File
@@ -8,6 +8,8 @@
#include "settingsdialog.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QLabel>
#include <QMenu>
#include <QSystemTrayIcon>
@@ -15,7 +17,7 @@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_settingsDialog(nullptr),
m_authDialog(nullptr)
m_authDialog(nullptr), m_data(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr)
{
m_authDialog = new AuthDialog(m_authManager, this);
@@ -27,6 +29,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->splitter->setStretchFactor(1, 1);
ui->splitter->setStretchFactor(2, 2);
setupModels();
m_authDialog->setModal(true);
QTimer::singleShot(3000, this, [this]() {
@@ -95,3 +99,69 @@ void MainWindow::on_settingsButton_clicked()
}
m_settingsDialog->show();
}
void MainWindow::setupModels()
{
// Create data with fake data
m_data = new Data(this);
// Create and set tree model
m_networkStreamModel = new NetworkStreamModel(m_data, this);
ui->topLevelParticlesView->setModel(m_networkStreamModel);
ui->topLevelParticlesView->setHeaderHidden(true);
ui->topLevelParticlesView->expandAll();
// Configure column behavior: name stretches, unseen count is fixed width
ui->topLevelParticlesView->header()->setStretchLastSection(false);
ui->topLevelParticlesView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->topLevelParticlesView->header()->setSectionResizeMode(1, QHeaderView::Fixed);
ui->topLevelParticlesView->setColumnWidth(1, 40);
// Create and set list model
m_particleListModel = new ParticleListModel(m_data, this);
ui->particlesView->setModel(m_particleListModel);
// Connect selection changes
connect(ui->topLevelParticlesView->selectionModel(),
&QItemSelectionModel::selectionChanged,
this,
&MainWindow::onTreeSelectionChanged);
}
void MainWindow::onTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected)
{
Q_UNUSED(deselected);
if (selected.indexes().isEmpty())
{
m_particleListModel->setStreamId(QString());
return;
}
QModelIndex index = selected.indexes().first();
if (m_networkStreamModel->isStreamItem(index))
{
QString streamId = m_networkStreamModel->streamIdFromIndex(index);
m_particleListModel->setStreamId(streamId);
// Auto-select first unseen particle (or first particle if all seen)
int unseenRow = m_particleListModel->firstUnseenRow();
if (unseenRow >= 0)
{
ui->particlesView->setCurrentIndex(m_particleListModel->index(unseenRow, 0));
ui->particlesView->setFocus();
}
else if (m_particleListModel->rowCount() > 0)
{
ui->particlesView->setCurrentIndex(m_particleListModel->index(0, 0));
ui->particlesView->setFocus();
}
}
else
{
m_particleListModel->setStreamId(QString());
}
}