#ifndef TOPICMODEL_H #define TOPICMODEL_H #include #include #include class Board; class TopicModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QString boardUrl READ boardUrl WRITE setBoardUrl NOTIFY boardUrlChanged) Q_PROPERTY(int topicId READ topicId WRITE setTopicId NOTIFY topicIdChanged) public: TopicModel(QObject *parent = 0); enum DataRoles { TitleRole = Qt::DisplayRole, IconRole = Qt::DecorationRole, ContentRole = Qt::ToolTipRole, PostIdRole = Qt::UserRole, UserIdRole, UserNameRole, DateTimeRole, HumanDateRole, HumanTimeRole }; QString boardUrl() const; void setBoardUrl(const QString& url); int topicId() const; void setTopicId(const int id); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; bool canFetchMore(const QModelIndex &parent = QModelIndex()) const; void fetchMore(const QModelIndex &parent = QModelIndex()); signals: void boardUrlChanged(); void topicIdChanged(); protected: struct Post { int post_id; QString title; QString content; int user_id; QString user_name; QDateTime time; QDateTime last_update_time; }; private: static QDateTime parseDbDateTime(const QVariant& v); static QDateTime oldestPostUpdate(const QList& posts); QDateTime lastTopPostUpdate(); QList loadPosts(int start, int end); void clearModel(); private slots: void handleTopicPostsChanged(int forumId, int start, int end); void update(); void reload(); private: QString _boardUrl; Board *_board; int _topicId; QList _data; bool _eof; }; #endif // TOPICMODEL_H