| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2009-03-25 |
| 7 |
* Description : Tree View for album models |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 10 |
* SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com> |
| 11 |
* SPDX-FileCopyrightText: 2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com> |
| 12 |
* SPDX-FileCopyrightText: 2014 by Michael G. Hansen <mike at mghansen dot de> |
| 13 |
* SPDX-FileCopyrightText: 2009-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 14 |
* |
| 15 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 16 |
* |
| 17 |
* ============================================================ */ |
| 18 |
|
| 19 |
#include "abstractcountingalbumtreeview.h" |
| 20 |
|
| 21 |
// Local includes |
| 22 |
|
| 23 |
#include "abstractalbumtreeview_p.h" |
| 24 |
|
| 25 |
namespace Digikam |
| 26 |
{ |
| 27 |
|
| 28 |
AbstractCountingAlbumTreeView::AbstractCountingAlbumTreeView(QWidget* const parent, Flags flags) |
| 29 |
: AbstractAlbumTreeView(parent, flags & ~CreateDefaultFilterModel) |
| 30 |
{ |
| 31 |
if (flags & CreateDefaultFilterModel) |
| 32 |
{ |
| 33 |
this->setAlbumFilterModel(new AlbumFilterModel(this)); |
| 34 |
} |
| 35 |
|
| 36 |
if (!(flags & AlwaysShowInclusiveCounts)) |
| 37 |
{ |
| 38 |
connect(this, SIGNAL(expanded(QModelIndex)), |
| 39 |
this, SLOT(slotExpanded(QModelIndex))); |
| 40 |
|
| 41 |
connect(this, SIGNAL(collapsed(QModelIndex)), |
| 42 |
this, SLOT(slotCollapsed(QModelIndex))); |
| 43 |
} |
| 44 |
|
| 45 |
if (flags & ShowCountAccordingToSettings) |
| 46 |
{ |
| 47 |
connect(ApplicationSettings::instance(), SIGNAL(setupChanged()), |
| 48 |
this, SLOT(setShowCountFromSettings())); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
void AbstractCountingAlbumTreeView::setAlbumModel(AbstractCountingAlbumModel* const model) |
| 53 |
{ |
| 54 |
AbstractAlbumTreeView::setAlbumModel(model); |
| 55 |
|
| 56 |
if (m_flags & ShowCountAccordingToSettings) |
| 57 |
{ |
| 58 |
setShowCountFromSettings(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void AbstractCountingAlbumTreeView::setAlbumFilterModel(AlbumFilterModel* const filterModel) |
| 63 |
{ |
| 64 |
AbstractAlbumTreeView::setAlbumFilterModel(filterModel); |
| 65 |
|
| 66 |
// Initialize expanded/collapsed showCount state |
| 67 |
|
| 68 |
updateShowCountState(QModelIndex(), true); |
| 69 |
} |
| 70 |
|
| 71 |
void AbstractCountingAlbumTreeView::updateShowCountState(const QModelIndex& index, bool recurse) |
| 72 |
{ |
| 73 |
if (isExpanded(index) && !(m_flags & AlwaysShowInclusiveCounts)) |
| 74 |
{ |
| 75 |
slotExpanded(index); |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
slotCollapsed(index); |
| 80 |
} |
| 81 |
|
| 82 |
if (recurse) |
| 83 |
{ |
| 84 |
const int rows = m_albumFilterModel->rowCount(index); |
| 85 |
|
| 86 |
for (int i = 0 ; i < rows ; ++i) |
| 87 |
{ |
| 88 |
updateShowCountState(m_albumFilterModel->index(i, 0, index), true); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
void AbstractCountingAlbumTreeView::slotCollapsed(const QModelIndex& index) |
| 94 |
{ |
| 95 |
static_cast<AbstractCountingAlbumModel*>(m_albumModel)->includeChildrenCount(m_albumFilterModel->mapToSourceAlbumModel(index)); |
| 96 |
} |
| 97 |
|
| 98 |
void AbstractCountingAlbumTreeView::slotExpanded(const QModelIndex& index) |
| 99 |
{ |
| 100 |
static_cast<AbstractCountingAlbumModel*>(m_albumModel)->excludeChildrenCount(m_albumFilterModel->mapToSourceAlbumModel(index)); |
| 101 |
} |
| 102 |
|
| 103 |
void AbstractCountingAlbumTreeView::setShowCountFromSettings() |
| 104 |
{ |
| 105 |
static_cast<AbstractCountingAlbumModel*>(m_albumModel)->setShowCount(ApplicationSettings::instance()->getShowFolderTreeViewItemsCount()); |
| 106 |
} |
| 107 |
|
| 108 |
void AbstractCountingAlbumTreeView::rowsInserted(const QModelIndex& parent, int start, int end) |
| 109 |
{ |
| 110 |
AbstractAlbumTreeView::rowsInserted(parent, start, end); |
| 111 |
|
| 112 |
// initialize showCount state when items are added |
| 113 |
|
| 114 |
for (int i = start ; i <= end ; ++i) |
| 115 |
{ |
| 116 |
updateShowCountState(m_albumFilterModel->index(i, 0, parent), false); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
} // namespace Digikam |
| 121 |
|
| 122 |
#include "moc_abstractcountingalbumtreeview.cpp" |