From: Manuel Nickschas Date: Mon, 8 Feb 2016 20:04:03 +0000 (+0100) Subject: Fix issues with buffer selection and filtered views X-Git-Tag: travis-deploy-test~529 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=30cc5367bf38d8720e55ece5cab218c4b52e0dbf Fix issues with buffer selection and filtered views Whenever the current buffer changed, filtered BufferViews need to check if the previously selected item should be hidden (e.g. due to activity settings). The existing code for this never really worked due to the currentChanged() signal emission being wonky (it would sometimes be eaten for some reason), and fully stopped working in Qt5 since it connected to a private, internal slot of QSFPM. This commit removes the old code and replaces it by faking the emission of a dataChanged() signal from the base model whenever the current buffer changes. --- diff --git a/src/client/selectionmodelsynchronizer.cpp b/src/client/selectionmodelsynchronizer.cpp index 0dcf7f8e..14c57c06 100644 --- a/src/client/selectionmodelsynchronizer.cpp +++ b/src/client/selectionmodelsynchronizer.cpp @@ -255,6 +255,13 @@ void SelectionModelSynchronizer::currentChanged(const QModelIndex ¤t, cons ++iter; } _changeCurrentEnabled = true; + + // Trigger a dataChanged() signal from the base model to update all proxy models (e.g. filters). + // Since signals are protected, we have to use invokeMethod for faking signal emission. + if (previous.isValid()) { + QMetaObject::invokeMethod(model(), "dataChanged", Qt::DirectConnection, + Q_ARG(QModelIndex, previous), Q_ARG(QModelIndex, previous)); + } } diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index d0921466..c27e3a31 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -158,21 +158,6 @@ void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig * } -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) diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index a49ce15c..2962e5e9 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -52,7 +52,6 @@ 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 c829267a..4c5d4a9c 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -33,13 +33,6 @@ #include "networkmodel.h" #include "uistyle.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 @@ -57,9 +50,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * setDynamicSortFilter(true); - connect(this, SIGNAL(_dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(_q_sourceDataChanged(QModelIndex, QModelIndex))); - _enableEditMode.setCheckable(true); _enableEditMode.setChecked(_editMode); connect(&_enableEditMode, SIGNAL(toggled(bool)), this, SLOT(enableEditMode(bool))); @@ -542,34 +532,6 @@ bool BufferViewFilter::setCheckedState(const QModelIndex &index, Qt::CheckState } -void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous) -{ - Q_UNUSED(current); - if (previous.isValid()) - QCoreApplication::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); -} - - bool BufferViewFilter::bufferIdLessThan(const BufferId &left, const BufferId &right) { Q_CHECK_PTR(Client::networkModel()); diff --git a/src/uisupport/bufferviewfilter.h b/src/uisupport/bufferviewfilter.h index 1a4d7818..5cf0ccec 100644 --- a/src/uisupport/bufferviewfilter.h +++ b/src/uisupport/bufferviewfilter.h @@ -69,20 +69,13 @@ public: QList actions(const QModelIndex &index); -public slots: - void checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous); - void checkItemForRemoval(const QModelIndex &index) { checkItemsForRemoval(index, index); } - void checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight); - protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; 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); void configChanged(); private slots: