17
17
#include " qgscodeeditorpython.h"
18
18
#include " qgslogger.h"
19
19
#include " qgssymbollayerutils.h"
20
- #include " qgssettings.h"
21
20
#include " qgis.h"
22
21
#include " qgspythonrunner.h"
23
22
#include " qgsprocessingutils.h"
23
+ #include " qgssettingsentryimpl.h"
24
+ #include " qgssettings.h"
24
25
#include < QWidget>
25
26
#include < QString>
26
27
#include < QFont>
@@ -42,6 +43,13 @@ const QMap<QString, QString> QgsCodeEditorPython::sCompletionPairs
42
43
};
43
44
const QStringList QgsCodeEditorPython::sCompletionSingleCharacters {" `" , " *" };
44
45
46
+ 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" ) );
51
+
52
+
45
53
QgsCodeEditorPython::QgsCodeEditorPython ( QWidget *parent, const QList<QString> &filenames, Mode mode )
46
54
: QgsCodeEditor( parent,
47
55
QString (),
@@ -74,11 +82,9 @@ Qgis::ScriptLanguageCapabilities QgsCodeEditorPython::languageCapabilities() con
74
82
75
83
void QgsCodeEditorPython::initializeLexer ()
76
84
{
77
- const QgsSettings settings;
78
-
79
85
// current line
80
86
setEdgeMode ( QsciScintilla::EdgeLine );
81
- setEdgeColumn ( settings. value ( QStringLiteral ( " pythonConsole/maxLineLength " ), 80 ). toInt () );
87
+ setEdgeColumn ( settingMaxLineLength-> value () );
82
88
setEdgeColor ( lexerColor ( QgsCodeEditorColorScheme::ColorRole::Edge ) );
83
89
84
90
setWhitespaceVisibility ( QsciScintilla::WsVisibleAfterIndent );
@@ -123,6 +129,7 @@ void QgsCodeEditorPython::initializeLexer()
123
129
124
130
std::unique_ptr< QsciAPIs > apis = std::make_unique< QsciAPIs >( pyLexer );
125
131
132
+ QgsSettings settings;
126
133
if ( mAPISFilesList .isEmpty () )
127
134
{
128
135
if ( settings.value ( QStringLiteral ( " pythonConsole/preloadAPI" ), true ).toBool () )
@@ -363,15 +370,14 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
363
370
return string;
364
371
}
365
372
366
- QgsSettings settings;
367
- const QString formatter = settings.value ( QStringLiteral ( " pythonConsole/formatter" ), QStringLiteral ( " autopep8" ) ).toString ();
368
- const int maxLineLength = settings.value ( QStringLiteral ( " pythonConsole/maxLineLength" ), 80 ).toInt ();
373
+ const QString formatter = settingCodeFormatter->value ();
374
+ const int maxLineLength = settingMaxLineLength->value ();
369
375
370
376
QString newText = string;
371
377
372
378
QStringList missingModules;
373
379
374
- if ( settings. value ( " pythonConsole/sortImports " , true ). toBool () )
380
+ if ( settingSortImports-> value () )
375
381
{
376
382
const QString defineSortImports = QStringLiteral (
377
383
" def __qgis_sort_imports(script):\n "
@@ -412,7 +418,7 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
412
418
413
419
if ( formatter == QLatin1String ( " autopep8" ) )
414
420
{
415
- const int level = settings. value ( QStringLiteral ( " pythonConsole/autopep8Level " ), 1 ). toInt ();
421
+ const int level = settingAutopep8Level-> value ();
416
422
417
423
const QString defineReformat = QStringLiteral (
418
424
" def __qgis_reformat(script):\n "
@@ -452,7 +458,7 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
452
458
}
453
459
else if ( formatter == QLatin1String ( " black" ) )
454
460
{
455
- const bool normalize = settings. value ( QStringLiteral ( " pythonConsole/blackNormalizeQuotes " ), true ). toBool ();
461
+ const bool normalize = settingBlackNormalizeQuotes-> value ();
456
462
457
463
if ( !checkSyntax () )
458
464
{
0 commit comments