fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / dnssd / domainmodel.cpp
blob234f3fabafb1eb13b184798411db7e03821aa3e9
1 /* This file is part of the KDE project
3 * Copyright (C) 2008 Jakub Stachowski <qbast@go2.pl>
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.
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.
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.
21 #include "domainmodel.h"
22 #include "domainbrowser.h"
23 #include <qstringlist.h>
25 namespace DNSSD
28 struct DomainModelPrivate
30 DomainBrowser* m_browser;
34 DomainModel::DomainModel(DomainBrowser* browser, QObject* parent)
35 : QAbstractItemModel(parent), d(new DomainModelPrivate)
37 d->m_browser=browser;
38 browser->setParent(this);
39 connect(browser, SIGNAL(domainAdded(const QString&)), this,
40 SIGNAL(layoutChanged()));
41 connect(browser, SIGNAL(domainRemoved(const QString&)), this,
42 SIGNAL(layoutChanged()));
43 browser->startBrowse();
46 DomainModel::~DomainModel()
48 delete d;
51 int DomainModel::columnCount(const QModelIndex& parent) const
53 Q_UNUSED(parent);
54 return 1;
56 int DomainModel::rowCount(const QModelIndex& parent ) const
58 return (parent.isValid()) ? 0 : d->m_browser->domains().size();
61 QModelIndex DomainModel::parent(const QModelIndex& index ) const
63 Q_UNUSED(index);
64 return QModelIndex();
67 QModelIndex DomainModel::index(int row, int column, const QModelIndex& parent ) const
69 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
72 bool DomainModel::hasIndex(int row, int column, const QModelIndex &parent) const
74 if (parent.isValid()) return false;
75 if (column!=0) return false;
76 if (row<0 || row>=rowCount(parent)) return false;
77 return true;
80 QVariant DomainModel::data(const QModelIndex& index, int role ) const
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();