-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppmodel.cpp
120 lines (87 loc) · 3.04 KB
/
cppmodel.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
#include "cppmodel.h"
#include "settings.h"
CppModel::CppModel(QObject *parent):
QAbstractListModel(parent)
{
}
int CppModel::rowCount(const QModelIndex &parent) const //переопределим возврат количества строк листа
{
if (parent.isValid()) {return 0;}
return m_number.size();
}
QVariant CppModel::data(const QModelIndex &index, int role) const //определим возврат данных о ролях элемента
{
if (!index.isValid()) {return QVariant();}
switch (role) {
case nameRole:
return m_name.at(index.row());
case colorRole:
return m_color.at(index.row());
case numberRole:
return m_number.at(index.row()+".");
case iconRole:
return m_icon.at(index.row());
case pathRole:
return m_path.at(index.row());
case markRole:
return m_mark.at(index.row());
default:
return QVariant();
}
}
QHash<int, QByteArray> CppModel::roleNames() const //roleNames хранит список имён ролей доступных из делегата. Переопредилим их имена в более удобные
{
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[nameRole] = "name";
roles[iconRole] = "icon";
roles[numberRole] = "number";
roles[colorRole] = "color";
roles[pathRole] = "path";
roles[markRole] = "mark";
return roles;
}
void CppModel::addElement(int indx)
{
beginInsertRows(QModelIndex(), m_number.size(), m_number.size());
m_name.append(indx);
m_icon.append(indx);
m_number.append(indx);
m_color.append(indx);
m_path.append(indx);
m_mark.append(indx);
endInsertRows();
//QModelIndex index = createIndex(0, 0, static_cast<void *>(0));
//emit dataChanged(index, index);
}
//currentPL, i, shuffle_state
QString CppModel::getName(int indx)
{
QString currentpl = Settings::viewPL(Settings::getCurrentPL(), indx, Settings::getShuffleState());
return currentpl;
}
QString CppModel::getIcon(int indx)
{
tmpstr = Settings::loadnamefromPL(Settings::setLastTrack(Settings::getShuffleState()));
QString currenticon = Settings::viewPL(Settings::getCurrentPL(), indx, Settings::getShuffleState()) == tmpstr ? (Settings::getStopState() == true ? "curstop.png" : Settings::getPauseState() == false ? "curplay.png" : "curpause.png") : "audio.png";
return currenticon;
}
QString CppModel::getNumber(int indx)
{
tmpstr = QString::number(indx);
return tmpstr;
}
QString CppModel::getColor(int indx)
{
tmpstr = Settings::loadnamefromPL(Settings::setLastTrack(Settings::getShuffleState()));
QString currentcolor = Settings::viewPL(Settings::getCurrentPL(), indx, Settings::getShuffleState()) == tmpstr ? "#22acee48" : "#00000000";
return currentcolor;
}
QString CppModel::getPath(int indx)
{
tmpstr = Settings::getPathOfTrack(Settings::getCurrentPL(), indx, Settings::getShuffleState());
return tmpstr;
}
QString CppModel::getMark(int indx)
{
return "mark_next.png";
}