From: Marcus Eggenberger Date: Sat, 3 May 2008 17:11:29 +0000 (+0000) Subject: fixing custom buffer views with minimum activity X-Git-Tag: 0.2.0-beta1~10 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=993d4d84b10d89197a100212b4aaa1b8ceca1dbb fixing custom buffer views with minimum activity --- diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 3b895d1e..c168eaaa 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -129,11 +129,25 @@ void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig * } else { BufferViewFilter *filter = new BufferViewFilter(model_, config); setModel(filter); - connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &))); + connect(this, SIGNAL(removeBuffer(const QModelIndex &)), + filter, SLOT(removeBuffer(const QModelIndex &))); } setConfig(config); } +void BufferView::setSelectionModel(QItemSelectionModel *selectionModel) { + if(QTreeView::selectionModel()) + disconnect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + model(), SIGNAL(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex))); + + QTreeView::setSelectionModel(selectionModel); + BufferViewFilter *filter = qobject_cast(model()); + if(filter) { + connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + filter, SLOT(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex))); + } +} + void BufferView::setConfig(BufferViewConfig *config) { if(_config == config) return; diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index b42c6c1a..66ee467b 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -42,6 +42,7 @@ public: void setModel(QAbstractItemModel *model); void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config); + virtual void setSelectionModel(QItemSelectionModel *selectionModel); void setConfig(BufferViewConfig *config); inline BufferViewConfig *config() { return _config; } diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 51f8b0e5..c34d023e 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -26,6 +26,12 @@ #include "uisettings.h" +class CheckRemovalEvent : public QEvent { +public: + CheckRemovalEvent(const QModelIndex &source_index) : QEvent(QEvent::User), index(source_index) {}; + QPersistentModelIndex index; +}; + /***************************************** * The Filter for the Tree View *****************************************/ @@ -40,6 +46,9 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * setDynamicSortFilter(true); loadColors(); + + connect(this, SIGNAL(_dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex))); } void BufferViewFilter::loadColors() { @@ -268,6 +277,28 @@ void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start, } } +void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous) { + Q_UNUSED(current); + if(previous.isValid()) + qApp->postEvent(this, new CheckRemovalEvent(previous)); +} + +void BufferViewFilter::customEvent(QEvent *event) { + if(event->type() != QEvent::User) + return; + + CheckRemovalEvent *removalEvent = static_cast(event); + checkItemForRemoval(removalEvent->index); + + event->accept(); +} + +void BufferViewFilter::checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight) { + QModelIndex source_topLeft = mapToSource(topLeft); + QModelIndex source_bottomRight = mapToSource(bottomRight); + emit _dataChanged(source_topLeft, source_bottomRight); +} + // ****************************** // Helper // ****************************** diff --git a/src/uisupport/bufferviewfilter.h b/src/uisupport/bufferviewfilter.h index 4715f11a..4a80f7ec 100644 --- a/src/uisupport/bufferviewfilter.h +++ b/src/uisupport/bufferviewfilter.h @@ -63,6 +63,9 @@ public: public slots: void removeBuffer(const QModelIndex &); + void checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous); + void checkItemForRemoval(const QModelIndex &index) { checkItemsForRemoval(index, index); } + void checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight); void source_rowsInserted(const QModelIndex &parent, int start, int end); protected: @@ -70,17 +73,21 @@ protected: bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; bool bufferLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; bool networkLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const; + virtual void customEvent(QEvent *event); +signals: + void _dataChanged(const QModelIndex &source_topLeft, const QModelIndex &source_bottomRight); + private: QPointer _config; - + QColor _FgColorInactiveActivity; QColor _FgColorNoActivity; QColor _FgColorHighlightActivity; QColor _FgColorNewMessageActivity; QColor _FgColorOtherActivity; void loadColors(); - + bool filterAcceptBuffer(const QModelIndex &) const; bool filterAcceptNetwork(const QModelIndex &) const; void addBuffer(const BufferId &); diff --git a/version.inc b/version.inc index 79f7d317..641fb539 100644 --- a/version.inc +++ b/version.inc @@ -4,8 +4,8 @@ { using namespace Global; quasselVersion = "0.2.0-beta1-pre"; - quasselDate = "2008-05-02"; - quasselBuild = 807; + quasselDate = "2008-05-03"; + quasselBuild = 808; //! Minimum client build number the core needs clientBuildNeeded = 731;