| 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 KDNSSD::DomainModel |
| 23 | * \inmodule KDNSSD |
| 24 | * \inheaderfile KDNSSD/DomainModel |
| 25 | * |
| 26 | * \brief Model for list of Zeroconf domains. |
| 27 | * |
| 28 | * This class provides a Qt Model for DomainBrowser to allow easy |
| 29 | * integration of domain discovery into a GUI. For example, to |
| 30 | * provide a combo box listing available domains, you can do: |
| 31 | * \code |
| 32 | * KDNSSD::DomainModel *domainModel = new DomainModel( |
| 33 | * new KDNSSD::DomainBrowser(KDNSSD::DomainBrowser::Browsing) |
| 34 | * ); |
| 35 | * QComboBox *domainCombo = new QComboBox(); |
| 36 | * domainCombo->setModel(domainModel); |
| 37 | * \endcode |
| 38 | * |
| 39 | * \since 4.1 |
| 40 | */ |
| 41 | class KDNSSD_EXPORT DomainModel : public QAbstractItemModel |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | |
| 45 | public: |
| 46 | /*! |
| 47 | * Creates a model for given domain browser and starts |
| 48 | * browsing for domains. |
| 49 | * |
| 50 | * The model takes ownership of the browser, |
| 51 | * so there is no need to delete it afterwards. |
| 52 | * |
| 53 | * \note You should \b not call DomainBrowser::startBrowse() on \a browser |
| 54 | * before passing it to DomainModel. |
| 55 | * |
| 56 | * \a browser is the domain browser that will provide the domains |
| 57 | * to be listed by the model |
| 58 | * |
| 59 | * \a parent is the parent object (see QObject documentation) |
| 60 | */ |
| 61 | explicit DomainModel(DomainBrowser *browser, QObject *parent = nullptr); |
| 62 | |
| 63 | ~DomainModel() override; |
| 64 | |
| 65 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 66 | |
| 67 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 68 | |
| 69 | QModelIndex parent(const QModelIndex &index) const override; |
| 70 | |
| 71 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
| 72 | |
| 73 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 74 | |
| 75 | /*! */ |
| 76 | virtual bool hasIndex(int row, int column, const QModelIndex &parent) const; |
| 77 | |
| 78 | private: |
| 79 | std::unique_ptr<DomainModelPrivate> const d; |
| 80 | friend struct DomainModelPrivate; |
| 81 | }; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | #endif |
| 86 | |