From c867e55403de9691bc0657378a078cf2bd774b85 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Tue, 1 Nov 2016 16:22:19 +0000
Subject: Explicitly synchronize chat view font sizes on font size change

Test-Information:

Unit tests pass with Qt 5.7.0. Chat view sizes are synchronised
on change. ASAN does not complain when opening/closing lots
of chat windows and then closing Swift.

Change-Id: Ib00260d2331f48f0ca3c47a2340311dcff85c5ed

diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index a9e0e8f..9eed822 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -6,6 +6,8 @@
 
 #include <Swift/QtUI/QtUIFactory.h>
 
+#include <algorithm>
+
 #include <QSplitter>
 
 #include <Swiften/Whiteboard/WhiteboardSession.h>
@@ -120,19 +122,15 @@ MUCSearchWindow* QtUIFactory::createMUCSearchWindow() {
 
 ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eventStream) {
     QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream));
+
+    // remove already closed and thereby deleted chat windows
+    chatWindows.erase(std::remove_if(chatWindows.begin(), chatWindows.end(),
+        [](QPointer<QtChatWindow>& window) {
+            return window.isNull();
+        }), chatWindows.end());
+
     chatWindows.push_back(window);
-    std::vector<QPointer<QtChatWindow> > deletions;
-    foreach (QPointer<QtChatWindow> existingWindow, chatWindows) {
-        if (existingWindow.isNull()) {
-            deletions.push_back(existingWindow);
-        } else {
-            connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int)));
-            connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int)));
-        }
-    }
-    foreach (QPointer<QtChatWindow> deletedWindow, deletions) {
-        chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), deletedWindow), chatWindows.end());
-    }
+
     connect(window, SIGNAL(fontResized(int)), this, SLOT(handleChatWindowFontResized(int)));
     window->handleFontResized(chatFontSize);
     return window;
@@ -141,6 +139,13 @@ ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eve
 void QtUIFactory::handleChatWindowFontResized(int size) {
     chatFontSize = size;
     settings->storeSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE, size);
+
+    // resize font in other chat windows
+    for (auto&& existingWindow : chatWindows) {
+        if (!existingWindow.isNull()) {
+            existingWindow->handleFontResized(size);
+        }
+    }
 }
 
 UserSearchWindow* QtUIFactory::createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) {
diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h
index a57d509..ce3b533 100644
--- a/Swift/QtUI/QtUIFactory.h
+++ b/Swift/QtUI/QtUIFactory.h
@@ -6,6 +6,8 @@
 
 #pragma once
 
+#include <vector>
+
 #include <QObject>
 #include <QPointer>
 
@@ -14,21 +16,20 @@
 class QSplitter;
 
 namespace Swift {
-    class QtSettingsProvider;
-    class SettingsProviderHierachy;
-    class QtChatTabsBase;
     class QtChatTabs;
-    class QtSystemTray;
-    class QtLoginWindow;
-    class QtMainWindow;
+    class QtChatTabsBase;
     class QtChatTheme;
-    class QtChatWindowFactory;
     class QtChatWindow;
+    class QtChatWindowFactory;
+    class QtLoginWindow;
+    class QtMainWindow;
+    class QtSettingsProvider;
+    class QtSingleWindow;
+    class QtSystemTray;
+    class SettingsProviderHierachy;
+    class StatusCache;
     class TimerFactory;
-    class historyWindow_;
     class WhiteboardSession;
-    class StatusCache;
-    class QtSingleWindow;
 
     class QtUIFactory : public QObject, public UIFactory {
             Q_OBJECT
-- 
cgit v0.10.2-6-g49f6