-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionTableModel.cpp
More file actions
40 lines (33 loc) · 1.16 KB
/
SessionTableModel.cpp
File metadata and controls
40 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "SessionTableModel.h"
#include <iomanip>
#include <sstream>
#include <QString>
SessionTableModel::SessionTableModel(QObject* parent)
: QAbstractTableModel(parent), movie(nullptr) {}
void SessionTableModel::setMovie(Movie* m) {
beginResetModel();
movie = m;
endResetModel();
}
int SessionTableModel::rowCount(const QModelIndex &) const {
return movie ? movie->getSessionCount() : 0;
}
int SessionTableModel::columnCount(const QModelIndex &) const {
return 1;
}
QVariant SessionTableModel::data(const QModelIndex &index, int role) const {
if (!movie || !index.isValid() || role != Qt::DisplayRole) return {};
std::vector<std::tm> sessions = movie->getSessionTimes();
if (index.row() >= 0 && index.row() < static_cast<int>(sessions.size())) {
std::ostringstream oss;
oss << std::put_time(&sessions[index.row()], "%Y-%m-%d %H:%M");
return QString::fromStdString(oss.str());
}
return {};
}
QVariant SessionTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
return "Date & Time";
}
return {};
}