diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-05-08 12:14:01 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-05-13 12:29:20 (GMT) |
commit | 705bd7256fa4812045677743fc1e939ccfd66d05 (patch) | |
tree | 84502c2c6bd6bda1bc38e7fce59cc451e05b21c4 /Swift/QtUI/MUCSearch/MUCSearchModel.cpp | |
parent | 61078c4e4fd553bf952bae5c9d44da6cb96a3a70 (diff) | |
download | swift-contrib-705bd7256fa4812045677743fc1e939ccfd66d05.zip swift-contrib-705bd7256fa4812045677743fc1e939ccfd66d05.tar.bz2 |
List MUCs available on services.
Resolves: #276
Diffstat (limited to 'Swift/QtUI/MUCSearch/MUCSearchModel.cpp')
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchModel.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp new file mode 100644 index 0000000..eb7fe20 --- /dev/null +++ b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swift/QtUI/MUCSearch/MUCSearchModel.h" + +namespace Swift { + +MUCSearchModel::MUCSearchModel() { +} + +void MUCSearchModel::clear() { + emit layoutAboutToBeChanged(); + services_.clear(); + emit layoutChanged(); +} + +void MUCSearchModel::addService(MUCSearchServiceItem* service) { + emit layoutAboutToBeChanged(); + services_.push_back(service); + emit layoutChanged(); +} + +int MUCSearchModel::columnCount(const QModelIndex& /*parent*/) const { + return 1; +} + +QVariant MUCSearchModel::data(const QModelIndex& index, int role) const { + return index.isValid() ? static_cast<MUCSearchItem*>(index.internalPointer())->data(role) : QVariant(); +} + +QModelIndex MUCSearchModel::index(int row, int column, const QModelIndex & parent) const { + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + + if (parent.isValid()) { + MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer()); + return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); + + } else { + return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex(); + } + + +} + +QModelIndex MUCSearchModel::parent(const QModelIndex& index) const { + if (!index.isValid()) { + return QModelIndex(); + } + MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); + if (!item) { + return QModelIndex(); + } + if (dynamic_cast<MUCSearchServiceItem*>(item)) { + return QModelIndex(); + } + MUCSearchServiceItem* parent = dynamic_cast<MUCSearchRoomItem*>(item)->getParent(); + int row = services_.indexOf(parent); + return parent ? createIndex(row, 1, parent) : QModelIndex(); +} + +int MUCSearchModel::rowCount(const QModelIndex& parentIndex) const { + if (!parentIndex.isValid()) { + return services_.size(); + } + if (dynamic_cast<MUCSearchServiceItem*>(static_cast<MUCSearchItem*>(parentIndex.internalPointer()))) { + return services_[parentIndex.row()]->rowCount(); + } else { + return 0; + } +} + +} |