File indexing completed on 2025-01-19 03:53:22

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 "albumtreeview.h"
0020 
0021 // Local includes
0022 
0023 #include "abstractalbumtreeview_p.h"
0024 
0025 namespace Digikam
0026 {
0027 
0028 AlbumTreeView::AlbumTreeView(QWidget* const parent, Flags flags)
0029     : AbstractCheckableAlbumTreeView(parent, flags)
0030 {
0031     setDragEnabled(true);
0032     setAcceptDrops(true);
0033     setRootIsDecorated(false);
0034     setDropIndicatorShown(false);
0035     setAutoExpandDelay(AUTOEXPANDDELAY);
0036 
0037     if (flags & CreateDefaultModel)
0038     {
0039         setAlbumModel(new AlbumModel(AlbumModel::IncludeRootAlbum, this));
0040     }
0041 }
0042 
0043 AlbumTreeView::~AlbumTreeView()
0044 {
0045 }
0046 
0047 void AlbumTreeView::setAlbumModel(AlbumModel* const model)
0048 {
0049     // changing model is not implemented
0050 
0051     if (m_albumModel)
0052     {
0053         return;
0054     }
0055 
0056     AbstractCheckableAlbumTreeView::setAlbumModel(model);
0057 
0058     m_dragDropHandler = albumModel()->dragDropHandler();
0059 
0060     if (!m_dragDropHandler)
0061     {
0062         m_dragDropHandler = new AlbumDragDropHandler(albumModel());
0063 
0064         model->setDragDropHandler(m_dragDropHandler);
0065     }
0066 }
0067 
0068 void AlbumTreeView::setAlbumFilterModel(CheckableAlbumFilterModel* const filterModel)
0069 {
0070     AbstractCheckableAlbumTreeView::setAlbumFilterModel(filterModel);
0071 }
0072 
0073 AlbumModel* AlbumTreeView::albumModel() const
0074 {
0075     return dynamic_cast<AlbumModel*>(m_albumModel);
0076 }
0077 
0078 PAlbum* AlbumTreeView::currentAlbum() const
0079 {
0080     return dynamic_cast<PAlbum*> (m_albumFilterModel->albumForIndex(currentIndex()));
0081 }
0082 
0083 PAlbum* AlbumTreeView::albumForIndex(const QModelIndex& index) const
0084 {
0085     return dynamic_cast<PAlbum*> (m_albumFilterModel->albumForIndex(index));
0086 }
0087 
0088 void AlbumTreeView::setCurrentAlbums(const QList<Album*>& albums, bool selectInAlbumManager)
0089 {
0090     AbstractCheckableAlbumTreeView::setCurrentAlbums(albums, selectInAlbumManager);
0091 }
0092 
0093 void AlbumTreeView::setCurrentAlbum(int albumId, bool selectInAlbumManager)
0094 {
0095     PAlbum* const album = AlbumManager::instance()->findPAlbum(albumId);
0096     setCurrentAlbums(QList<Album*>() << album, selectInAlbumManager);
0097 }
0098 
0099 } // namespace Digikam
0100 
0101 #include "moc_albumtreeview.cpp"