forked from saa7go/qDebDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortproxymodel.cpp
79 lines (71 loc) · 2.78 KB
/
sortproxymodel.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
/* This file is part of qDebDownloader.
*
* Copyright (c) 2011 - Christian Kurniawan Ginting S. <saa7_go@terralinux.org>
*
* qDebDownloader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qDebDownloader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qDebDownloader. If not, see <http://www.gnu.org/licenses/>. */
#include "sortproxymodel.h"
#include "downloadtablemodel.h"
#include <QDebug>
SortProxyModel::SortProxyModel(QObject *parent) :
QSortFilterProxyModel(parent), m_hideUnchecked(false)
{
}
SortProxyModel::~SortProxyModel()
{
qDebug() << this << "destroyed!";
}
bool SortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
int column = left.column();
QVariant leftData, rightData;
if(column == DownloadTableModel::COL_CHECHED) {
leftData = sourceModel()->data(left, Qt::EditRole);
rightData = sourceModel()->data(right, Qt::EditRole);
return leftData.toInt() < rightData.toInt();
}
if(column == DownloadTableModel::COL_PACKAGE_NAME) {
leftData = sourceModel()->data(left, Qt::DisplayRole);
rightData = sourceModel()->data(right, Qt::DisplayRole);
return leftData.toString().toAscii() < rightData.toString().toAscii();
}
else if(column == DownloadTableModel::COL_PROGRESS) {
leftData = sourceModel()->data(left, Qt::EditRole);
rightData = sourceModel()->data(right, Qt::EditRole);
return leftData.toInt() < rightData.toInt();
}
else if (column == DownloadTableModel::COL_CURRENT_SIZE || column == DownloadTableModel::COL_TARGET_SIZE){ // semoga column 5 & 6
leftData = sourceModel()->data(left, Qt::EditRole);
rightData = sourceModel()->data(right, Qt::EditRole);
return leftData.toLongLong() < rightData.toLongLong();
}
else {
qDebug() << "ELSE!";
return QSortFilterProxyModel::lessThan(left, right);
}
}
bool SortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if(m_hideUnchecked == false)
return true;
QModelIndex idx = sourceModel()->index(source_row, DownloadTableModel::COL_CHECHED, source_parent);
return idx.data(Qt::CheckStateRole).toBool();
}
void SortProxyModel::setHideUncheked(bool val)
{
if(m_hideUnchecked == val)
return;
qDebug() << "reset";
m_hideUnchecked = val;
invalidateFilter();
}