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

DNSSD

domainmodel.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2008 Jakub Stachowski <qbast@go2.pl>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "domainmodel.h"
00022 #include "domainbrowser.h"
00023 #include <qstringlist.h>
00024 
00025 namespace DNSSD
00026 {
00027 
00028 struct DomainModelPrivate
00029 {
00030         DomainBrowser* m_browser;
00031 };
00032 
00033 
00034 DomainModel::DomainModel(DomainBrowser* browser, QObject* parent) 
00035     :  QAbstractItemModel(parent), d(new DomainModelPrivate)
00036 {
00037     d->m_browser=browser;
00038     browser->setParent(this);
00039     connect(browser, SIGNAL(domainAdded(const QString&)), this,
00040     SIGNAL(layoutChanged()));
00041     connect(browser, SIGNAL(domainRemoved(const QString&)), this,
00042     SIGNAL(layoutChanged()));
00043     browser->startBrowse();
00044 }
00045 
00046 DomainModel::~DomainModel()
00047 {
00048     delete d;
00049 }
00050 
00051 int DomainModel::columnCount(const QModelIndex& parent) const
00052 {
00053     Q_UNUSED(parent);
00054     return 1;
00055 }
00056 int DomainModel::rowCount(const QModelIndex& parent ) const
00057 {
00058     return (parent.isValid()) ? 0 : d->m_browser->domains().size();
00059 }
00060 
00061 QModelIndex DomainModel::parent(const QModelIndex& index ) const
00062 {
00063     Q_UNUSED(index);
00064     return QModelIndex();
00065 }
00066 
00067 QModelIndex DomainModel::index(int row, int column, const QModelIndex& parent  ) const
00068 {
00069     return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
00070 }
00071 
00072 bool DomainModel::hasIndex(int row, int column, const QModelIndex &parent) const
00073 {
00074     if (parent.isValid()) return false;
00075     if (column!=0) return false;
00076     if (row<0 || row>=rowCount(parent)) return false;
00077     return true;
00078 }
00079 
00080 QVariant DomainModel::data(const QModelIndex& index, int role  ) const
00081 {
00082     if (!index.isValid()) return QVariant();
00083     if (!hasIndex(index.row(), index.column(), index.parent())) return QVariant();
00084     const QStringList domains=d->m_browser->domains();
00085     if (role==Qt::DisplayRole) return domains[index.row()];
00086     return QVariant();
00087 }
00088 
00089 }

DNSSD

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal