File indexing completed on 2024-04-07 14:13:06

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2008 Rafael Fernández López <ereslibre@kde.org>
0004     SPDX-FileCopyrightText: 2008 Kevin Ottens <ervin@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KWIDGETITEMDELEGATEPOOL_P_H
0010 #define KWIDGETITEMDELEGATEPOOL_P_H
0011 
0012 #include <QHash>
0013 #include <QList>
0014 #include <QPersistentModelIndex>
0015 
0016 class QWidget;
0017 class QStyleOptionViewItem;
0018 class KWidgetItemDelegate;
0019 class KWidgetItemDelegatePoolPrivate;
0020 
0021 /**
0022  * @internal
0023  */
0024 class KWidgetItemDelegatePool
0025 {
0026 public:
0027     enum UpdateWidgetsEnum {
0028         UpdateWidgets = 0,
0029         NotUpdateWidgets,
0030     };
0031 
0032     /**
0033      * Creates a new ItemDelegatePool.
0034      *
0035      * @param delegate the ItemDelegate for this pool.
0036      */
0037 
0038     KWidgetItemDelegatePool(KWidgetItemDelegate *delegate);
0039 
0040     /**
0041      * Destroys an ItemDelegatePool.
0042      */
0043     ~KWidgetItemDelegatePool();
0044 
0045     KWidgetItemDelegatePool(const KWidgetItemDelegatePool &) = delete;
0046     KWidgetItemDelegatePool &operator=(const KWidgetItemDelegatePool &) = delete;
0047 
0048     /**
0049      * @brief Returns the widget associated to @p index and @p widget
0050      * @param index The index to search into.
0051      * @param option a QStyleOptionViewItem.
0052      * @return A QList of the pointers to the widgets found.
0053      * @internal
0054      */
0055     QList<QWidget *> findWidgets(const QPersistentModelIndex &index, const QStyleOptionViewItem &option, UpdateWidgetsEnum updateWidgets = UpdateWidgets) const;
0056 
0057     /**
0058      * @internal
0059      */
0060     QList<QWidget *> invalidIndexesWidgets() const;
0061 
0062     /**
0063      * @internal
0064      */
0065     void fullClear();
0066 
0067 private:
0068     friend class KWidgetItemDelegate;
0069     friend class KWidgetItemDelegatePrivate;
0070     KWidgetItemDelegatePoolPrivate *const d;
0071 };
0072 
0073 class KWidgetItemDelegateEventListener;
0074 
0075 /**
0076  * @internal
0077  */
0078 class KWidgetItemDelegatePoolPrivate
0079 {
0080 public:
0081     KWidgetItemDelegatePoolPrivate(KWidgetItemDelegate *d);
0082 
0083     KWidgetItemDelegate *delegate;
0084     KWidgetItemDelegateEventListener *eventListener;
0085 
0086     QList<QList<QWidget *>> allocatedWidgets;
0087     QHash<QPersistentModelIndex, QList<QWidget *>> usedWidgets;
0088     QHash<QWidget *, QPersistentModelIndex> widgetInIndex;
0089 
0090     bool clearing = false;
0091 };
0092 
0093 #endif