Add a count property

Fixes #3 and #5
This commit is contained in:
oKcerG 2016-05-02 22:28:15 +02:00
parent eaff2aa0b9
commit c5d9e46917
2 changed files with 14 additions and 0 deletions

View File

@ -9,9 +9,18 @@ QQmlSortFilterProxyModel::QQmlSortFilterProxyModel(QObject *parent) :
{
connect(this, &QAbstractProxyModel::sourceModelChanged, this, &QQmlSortFilterProxyModel::updateRoles);
connect(this, &QAbstractItemModel::modelReset, this, &QQmlSortFilterProxyModel::updateRoles);
connect(this, &QAbstractItemModel::rowsInserted, this, &QQmlSortFilterProxyModel::countChanged);
connect(this, &QAbstractItemModel::rowsRemoved, this, &QQmlSortFilterProxyModel::countChanged);
connect(this, &QAbstractItemModel::modelReset, this, &QQmlSortFilterProxyModel::countChanged);
connect(this, &QAbstractItemModel::layoutChanged, this, &QQmlSortFilterProxyModel::countChanged);
setDynamicSortFilter(true);
}
int QQmlSortFilterProxyModel::count() const
{
return rowCount();
}
QString QQmlSortFilterProxyModel::filterRoleName() const
{
return m_filterRoleName;

View File

@ -7,6 +7,7 @@
class QQmlSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QString filterRoleName READ filterRoleName WRITE setFilterRoleName NOTIFY filterRoleNameChanged)
Q_PROPERTY(QString filterPattern READ filterPattern WRITE setFilterPattern NOTIFY filterPatternChanged)
Q_PROPERTY(PatternSyntax filterPatternSyntax READ filterPatternSyntax WRITE setFilterPatternSyntax NOTIFY filterPatternSyntaxChanged)
@ -29,6 +30,8 @@ public:
QQmlSortFilterProxyModel(QObject* parent = 0);
int count() const;
QString filterRoleName() const;
void setFilterRoleName(QString filterRoleName);
@ -53,6 +56,8 @@ public:
void setSortExpression(QQmlScriptString compareScriptString);
signals:
void countChanged();
void filterRoleNameChanged();
void filterPatternSyntaxChanged();
void filterPatternChanged();