File indexing completed on 2024-04-28 15:22:06

0001 /*
0002     This file is part of the KDE project
0003 
0004     SPDX-FileCopyrightText: 2008 Jakub Stachowski <qbast@go2.pl>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KDNSSDDOMAINMODEL_H
0010 #define KDNSSDDOMAINMODEL_H
0011 
0012 #include "kdnssd_export.h"
0013 #include <QAbstractItemModel>
0014 #include <memory>
0015 
0016 namespace KDNSSD
0017 {
0018 struct DomainModelPrivate;
0019 class DomainBrowser;
0020 
0021 /**
0022  * @class DomainModel domainmodel.h KDNSSD/DomainModel
0023  * @short Model for list of Zeroconf domains
0024  *
0025  * This class provides a Qt Model for DomainBrowser to allow easy
0026  * integration of domain discovery into a GUI.  For example, to
0027  * provide a combo box listing available domains, you can do:
0028  * @code
0029  * KDNSSD::DomainModel *domainModel = new DomainModel(
0030  *     new KDNSSD::DomainBrowser(KDNSSD::DomainBrowser::Browsing)
0031  *     );
0032  * QComboBox *domainCombo = new QComboBox();
0033  * domainCombo->setModel(domainModel);
0034  * @endcode
0035  *
0036  * @since 4.1
0037  * @author Jakub Stachowski
0038  */
0039 
0040 class KDNSSD_EXPORT DomainModel : public QAbstractItemModel
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     /**
0046      * Creates a model for given domain browser and starts
0047      * browsing for domains.
0048      *
0049      * The model takes ownership of the browser,
0050      * so there is no need to delete it afterwards.
0051      *
0052      * You should @b not call DomainBrowser::startBrowse() on @p browser
0053      * before passing it to DomainModel.
0054      *
0055      * @param browser the domain browser that will provide the domains
0056      *                to be listed by the model
0057      * @param parent  the parent object (see QObject documentation)
0058      */
0059     explicit DomainModel(DomainBrowser *browser, QObject *parent = nullptr);
0060 
0061     ~DomainModel() override;
0062 
0063     /** @reimp */
0064     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0065     /** @reimp */
0066     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0067     /** @reimp */
0068     QModelIndex parent(const QModelIndex &index) const override;
0069     /** @reimp */
0070     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0071     /** @reimp */
0072     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0073     /** @reimp */
0074     virtual bool hasIndex(int row, int column, const QModelIndex &parent) const;
0075 
0076 private:
0077     std::unique_ptr<DomainModelPrivate> const d;
0078     friend struct DomainModelPrivate;
0079 };
0080 
0081 }
0082 
0083 #endif