ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
EditorSettings.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "EditorSettings.h"
9 
10 #include <QPushButton>
11 #include <QSettings>
12 
13 static const auto SHOULD_HIGHLIGHT_SETTINGS_KEY = QStringLiteral("ShouldHighlightCurrentLine");
14 static const auto COLOR_SCHEME_SETTINGS_KEY = QStringLiteral("ColorSchemeName");
15 
16 static QString SettingsScopeName()
17 {
18  return QCoreApplication::applicationName().append(":PythonRuntime.Editor");
19 }
20 
22 {
23  setupUi();
26 }
27 
29 {
30  Ui_EditorSettings::setupUi(this);
32  {
33  colorSchemeComboBox->addItem(colorScheme.name());
34  }
35 }
36 
38 {
39  return this->fontSizeSpinBox->value();
40 }
41 
43 {
44  return m_shouldHighlightCurrentLine;
45 }
46 
48 {
49  return m_colorScheme;
50 }
51 
53 {
54  const auto *colorScheme = ColorScheme::ColorSchemeByName(colorSchemeComboBox->currentText());
55  Q_ASSERT(colorScheme != nullptr);
56  m_colorScheme = *colorScheme;
57  m_shouldHighlightCurrentLine = highlightCurrentLineCheckBox->isChecked();
58 
59  QSettings savedSettings(QCoreApplication::organizationName(), SettingsScopeName());
60  savedSettings.setValue(COLOR_SCHEME_SETTINGS_KEY, m_colorScheme.name());
61  savedSettings.setValue(SHOULD_HIGHLIGHT_SETTINGS_KEY, m_shouldHighlightCurrentLine);
62 
63  Q_EMIT settingsChanged();
64 }
65 
67 {
68  saveChanges();
69  close();
70 }
71 
73 {
75  close();
76 }
77 
79 {
80  highlightCurrentLineCheckBox->setChecked(m_shouldHighlightCurrentLine);
81  colorSchemeComboBox->setCurrentText(m_colorScheme.name());
82 }
83 
85 {
86  const QSettings savedSettings(QCoreApplication::organizationName(), SettingsScopeName());
87 
88  QVariant value = savedSettings.value(COLOR_SCHEME_SETTINGS_KEY);
89  const auto *colorScheme = ColorScheme::ColorSchemeByName(value.toString());
90  if (colorScheme)
91  {
92  m_colorScheme = *colorScheme;
93  }
94 
95  if (savedSettings.contains(SHOULD_HIGHLIGHT_SETTINGS_KEY))
96  {
97  value = savedSettings.value(SHOULD_HIGHLIGHT_SETTINGS_KEY);
98  m_shouldHighlightCurrentLine = value.toBool();
99  }
101 }
102 
104 {
105  connect(buttonBox, &QDialogButtonBox::accepted, this, &EditorSettings::saveChangesAndClose);
106  connect(buttonBox->button(QDialogButtonBox::Apply),
107  &QPushButton::clicked,
108  this,
110  connect(buttonBox, &QDialogButtonBox::rejected, this, &EditorSettings::cancel);
111 }
static const auto COLOR_SCHEME_SETTINGS_KEY
static QString SettingsScopeName()
static const auto SHOULD_HIGHLIGHT_SETTINGS_KEY
ColorScheme to be used by the PythonHighlighter & Editor.
Definition: ColorScheme.h:14
const QString & name() const
The name of the color scheme.
static const Vector & AvailableColorSchemes()
Returns the vector of available color schemes.
static const ColorScheme * ColorSchemeByName(const QString &name)
const ColorScheme & colorScheme() const
int fontSize() const
void saveChangesAndClose()
bool shouldHighlightCurrentLine() const
void connectSignals() const
void settingsChanged()
void setFormValuesToCurrentValues() const