Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/PyQt6/gui/auto_additions/qgscodeeditorpython.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The following has been generated automatically from src/gui/codeeditors/qgscodeeditorpython.h
try:
QgsCodeEditorPython.__virtual_methods__ = ['showApiDocumentation']
QgsCodeEditorPython.__overridden_methods__ = ['language', 'languageCapabilities', 'checkSyntax', 'toggleComment', 'initializeLexer', 'keyPressEvent', 'reformatCodeString', 'populateContextMenu']
QgsCodeEditorPython.__overridden_methods__ = ['language', 'languageCapabilities', 'checkSyntax', 'toggleComment', 'initializeLexer', 'keyPressEvent', 'showEvent', 'reformatCodeString', 'populateContextMenu']
QgsCodeEditorPython.__group__ = ['codeeditors']
except (NameError, AttributeError):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Toggle comment for the selected text.

virtual void keyPressEvent( QKeyEvent *event );

virtual void showEvent( QShowEvent *event );

virtual QString reformatCodeString( const QString &string );

virtual void populateContextMenu( QMenu *menu );
Expand Down
71 changes: 45 additions & 26 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,42 @@ void QgsCodeEditorPython::initializeLexer()
pyLexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::TripleSingleQuote ), QsciLexerPython::TripleSingleQuotedString );
pyLexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::TripleDoubleQuote ), QsciLexerPython::TripleDoubleQuotedString );

auto apis = std::make_unique<QsciAPIs>( pyLexer );
setLexer( pyLexer );

QgsSettings settings;
const int threshold = settings.value( u"pythonConsole/autoCompThreshold"_s, 2 ).toInt();
setAutoCompletionThreshold( threshold );
if ( !settings.value( "pythonConsole/autoCompleteEnabled", true ).toBool() )
{
setAutoCompletionSource( AcsNone );
}
else
{
const QString autoCompleteSource = settings.value( u"pythonConsole/autoCompleteSource"_s, u"fromAPI"_s ).toString();
if ( autoCompleteSource == "fromDoc"_L1 )
setAutoCompletionSource( AcsDocument );
else if ( autoCompleteSource == "fromDocAPI"_L1 )
setAutoCompletionSource( AcsAll );
else
setAutoCompletionSource( AcsAPIs );
}

setLineNumbersVisible( true );
setIndentationsUseTabs( false );
setIndentationGuides( true );

runPostLexerConfigurationTasks();

mInitializedLexer = false;
if ( isVisible() )
deferredInitializeLexer();
}

void QgsCodeEditorPython::deferredInitializeLexer()
{
QgsSettings settings;
auto apis = std::make_unique<QsciAPIs>( lexer() );

if ( mAPISFilesList.isEmpty() )
{
if ( settings.value( u"pythonConsole/preloadAPI"_s, true ).toBool() )
Expand Down Expand Up @@ -195,32 +228,9 @@ void QgsCodeEditorPython::initializeLexer()
}
apis->prepare();
}
pyLexer->setAPIs( apis.release() );
lexer()->setAPIs( apis.release() );

setLexer( pyLexer );

const int threshold = settings.value( u"pythonConsole/autoCompThreshold"_s, 2 ).toInt();
setAutoCompletionThreshold( threshold );
if ( !settings.value( "pythonConsole/autoCompleteEnabled", true ).toBool() )
{
setAutoCompletionSource( AcsNone );
}
else
{
const QString autoCompleteSource = settings.value( u"pythonConsole/autoCompleteSource"_s, u"fromAPI"_s ).toString();
if ( autoCompleteSource == "fromDoc"_L1 )
setAutoCompletionSource( AcsDocument );
else if ( autoCompleteSource == "fromDocAPI"_L1 )
setAutoCompletionSource( AcsAll );
else
setAutoCompletionSource( AcsAPIs );
}

setLineNumbersVisible( true );
setIndentationsUseTabs( false );
setIndentationGuides( true );

runPostLexerConfigurationTasks();
mInitializedLexer = true;
}

void QgsCodeEditorPython::keyPressEvent( QKeyEvent *event )
Expand Down Expand Up @@ -350,6 +360,15 @@ void QgsCodeEditorPython::keyPressEvent( QKeyEvent *event )
return QgsCodeEditor::keyPressEvent( event );
}

void QgsCodeEditorPython::showEvent( QShowEvent *event )
{
if ( !mInitializedLexer )
{
deferredInitializeLexer();
}
QgsCodeEditor::showEvent( event );
}

QString QgsCodeEditorPython::reformatCodeString( const QString &string )
{
if ( !QgsPythonRunner::isValid() )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/codeeditors/qgscodeeditorpython.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
protected:
void initializeLexer() override;
void keyPressEvent( QKeyEvent *event ) override;
void showEvent( QShowEvent *event ) override;
QString reformatCodeString( const QString &string ) override;
void populateContextMenu( QMenu *menu ) override;

Expand All @@ -171,11 +172,13 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
QString mPapFile;

Qgis::ScriptLanguageCapabilities mCapabilities;
bool mInitializedLexer = false;

static const QMap<QString, QString> sCompletionPairs;

// Only used for selected text
static const QStringList sCompletionSingleCharacters;
void deferredInitializeLexer();
};

#endif
Loading