File indexing completed on 2025-01-19 03:59:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-11-15
0007  * Description : widget item delegate for setup collection view
0008  *
0009  * SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2007-2008 by Rafael Fernández López <ereslibre at kde dot org>
0011  * SPDX-FileCopyrightText: 2008      by Kevin Ottens <ervin at kde dot org>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_DW_ITEM_DELEGATE_POOL_H
0018 #define DIGIKAM_DW_ITEM_DELEGATE_POOL_H
0019 
0020 // Qt includes
0021 
0022 #include <QModelIndex>
0023 #include <QHash>
0024 #include <QList>
0025 
0026 // Local includes
0027 
0028 #include "digikam_export.h"
0029 
0030 class QWidget;
0031 class QStyleOptionViewItem;
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DWItemDelegate;
0037 class DWItemDelegatePoolPrivate;
0038 
0039 class DIGIKAM_GUI_EXPORT DWItemDelegatePool
0040 {
0041 public:
0042 
0043     enum UpdateWidgetsEnum
0044     {
0045         UpdateWidgets = 0,
0046         NotUpdateWidgets
0047     };
0048 
0049 public:
0050 
0051     /**
0052      * Creates a new ItemDelegatePool.
0053      *
0054      * @param delegate the ItemDelegate for this pool.
0055      */
0056     explicit DWItemDelegatePool(DWItemDelegate* const delegate);
0057     ~DWItemDelegatePool();
0058 
0059     /**
0060      * @brief Returns the widget associated to @p index and @p widget
0061      * @param index The index to search into.
0062      * @param option a QStyleOptionViewItem.
0063      * @return A QList of the pointers to the widgets found.
0064      * @internal
0065      */
0066     QList<QWidget*> findWidgets(const QPersistentModelIndex& index, const QStyleOptionViewItem& option,
0067                                 UpdateWidgetsEnum updateWidgets = UpdateWidgets) const;
0068 
0069     QList<QWidget*> invalidIndexesWidgets() const;
0070 
0071     void fullClear();
0072 
0073 private:
0074 
0075     // Disable
0076     DWItemDelegatePool(const DWItemDelegatePool&)            = delete;
0077     DWItemDelegatePool& operator=(const DWItemDelegatePool&) = delete;
0078 
0079 private:
0080 
0081     friend class DWItemDelegate;
0082     friend class DWItemDelegatePrivate;
0083 
0084     DWItemDelegatePoolPrivate* const d;
0085 };
0086 
0087 // -----------------------------------------------------------------------------------------------------------
0088 
0089 class DWItemDelegateEventListener;
0090 
0091 class DWItemDelegatePoolPrivate
0092 {
0093 public:
0094 
0095     explicit DWItemDelegatePoolPrivate(DWItemDelegate* const d);
0096 
0097 public:
0098 
0099     DWItemDelegate*                                delegate;
0100     DWItemDelegateEventListener*                   eventListener;
0101 
0102     QHash<QPersistentModelIndex, QList<QWidget*> > usedWidgets;
0103     QHash<QWidget*, QPersistentModelIndex>         widgetInIndex;
0104 
0105     bool                                           clearing;
0106 
0107 private:
0108 
0109     // Disable
0110     DWItemDelegatePoolPrivate(const DWItemDelegatePoolPrivate&)            = delete;
0111     DWItemDelegatePoolPrivate& operator=(const DWItemDelegatePoolPrivate&) = delete;
0112 };
0113 
0114 } // namespace Digikam
0115 
0116 #endif // DIGIKAM_DW_ITEM_DELEGATE_POOL_H