From 5d8d6fed3fd7dd796a5a3093a7dbd46fab8d380a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 4 Apr 2013 00:00:38 +0200 Subject: pass Board objects instead of boardUrls around QML --- topicmodel.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'topicmodel.cpp') diff --git a/topicmodel.cpp b/topicmodel.cpp index 0c7541e..965481f 100644 --- a/topicmodel.cpp +++ b/topicmodel.cpp @@ -8,7 +8,7 @@ #include "topicmodel.h" TopicModel::TopicModel(QObject *parent) : - QAbstractListModel(parent), _boardUrl(), _board(0), _topicId(-1) + QAbstractListModel(parent), _board(0), _topicId(-1), _eof(false) { QHash roles = roleNames(); roles[TitleRole] = QByteArray("title"); @@ -23,21 +23,20 @@ TopicModel::TopicModel(QObject *parent) : setRoleNames(roles); } -QString TopicModel::boardUrl() const +Board * TopicModel::board() const { - return _boardUrl; + return _board; } -void TopicModel::setBoardUrl(const QString &url) +void TopicModel::setBoard(Board *board) { - if (_boardUrl != url) { + if (_board != board) { disconnect(this, SLOT(handleTopicPostsChanged(int,int,int))); clearModel(); - _board = 0; - _boardUrl = url; - if (!_boardUrl.isEmpty()) { - _board = board_manager->getBoard(_boardUrl); + _board = board; + + if (_board) { connect(_board, SIGNAL(topicPostsChanged(int,int,int)), SLOT(handleTopicPostsChanged(int,int,int))); if (_topicId >= 0) { @@ -45,7 +44,7 @@ void TopicModel::setBoardUrl(const QString &url) reload(); } } - emit boardUrlChanged(); + emit boardChanged(); } } @@ -109,14 +108,14 @@ QVariant TopicModel::data(const QModelIndex &index, int role) const bool TopicModel::canFetchMore(const QModelIndex &parent) const { - if (parent.isValid() || !_board) return false; // Invalid state + if (parent.isValid() || !_board || _topicId < 0) return false; // Invalid state return !_eof; } void TopicModel::fetchMore(const QModelIndex &parent) { if (parent.isValid()) return; - if (!_board) return; + if (!_board || _topicId < 0) return; if (_eof) return; const int start = _data.size(); -- cgit v1.2.3