From a787e8b6e8dd5357531fa89d22da95ebf987469c Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Mon, 18 Aug 2008 14:31:57 +0200 Subject: [PATCH] reverting the backlog request to how it was in the old chatwidget --- src/client/messagefilter.cpp | 31 +++++++++++++++++----------- src/client/messagefilter.h | 24 +++++++++++----------- src/qtui/bufferwidget.cpp | 1 - src/qtui/chatmonitorfilter.cpp | 2 +- src/qtui/chatscene.cpp | 35 +++++++++----------------------- src/qtui/chatscene.h | 30 +++------------------------ src/qtui/chatview.cpp | 37 ++++++++-------------------------- src/qtui/chatview.h | 3 --- 8 files changed, 53 insertions(+), 110 deletions(-) diff --git a/src/client/messagefilter.cpp b/src/client/messagefilter.cpp index 543d1fc5..17006720 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -20,31 +20,38 @@ #include "messagefilter.h" -MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent) : QSortFilterProxyModel(parent) { +MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent) + : QSortFilterProxyModel(parent) +{ setSourceModel(source); } MessageFilter::MessageFilter(MessageModel *source, const QList &buffers, QObject *parent) : QSortFilterProxyModel(parent), - _bufferList(buffers) + _validBuffers(buffers.toSet()) { setSourceModel(source); } QString MessageFilter::idString() const { - if(_bufferList.isEmpty()) return "*"; - QString idstr; - QStringList bufids; - foreach(BufferId id, _bufferList) bufids << QString::number(id.toInt()); - bufids.sort(); - foreach(QString id, bufids) idstr += id + '|'; - idstr.chop(1); - return idstr; + if(_validBuffers.isEmpty()) + return "*"; + + QList bufferIds = _validBuffers.toList();; + qSort(bufferIds); + + QStringList bufferIdStrings; + foreach(BufferId id, bufferIds) + bufferIdStrings << QString::number(id.toInt()); + + return bufferIdStrings.join("|"); } bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); - if(_bufferList.isEmpty()) return true; + if(_validBuffers.isEmpty()) + return true; + BufferId id = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value(); - return _bufferList.contains(id); + return _validBuffers.contains(id); } diff --git a/src/client/messagefilter.h b/src/client/messagefilter.h index e767a95e..eeca9643 100644 --- a/src/client/messagefilter.h +++ b/src/client/messagefilter.h @@ -29,18 +29,18 @@ class MessageFilter : public QSortFilterProxyModel { Q_OBJECT - protected: - MessageFilter(QAbstractItemModel *source, QObject *parent = 0); - - public: - MessageFilter(MessageModel *, const QList &buffers = QList(), QObject *parent = 0); - - virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - virtual QString idString() const; - inline bool isSingleBufferFilter() const { return _bufferList.count() == 1; } - - private: - QList _bufferList; +protected: + MessageFilter(QAbstractItemModel *source, QObject *parent = 0); + +public: + MessageFilter(MessageModel *, const QList &buffers = QList(), QObject *parent = 0); + + virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + virtual QString idString() const; + inline bool isSingleBufferFilter() const { return _validBuffers.count() == 1; } + +private: + QSet _validBuffers; }; #endif diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index a0f71c6c..e16735e5 100644 --- a/src/qtui/bufferwidget.cpp +++ b/src/qtui/bufferwidget.cpp @@ -66,7 +66,6 @@ AbstractChatView *BufferWidget::createChatView(BufferId id) { _chatViews[id] = chatView; ui.stackedWidget->addWidget(chatView); chatView->setFocusProxy(this); - chatView->setBufferForBacklogFetching(id); return chatView; } diff --git a/src/qtui/chatmonitorfilter.cpp b/src/qtui/chatmonitorfilter.cpp index 1fbab84f..6bec8c3d 100644 --- a/src/qtui/chatmonitorfilter.cpp +++ b/src/qtui/chatmonitorfilter.cpp @@ -26,7 +26,7 @@ #include "networkmodel.h" ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent) - : MessageFilter(model, QList(), parent) + : MessageFilter(model, parent) { } diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 681996a5..67ce63c6 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -45,8 +45,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject _singleBufferScene(false), _selectingItem(0), _selectionStart(-1), - _isSelecting(false), - _fetchingBacklog(false) + _isSelecting(false) { MessageFilter *filter = qobject_cast(model); if(filter) { @@ -129,8 +128,6 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { setSceneRect(QRectF(0, 0, _width, _height)); emit heightChanged(_height); } - - requestBacklogIfNeeded(); } void ChatScene::modelReset() { @@ -308,27 +305,15 @@ QString ChatScene::selectionToString() const { return result; } -void ChatScene::setIsFetchingBacklog(bool fetch) { - if(!isBacklogFetchingEnabled()) return; - - if(!fetch) { - _fetchingBacklog = false; - } else { - _fetchingBacklog = true; - requestBacklogIfNeeded(); - } -} - -void ChatScene::requestBacklogIfNeeded() { - const int REQUEST_COUNT = 50; - - if(!isBacklogFetchingEnabled() || !isFetchingBacklog() || !model()->rowCount()) return; - - MsgId msgId = model()->data(model()->index(0, 0), ChatLineModel::MsgIdRole).value(); - if(!_lastBacklogOffset.isValid() || (msgId < _lastBacklogOffset && _lastBacklogSize + REQUEST_COUNT <= model()->rowCount())) { - Client::backlogManager()->requestBacklog(bufferForBacklogFetching(), REQUEST_COUNT, msgId.toInt()); - _lastBacklogOffset = msgId; - _lastBacklogSize = model()->rowCount(); +void ChatScene::requestBacklog() { + static const int REQUEST_COUNT = 50; + int backlogSize = model()->rowCount(); + if(isSingleBufferScene() && backlogSize != 0 && _lastBacklogSize + REQUEST_COUNT <= backlogSize) { + QModelIndex msgIdx = model()->index(0, 0); + MsgId msgId = model()->data(msgIdx, ChatLineModel::MsgIdRole).value(); + BufferId bufferId = model()->data(msgIdx, ChatLineModel::BufferIdRole).value(); + _lastBacklogSize = backlogSize; + Client::backlogManager()->requestBacklog(bufferId, REQUEST_COUNT, msgId.toInt()); } } diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 1b31d1f8..1fee5c29 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -18,8 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _CHATSCENE_H_ -#define _CHATSCENE_H_ +#ifndef CHATSCENE_H_ +#define CHATSCENE_H_ #include #include @@ -44,9 +44,6 @@ class ChatScene : public QGraphicsScene { inline QAbstractItemModel *model() const { return _model; } inline QString idString() const { return _idString; } - inline bool isFetchingBacklog() const; - inline bool isBacklogFetchingEnabled() const; - inline BufferId bufferForBacklogFetching() const; int sectionByScenePos(int x); inline int sectionByScenePos(const QPoint &pos) { return sectionByScenePos(pos.x()); } inline bool isSingleBufferScene() const { return _singleBufferScene; } @@ -61,8 +58,7 @@ class ChatScene : public QGraphicsScene { void startGlobalSelection(ChatItem *item, const QPointF &itemPos); void putToClipboard(const QString &); - void setIsFetchingBacklog(bool); - inline void setBufferForBacklogFetching(BufferId buffer); + void requestBacklog(); signals: void heightChanged(qreal height); @@ -83,7 +79,6 @@ class ChatScene : public QGraphicsScene { private: void updateSelection(const QPointF &pos); QString selectionToString() const; - void requestBacklogIfNeeded(); QString _idString; qreal _width, _height; @@ -101,26 +96,7 @@ class ChatScene : public QGraphicsScene { int _firstSelectionRow, _lastSelectionRow; bool _isSelecting; - bool _fetchingBacklog; - BufferId _backlogFetchingBuffer; - MsgId _lastBacklogOffset; int _lastBacklogSize; }; -bool ChatScene::isFetchingBacklog() const { - return _fetchingBacklog; -} - -bool ChatScene::isBacklogFetchingEnabled() const { - return _backlogFetchingBuffer.isValid(); -} - -BufferId ChatScene::bufferForBacklogFetching() const { - return _backlogFetchingBuffer; -} - -void ChatScene::setBufferForBacklogFetching(BufferId buf) { - _backlogFetchingBuffer = buf; -} - #endif diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 77a0976f..20557e2f 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -37,7 +37,6 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent) filterList.append(bufferId); MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this); init(filter); - } ChatView::ChatView(MessageFilter *filter, QWidget *parent) @@ -56,8 +55,6 @@ void ChatView::init(MessageFilter *filter) { connect(_scene, SIGNAL(heightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal))); setScene(_scene); - connect(verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(sliderPressed())); - connect(verticalScrollBar(), SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int))); } @@ -73,33 +70,16 @@ void ChatView::sceneHeightChanged(qreal h) { if(scrollable) verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } -void ChatView::setBufferForBacklogFetching(BufferId id) { - scene()->setBufferForBacklogFetching(id); -} - -void ChatView::sliderPressed() { - verticalScrollbarChanged(verticalScrollBar()->value()); -} - -void ChatView::sliderReleased() { - if(scene()->isFetchingBacklog()) scene()->setIsFetchingBacklog(false); -} - void ChatView::verticalScrollbarChanged(int newPos) { - Q_UNUSED(newPos); - if(!scene()->isBacklogFetchingEnabled()) return; - QAbstractSlider *vbar = verticalScrollBar(); - if(!vbar) - return; - if(vbar->isSliderDown()) { - /* - int relativePos = 100; - if(vbar->maximum() - vbar->minimum() != 0) - relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum()); - scene()->setIsFetchingBacklog(relativePos < 20); - */ - scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum()); + Q_ASSERT(vbar); + + int relativePos = 100; + if(vbar->maximum() - vbar->minimum() != 0) + relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum()); + + if(relativePos < 20) { + scene()->requestBacklog(); } } @@ -111,6 +91,5 @@ MsgId ChatView::lastMsgId() const { if(!model || model->rowCount() == 0) return MsgId(); - return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); } diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 998d9fc8..21367fe4 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -43,7 +43,6 @@ public: public slots: inline virtual void clear() {} - void setBufferForBacklogFetching(BufferId buffer); protected: virtual void resizeEvent(QResizeEvent *event); @@ -51,8 +50,6 @@ protected: protected slots: virtual void sceneHeightChanged(qreal height); virtual void verticalScrollbarChanged(int); - virtual void sliderPressed(); - virtual void sliderReleased(); private: void init(MessageFilter *filter); -- 2.20.1