KLdap

ldapsortproxymodel.cpp
1// SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org>
2// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3
4#include "ldapsortproxymodel.h"
5#include "ldapactivitiesabstract.h"
6#include "ldapmodel.h"
7using namespace KLDAPCore;
8LdapSortProxyModel::LdapSortProxyModel(QObject *parent)
10{
11}
12
13LdapSortProxyModel::~LdapSortProxyModel() = default;
14
15bool LdapSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
16{
17 if (mLdapActivitiesAbstract && mEnablePlasmaActivities) {
18 const bool enableActivities = sourceModel()->index(source_row, LdapModel::EnabledActivitiesRole).data().toBool();
19 if (enableActivities) {
20 const auto activities = sourceModel()->index(source_row, LdapModel::Activities).data().toStringList();
21 return mLdapActivitiesAbstract->filterAcceptsRow(activities);
22 }
23 }
24 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
25}
26
27bool LdapSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
28{
29 if (!sourceModel()) {
30 return false;
31 }
32 if (source_left.isValid() && source_right.isValid()) {
33 const int left = sourceModel()->index(source_left.row(), LdapModel::Index).data().toInt();
34 const int right = sourceModel()->index(source_right.row(), LdapModel::Index).data().toInt();
35 return left < right;
36 } else {
37 return false;
38 }
39 return true;
40}
41
42LdapActivitiesAbstract *LdapSortProxyModel::ldapActivitiesAbstract() const
43{
44 return mLdapActivitiesAbstract;
45}
46
47void LdapSortProxyModel::setLdapActivitiesAbstract(LdapActivitiesAbstract *newIdentityActivitiesAbstract)
48{
49 if (mLdapActivitiesAbstract != newIdentityActivitiesAbstract) {
50 mLdapActivitiesAbstract = newIdentityActivitiesAbstract;
51 connect(mLdapActivitiesAbstract, &LdapActivitiesAbstract::activitiesChanged, this, &LdapSortProxyModel::invalidateFilter);
53 }
54}
55
56bool LdapSortProxyModel::enablePlasmaActivities() const
57{
58 return mEnablePlasmaActivities;
59}
60
61void LdapSortProxyModel::setEnablePlasmaActivities(bool newEnablePlasmaActivities)
62{
63 if (mEnablePlasmaActivities != newEnablePlasmaActivities) {
64 mEnablePlasmaActivities = newEnablePlasmaActivities;
66 }
67}
68
69#include "moc_ldapsortproxymodel.cpp"
The LdapActivitiesAbstract class.
bool isValid() const const
int row() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.