File indexing completed on 2024-04-28 05:34:17

0001 // SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
0002 //
0003 // SPDX-License-Identifier: LGPL-2.1-or-later
0004 
0005 #include "passwordsortproxymodel.h"
0006 #include "passwordsmodel.h"
0007 
0008 #include <QDebug>
0009 
0010 using namespace PlasmaPass;
0011 
0012 PasswordSortProxyModel::PasswordSortProxyModel(QObject *parent)
0013     : QSortFilterProxyModel(parent)
0014 {
0015     sort(0); // enable sorting
0016 }
0017 
0018 bool PasswordSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
0019 {
0020     const auto typeLeft = static_cast<PasswordsModel::EntryType>(source_left.data(PasswordsModel::EntryTypeRole).toInt());
0021     const auto typeRight = static_cast<PasswordsModel::EntryType>(source_right.data(PasswordsModel::EntryTypeRole).toInt());
0022 
0023     // Folders first
0024     if (typeLeft != typeRight) {
0025         return typeLeft == PasswordsModel::FolderEntry;
0026     }
0027 
0028     return QSortFilterProxyModel::lessThan(source_left, source_right);
0029 }
0030 
0031 #include "moc_passwordsortproxymodel.cpp"