syncthingtray/model/syncthingsortfiltermodel.h

60 lines
1.6 KiB
C
Raw Normal View History

#ifndef DATA_SYNCTHINGSORTFILTERDIRECTORYMODEL_H
#define DATA_SYNCTHINGSORTFILTERDIRECTORYMODEL_H
#include "./global.h"
#include <QSortFilterProxyModel>
2021-06-17 00:05:03 +02:00
#include <iostream>
namespace Data {
2020-10-20 19:16:53 +02:00
enum class SyncthingSortBehavior {
KeepRawOrder,
Alphabetically,
};
2020-10-20 19:16:53 +02:00
class LIB_SYNCTHING_MODEL_EXPORT SyncthingSortFilterModel : public QSortFilterProxyModel {
Q_OBJECT
public:
2020-10-20 19:16:53 +02:00
explicit SyncthingSortFilterModel(QAbstractItemModel *sourceModel = nullptr, QObject *parent = nullptr);
2020-10-20 19:16:53 +02:00
SyncthingSortBehavior behavior() const;
void setBehavior(SyncthingSortBehavior behavior);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
2020-10-20 19:16:53 +02:00
SyncthingSortBehavior m_behavior;
};
2020-10-20 19:16:53 +02:00
inline SyncthingSortFilterModel::SyncthingSortFilterModel(QAbstractItemModel *sourceModel, QObject *parent)
: QSortFilterProxyModel(parent)
2020-10-20 19:16:53 +02:00
, m_behavior(SyncthingSortBehavior::Alphabetically)
{
2021-06-17 00:05:03 +02:00
std::cerr << ("before sfm\n");
setSortCaseSensitivity(Qt::CaseInsensitive);
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSourceModel(sourceModel);
2021-06-17 00:05:03 +02:00
std::cerr << ("after sfm\n");
}
2020-10-20 19:16:53 +02:00
inline SyncthingSortBehavior SyncthingSortFilterModel::behavior() const
{
return m_behavior;
}
2020-10-20 19:16:53 +02:00
inline void SyncthingSortFilterModel::setBehavior(SyncthingSortBehavior behavior)
{
if (behavior != m_behavior) {
m_behavior = behavior;
invalidate();
}
}
} // namespace Data
#endif // DATA_SYNCTHINGSORTFILTERDIRECTORYMODEL_H