Mercurial > octave
comparison libgui/src/documentation-bookmarks.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 | 796f54d4ddbf |
children | 0645ea65ca6b |
comparison
equal
deleted
inserted
replaced
31618:cd833a9baaa7 | 31619:ad014fc78bd6 |
---|---|
34 #include <QWidget> | 34 #include <QWidget> |
35 | 35 |
36 #include "documentation.h" | 36 #include "documentation.h" |
37 #include "documentation-bookmarks.h" | 37 #include "documentation-bookmarks.h" |
38 | 38 |
39 #include "gui-settings.h" | |
40 #include "gui-preferences-global.h" | 39 #include "gui-preferences-global.h" |
41 #include "gui-preferences-dc.h" | 40 #include "gui-preferences-dc.h" |
42 #include "gui-preferences-sc.h" | 41 #include "gui-preferences-sc.h" |
42 #include "gui-settings.h" | |
43 #include "octave-qtutils.h" | 43 #include "octave-qtutils.h" |
44 #include "shortcut-manager.h" | 44 #include "shortcut-manager.h" |
45 | 45 |
46 #include "defaults.h" | 46 #include "defaults.h" |
47 #include "file-ops.h" | 47 #include "file-ops.h" |
56 m_doc (doc), m_browser (browser), m_octave_qobj (oct_qobj), | 56 m_doc (doc), m_browser (browser), m_octave_qobj (oct_qobj), |
57 m_ctx_menu_item (nullptr) | 57 m_ctx_menu_item (nullptr) |
58 { | 58 { |
59 setObjectName ("documentation_tab_bookmarks"); | 59 setObjectName ("documentation_tab_bookmarks"); |
60 | 60 |
61 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 61 gui_settings settings; |
62 gui_settings *settings = rmgr.get_settings (); | |
63 | 62 |
64 // Setup the tree view with the bookmarks | 63 // Setup the tree view with the bookmarks |
65 m_tree = new QTreeWidget (p); | 64 m_tree = new QTreeWidget (p); |
66 | 65 |
67 m_tree->setContextMenuPolicy (Qt::CustomContextMenu); | 66 m_tree->setContextMenuPolicy (Qt::CustomContextMenu); |
87 icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), | 86 icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), |
88 QIcon::Normal, QIcon::On); | 87 QIcon::Normal, QIcon::On); |
89 icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); | 88 icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); |
90 | 89 |
91 // Setup and read the bookmarkfile | 90 // Setup and read the bookmarkfile |
92 QFileInfo f (settings->fileName ()); | 91 QFileInfo f (settings.fileName ()); |
93 QString f_path = f.absolutePath (); | 92 QString f_path = f.absolutePath (); |
94 f.setFile (QDir (f_path), dc_bookmark_file); | 93 f.setFile (QDir (f_path), dc_bookmark_file); |
95 m_xbel_file.setFileName (f.absoluteFilePath ()); | 94 m_xbel_file.setFileName (f.absoluteFilePath ()); |
96 | 95 |
97 if (m_xbel_file.exists ()) | 96 if (m_xbel_file.exists ()) |
119 m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); | 118 m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); |
120 QSizePolicy size_pol (QSizePolicy::Expanding, QSizePolicy::Preferred); | 119 QSizePolicy size_pol (QSizePolicy::Expanding, QSizePolicy::Preferred); |
121 m_filter->setSizePolicy (size_pol); | 120 m_filter->setSizePolicy (size_pol); |
122 m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); | 121 m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); |
123 | 122 |
124 m_filter->addItems (settings->value (dc_bookmark_filter_mru).toStringList ()); | 123 m_filter->addItems (settings.value (dc_bookmark_filter_mru).toStringList ()); |
125 | 124 |
126 connect (m_filter, &QComboBox::editTextChanged, | 125 connect (m_filter, &QComboBox::editTextChanged, |
127 this, &documentation_bookmarks::filter_bookmarks); | 126 this, &documentation_bookmarks::filter_bookmarks); |
128 connect (m_filter->lineEdit (), &QLineEdit::editingFinished, | 127 connect (m_filter->lineEdit (), &QLineEdit::editingFinished, |
129 this, &documentation_bookmarks::update_filter_history); | 128 this, &documentation_bookmarks::update_filter_history); |
130 | 129 |
131 m_filter_checkbox = new QCheckBox (m_filter_widget); | 130 m_filter_checkbox = new QCheckBox (m_filter_widget); |
132 bool filter_state = settings->value (dc_bookmark_filter_active).toBool (); | 131 bool filter_state = settings.value (dc_bookmark_filter_active).toBool (); |
133 m_filter_checkbox->setChecked (filter_state); | 132 m_filter_checkbox->setChecked (filter_state); |
134 filter_activate (filter_state); | 133 filter_activate (filter_state); |
135 | 134 |
136 connect (m_filter_checkbox, &QCheckBox::toggled, | 135 connect (m_filter_checkbox, &QCheckBox::toggled, |
137 this, &documentation_bookmarks::filter_activate); | 136 this, &documentation_bookmarks::filter_activate); |
142 h_box_bm->addWidget (m_filter_checkbox); | 141 h_box_bm->addWidget (m_filter_checkbox); |
143 h_box_bm->addWidget (m_filter); | 142 h_box_bm->addWidget (m_filter); |
144 h_box_bm->setMargin (2); | 143 h_box_bm->setMargin (2); |
145 m_filter_widget->setLayout (h_box_bm); | 144 m_filter_widget->setLayout (h_box_bm); |
146 | 145 |
147 m_filter_shown = settings->value (dc_bookmark_filter_shown).toBool (); | 146 m_filter_shown = settings.value (dc_bookmark_filter_shown).toBool (); |
148 m_filter_widget->setVisible (m_filter_shown); | 147 m_filter_widget->setVisible (m_filter_shown); |
149 | 148 |
150 // Resulting Layout of this widget | 149 // Resulting Layout of this widget |
151 QVBoxLayout *v_box_bm = new QVBoxLayout (this); | 150 QVBoxLayout *v_box_bm = new QVBoxLayout (this); |
152 v_box_bm->addWidget (m_filter_widget); | 151 v_box_bm->addWidget (m_filter_widget); |
378 { | 377 { |
379 m_filter_shown = ! m_filter_shown; | 378 m_filter_shown = ! m_filter_shown; |
380 m_filter_widget->setVisible (m_filter_shown); | 379 m_filter_widget->setVisible (m_filter_shown); |
381 } | 380 } |
382 | 381 |
383 void documentation_bookmarks::save_settings (gui_settings *settings) | 382 void documentation_bookmarks::save_settings (void) |
384 { | 383 { |
385 // Write the bookmarks to the xbel-file | 384 // Write the bookmarks to the xbel-file |
386 write_bookmarks (); | 385 write_bookmarks (); |
387 | 386 |
388 // Store settings | 387 // Store settings |
389 settings->setValue (dc_bookmark_filter_active.key, m_filter_checkbox->isChecked ()); | 388 gui_settings settings; |
390 settings->setValue (dc_bookmark_filter_shown.key, m_filter_shown); | 389 |
390 settings.setValue (dc_bookmark_filter_active.key, m_filter_checkbox->isChecked ()); | |
391 settings.setValue (dc_bookmark_filter_shown.key, m_filter_shown); | |
391 | 392 |
392 QStringList mru; | 393 QStringList mru; |
393 for (int i = 0; i < m_filter->count (); i++) | 394 for (int i = 0; i < m_filter->count (); i++) |
394 mru.append (m_filter->itemText (i)); | 395 mru.append (m_filter->itemText (i)); |
395 settings->setValue (dc_bookmark_filter_mru.key, mru); | 396 settings.setValue (dc_bookmark_filter_mru.key, mru); |
396 | 397 |
397 settings->sync (); | 398 settings.sync (); |
398 } | 399 } |
399 | 400 |
400 void documentation_bookmarks::write_bookmarks (void) | 401 void documentation_bookmarks::write_bookmarks (void) |
401 { | 402 { |
402 if (! m_xbel_file.open (QFile::WriteOnly | QFile::Text)) | 403 if (! m_xbel_file.open (QFile::WriteOnly | QFile::Text)) |