Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
SnapshotTableModel.cpp
Go to the documentation of this file.
3
4SnapshotTableModel::SnapshotTableModel(QObject* parent) : QAbstractTableModel(parent){}
5
6void SnapshotTableModel::setSnapshots(const std::vector<ObjectSnapshot> &snaps) {
7 beginResetModel();
8 snapshots = snaps;
9 endResetModel();
10}
11
12int SnapshotTableModel::rowCount(const QModelIndex &parent) const {
13 return static_cast<int>(snapshots.size());
14}
15
16int SnapshotTableModel::columnCount(const QModelIndex &parent) const {
17 return 8; // time, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z, temp
18}
19
20QVariant SnapshotTableModel::data(const QModelIndex &index, int role) const {
21 if (!index.isValid() || role != Qt::DisplayRole) return {};
22 const auto& s = snapshots[index.row()];
23
24 switch (index.column()) {
25 case 0: return s.time;
26 case 1: return s.position.x;
27 case 2: return s.position.y;
28 case 3: return s.position.z;
29 case 4: return s.velocity.x;
30 case 5: return s.velocity.y;
31 case 6: return s.velocity.z;
32 case 7: return s.temperature;
33 }
34 return {};
35}
36
37QVariant SnapshotTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
38 if (role != Qt::DisplayRole || orientation != Qt::Horizontal) return {};
39 switch (section) {
40 case 0: return QStringLiteral("Time (s)");
41 case 1: return QStringLiteral("Pos X");
42 case 2: return QStringLiteral("Pos Y");
43 case 3: return QStringLiteral("Pos Z");
44 case 4: return QStringLiteral("Vel X");
45 case 5: return QStringLiteral("Vel Y");
46 case 6: return QStringLiteral("Vel Z");
47 case 7: return QStringLiteral("Temp (K)");
48 }
49 return {};
50}
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent) const override
SnapshotTableModel(QObject *parent=nullptr)
int columnCount(const QModelIndex &parent) const override
void setSnapshots(const std::vector< ObjectSnapshot > &snaps)
QVariant data(const QModelIndex &index, int role) const override