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
|
|
|
|
{
|
2019-05-04 22:17:28 +02:00
|
|
|
const auto *const sourceModel = this->sourceModel();
|
|
|
|
const auto sourceIndex = sourceModel->index(sourceRow, 0, sourceParent);
|
2018-08-15 21:49:06 +02:00
|
|
|
if (!sourceIndex.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto *const item = reinterpret_cast<FileSystemItem *>(sourceIndex.internalPointer());
|
|
|
|
if (!item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->status() == m_statusFilter || (item->status() == ItemStatus::Current && !item->counterpart() && !item->note().isEmpty())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (item->type() != ItemType::Dir) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-04 22:17:28 +02:00
|
|
|
auto child = sourceModel->index(0, 0, sourceIndex);
|
2018-08-15 21:49:06 +02:00
|
|
|
while (child.isValid()) {
|
|
|
|
if (filterAcceptsRow(child.row(), sourceIndex)) {
|
|
|
|
return true;
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
2019-05-04 22:17:28 +02:00
|
|
|
child = sourceModel->index(child.row() + 1, 0, sourceIndex);
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2018-08-15 21:49:06 +02:00
|
|
|
return false;
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2018-03-07 01:18:01 +01:00
|
|
|
} // namespace RenamingUtility
|