File indexing completed on 2024-05-05 16:27:56

0001 /* SPDX-FileCopyrightText: 2003-2020 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "FlatCategoryModel.h"
0007 
0008 #include <DB/ImageDB.h>
0009 
0010 #include <KLocalizedString>
0011 
0012 Browser::FlatCategoryModel::FlatCategoryModel(const DB::CategoryPtr &category, const DB::ImageSearchInfo &info)
0013     : AbstractCategoryModel(category, info)
0014 {
0015     if (hasNoneEntry())
0016         m_items.append(DB::ImageDB::NONE());
0017 
0018     QStringList items = m_category->itemsInclCategories();
0019     items.sort();
0020 
0021     for (const QString &name : qAsConst(items)) {
0022         const int imageCount = m_images.contains(name) ? m_images[name].count : 0;
0023         const int videoCount = m_videos.contains(name) ? m_videos[name].count : 0;
0024 
0025         if (imageCount + videoCount > 0)
0026             m_items.append(name);
0027     }
0028 }
0029 
0030 int Browser::FlatCategoryModel::rowCount(const QModelIndex &index) const
0031 {
0032     if (!index.isValid())
0033         return m_items.count();
0034     else
0035         return 0;
0036 }
0037 
0038 int Browser::FlatCategoryModel::columnCount(const QModelIndex &) const
0039 {
0040     return 1;
0041 }
0042 
0043 QModelIndex Browser::FlatCategoryModel::index(int row, int column, const QModelIndex &parent) const
0044 {
0045     if (row >= 0 && row < rowCount(parent) && column >= 0 && column < columnCount(parent))
0046         return createIndex(row, column);
0047     else
0048         return QModelIndex();
0049 }
0050 
0051 QModelIndex Browser::FlatCategoryModel::parent(const QModelIndex &) const
0052 {
0053     return QModelIndex();
0054 }
0055 
0056 QString Browser::FlatCategoryModel::indexToName(const QModelIndex &index) const
0057 {
0058     return m_items[index.row()];
0059 }
0060 
0061 // vi:expandtab:tabstop=4 shiftwidth=4: