mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Use settings registry for new settings
This commit is contained in:
parent
1c2aead582
commit
a6b4742e97
@ -212,11 +212,11 @@ class ConsoleOptionsWidget(QWidget, Ui_SettingsDialogPythonConsole):
|
||||
settings.setValue("pythonConsole/autoInsertImport", self.autoInsertImport.isChecked())
|
||||
|
||||
settings.setValue("pythonConsole/formatOnSave", self.formatOnSave.isChecked())
|
||||
settings.setValue("pythonConsole/sortImports", self.sortImports.isChecked())
|
||||
settings.setValue("pythonConsole/formatter", self.formatter.currentText())
|
||||
settings.setValue("pythonConsole/autopep8Level", self.autopep8Level.value())
|
||||
settings.setValue("pythonConsole/blackNormalizeQuotes", self.blackNormalizeQuotes.isChecked())
|
||||
settings.setValue("pythonConsole/maxLineLength", self.maxLineLength.value())
|
||||
settings.setValue("gui/code-editor/python/sortImports", self.sortImports.isChecked())
|
||||
settings.setValue("gui/code-editor/python/formatter", self.formatter.currentText())
|
||||
settings.setValue("gui/code-editor/python/autopep8Level", self.autopep8Level.value())
|
||||
settings.setValue("gui/code-editor/python/blackNormalizeQuotes", self.blackNormalizeQuotes.isChecked())
|
||||
settings.setValue("gui/code-editor/python/maxLineLength", self.maxLineLength.value())
|
||||
|
||||
def restoreSettings(self):
|
||||
settings = QgsSettings()
|
||||
@ -244,11 +244,11 @@ class ConsoleOptionsWidget(QWidget, Ui_SettingsDialogPythonConsole):
|
||||
self.autoInsertImport.setChecked(settings.value("pythonConsole/autoInsertImport", False, type=bool))
|
||||
|
||||
self.formatOnSave.setChecked(settings.value("pythonConsole/formatOnSave", False, type=bool))
|
||||
self.sortImports.setChecked(settings.value("pythonConsole/sortImports", True, type=bool))
|
||||
self.formatter.setCurrentText(settings.value("pythonConsole/formatter", "autopep8", type=str))
|
||||
self.autopep8Level.setValue(settings.value("pythonConsole/autopep8Level", 1, type=int))
|
||||
self.blackNormalizeQuotes.setChecked(settings.value("pythonConsole/blackNormalizeQuotes", True, type=bool))
|
||||
self.maxLineLength.setValue(settings.value("pythonConsole/maxLineLength", 80, type=int))
|
||||
self.sortImports.setChecked(settings.value("gui/code-editor/python/sortImports", True, type=bool))
|
||||
self.formatter.setCurrentText(settings.value("gui/code-editor/python/formatter", "autopep8", type=str))
|
||||
self.autopep8Level.setValue(settings.value("gui/code-editor/python/autopep8Level", 1, type=int))
|
||||
self.blackNormalizeQuotes.setChecked(settings.value("gui/code-editor/python/blackNormalizeQuotes", True, type=bool))
|
||||
self.maxLineLength.setValue(settings.value("gui/code-editor/python/maxLineLength", 80, type=int))
|
||||
|
||||
if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
|
||||
self.autoCompFromDoc.setChecked(True)
|
||||
|
@ -80,6 +80,8 @@ A text editor based on QScintilla2.
|
||||
%End
|
||||
public:
|
||||
|
||||
|
||||
|
||||
enum class Mode
|
||||
{
|
||||
ScriptEditor,
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsCodeEditorPython : QgsCodeEditor
|
||||
{
|
||||
%Docstring(signature="appended")
|
||||
@ -28,6 +29,7 @@ code autocompletion.
|
||||
%End
|
||||
public:
|
||||
|
||||
|
||||
QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList<QString> &filenames = QList<QString>(),
|
||||
QgsCodeEditor::Mode mode = QgsCodeEditor::Mode::ScriptEditor );
|
||||
%Docstring
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QString>
|
||||
#include "qgscodeeditorcolorscheme.h"
|
||||
#include "qgis.h"
|
||||
#include "qgssettingstree.h"
|
||||
|
||||
// qscintilla includes
|
||||
#include <Qsci/qsciapis.h>
|
||||
@ -95,6 +96,13 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
|
||||
|
||||
public:
|
||||
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
||||
static inline QgsSettingsTreeNode *sTreeCodeEditor = QgsSettingsTree::sTreeGui->createChildNode( QStringLiteral( "code-editor" ) );
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Code editor modes.
|
||||
*
|
||||
|
@ -17,10 +17,11 @@
|
||||
#include "qgscodeeditorpython.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgis.h"
|
||||
#include "qgspythonrunner.h"
|
||||
#include "qgsprocessingutils.h"
|
||||
#include "qgssettingsentryimpl.h"
|
||||
#include "qgssettings.h"
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QFont>
|
||||
@ -42,6 +43,13 @@ const QMap<QString, QString> QgsCodeEditorPython::sCompletionPairs
|
||||
};
|
||||
const QStringList QgsCodeEditorPython::sCompletionSingleCharacters{"`", "*"};
|
||||
|
||||
const QgsSettingsEntryString *QgsCodeEditorPython::settingCodeFormatter = new QgsSettingsEntryString( QStringLiteral( "formatter" ), sTreePythonCodeEditor, QStringLiteral( "autopep8" ), QStringLiteral( "Python code autoformatter" ) );
|
||||
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingMaxLineLength = new QgsSettingsEntryInteger( QStringLiteral( "maxLineLength" ), sTreePythonCodeEditor, 80, QStringLiteral( "Maximum line length" ) );
|
||||
const QgsSettingsEntryBool *QgsCodeEditorPython::settingSortImports = new QgsSettingsEntryBool( QStringLiteral( "sortImports" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether imports should be sorted when auto-formatting code" ) );
|
||||
const QgsSettingsEntryInteger *QgsCodeEditorPython::settingAutopep8Level = new QgsSettingsEntryInteger( QStringLiteral( "autopep8Level" ), sTreePythonCodeEditor, 1, QStringLiteral( "Autopep8 aggressive level" ) );
|
||||
const QgsSettingsEntryBool *QgsCodeEditorPython::settingBlackNormalizeQuotes = new QgsSettingsEntryBool( QStringLiteral( "blackNormalizeQuotes" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether quotes should be normalized when auto-formatting code using black" ) );
|
||||
|
||||
|
||||
QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames, Mode mode )
|
||||
: QgsCodeEditor( parent,
|
||||
QString(),
|
||||
@ -74,11 +82,9 @@ Qgis::ScriptLanguageCapabilities QgsCodeEditorPython::languageCapabilities() con
|
||||
|
||||
void QgsCodeEditorPython::initializeLexer()
|
||||
{
|
||||
const QgsSettings settings;
|
||||
|
||||
// current line
|
||||
setEdgeMode( QsciScintilla::EdgeLine );
|
||||
setEdgeColumn( settings.value( QStringLiteral( "pythonConsole/maxLineLength" ), 80 ).toInt() );
|
||||
setEdgeColumn( settingMaxLineLength->value() );
|
||||
setEdgeColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Edge ) );
|
||||
|
||||
setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );
|
||||
@ -123,6 +129,7 @@ void QgsCodeEditorPython::initializeLexer()
|
||||
|
||||
std::unique_ptr< QsciAPIs > apis = std::make_unique< QsciAPIs >( pyLexer );
|
||||
|
||||
QgsSettings settings;
|
||||
if ( mAPISFilesList.isEmpty() )
|
||||
{
|
||||
if ( settings.value( QStringLiteral( "pythonConsole/preloadAPI" ), true ).toBool() )
|
||||
@ -363,15 +370,14 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
|
||||
return string;
|
||||
}
|
||||
|
||||
QgsSettings settings;
|
||||
const QString formatter = settings.value( QStringLiteral( "pythonConsole/formatter" ), QStringLiteral( "autopep8" ) ).toString();
|
||||
const int maxLineLength = settings.value( QStringLiteral( "pythonConsole/maxLineLength" ), 80 ).toInt();
|
||||
const QString formatter = settingCodeFormatter->value();
|
||||
const int maxLineLength = settingMaxLineLength->value();
|
||||
|
||||
QString newText = string;
|
||||
|
||||
QStringList missingModules;
|
||||
|
||||
if ( settings.value( "pythonConsole/sortImports", true ).toBool() )
|
||||
if ( settingSortImports->value() )
|
||||
{
|
||||
const QString defineSortImports = QStringLiteral(
|
||||
"def __qgis_sort_imports(script):\n"
|
||||
@ -412,7 +418,7 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
|
||||
|
||||
if ( formatter == QLatin1String( "autopep8" ) )
|
||||
{
|
||||
const int level = settings.value( QStringLiteral( "pythonConsole/autopep8Level" ), 1 ).toInt();
|
||||
const int level = settingAutopep8Level->value();
|
||||
|
||||
const QString defineReformat = QStringLiteral(
|
||||
"def __qgis_reformat(script):\n"
|
||||
@ -452,7 +458,7 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
|
||||
}
|
||||
else if ( formatter == QLatin1String( "black" ) )
|
||||
{
|
||||
const bool normalize = settings.value( QStringLiteral( "pythonConsole/blackNormalizeQuotes" ), true ).toBool();
|
||||
const bool normalize = settingBlackNormalizeQuotes->value();
|
||||
|
||||
if ( !checkSyntax() )
|
||||
{
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "qgis_gui.h"
|
||||
#include <Qsci/qscilexerpython.h>
|
||||
|
||||
class QgsSettingsEntryInteger;
|
||||
class QgsSettingsEntryBool;
|
||||
|
||||
SIP_IF_MODULE( HAVE_QSCI_SIP )
|
||||
|
||||
#ifndef SIP_RUN
|
||||
@ -51,6 +54,46 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
|
||||
|
||||
public:
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
||||
static inline QgsSettingsTreeNode *sTreePythonCodeEditor = QgsCodeEditor::sTreeCodeEditor->createChildNode( QStringLiteral( "python" ) );
|
||||
|
||||
/**
|
||||
* Code auto formatter.
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
static const QgsSettingsEntryString *settingCodeFormatter;
|
||||
|
||||
/**
|
||||
* Maximum line length.
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
static const QgsSettingsEntryInteger *settingMaxLineLength;
|
||||
|
||||
/**
|
||||
* Whether imports should be sorted when auto formatting code.
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
static const QgsSettingsEntryBool *settingSortImports;
|
||||
|
||||
/**
|
||||
* Autopep8 aggressive level.
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
static const QgsSettingsEntryInteger *settingAutopep8Level;
|
||||
|
||||
/**
|
||||
* Whether imports should be sorted when auto formatting code.
|
||||
*
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
static const QgsSettingsEntryBool *settingBlackNormalizeQuotes;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Construct a new Python editor.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user