#include "message.h"
MessageModel::MessageModel(QObject *parent) : QAbstractItemModel(parent) {
-
-
-
+
+
+
}
MessageModel::~MessageModel() {
-
-
+
+
}
QVariant MessageModel::data(const QModelIndex &index, int role) const {
}
+void MessageModel::clear() {
+ reset();
+ qDeleteAll(_messageList);
+ _messageList.clear();
+}
+
// returns index of msg with given Id or of the next message after that (i.e., the index where we'd insert this msg)
int MessageModel::indexForId(MsgId id) {
if(_messageList.isEmpty() || id <= _messageList[0]->data(0, MsgIdRole).value<MsgId>()) return 0;
connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &)));
connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
+ connect(model, SIGNAL(modelAboutToBeReset()), this, SLOT(modelReset()));
for(int i = 0; i < model->rowCount(); i++) {
ChatLine *line = new ChatLine(model->index(i, 0));
_lines.append(line);
ChatScene::~ChatScene() {
-
}
void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
}
}
+void ChatScene::modelReset() {
+ foreach(ChatLine *line, _lines) {
+ removeItem(line);
+ delete line;
+ }
+ _lines.clear();
+ setSceneRect(QRectF(0, 0, _width, 0));
+}
+
void ChatScene::setWidth(qreal w) {
_width = w;
_height = 0;