Fix issues with buffer selection and filtered views
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 8 Feb 2016 20:04:03 +0000 (21:04 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 8 Feb 2016 20:04:03 +0000 (21:04 +0100)
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.

src/client/selectionmodelsynchronizer.cpp
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h
src/uisupport/bufferviewfilter.cpp
src/uisupport/bufferviewfilter.h

index 0dcf7f8..14c57c0 100644 (file)
@@ -255,6 +255,13 @@ void SelectionModelSynchronizer::currentChanged(const QModelIndex &current, cons
         ++iter;
     }
     _changeCurrentEnabled = true;
         ++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));
+    }
 }
 
 
 }
 
 
index d092146..c27e3a3 100644 (file)
@@ -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<BufferViewFilter *>(model());
-    if (filter) {
-        connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
-            filter, SLOT(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
-    }
-}
-
-
 void BufferView::setConfig(BufferViewConfig *config)
 {
     if (_config == config)
 void BufferView::setConfig(BufferViewConfig *config)
 {
     if (_config == config)
index a49ce15..2962e5e 100644 (file)
@@ -52,7 +52,6 @@ public:
 
     void setModel(QAbstractItemModel *model);
     void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
 
     void setModel(QAbstractItemModel *model);
     void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
-    virtual void setSelectionModel(QItemSelectionModel *selectionModel);
 
     void setConfig(BufferViewConfig *config);
     inline BufferViewConfig *config() { return _config; }
 
     void setConfig(BufferViewConfig *config);
     inline BufferViewConfig *config() { return _config; }
index c829267..4c5d4a9 100644 (file)
 #include "networkmodel.h"
 #include "uistyle.h"
 
 #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
 
 /*****************************************
 * The Filter for the Tree View
@@ -57,9 +50,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *
 
     setDynamicSortFilter(true);
 
 
     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)));
     _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 &current, 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<CheckRemovalEvent *>(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());
 bool BufferViewFilter::bufferIdLessThan(const BufferId &left, const BufferId &right)
 {
     Q_CHECK_PTR(Client::networkModel());
index 1a4d781..5cf0cce 100644 (file)
@@ -69,20 +69,13 @@ public:
 
     QList<QAction *> actions(const QModelIndex &index);
 
 
     QList<QAction *> actions(const QModelIndex &index);
 
-public slots:
-    void checkPreviousCurrentForRemoval(const QModelIndex &current, 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;
 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:
 
 signals:
-    void _dataChanged(const QModelIndex &source_topLeft, const QModelIndex &source_bottomRight);
     void configChanged();
 
 private slots:
     void configChanged();
 
 private slots: