File indexing completed on 2025-01-19 03:53:21
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-03-25 0007 * Description : Tree View for album models 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com> 0011 * SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0012 * SPDX-FileCopyrightText: 2014 by Michael G. Hansen <mike at mghansen dot de> 0013 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0014 * 0015 * SPDX-License-Identifier: GPL-2.0-or-later 0016 * 0017 * ============================================================ */ 0018 0019 #include "abstractcountingalbumtreeview.h" 0020 0021 // Local includes 0022 0023 #include "abstractalbumtreeview_p.h" 0024 0025 namespace Digikam 0026 { 0027 0028 AbstractCountingAlbumTreeView::AbstractCountingAlbumTreeView(QWidget* const parent, Flags flags) 0029 : AbstractAlbumTreeView(parent, flags & ~CreateDefaultFilterModel) 0030 { 0031 if (flags & CreateDefaultFilterModel) 0032 { 0033 setAlbumFilterModel(new AlbumFilterModel(this)); 0034 } 0035 0036 if (!(flags & AlwaysShowInclusiveCounts)) 0037 { 0038 connect(this, SIGNAL(expanded(QModelIndex)), 0039 this, SLOT(slotExpanded(QModelIndex))); 0040 0041 connect(this, SIGNAL(collapsed(QModelIndex)), 0042 this, SLOT(slotCollapsed(QModelIndex))); 0043 } 0044 0045 if (flags & ShowCountAccordingToSettings) 0046 { 0047 connect(ApplicationSettings::instance(), SIGNAL(setupChanged()), 0048 this, SLOT(setShowCountFromSettings())); 0049 } 0050 } 0051 0052 void AbstractCountingAlbumTreeView::setAlbumModel(AbstractCountingAlbumModel* const model) 0053 { 0054 AbstractAlbumTreeView::setAlbumModel(model); 0055 0056 if (m_flags & ShowCountAccordingToSettings) 0057 { 0058 setShowCountFromSettings(); 0059 } 0060 } 0061 0062 void AbstractCountingAlbumTreeView::setAlbumFilterModel(AlbumFilterModel* const filterModel) 0063 { 0064 AbstractAlbumTreeView::setAlbumFilterModel(filterModel); 0065 0066 // Initialize expanded/collapsed showCount state 0067 0068 updateShowCountState(QModelIndex(), true); 0069 } 0070 0071 void AbstractCountingAlbumTreeView::updateShowCountState(const QModelIndex& index, bool recurse) 0072 { 0073 if (isExpanded(index) && !(m_flags & AlwaysShowInclusiveCounts)) 0074 { 0075 slotExpanded(index); 0076 } 0077 else 0078 { 0079 slotCollapsed(index); 0080 } 0081 0082 if (recurse) 0083 { 0084 const int rows = m_albumFilterModel->rowCount(index); 0085 0086 for (int i = 0 ; i < rows ; ++i) 0087 { 0088 updateShowCountState(m_albumFilterModel->index(i, 0, index), true); 0089 } 0090 } 0091 } 0092 0093 void AbstractCountingAlbumTreeView::slotCollapsed(const QModelIndex& index) 0094 { 0095 static_cast<AbstractCountingAlbumModel*>(m_albumModel)->includeChildrenCount(m_albumFilterModel->mapToSourceAlbumModel(index)); 0096 } 0097 0098 void AbstractCountingAlbumTreeView::slotExpanded(const QModelIndex& index) 0099 { 0100 static_cast<AbstractCountingAlbumModel*>(m_albumModel)->excludeChildrenCount(m_albumFilterModel->mapToSourceAlbumModel(index)); 0101 } 0102 0103 void AbstractCountingAlbumTreeView::setShowCountFromSettings() 0104 { 0105 static_cast<AbstractCountingAlbumModel*>(m_albumModel)->setShowCount(ApplicationSettings::instance()->getShowFolderTreeViewItemsCount()); 0106 } 0107 0108 void AbstractCountingAlbumTreeView::rowsInserted(const QModelIndex& parent, int start, int end) 0109 { 0110 AbstractAlbumTreeView::rowsInserted(parent, start, end); 0111 0112 // initialize showCount state when items are added 0113 0114 for (int i = start ; i <= end ; ++i) 0115 { 0116 updateShowCountState(m_albumFilterModel->index(i, 0, parent), false); 0117 } 0118 } 0119 0120 } // namespace Digikam 0121 0122 #include "moc_abstractcountingalbumtreeview.cpp"