• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

DNSSD

  • sources
  • kde-4.14
  • kdelibs
  • dnssd
domainmodel.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2008 Jakub Stachowski <qbast@go2.pl>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "domainmodel.h"
22 #include "domainbrowser.h"
23 #include <qstringlist.h>
24 
25 namespace DNSSD
26 {
27 
28 struct DomainModelPrivate
29 {
30  DomainBrowser* m_browser;
31 };
32 
33 
34 DomainModel::DomainModel(DomainBrowser* browser, QObject* parent)
35  : QAbstractItemModel(parent), d(new DomainModelPrivate)
36 {
37  d->m_browser=browser;
38  browser->setParent(this);
39  connect(browser, SIGNAL(domainAdded(QString)), this,
40  SIGNAL(layoutChanged()));
41  connect(browser, SIGNAL(domainRemoved(QString)), this,
42  SIGNAL(layoutChanged()));
43  browser->startBrowse();
44 }
45 
46 DomainModel::~DomainModel()
47 {
48  delete d;
49 }
50 
51 int DomainModel::columnCount(const QModelIndex& parent) const
52 {
53  Q_UNUSED(parent);
54  return 1;
55 }
56 int DomainModel::rowCount(const QModelIndex& parent ) const
57 {
58  return (parent.isValid()) ? 0 : d->m_browser->domains().size();
59 }
60 
61 QModelIndex DomainModel::parent(const QModelIndex& index ) const
62 {
63  Q_UNUSED(index);
64  return QModelIndex();
65 }
66 
67 QModelIndex DomainModel::index(int row, int column, const QModelIndex& parent ) const
68 {
69  return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
70 }
71 
72 bool DomainModel::hasIndex(int row, int column, const QModelIndex &parent) const
73 {
74  if (parent.isValid()) return false;
75  if (column!=0) return false;
76  if (row<0 || row>=rowCount(parent)) return false;
77  return true;
78 }
79 
80 QVariant DomainModel::data(const QModelIndex& index, int role ) const
81 {
82  if (!index.isValid()) return QVariant();
83  if (!hasIndex(index.row(), index.column(), index.parent())) return QVariant();
84  const QStringList domains=d->m_browser->domains();
85  if (role==Qt::DisplayRole) return domains[index.row()];
86  return QVariant();
87 }
88 
89 }
QModelIndex
QAbstractItemModel::layoutChanged
void layoutChanged()
DNSSD::DomainModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: domainmodel.cpp:51
DNSSD::DomainModel::DomainModel
DomainModel(DomainBrowser *browser, QObject *parent=0)
Creates a model for given domain browser and starts browsing for domains.
Definition: domainmodel.cpp:34
DNSSD::DomainModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: domainmodel.cpp:67
DNSSD::DomainBrowser::startBrowse
void startBrowse()
Starts browsing.
Definition: dummy-domainbrowser.cpp:34
DNSSD::DomainModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: domainmodel.cpp:56
QModelIndex::isValid
bool isValid() const
QObject
QModelIndex::row
int row() const
QString
QModelIndex::parent
QModelIndex parent() const
QStringList
DNSSD::DomainModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: domainmodel.cpp:80
QAbstractItemModel::createIndex
QModelIndex createIndex(int row, int column, void *ptr) const
DNSSD::DomainModel::hasIndex
virtual bool hasIndex(int row, int column, const QModelIndex &parent) const
Definition: domainmodel.cpp:72
QObject::setParent
void setParent(QObject *parent)
DNSSD::DomainBrowser
Browses recommended domains for browsing or publishing to.
Definition: domainbrowser.h:54
DNSSD::DomainModel::~DomainModel
virtual ~DomainModel()
Definition: domainmodel.cpp:46
domainbrowser.h
QModelIndex::column
int column() const
QAbstractItemModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
domainmodel.h
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

DNSSD

Skip menu "DNSSD"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal