DNSSD
domainmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }