Fix expanding networks in Chat Monitor settings
authorShane Synan <digitalcircuit36939@gmail.com>
Sat, 14 Jan 2017 20:54:53 +0000 (14:54 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 4 Apr 2018 21:14:03 +0000 (23:14 +0200)
Update the network expanded/collapsed state when setting a model,
including filtered models.

This fixes the Chat Monitor settings page not updating the expanded
and collapsed networks on first load.  It might be excessive to apply
on every model change; if performance issues arise, it can be moved
to BufferView::setFilteredModel() or elsewhere.

Add comments!

Resolves GH-271.

(cherry picked from commit efee441a243efb88929e1e275d71ee27991bf074)

src/uisupport/bufferview.cpp
src/uisupport/bufferview.h

index 76bb297..f14cff2 100644 (file)
@@ -129,6 +129,11 @@ void BufferView::setModel(QAbstractItemModel *model)
     }
 
     connect(model, SIGNAL(layoutChanged()), this, SLOT(on_layoutChanged()));
     }
 
     connect(model, SIGNAL(layoutChanged()), this, SLOT(on_layoutChanged()));
+
+    // Make sure collapsation is correct after setting a model
+    // This might not be needed here, only in BufferView::setFilteredModel().  If issues arise, just
+    // move down to setFilteredModel (which calls this function).
+    setExpandedState();
 }
 
 
 }
 
 
@@ -329,7 +334,19 @@ void BufferView::on_configChanged()
 {
     Q_ASSERT(model());
 
 {
     Q_ASSERT(model());
 
-    // expand all active networks... collapse inactive ones... unless manually changed
+    // Expand/collapse as needed
+    setExpandedState();
+
+    if (config()) {
+        // update selection to current one
+        Client::bufferModel()->synchronizeView(this);
+    }
+}
+
+
+void BufferView::setExpandedState()
+{
+    // Expand all active networks, collapse inactive ones... unless manually changed
     QModelIndex networkIdx;
     NetworkId networkId;
     for (int row = 0; row < model()->rowCount(); row++) {
     QModelIndex networkIdx;
     NetworkId networkId;
     for (int row = 0; row < model()->rowCount(); row++) {
@@ -343,11 +360,6 @@ void BufferView::on_configChanged()
 
         setExpandedState(networkIdx);
     }
 
         setExpandedState(networkIdx);
     }
-
-    if (config()) {
-        // update selection to current one
-        Client::bufferModel()->synchronizeView(this);
-    }
 }
 
 
 }
 
 
index 3e0384c..ce8b956 100644 (file)
@@ -90,7 +90,31 @@ private slots:
     void joinChannel(const QModelIndex &index);
     void toggleHeader(bool checked);
 
     void joinChannel(const QModelIndex &index);
     void toggleHeader(bool checked);
 
+    /**
+     * Expand all active networks and collapse inactive ones unless manually changed
+     *
+     * Applies to all networks.  Shouldn't need called except during initialization.
+     */
+    void setExpandedState();
+
+    /**
+     * Save the current display state of the given network
+     *
+     * Tracks expanded or collapsed and active or inactive.
+     *
+     * @see setExpandedState()
+     * @param[in] networkIdx QModelIndex of the root network to store
+     */
     void storeExpandedState(const QModelIndex &networkIdx);
     void storeExpandedState(const QModelIndex &networkIdx);
+
+    /**
+     * Set the display state of the given network according to network status and manual changes
+     *
+     * Expands if active or previously expanded, collapses if inactive or previously collapsed.
+     *
+     * @see storeExpandedState()
+     * @param[in] networkIdx QModelIndex of the root network to update
+     */
     void setExpandedState(const QModelIndex &networkIdx);
 
     void on_configChanged();
     void setExpandedState(const QModelIndex &networkIdx);
 
     void on_configChanged();