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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-03
0007  * Description : A dialog base class which can handle multiple pages.
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2007      by Matthias Kretz <kretz at kde dot org>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_DCONFIG_DLG_MODELS_PRIVATE_H
0017 #define DIGIKAM_DCONFIG_DLG_MODELS_PRIVATE_H
0018 
0019 #include "dconfigdlgmodels.h"
0020 
0021 namespace Digikam
0022 {
0023 
0024 class Q_DECL_HIDDEN DConfigDlgModelPrivate
0025 {
0026     Q_DECLARE_PUBLIC(DConfigDlgModel)
0027 
0028 public:
0029 
0030     DConfigDlgModelPrivate()          = default;
0031     virtual ~DConfigDlgModelPrivate() = default;
0032 
0033 protected:
0034 
0035     DConfigDlgModel* q_ptr = nullptr;
0036 
0037 private:
0038 
0039     Q_DISABLE_COPY(DConfigDlgModelPrivate)
0040 };
0041 
0042 // ----------------------------------------------------------------------------
0043 
0044 class Q_DECL_HIDDEN PageItem
0045 {
0046 public:
0047 
0048     explicit PageItem(DConfigDlgWdgItem* const pageItem, PageItem* const parent = nullptr);
0049     ~PageItem();
0050 
0051     void appendChild(PageItem* child);
0052     void insertChild(int row, PageItem* child);
0053     void removeChild(int row);
0054 
0055     PageItem* child(int row);
0056     int childCount()                    const;
0057     int columnCount()                   const;
0058     int row()                           const;
0059     PageItem* parent();
0060 
0061     DConfigDlgWdgItem* pageWidgetItem() const;
0062 
0063     PageItem* findChild(const DConfigDlgWdgItem* item);
0064 
0065     void dump(int indent = 0);
0066 
0067 private:
0068 
0069     DConfigDlgWdgItem* mPageWidgetItem;
0070     QList<PageItem*>   mChildItems;
0071     PageItem*          mParentItem;
0072 };
0073 
0074 // ----------------------------------------------------------------------------
0075 
0076 class Q_DECL_HIDDEN DConfigDlgWdgModelPrivate : public DConfigDlgModelPrivate
0077 {
0078     Q_DECLARE_PUBLIC(DConfigDlgWdgModel)
0079 
0080 protected:
0081 
0082     DConfigDlgWdgModelPrivate()
0083         : rootItem(new PageItem(nullptr, nullptr))
0084     {
0085     }
0086 
0087     ~DConfigDlgWdgModelPrivate()
0088     {
0089         delete rootItem;
0090         rootItem = nullptr;
0091     }
0092 
0093     void _k_itemChanged()
0094     {
0095         Q_Q(DConfigDlgWdgModel);
0096 
0097         DConfigDlgWdgItem* const item = qobject_cast<DConfigDlgWdgItem*>(q->sender());
0098 
0099         if (!item)
0100         {
0101             return;
0102         }
0103 
0104         const QModelIndex index = q->index(item);
0105 
0106         if (!index.isValid())
0107         {
0108             return;
0109         }
0110 
0111         Q_EMIT q->dataChanged(index, index);
0112     }
0113 
0114     void _k_itemToggled(bool checked)
0115     {
0116         Q_Q(DConfigDlgWdgModel);
0117 
0118         DConfigDlgWdgItem* const item = qobject_cast<DConfigDlgWdgItem*>(q->sender());
0119 
0120         if (!item)
0121         {
0122             return;
0123         }
0124 
0125         Q_EMIT q->toggled(item, checked);
0126     }
0127 
0128 protected:
0129 
0130     PageItem* rootItem = nullptr;
0131 
0132 private:
0133 
0134     // Disable
0135     DConfigDlgWdgModelPrivate(const DConfigDlgWdgModelPrivate&)            = delete;
0136     DConfigDlgWdgModelPrivate& operator=(const DConfigDlgWdgModelPrivate&) = delete;
0137 };
0138 
0139 } // namespace Digikam
0140 
0141 #endif // DIGIKAM_DCONFIG_DLG_MODELS_PRIVATE_H