PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/quassel-0.7.3/src/client/irclistmodel.cpp

#
C++ | 89 lines | 55 code | 15 blank | 19 comment | 15 complexity | f4d17b46f1b5f09212f7d3fad626e357 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-09 by the Quassel Project *
  3. * devel@quassel-irc.org *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) version 3. *
  9. * *
  10. * This program 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 *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "irclistmodel.h"
  21. #include <QStringList>
  22. IrcListModel::IrcListModel(QObject *parent)
  23. : QAbstractItemModel(parent)
  24. {
  25. }
  26. QVariant IrcListModel::data(const QModelIndex &index, int role) const {
  27. if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount() || role != Qt::DisplayRole)
  28. return QVariant();
  29. IrcListHelper::ChannelDescription channel = _channelList[index.row()];
  30. switch(index.column()) {
  31. case 0:
  32. return channel.channelName;
  33. case 1:
  34. return channel.userCount;
  35. case 2:
  36. return channel.topic;
  37. default:
  38. return QVariant();
  39. }
  40. }
  41. Qt::ItemFlags IrcListModel::flags(const QModelIndex &index) const {
  42. if(!index.isValid()) {
  43. return Qt::ItemIsDropEnabled;
  44. } else {
  45. return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
  46. }
  47. }
  48. QVariant IrcListModel::headerData(int section, Qt::Orientation orientation, int role) const {
  49. QStringList header;
  50. header << tr("Channel")
  51. << tr("Users")
  52. << tr("Topic");
  53. if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
  54. return header[section];
  55. return QVariant();
  56. }
  57. QModelIndex IrcListModel::index(int row, int column, const QModelIndex &parent) const {
  58. Q_UNUSED(parent);
  59. if(row >= rowCount() || column >= columnCount())
  60. return QModelIndex();
  61. return createIndex(row, column);
  62. }
  63. void IrcListModel::setChannelList(const QList<IrcListHelper::ChannelDescription> &channelList) {
  64. if(rowCount() > 0) {
  65. beginRemoveRows(QModelIndex(), 0, _channelList.count() - 1);
  66. _channelList.clear();
  67. endRemoveRows();
  68. }
  69. if(channelList.count() > 0) {
  70. beginInsertRows(QModelIndex(), 0, channelList.count() - 1);
  71. _channelList = channelList;
  72. endInsertRows();
  73. }
  74. }