forked from ILightburn/KLM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tablemodelpaths.cpp
90 lines (79 loc) · 2.15 KB
/
tablemodelpaths.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
#include "tablemodelpaths.h"
TableModelPaths::TableModelPaths(QObject *parent)
: QAbstractTableModel(parent)
{
}
QVariant TableModelPaths::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
switch (section) {
case PATH:
return "Path";
case PATTERN:
return "Naming Pattern";
}
}
return QVariant();
}
int TableModelPaths::rowCount([[maybe_unused]]const QModelIndex &parent) const
{
return m_paths.size();
}
int TableModelPaths::columnCount([[maybe_unused]]const QModelIndex &parent) const
{
return 2;
}
QVariant TableModelPaths::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole)
{
switch (index.column()) {
case PATH:
return m_paths.at(index.row())->path();
case PATTERN:
return m_paths.at(index.row())->pattern().name;
}
}
return QVariant();
}
void TableModelPaths::addPath(QSharedPointer<KaraokePath> path)
{
emit layoutAboutToBeChanged();
m_paths.push_back(path);
emit layoutChanged();
}
const KLM::KaraokePathList &TableModelPaths::paths() const
{
return m_paths;
}
bool TableModelPaths::exists(const QString &path)
{
auto it = std::find_if(m_paths.begin(), m_paths.end(), [path] (auto kPath) {
return (kPath->path() == path);
});
if (it == m_paths.end())
return false;
return true;
}
void TableModelPaths::remove(const QString &path)
{
emit layoutAboutToBeChanged();
m_paths.erase(std::remove_if(m_paths.begin(), m_paths.end(), [path] (auto kPath) {
return (kPath->path() == path);
}), m_paths.end());
emit layoutChanged();
}
void TableModelPaths::modifyNamingPattern(const QString &path, NamingPattern newPattern)
{
auto it = std::find_if(m_paths.begin(), m_paths.end(), [path] (auto kPath) {
return (kPath->path() == path);
});
if (it == m_paths.end())
return;
emit layoutAboutToBeChanged();
it->get()->setPattern(newPattern);
emit layoutChanged();
}