digiKam
dconfigdlgmodels.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-11-03
7  * Description : A dialog base class which can handle multiple pages.
8  *
9  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2007 by Matthias Kretz <kretz at kde dot org>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DCONFIG_DLG_MODELS_H
26 #define DIGIKAM_DCONFIG_DLG_MODELS_H
27 
28 // Qt includes
29 
30 #include <QAbstractItemModel>
31 #include <QWidget>
32 
33 // Local includes
34 
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class DConfigDlgModelPrivate;
41 
55 class DConfigDlgModel : public QAbstractItemModel
56 {
57  Q_OBJECT
58  Q_DECLARE_PRIVATE(DConfigDlgModel)
59 
60 public:
61 
65  enum Role
66  {
70  HeaderRole = Qt::UserRole + 1,
71 
77  };
78 
82  explicit DConfigDlgModel(QObject* const parent = nullptr);
83 
87  ~DConfigDlgModel() override;
88 
89 protected:
90 
91  DConfigDlgModel(DConfigDlgModelPrivate& dd, QObject* const parent);
92 
93 protected:
94 
96 };
97 
98 // --------------------------------------------------------------------------
99 
104 class DIGIKAM_EXPORT DConfigDlgWdgItem : public QObject
105 {
106  Q_OBJECT
107  Q_PROPERTY(QString name READ name WRITE setName)
108  Q_PROPERTY(QString header READ header WRITE setHeader)
109  Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
110  Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
111  Q_PROPERTY(bool checked READ isChecked WRITE setChecked)
116  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
117 
118 public:
119 
125  explicit DConfigDlgWdgItem(QWidget* widget);
126 
134  DConfigDlgWdgItem(QWidget* widget, const QString& name);
135 
139  ~DConfigDlgWdgItem() override;
140 
144  QWidget* widget() const;
145 
150  void setName(const QString& name);
151 
155  QString name() const;
156 
167  void setHeader(const QString& header);
168 
172  QString header() const;
173 
178  void setIcon(const QIcon& icon);
179 
183  QIcon icon() const;
184 
190  void setCheckable(bool checkable);
191 
195  bool isCheckable() const;
196 
200  bool isChecked() const;
201 
205  bool isEnabled() const;
206 
207 public Q_SLOTS:
208 
212  void setEnabled(bool);
213 
217  void setChecked(bool checked);
218 
219 Q_SIGNALS:
220 
225  void changed();
226 
231  void toggled(bool checked);
232 
233 private:
234 
235  class Private;
236  Private* const d;
237 };
238 
239 // --------------------------------------------------------------------------
240 
242 
248 {
249  Q_OBJECT
250  Q_DECLARE_PRIVATE(DConfigDlgWdgModel)
251 
252 public:
253 
259  explicit DConfigDlgWdgModel(QObject* const parent = nullptr);
260 
264  ~DConfigDlgWdgModel() override;
265 
274  DConfigDlgWdgItem* addPage(QWidget* widget, const QString& name);
275 
282 
293  DConfigDlgWdgItem* insertPage(DConfigDlgWdgItem* before, QWidget* widget, const QString& name);
294 
304 
314  DConfigDlgWdgItem* addSubPage(DConfigDlgWdgItem* parent, QWidget* widget, const QString& name);
315 
324 
329 
333  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
334  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
335  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
336  Qt::ItemFlags flags(const QModelIndex& index) const override;
337  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
338  QModelIndex parent(const QModelIndex& index) const override;
339  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
340 
344  DConfigDlgWdgItem* item(const QModelIndex& index) const;
345 
350  QModelIndex index(const DConfigDlgWdgItem* item) const;
351 
352 Q_SIGNALS:
353 
358  void toggled(DConfigDlgWdgItem* page, bool checked);
359 
360 private:
361 
362  Q_PRIVATE_SLOT(d_func(), void _k_itemChanged())
363  Q_PRIVATE_SLOT(d_func(), void _k_itemToggled(bool))
364 };
365 
366 } // namespace Digikam
367 
368 #endif // DIGIKAM_DCONFIG_DLG_MODELS_H
Definition: dconfigdlgmodels_p.h:34
A base class for a model used by DConfigDlgView.
Definition: dconfigdlgmodels.h:56
~DConfigDlgModel() override
Definition: dconfigdlgmodels.cpp:52
DConfigDlgModelPrivate *const d_ptr
Definition: dconfigdlgmodels.h:95
DConfigDlgModel(QObject *const parent=nullptr)
Definition: dconfigdlgmodels.cpp:39
Role
Definition: dconfigdlgmodels.h:66
@ HeaderRole
Definition: dconfigdlgmodels.h:70
@ WidgetRole
Definition: dconfigdlgmodels.h:76
Definition: dconfigdlgmodels.h:105
void toggled(bool checked)
Definition: dconfigdlgmodels_p.h:86
Definition: dconfigdlgmodels.h:248
void toggled(DConfigDlgWdgItem *page, bool checked)
DConfigDlgWdgModel(QObject *const parent=nullptr)
Definition: dconfigdlgmodels.cpp:314
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: dconfigdlgmodels.cpp:475
~DConfigDlgWdgModel() override
Definition: dconfigdlgmodels.cpp:319
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: dconfigdlgmodels.cpp:430
void removePage(DConfigDlgWdgItem *item)
Definition: dconfigdlgmodels.cpp:623
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: dconfigdlgmodels.cpp:406
DConfigDlgWdgItem * addSubPage(DConfigDlgWdgItem *parent, QWidget *widget, const QString &name)
Definition: dconfigdlgmodels.cpp:575
DConfigDlgWdgItem * addPage(QWidget *widget, const QString &name)
Definition: dconfigdlgmodels.cpp:491
DConfigDlgWdgItem * item(const QModelIndex &index) const
Definition: dconfigdlgmodels.cpp:668
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: dconfigdlgmodels.cpp:323
DConfigDlgWdgItem * insertPage(DConfigDlgWdgItem *before, QWidget *widget, const QString &name)
Definition: dconfigdlgmodels.cpp:525
QModelIndex parent(const QModelIndex &index) const override
Definition: dconfigdlgmodels.cpp:455
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: dconfigdlgmodels.cpp:370
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: dconfigdlgmodels.cpp:328
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43