comparison libgui/src/documentation.cc @ 31619:ad014fc78bd6

use individual local gui_settings objects Previously, we created a single gui_settings object (derived from QSettings) and accessed it from the resource_manager object. That design is not necessary and is not the way QSettings was designed to be used. Instead of managing a single object, we should be using individual QSettings objects where needed. Each individual QSettings object manages thread-safe access to a single global collection of settings. The Qt docs say that operations on QSettings are not thread safe, but that means that you can't create a QSettings object in one thread and use it in another without some locking. I'm not sure whether we were doing that correctly, but with this change it no longer matters. Each QSettings object does perform locking when reading or writing the underlying global data. * resource-manager.h, resource-manager.cc (resource_manager::m_settings): Delete data member. (resource_manager::get_settings): Delete. * annotation-dialog.cc, QTerminal.cc, QTerminal.h, command-widget.cc, command-widget.h, community-news.cc, dialog.cc, documentation-bookmarks.cc, documentation-bookmarks.h, documentation-dock-widget.cc, documentation-dock-widget.h, documentation.cc, documentation.h, dw-main-window.cc, dw-main-window.h, external-editor-interface.cc, files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc, history-dock-widget.cc, history-dock-widget.h, file-editor-interface.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc, octave-qscintilla.cc, main-window.cc, main-window.h, news-reader.cc, octave-dock-widget.cc, octave-dock-widget.h, qt-interpreter-events.cc, qt-interpreter-events.h, release-notes.cc, resource-manager.cc, resource-manager.h, set-path-dialog.cc, settings-dialog.cc, settings-dialog.h, shortcut-manager.cc, shortcut-manager.h, terminal-dock-widget.cc, terminal-dock-widget.h, variable-editor.cc, variable-editor.h, welcome-wizard.cc, workspace-model.cc, workspace-model.h, workspace-view.cc: Use local gui_settings objects instead of accessing a pointer to a single gui_settings object owned by the resource_manager object.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Dec 2022 14:23:53 -0500
parents c8ad083a5802
children 0645ea65ca6b
comparison
equal deleted inserted replaced
31618:cd833a9baaa7 31619:ad014fc78bd6
54 #include "documentation.h" 54 #include "documentation.h"
55 #include "documentation-bookmarks.h" 55 #include "documentation-bookmarks.h"
56 #include "gui-preferences-global.h" 56 #include "gui-preferences-global.h"
57 #include "gui-preferences-dc.h" 57 #include "gui-preferences-dc.h"
58 #include "gui-preferences-sc.h" 58 #include "gui-preferences-sc.h"
59 #include "gui-settings.h"
59 #include "octave-qobject.h" 60 #include "octave-qobject.h"
60 #include "shortcut-manager.h" 61 #include "shortcut-manager.h"
61 62
62 #include "defaults.h" 63 #include "defaults.h"
63 #include "file-ops.h" 64 #include "file-ops.h"
178 v_box_browser_find->addWidget (m_tool_bar); 179 v_box_browser_find->addWidget (m_tool_bar);
179 v_box_browser_find->addWidget (m_doc_browser); 180 v_box_browser_find->addWidget (m_doc_browser);
180 v_box_browser_find->addWidget (find_footer); 181 v_box_browser_find->addWidget (find_footer);
181 browser_find->setLayout (v_box_browser_find); 182 browser_find->setLayout (v_box_browser_find);
182 183
183 notice_settings (rmgr.get_settings ()); 184 notice_settings ();
184 185
185 m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut); 186 m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
186 connect (m_findnext_shortcut, &QShortcut::activated, 187 connect (m_findnext_shortcut, &QShortcut::activated,
187 this, [=] () { find (); }); 188 this, [=] () { find (); });
188 m_findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut); 189 m_findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
601 // Apply selection and move back to the beginning 602 // Apply selection and move back to the beginning
602 m_doc_browser->setExtraSelections (selected); 603 m_doc_browser->setExtraSelections (selected);
603 m_doc_browser->moveCursor (QTextCursor::Start); 604 m_doc_browser->moveCursor (QTextCursor::Start);
604 } 605 }
605 606
606 void documentation::notice_settings (const gui_settings *settings) 607 void documentation::notice_settings (void)
607 { 608 {
609 gui_settings settings;
610
608 // If m_help_engine is not defined, the objects accessed by this method 611 // If m_help_engine is not defined, the objects accessed by this method
609 // are not valid. Thus, just return in this case. 612 // are not valid. Thus, just return in this case.
610 if (! m_help_engine) 613 if (! m_help_engine)
611 return; 614 return;
612 615
613 // Icon size in the toolbar. 616 // Icon size in the toolbar.
614 int size_idx = settings->value (global_icon_size).toInt (); 617 int size_idx = settings.value (global_icon_size).toInt ();
615 size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 618 size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2
616 619
617 QStyle *st = style (); 620 QStyle *st = style ();
618 int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); 621 int icon_size = st->pixelMetric (global_icon_sizes[size_idx]);
619 m_tool_bar->setIconSize (QSize (icon_size, icon_size)); 622 m_tool_bar->setIconSize (QSize (icon_size, icon_size));
631 scmgr.set_shortcut (m_action_go_prev, sc_doc_go_back); 634 scmgr.set_shortcut (m_action_go_prev, sc_doc_go_back);
632 scmgr.set_shortcut (m_action_go_next, sc_doc_go_next); 635 scmgr.set_shortcut (m_action_go_next, sc_doc_go_next);
633 scmgr.set_shortcut (m_action_bookmark, sc_doc_bookmark); 636 scmgr.set_shortcut (m_action_bookmark, sc_doc_bookmark);
634 637
635 // Settings for the browser 638 // Settings for the browser
636 m_doc_browser->notice_settings (settings); 639 m_doc_browser->notice_settings ();
637 } 640 }
638 641
639 void documentation::save_settings (void) 642 void documentation::save_settings (void)
640 { 643 {
641 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); 644 gui_settings settings;
642 gui_settings *settings = rmgr.get_settings (); 645
643 646 m_doc_browser->save_settings ();
644 m_doc_browser->save_settings (settings); 647 m_bookmarks->save_settings ();
645 m_bookmarks->save_settings (settings);
646 } 648 }
647 649
648 void documentation::copyClipboard (void) 650 void documentation::copyClipboard (void)
649 { 651 {
650 if (m_doc_browser->hasFocus ()) 652 if (m_doc_browser->hasFocus ())
1037 setSource (url); 1039 setSource (url);
1038 else 1040 else
1039 QDesktopServices::openUrl (url); 1041 QDesktopServices::openUrl (url);
1040 } 1042 }
1041 1043
1042 void documentation_browser::notice_settings (const gui_settings *settings) 1044 void documentation_browser::notice_settings (void)
1043 { 1045 {
1046 gui_settings settings;
1047
1044 // Zoom level only at startup, not when other settings have changed 1048 // Zoom level only at startup, not when other settings have changed
1045 if (m_zoom_level > max_zoom_level) 1049 if (m_zoom_level > max_zoom_level)
1046 { 1050 {
1047 m_zoom_level = settings->value (dc_browser_zoom_level).toInt (); 1051 m_zoom_level = settings.value (dc_browser_zoom_level).toInt ();
1048 zoomIn (m_zoom_level); 1052 zoomIn (m_zoom_level);
1049 } 1053 }
1050 } 1054 }
1051 1055
1052 QVariant documentation_browser::loadResource (int type, const QUrl& url) 1056 QVariant documentation_browser::loadResource (int type, const QUrl& url)
1055 return QVariant (m_help_engine->fileData(url)); 1059 return QVariant (m_help_engine->fileData(url));
1056 else 1060 else
1057 return QTextBrowser::loadResource(type, url); 1061 return QTextBrowser::loadResource(type, url);
1058 } 1062 }
1059 1063
1060 void documentation_browser::save_settings (gui_settings *settings) 1064 void documentation_browser::save_settings (void)
1061 { 1065 {
1062 settings->setValue (dc_browser_zoom_level.key, m_zoom_level); 1066 gui_settings settings;
1063 1067
1064 settings->sync (); 1068 settings.setValue (dc_browser_zoom_level.key, m_zoom_level);
1069
1070 settings.sync ();
1065 } 1071 }
1066 1072
1067 void documentation_browser::zoom_in (void) 1073 void documentation_browser::zoom_in (void)
1068 { 1074 {
1069 if (m_zoom_level < max_zoom_level) 1075 if (m_zoom_level < max_zoom_level)