Mercurial > octave
comparison libgui/src/variable-editor.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 | 9f4a9dd4a6ee |
children | 0645ea65ca6b |
comparison
equal
deleted
inserted
replaced
31618:cd833a9baaa7 | 31619:ad014fc78bd6 |
---|---|
53 #include "gui-preferences-cs.h" | 53 #include "gui-preferences-cs.h" |
54 #include "gui-preferences-dw.h" | 54 #include "gui-preferences-dw.h" |
55 #include "gui-preferences-global.h" | 55 #include "gui-preferences-global.h" |
56 #include "gui-preferences-sc.h" | 56 #include "gui-preferences-sc.h" |
57 #include "gui-preferences-ve.h" | 57 #include "gui-preferences-ve.h" |
58 #include "gui-settings.h" | |
58 #include "octave-qobject.h" | 59 #include "octave-qobject.h" |
59 #include "octave-qtutils.h" | 60 #include "octave-qtutils.h" |
60 #include "ovl.h" | 61 #include "ovl.h" |
61 #include "qt-utils.h" | 62 #include "qt-utils.h" |
62 #include "shortcut-manager.h" | 63 #include "shortcut-manager.h" |
491 } | 492 } |
492 } | 493 } |
493 | 494 |
494 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. | 495 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. |
495 int opts = 0; // No options by default. | 496 int opts = 0; // No options by default. |
496 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 497 |
497 gui_settings *settings = rmgr.get_settings (); | 498 gui_settings settings; |
498 if (! settings->value (global_use_native_dialogs).toBool ()) | 499 |
500 if (! settings.value (global_use_native_dialogs).toBool ()) | |
499 opts = QFileDialog::DontUseNativeDialog; | 501 opts = QFileDialog::DontUseNativeDialog; |
500 | 502 |
501 QString name = objectName (); | 503 QString name = objectName (); |
502 QString file | 504 QString file |
503 = QFileDialog::getSaveFileName (this, | 505 = QFileDialog::getSaveFileName (this, |
1201 } | 1203 } |
1202 | 1204 |
1203 void | 1205 void |
1204 variable_editor::edit_variable (const QString& name, const octave_value& val) | 1206 variable_editor::edit_variable (const QString& name, const octave_value& val) |
1205 { | 1207 { |
1206 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | |
1207 | |
1208 if (m_stylesheet.isEmpty ()) | 1208 if (m_stylesheet.isEmpty ()) |
1209 { | 1209 notice_settings (); |
1210 gui_settings *settings = rmgr.get_settings (); | |
1211 notice_settings (settings); | |
1212 } | |
1213 | 1210 |
1214 QDockWidget *existing_qdw = m_main->findChild<QDockWidget *> (name); | 1211 QDockWidget *existing_qdw = m_main->findChild<QDockWidget *> (name); |
1215 if (existing_qdw) | 1212 if (existing_qdw) |
1216 { | 1213 { |
1217 // Already open. | 1214 // Already open. |
1415 { | 1412 { |
1416 emit updated (); | 1413 emit updated (); |
1417 } | 1414 } |
1418 | 1415 |
1419 void | 1416 void |
1420 variable_editor::notice_settings (const gui_settings *settings) | 1417 variable_editor::notice_settings (void) |
1421 { | 1418 { |
1422 m_main->notice_settings (settings); // update settings in parent main win | 1419 gui_settings settings; |
1423 | 1420 |
1424 m_default_width = settings->value (ve_column_width).toInt (); | 1421 m_main->notice_settings (); // update settings in parent main win |
1425 | 1422 |
1426 m_default_height = settings->value (ve_row_height).toInt (); | 1423 m_default_width = settings.value (ve_column_width).toInt (); |
1427 | 1424 |
1428 m_alternate_rows = settings->value (ve_alternate_rows).toBool (); | 1425 m_default_height = settings.value (ve_row_height).toInt (); |
1429 | 1426 |
1430 m_use_terminal_font = settings->value (ve_use_terminal_font).toBool (); | 1427 m_alternate_rows = settings.value (ve_alternate_rows).toBool (); |
1428 | |
1429 m_use_terminal_font = settings.value (ve_use_terminal_font).toBool (); | |
1431 | 1430 |
1432 QString font_name; | 1431 QString font_name; |
1433 int font_size; | 1432 int font_size; |
1434 QString default_font = settings->value (global_mono_font).toString (); | 1433 QString default_font = settings.value (global_mono_font).toString (); |
1435 | 1434 |
1436 if (m_use_terminal_font) | 1435 if (m_use_terminal_font) |
1437 { | 1436 { |
1438 font_name = settings->value (cs_font.key, default_font).toString (); | 1437 font_name = settings.value (cs_font.key, default_font).toString (); |
1439 font_size = settings->value (cs_font_size).toInt (); | 1438 font_size = settings.value (cs_font_size).toInt (); |
1440 } | 1439 } |
1441 else | 1440 else |
1442 { | 1441 { |
1443 font_name = settings->value (ve_font_name.key, default_font).toString (); | 1442 font_name = settings.value (ve_font_name.key, default_font).toString (); |
1444 font_size = settings->value (ve_font_size).toInt (); | 1443 font_size = settings.value (ve_font_size).toInt (); |
1445 } | 1444 } |
1446 | 1445 |
1447 m_font = QFont (font_name, font_size); | 1446 m_font = QFont (font_name, font_size); |
1448 | 1447 |
1449 QFontMetrics fm (m_font); | 1448 QFontMetrics fm (m_font); |
1450 | 1449 |
1451 m_add_font_height = fm.height (); | 1450 m_add_font_height = fm.height (); |
1452 | 1451 |
1453 int mode = settings->value (ve_color_mode).toInt (); | 1452 int mode = settings.value (ve_color_mode).toInt (); |
1454 | 1453 |
1455 for (int i = 0; i < ve_colors_count; i++) | 1454 for (int i = 0; i < ve_colors_count; i++) |
1456 { | 1455 { |
1457 QColor setting_color = settings->color_value (ve_colors[i], mode); | 1456 QColor setting_color = settings.color_value (ve_colors[i], mode); |
1458 m_table_colors.replace (i, setting_color); | 1457 m_table_colors.replace (i, setting_color); |
1459 } | 1458 } |
1460 | 1459 |
1461 update_colors (); | 1460 update_colors (); |
1462 | 1461 |
1463 // Icon size in the toolbar. | 1462 // Icon size in the toolbar. |
1464 | 1463 |
1465 if (m_tool_bar) | 1464 if (m_tool_bar) |
1466 { | 1465 { |
1467 int size_idx = settings->value (global_icon_size).toInt (); | 1466 int size_idx = settings.value (global_icon_size).toInt (); |
1468 size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 | 1467 size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 |
1469 | 1468 |
1470 QStyle *st = style (); | 1469 QStyle *st = style (); |
1471 int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); | 1470 int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); |
1472 m_tool_bar->setIconSize (QSize (icon_size, icon_size)); | 1471 m_tool_bar->setIconSize (QSize (icon_size, icon_size)); |