1 | /* |
2 | This file is part of the KDE project |
3 | |
4 | SPDX-FileCopyrightText: 2008 Jakub Stachowski <qbast@go2.pl> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KDNSSDDOMAINMODEL_H |
10 | #define KDNSSDDOMAINMODEL_H |
11 | |
12 | #include "kdnssd_export.h" |
13 | #include <QAbstractItemModel> |
14 | #include <memory> |
15 | |
16 | namespace KDNSSD |
17 | { |
18 | struct DomainModelPrivate; |
19 | class DomainBrowser; |
20 | |
21 | /** |
22 | * @class DomainModel domainmodel.h KDNSSD/DomainModel |
23 | * @short Model for list of Zeroconf domains |
24 | * |
25 | * This class provides a Qt Model for DomainBrowser to allow easy |
26 | * integration of domain discovery into a GUI. For example, to |
27 | * provide a combo box listing available domains, you can do: |
28 | * @code |
29 | * KDNSSD::DomainModel *domainModel = new DomainModel( |
30 | * new KDNSSD::DomainBrowser(KDNSSD::DomainBrowser::Browsing) |
31 | * ); |
32 | * QComboBox *domainCombo = new QComboBox(); |
33 | * domainCombo->setModel(domainModel); |
34 | * @endcode |
35 | * |
36 | * @since 4.1 |
37 | * @author Jakub Stachowski |
38 | */ |
39 | |
40 | class KDNSSD_EXPORT DomainModel : public QAbstractItemModel |
41 | { |
42 | Q_OBJECT |
43 | |
44 | public: |
45 | /** |
46 | * Creates a model for given domain browser and starts |
47 | * browsing for domains. |
48 | * |
49 | * The model takes ownership of the browser, |
50 | * so there is no need to delete it afterwards. |
51 | * |
52 | * You should @b not call DomainBrowser::startBrowse() on @p browser |
53 | * before passing it to DomainModel. |
54 | * |
55 | * @param browser the domain browser that will provide the domains |
56 | * to be listed by the model |
57 | * @param parent the parent object (see QObject documentation) |
58 | */ |
59 | explicit DomainModel(DomainBrowser *browser, QObject *parent = nullptr); |
60 | |
61 | ~DomainModel() override; |
62 | |
63 | /** @reimp */ |
64 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
65 | /** @reimp */ |
66 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
67 | /** @reimp */ |
68 | QModelIndex parent(const QModelIndex &index) const override; |
69 | /** @reimp */ |
70 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
71 | /** @reimp */ |
72 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
73 | /** @reimp */ |
74 | virtual bool hasIndex(int row, int column, const QModelIndex &parent) const; |
75 | |
76 | private: |
77 | std::unique_ptr<DomainModelPrivate> const d; |
78 | friend struct DomainModelPrivate; |
79 | }; |
80 | |
81 | } |
82 | |
83 | #endif |
84 | |