Skip to content

Commit 4e10546

Browse files
3nidsnyalldawson
authored andcommittedMar 20, 2023
follow-up refctoring settings for code editor
1 parent 61087b9 commit 4e10546

File tree

3 files changed

+21
-46
lines changed

3 files changed

+21
-46
lines changed
 

‎python/console/console_settings.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from qgis.PyQt.QtWidgets import QWidget, QFileDialog, QMessageBox, QTableWidgetItem, QHBoxLayout
2424
from qgis.PyQt.QtGui import QIcon, QDesktopServices
2525

26-
from qgis.core import QgsSettings, QgsApplication
26+
from qgis.core import QgsSettings, QgsApplication, QgsSettingsTree
2727
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
2828

2929
from .console_compile_apis import PrepareAPIDialog
@@ -215,11 +215,13 @@ def saveSettings(self):
215215
settings.setValue("pythonConsole/autoInsertImport", self.autoInsertImport.isChecked())
216216

217217
settings.setValue("pythonConsole/formatOnSave", self.formatOnSave.isChecked())
218-
settings.setValue("gui/code-editor/python/sortImports", self.sortImports.isChecked())
219-
settings.setValue("gui/code-editor/python/formatter", self.formatter.currentText())
220-
settings.setValue("gui/code-editor/python/autopep8Level", self.autopep8Level.value())
221-
settings.setValue("gui/code-editor/python/blackNormalizeQuotes", self.blackNormalizeQuotes.isChecked())
222-
settings.setValue("gui/code-editor/python/maxLineLength", self.maxLineLength.value())
218+
219+
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
220+
pythonSettingsTreeNode.childSetting("sort-imports").setValue(self.sortImports.isChecked())
221+
pythonSettingsTreeNode.childSetting("formatter").setValue(self.formatter.currentText())
222+
pythonSettingsTreeNode.childSetting("autopep8-level").setValue(self.autopep8Level.value())
223+
pythonSettingsTreeNode.childSetting("black-normalize-quotes").setValue(self.blackNormalizeQuotes.isChecked())
224+
pythonSettingsTreeNode.childSetting("max-line-length").setValue(self.maxLineLength.value())
223225

224226
def restoreSettings(self):
225227
settings = QgsSettings()
@@ -246,12 +248,14 @@ def restoreSettings(self):
246248
self.autoSurround.setChecked(settings.value("pythonConsole/autoSurround", True, type=bool))
247249
self.autoInsertImport.setChecked(settings.value("pythonConsole/autoInsertImport", False, type=bool))
248250

251+
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
252+
249253
self.formatOnSave.setChecked(settings.value("pythonConsole/formatOnSave", False, type=bool))
250-
self.sortImports.setChecked(settings.value("gui/code-editor/python/sortImports", True, type=bool))
251-
self.formatter.setCurrentText(settings.value("gui/code-editor/python/formatter", "autopep8", type=str))
252-
self.autopep8Level.setValue(settings.value("gui/code-editor/python/autopep8Level", 1, type=int))
253-
self.blackNormalizeQuotes.setChecked(settings.value("gui/code-editor/python/blackNormalizeQuotes", True, type=bool))
254-
self.maxLineLength.setValue(settings.value("gui/code-editor/python/maxLineLength", 80, type=int))
254+
self.sortImports.setChecked(pythonSettingsTreeNode.childSetting("sort-imports").value())
255+
self.formatter.setCurrentText(pythonSettingsTreeNode.childSetting("formatter").value())
256+
self.autopep8Level.setValue(pythonSettingsTreeNode.childSetting("autopep8-level").value())
257+
self.blackNormalizeQuotes.setChecked(pythonSettingsTreeNode.childSetting("black-normalize-quotes").value())
258+
self.maxLineLength.setValue(pythonSettingsTreeNode.childSetting("max-line-length").value())
255259

256260
if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
257261
self.autoCompFromDoc.setChecked(True)

