-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieTableModel.cpp
More file actions
39 lines (31 loc) · 1.17 KB
/
MovieTableModel.cpp
File metadata and controls
39 lines (31 loc) · 1.17 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
#include "MovieTableModel.h"
MovieTableModel::MovieTableModel(CinemaSchedule* schedule, QObject* parent)
: QAbstractTableModel(parent), schedule(schedule) {}
int MovieTableModel::rowCount(const QModelIndex &) const {
return schedule->getMovieCount();
}
int MovieTableModel::columnCount(const QModelIndex &) const {
return 4;
}
QVariant MovieTableModel::data(const QModelIndex &index, int role) const {
if (!index.isValid() || role != Qt::DisplayRole) return {};
Movie* movie = schedule->getMovieAt(index.row());
if (!movie) return {};
switch (index.column()) {
case 0: return QString::fromStdString(movie->getTitle());
case 1: return movie->getDurationMinutes();
case 2: return movie->getSessionCount();
case 3: return movie->getTotalDuration();
}
return {};
}
QVariant MovieTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role != Qt::DisplayRole || orientation != Qt::Horizontal) return {};
switch (section) {
case 0: return "Title";
case 1: return "Duration (min)";
case 2: return "Sessions";
case 3: return "Total Time";
}
return {};
}