-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathhiddentablemodel.cpp
90 lines (73 loc) · 3.24 KB
/
hiddentablemodel.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 "library/hiddentablemodel.h"
#include "library/dao/trackschema.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
HiddenTableModel::HiddenTableModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager)
: BaseSqlTableModel(parent, pTrackCollectionManager, "mixxx.db.model.missing") {
setTableModel();
}
HiddenTableModel::~HiddenTableModel() {
}
void HiddenTableModel::setTableModel() {
const QString tableName("hidden_songs");
QStringList columns;
columns << "library." + LIBRARYTABLE_ID;
QSqlQuery query(m_database);
query.prepare(
"CREATE TEMPORARY VIEW IF NOT EXISTS " + tableName +
" AS SELECT " + columns.join(",") +
" FROM library "
"INNER JOIN track_locations "
"ON library.location=track_locations.id "
"WHERE mixxx_deleted=1");
if (!query.exec()) {
qDebug() << query.executedQuery() << query.lastError();
}
//Print out any SQL error, if there was one.
if (query.lastError().isValid()) {
qDebug() << __FILE__ << __LINE__ << query.lastError();
}
QStringList tableColumns;
tableColumns << LIBRARYTABLE_ID;
setTable(tableName,
LIBRARYTABLE_ID,
tableColumns,
m_pTrackCollectionManager->internalCollection()->getTrackSource());
setDefaultSort(fieldIndex("artist"), Qt::AscendingOrder);
setSearch("");
}
void HiddenTableModel::purgeTracks(const QModelIndexList& indices) {
m_pTrackCollectionManager->purgeTracks(getTrackRefs(indices));
// TODO(rryan) : do not select, instead route event to BTC and notify from
// there.
select(); // Repopulate the data model.
}
void HiddenTableModel::unhideTracks(const QModelIndexList& indices) {
QList<TrackId> trackIds;
foreach (QModelIndex index, indices) {
trackIds.append(getTrackId(index));
}
m_pTrackCollectionManager->unhideTracks(trackIds);
// TODO(rryan) : do not select, instead route event to BTC and notify from there.
select(); // Repopulate the data model.
}
bool HiddenTableModel::isColumnInternal(int column) {
return column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH);
}
// Override flags from BaseSqlModel since we don't want edit this model
Qt::ItemFlags HiddenTableModel::flags(const QModelIndex& index) const {
return readOnlyFlags(index);
}
TrackModel::CapabilitiesFlags HiddenTableModel::getCapabilities() const {
return TRACKMODELCAPS_PURGE | TRACKMODELCAPS_UNHIDE;
}