-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieTableModel.cpp
116 lines (97 loc) · 2.74 KB
/
MovieTableModel.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Created by Panaite Dorinel on 24/05/2017.
//
#include "MovieTableModel.h"
#include <string>
using namespace std;
QVariant MovieTableModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
int col = index.column();
std::vector<Movie> genes = this->wlist->getArray();
if (row < 0 || row >= genes.size())
return QVariant{};
Movie currentMovie = genes[row];
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
switch (col)
{
case 0:
return QString::fromStdString(currentMovie.getTitle());
case 1:
return QString::fromStdString(currentMovie.getGenre());
case 2:
return QString::fromStdString(currentMovie.getTrailer());
}
}
// if (role == Qt::FontRole)
// {
// QFont f{ "Times", 15, 10 };
// return f;
// }
// if (row % 2 == 0)
// {
// if (role == Qt::BackgroundRole)
// {
// QBrush brush{ QColor{ Qt::green } };
// return brush;
// }
// }
return QVariant();
}
QVariant MovieTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole)
{
if (orientation == Qt::Horizontal)
{
switch (section)
{
case 0:
return QString{ "Name" };
case 1:
return QString{ "Genre" };
case 2:
return QString{ "Trailer" };
default:
break;
}
}
}
// if (role == Qt::FontRole)
// {
// QFont font("Times", 15, 10, true);
// font.setBold(true);
// font.setItalic(false);
// return font;
// }
return QVariant{};
}
Qt::ItemFlags MovieTableModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
}
//bool MovieTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
//{
// if (!index.isValid() || role != Qt::EditRole)
// return false;
// // set the new data to the gene
// int movieIndex = index.row();
// vector<Movie> movies = this->wlist->getArray();
// Movie currentMovie = movies[movieIndex];
// switch (index.column())
// {
// case 0:
// currentGene.setOrganismName(value.toString().toStdString());
// break;
// case 1:
// currentGene.setName(value.toString().toStdString());
// break;
// case 2:
// currentGene.setFunction(value.toString().toStdString());
// }
// this->repo.updateGene(movieIndex, currentGene);
// // emit the dataChanged signal
// emit dataChanged(index, index);
// return true;
//}