Mercurial > octave
comparison libgui/qterminal/libqterminal/QTerminal.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 | 5154c91e0d98 |
children | 0645ea65ca6b |
comparison
equal
deleted
inserted
replaced
31618:cd833a9baaa7 | 31619:ad014fc78bd6 |
---|---|
36 #include <QAction> | 36 #include <QAction> |
37 | 37 |
38 #include "gui-preferences-global.h" | 38 #include "gui-preferences-global.h" |
39 #include "gui-preferences-cs.h" | 39 #include "gui-preferences-cs.h" |
40 #include "gui-preferences-sc.h" | 40 #include "gui-preferences-sc.h" |
41 #include "gui-settings.h" | |
41 #include "octave-qobject.h" | 42 #include "octave-qobject.h" |
42 #include "resource-manager.h" | 43 #include "resource-manager.h" |
43 | 44 |
44 #include "QTerminal.h" | 45 #include "QTerminal.h" |
45 #if defined (Q_OS_WIN32) | 46 #if defined (Q_OS_WIN32) |
197 QString expr = m_doc_selected_action->data ().toString (); | 198 QString expr = m_doc_selected_action->data ().toString (); |
198 m_octave_qobj.show_documentation_window (expr); | 199 m_octave_qobj.show_documentation_window (expr); |
199 } | 200 } |
200 | 201 |
201 void | 202 void |
202 QTerminal::notice_settings (const gui_settings *settings) | 203 QTerminal::notice_settings (void) |
203 { | 204 { |
204 if (! settings) | 205 octave::gui_settings settings; |
205 return; | |
206 | 206 |
207 // Set terminal font: | 207 // Set terminal font: |
208 QFont term_font = QFont (); | 208 QFont term_font = QFont (); |
209 term_font.setStyleHint (QFont::TypeWriter); | 209 term_font.setStyleHint (QFont::TypeWriter); |
210 QString default_font = settings->value (global_mono_font).toString (); | 210 QString default_font = settings.value (global_mono_font).toString (); |
211 term_font.setFamily | 211 term_font.setFamily |
212 (settings->value (cs_font.key, default_font).toString ()); | 212 (settings.value (cs_font.key, default_font).toString ()); |
213 term_font.setPointSize | 213 term_font.setPointSize |
214 (settings->value (cs_font_size).toInt ()); | 214 (settings.value (cs_font_size).toInt ()); |
215 setTerminalFont (term_font); | 215 setTerminalFont (term_font); |
216 | 216 |
217 QFontMetrics metrics (term_font); | 217 QFontMetrics metrics (term_font); |
218 setMinimumSize (metrics.maxWidth ()*16, metrics.height ()*3); | 218 setMinimumSize (metrics.maxWidth ()*16, metrics.height ()*3); |
219 | 219 |
220 QString cursor_type | 220 QString cursor_type |
221 = settings->value (cs_cursor).toString (); | 221 = settings.value (cs_cursor).toString (); |
222 | 222 |
223 bool cursor_blinking; | 223 bool cursor_blinking; |
224 if (settings->contains (global_cursor_blinking.key)) | 224 if (settings.contains (global_cursor_blinking.key)) |
225 cursor_blinking = settings->value (global_cursor_blinking).toBool (); | 225 cursor_blinking = settings.value (global_cursor_blinking).toBool (); |
226 else | 226 else |
227 cursor_blinking = settings->value (cs_cursor_blinking).toBool (); | 227 cursor_blinking = settings.value (cs_cursor_blinking).toBool (); |
228 | 228 |
229 for (int ct = IBeamCursor; ct <= UnderlineCursor; ct++) | 229 for (int ct = IBeamCursor; ct <= UnderlineCursor; ct++) |
230 { | 230 { |
231 if (cursor_type.toStdString () == cs_cursor_types[ct]) | 231 if (cursor_type.toStdString () == cs_cursor_types[ct]) |
232 { | 232 { |
234 break; | 234 break; |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 bool cursorUseForegroundColor | 238 bool cursorUseForegroundColor |
239 = settings->value (cs_cursor_use_fgcol).toBool (); | 239 = settings.value (cs_cursor_use_fgcol).toBool (); |
240 | 240 |
241 int mode = settings->value (cs_color_mode).toInt (); | 241 int mode = settings.value (cs_color_mode).toInt (); |
242 | 242 |
243 setForegroundColor (settings->color_value (cs_colors[0], mode)); | 243 setForegroundColor (settings.color_value (cs_colors[0], mode)); |
244 | 244 |
245 setBackgroundColor (settings->color_value (cs_colors[1], mode)); | 245 setBackgroundColor (settings.color_value (cs_colors[1], mode)); |
246 | 246 |
247 setSelectionColor (settings->color_value (cs_colors[2], mode)); | 247 setSelectionColor (settings.color_value (cs_colors[2], mode)); |
248 | 248 |
249 setCursorColor (cursorUseForegroundColor, | 249 setCursorColor (cursorUseForegroundColor, |
250 settings->color_value (cs_colors[3], mode)); | 250 settings.color_value (cs_colors[3], mode)); |
251 | 251 |
252 setScrollBufferSize (settings->value (cs_hist_buffer).toInt ()); | 252 setScrollBufferSize (settings.value (cs_hist_buffer).toInt ()); |
253 | 253 |
254 // If the Copy shortcut is Ctrl+C, then the Copy action also emits | 254 // If the Copy shortcut is Ctrl+C, then the Copy action also emits |
255 // a signal for interrupting the current code executed by the worker. | 255 // a signal for interrupting the current code executed by the worker. |
256 // If the Copy shortcut is not Ctrl+C, an extra interrupt action is | 256 // If the Copy shortcut is not Ctrl+C, an extra interrupt action is |
257 // set up for emitting the interrupt signal. | 257 // set up for emitting the interrupt signal. |
258 | 258 |
259 QString sc = settings->sc_value (sc_main_edit_copy); | 259 QString sc = settings.sc_value (sc_main_edit_copy); |
260 | 260 |
261 // Dis- or enable extra interrupt action: We need an extra option when | 261 // Dis- or enable extra interrupt action: We need an extra option when |
262 // copy shortcut is not Ctrl-C or when global shortcuts (like copy) are | 262 // copy shortcut is not Ctrl-C or when global shortcuts (like copy) are |
263 // disabled. | 263 // disabled. |
264 bool extra_ir_action | 264 bool extra_ir_action |
265 = (sc != QKeySequence (Qt::ControlModifier | Qt::Key_C).toString ()) | 265 = (sc != QKeySequence (Qt::ControlModifier | Qt::Key_C).toString ()) |
266 || settings->value (sc_prevent_rl_conflicts).toBool (); | 266 || settings.value (sc_prevent_rl_conflicts).toBool (); |
267 | 267 |
268 _interrupt_action->setEnabled (extra_ir_action); | 268 _interrupt_action->setEnabled (extra_ir_action); |
269 has_extra_interrupt (extra_ir_action); | 269 has_extra_interrupt (extra_ir_action); |
270 | 270 |
271 // check whether shortcut Ctrl-D is in use by the main-window | 271 // check whether shortcut Ctrl-D is in use by the main-window |
272 bool ctrld = settings->value (sc_main_ctrld).toBool (); | 272 bool ctrld = settings.value (sc_main_ctrld).toBool (); |
273 _nop_action->setEnabled (! ctrld); | 273 _nop_action->setEnabled (! ctrld); |
274 } | 274 } |
275 | 275 |
276 void | 276 void |
277 QTerminal::construct (octave::base_qobject& oct_qobj) | 277 QTerminal::construct (octave::base_qobject& oct_qobj) |