tageditor/renamingutility/filteredfilesystemitemmodel...

52 lines
1.6 KiB
C++
Raw Normal View History

2015-09-06 20:20:00 +02:00
#include "./filteredfilesystemitemmodel.h"
2015-04-22 19:33:53 +02:00
namespace RenamingUtility {
/*
TRANSLATOR RenamingUtility::FilteredFileSystemItemModel
Necessary for lupdate.
*/
2018-03-07 01:18:01 +01:00
FilteredFileSystemItemModel::FilteredFileSystemItemModel(ItemStatus statusFilter, QObject *parent)
: QSortFilterProxyModel(parent)
, m_statusFilter(statusFilter)
{
}
2015-04-22 19:33:53 +02:00
bool FilteredFileSystemItemModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
2018-03-07 01:18:01 +01:00
if (sourceIndex.isValid()) {
if (FileSystemItem *item = reinterpret_cast<FileSystemItem *>(sourceIndex.internalPointer())) {
if (item->status() == m_statusFilter) {
2015-04-22 19:33:53 +02:00
return true;
2018-03-07 01:18:01 +01:00
} else if (item->status() == ItemStatus::Current && !item->counterpart() && !item->note().isEmpty()) {
2015-04-22 19:33:53 +02:00
return true;
2018-03-07 01:18:01 +01:00
} else if (item->type() == ItemType::Dir) {
2015-04-22 19:33:53 +02:00
QModelIndex child = sourceIndex.child(0, 0);
2018-03-07 01:18:01 +01:00
while (child.isValid()) {
if (filterAcceptsRow(child.row(), sourceIndex)) {
2015-04-22 19:33:53 +02:00
return true;
}
child = sourceIndex.child(child.row() + 1, 0);
}
}
}
}
return false;
}
bool FilteredFileSystemItemModel::filterAcceptsColumn(int sourceColumn, const QModelIndex &) const
{
2018-03-07 01:18:01 +01:00
switch (m_statusFilter) {
2015-04-22 19:33:53 +02:00
case ItemStatus::Current:
return sourceColumn == 0;
case ItemStatus::New:
return sourceColumn == 1 || sourceColumn == 2;
default:
return false;
}
}
2018-03-07 01:18:01 +01:00
} // namespace RenamingUtility