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 setFilterKeyColumn(LdapModel::Index);
12}
13
14LdapSortProxyModel::~LdapSortProxyModel() = default;
15
16bool LdapSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
17{
18 if (mLdapActivitiesAbstract && mEnablePlasmaActivities) {
19 const bool enableActivities = sourceModel()->index(source_row, LdapModel::EnabledActivitiesRole).data().toBool();
20 if (enableActivities) {
21 const auto activities = sourceModel()->index(source_row, 0).data(LdapModel::Activities).toStringList();
22 return mLdapActivitiesAbstract->filterAcceptsRow(activities);
23 }
24 }
25 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
26}
27
28bool LdapSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
29{
30 if (!sourceModel()) {
31 return false;
32 }
33 if (source_left.isValid() && source_right.isValid()) {
34 const int left = sourceModel()->data(source_left, LdapModel::Index).toInt();
35 const int right = sourceModel()->data(source_right, LdapModel::Index).toInt();
36 return left < right;
37 } else {
38 return false;
39 }
40 return true;
41}
42
43LdapActivitiesAbstract *LdapSortProxyModel::ldapActivitiesAbstract() const
44{
45 return mLdapActivitiesAbstract;
46}
47
48void LdapSortProxyModel::setLdapActivitiesAbstract(LdapActivitiesAbstract *newIdentityActivitiesAbstract)
49{
50 if (mLdapActivitiesAbstract != newIdentityActivitiesAbstract) {
51 mLdapActivitiesAbstract = newIdentityActivitiesAbstract;
52 connect(mLdapActivitiesAbstract, &LdapActivitiesAbstract::activitiesChanged, this, &LdapSortProxyModel::invalidateFilter);
54 }
55}
56
57bool LdapSortProxyModel::enablePlasmaActivities() const
58{
59 return mEnablePlasmaActivities;
60}
61
62void LdapSortProxyModel::setEnablePlasmaActivities(bool newEnablePlasmaActivities)
63{
64 if (mEnablePlasmaActivities != newEnablePlasmaActivities) {
65 mEnablePlasmaActivities = newEnablePlasmaActivities;
67 }
68}
69
70#include "moc_ldapsortproxymodel.cpp"
The LdapActivitiesAbstract class.
bool isValid() 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 Mon Nov 4 2024 16:34:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.