Plasma-workspace

limitedrowcountproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "limitedrowcountproxymodel_p.h"
8
9#include "notifications.h"
10
11using namespace NotificationManager;
12
13LimitedRowCountProxyModel::LimitedRowCountProxyModel(QObject *parent)
14 : QSortFilterProxyModel(parent)
15{
16}
17
18LimitedRowCountProxyModel::~LimitedRowCountProxyModel() = default;
19
20void LimitedRowCountProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
21{
22 if (sourceModel == QAbstractProxyModel::sourceModel()) {
23 return;
24 }
25
27 disconnect(QAbstractProxyModel::sourceModel(), nullptr, this, nullptr);
28 }
29
31
32 if (sourceModel) {
33 connect(sourceModel, &QAbstractItemModel::rowsInserted, this, &LimitedRowCountProxyModel::invalidateFilter);
34 connect(sourceModel, &QAbstractItemModel::rowsMoved, this, &LimitedRowCountProxyModel::invalidateFilter);
35 connect(sourceModel, &QAbstractItemModel::rowsRemoved, this, &LimitedRowCountProxyModel::invalidateFilter);
36 }
37}
38
39int LimitedRowCountProxyModel::limit() const
40{
41 return m_limit;
42}
43
44void LimitedRowCountProxyModel::setLimit(int limit)
45{
46 if (m_limit != limit) {
47 m_limit = limit;
48 invalidateFilter();
49 Q_EMIT limitChanged();
50 }
51}
52
53bool LimitedRowCountProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
54{
55 if (source_parent.isValid()) {
56 return true;
57 }
58
59 if (m_limit > 0) {
60 return source_row < m_limit;
61 }
62
63 return true;
64}
65
66#include "moc_limitedrowcountproxymodel_p.cpp"
void rowsInserted(const QModelIndex &parent, int first, int last)
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
void rowsRemoved(const QModelIndex &parent, int first, int last)
bool isValid() const const
virtual void setSourceModel(QAbstractItemModel *sourceModel) override
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.