KDNSSD

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

KDE's Doxygen guidelines are available online.