KDNSSD

domainmodel.cpp
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#include "domainmodel.h"
10#include "domainbrowser.h"
11#include <QStringList>
12
13namespace KDNSSD
14{
15struct DomainModelPrivate {
16 DomainBrowser *m_browser;
17};
18
20 : QAbstractItemModel(parent)
21 , d(new DomainModelPrivate)
22{
23 d->m_browser = browser;
24 browser->setParent(this);
25 connect(browser, SIGNAL(domainAdded(QString)), this, SIGNAL(layoutChanged()));
26 connect(browser, SIGNAL(domainRemoved(QString)), this, SIGNAL(layoutChanged()));
27 browser->startBrowse();
28}
29
30DomainModel::~DomainModel() = default;
31
32int DomainModel::columnCount(const QModelIndex &parent) const
33{
34 Q_UNUSED(parent);
35 return 1;
36}
37int DomainModel::rowCount(const QModelIndex &parent) const
38{
39 return (parent.isValid()) ? 0 : d->m_browser->domains().size();
40}
41
43{
44 Q_UNUSED(index);
45 return QModelIndex();
46}
47
48QModelIndex DomainModel::index(int row, int column, const QModelIndex &parent) const
49{
50 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
51}
52
53bool DomainModel::hasIndex(int row, int column, const QModelIndex &parent) const
54{
55 if (parent.isValid()) {
56 return false;
57 }
58 if (column != 0) {
59 return false;
60 }
61 if (row < 0 || row >= rowCount(parent)) {
62 return false;
63 }
64 return true;
65}
66
67QVariant DomainModel::data(const QModelIndex &index, int role) const
68{
69 if (!index.isValid()) {
70 return QVariant();
71 }
72 if (!hasIndex(index.row(), index.column(), index.parent())) {
73 return QVariant();
74 }
75 const QStringList domains = d->m_browser->domains();
76 if (role == Qt::DisplayRole) {
77 return domains[index.row()];
78 }
79 return QVariant();
80}
81
82}
83
84#include "moc_domainmodel.cpp"
Browses recommended domains for browsing or publishing to.
void startBrowse()
Starts browsing.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual bool hasIndex(int row, int column, const QModelIndex &parent) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
DomainModel(DomainBrowser *browser, QObject *parent=nullptr)
Creates a model for given domain browser and starts browsing for domains.
QModelIndex createIndex(int row, int column, const void *ptr) const const
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
int column() const const
bool isValid() const const
QModelIndex parent() const const
int row() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void setParent(QObject *parent)
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:10:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.