Repository navigation
Expand file tree
/
Copy pathtableviewmodel.cpp
More file actions
157 lines (133 loc) · 3.42 KB
/
Copy pathtableviewmodel.cpp
File metadata and controls
157 lines (133 loc) · 3.42 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "tableviewmodel.h"
#include <QDebug>
TableViewModel::TableViewModel(QObject *parent)
{
Q_UNUSED(parent);
}
int TableViewModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return arrBooksName.size();
}
int TableViewModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant TableViewModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
QVariant value;
if (role == Qt::DisplayRole /*|| role == Qt::EditRole*/)
{
switch (index.column())
{
case 0:
{
value = arrBooksName.at(index.row());
return value;
}
case 1:
{
value = arrBooksAuth.at(index.row());
return value;
}
case 2:
{
value = arrCaseNumber.at(index.row());
return value;
}
}
}
return QVariant();
}
Qt::ItemFlags TableViewModel::flags(const QModelIndex &index) const
{
if(!index.isValid())
return Qt::NoItemFlags;
else if (index.column() != 0)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
QVariant TableViewModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role != Qt::DisplayRole)
{
return QVariant();
}
else if (orientation == Qt::Horizontal)
{
if(section==0)
{
return QString("Название кгини");
}
else if(section==1)
{
return QString("Автор кгини");
}
else if(section==2)
{
return QString("Номер шкафа");
}
}
else if (orientation == Qt::Vertical)
{
return section + 1;
}
else
{
return QVariant();
}
}
bool TableViewModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(!index.isValid())
return false;
if (role == Qt::EditRole && index.column() == 0)
{
if (value == "")
{
_nameOfDelBook = arrBooksName.at(index.row());
_numberOfCaseDelBook = arrCaseNumber.at(index.row()).toInt();
emit dataIsChanged(_nameOfDelBook, _numberOfCaseDelBook);
//emit dataChanged(index,index);
emit layoutChanged();
return true;
}
}
return false;
}
QString TableViewModel::nameOfDelBook() const
{
return _nameOfDelBook;
}
int TableViewModel::numberOfCaseDelBook() const
{
return _numberOfCaseDelBook;
}
void TableViewModel::setLibrary(std::vector<BookCase *> _arrCase)
{
arrBooksName.clear();
arrBooksAuth.clear();
arrCaseNumber.clear();
for(auto &var : _arrCase)
{
for(auto &a : var->getArrBook()) {
arrCaseNumber.append(QString::number(var->getCaseBookNumber()));
arrBooksName.append(a->getBookName());
arrBooksAuth.append(a->getBookAuthor());
}
}
emit layoutChanged();
}
/*
void TableViewModel::fillVector()
{
libr.writeBooksMethod(_dataArr);
qDebug() << _dataArr;
emit layoutChanged();
}
*/