‎src/gui/codeeditors/qgscodeeditorpython.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ const QMap<QString, QString> QgsCodeEditorPython::sCompletionPairs
4444
const QStringList QgsCodeEditorPython::sCompletionSingleCharacters{"`", "*"};
4545

4646
const QgsSettingsEntryString *QgsCodeEditorPython::settingCodeFormatter = new QgsSettingsEntryString( QStringLiteral( "formatter" ), sTreePythonCodeEditor, QStringLiteral( "autopep8" ), QStringLiteral( "Python code autoformatter" ) );
47-
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingMaxLineLength = new QgsSettingsEntryInteger( QStringLiteral( "maxLineLength" ), sTreePythonCodeEditor, 80, QStringLiteral( "Maximum line length" ) );
48-
const QgsSettingsEntryBool *QgsCodeEditorPython::settingSortImports = new QgsSettingsEntryBool( QStringLiteral( "sortImports" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether imports should be sorted when auto-formatting code" ) );
49-
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingAutopep8Level = new QgsSettingsEntryInteger( QStringLiteral( "autopep8Level" ), sTreePythonCodeEditor, 1, QStringLiteral( "Autopep8 aggressive level" ) );
50-
const QgsSettingsEntryBool *QgsCodeEditorPython::settingBlackNormalizeQuotes = new QgsSettingsEntryBool( QStringLiteral( "blackNormalizeQuotes" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether quotes should be normalized when auto-formatting code using black" ) );
47+
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingMaxLineLength = new QgsSettingsEntryInteger( QStringLiteral( "max-line-length" ), sTreePythonCodeEditor, 80, QStringLiteral( "Maximum line length" ) );
48+
const QgsSettingsEntryBool *QgsCodeEditorPython::settingSortImports = new QgsSettingsEntryBool( QStringLiteral( "sort-imports" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether imports should be sorted when auto-formatting code" ) );
49+
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingAutopep8Level = new QgsSettingsEntryInteger( QStringLiteral( "autopep8-level" ), sTreePythonCodeEditor, 1, QStringLiteral( "Autopep8 aggressive level" ) );
50+
const QgsSettingsEntryBool *QgsCodeEditorPython::settingBlackNormalizeQuotes = new QgsSettingsEntryBool( QStringLiteral( "black-normalize-quotes" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether quotes should be normalized when auto-formatting code using black" ) );
5151

5252

5353
QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames, Mode mode )

‎src/gui/codeeditors/qgscodeeditorpython.h

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,14 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
5555
public:
5656

5757
#ifndef SIP_RUN
58-
58+
///@cond PRIVATE
5959
static inline QgsSettingsTreeNode *sTreePythonCodeEditor = QgsCodeEditor::sTreeCodeEditor->createChildNode( QStringLiteral( "python" ) );
60-
61-
/**
62-
* Code auto formatter.
63-
*
64-
* \since QGIS 3.32
65-
*/
6660
static const QgsSettingsEntryString *settingCodeFormatter;
67-
68-
/**
69-
* Maximum line length.
70-
*
71-
* \since QGIS 3.32
72-
*/
7361
static const QgsSettingsEntryInteger *settingMaxLineLength;
74-
75-
/**
76-
* Whether imports should be sorted when auto formatting code.
77-
*
78-
* \since QGIS 3.32
79-
*/
8062
static const QgsSettingsEntryBool *settingSortImports;
81-
82-
/**
83-
* Autopep8 aggressive level.
84-
*
85-
* \since QGIS 3.32
86-
*/
8763
static const QgsSettingsEntryInteger *settingAutopep8Level;
88-
89-
/**
90-
* Whether imports should be sorted when auto formatting code.
91-
*
92-
* \since QGIS 3.32
93-
*/
9464
static const QgsSettingsEntryBool *settingBlackNormalizeQuotes;
65+
///@endcond PRIVATE
9566
#endif
9667

9768
/**

0 commit comments

Comments
 (0)
Please sign in to comment.