syncthingtray/syncthingmodel/syncthingsortfiltermodel.h

56 lines
1.5 KiB
C
Raw Normal View History

#ifndef DATA_SYNCTHINGSORTFILTERDIRECTORYMODEL_H
#define DATA_SYNCTHINGSORTFILTERDIRECTORYMODEL_H
#include "./global.h"
#include <QSortFilterProxyModel>
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)
{
setSortCaseSensitivity(Qt::CaseInsensitive);
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSourceModel(sourceModel);
}
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