53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
|
#ifndef SORTER_H
|
||
|
#define SORTER_H
|
||
|
|
||
|
#include <QObject>
|
||
|
|
||
|
namespace qqsfpm {
|
||
|
|
||
|
class QQmlSortFilterProxyModel;
|
||
|
|
||
|
class Sorter : public QObject
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
||
|
Q_PROPERTY(bool ascendingOrder READ ascendingOrder WRITE setAscendingOrder NOTIFY sortOrderChanged)
|
||
|
Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
|
||
|
|
||
|
public:
|
||
|
Sorter(QObject* parent = nullptr);
|
||
|
virtual ~Sorter() = 0;
|
||
|
|
||
|
bool enabled() const;
|
||
|
void setEnabled(bool enabled);
|
||
|
|
||
|
bool ascendingOrder() const;
|
||
|
void setAscendingOrder(bool ascendingOrder);
|
||
|
|
||
|
Qt::SortOrder sortOrder() const;
|
||
|
void setSortOrder(Qt::SortOrder sortOrder);
|
||
|
|
||
|
int compareRows(const QModelIndex& source_left, const QModelIndex& source_right, const QQmlSortFilterProxyModel& proxyModel) const;
|
||
|
|
||
|
virtual void proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel);
|
||
|
|
||
|
Q_SIGNALS:
|
||
|
void enabledChanged();
|
||
|
void sortOrderChanged();
|
||
|
|
||
|
void invalidated();
|
||
|
|
||
|
protected:
|
||
|
virtual int compare(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
||
|
virtual bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
||
|
void invalidate();
|
||
|
|
||
|
private:
|
||
|
bool m_enabled = true;
|
||
|
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif // SORTER_H
|