54 setEdgeMode( QsciScintilla::EdgeLine );
58 setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );
63 QsciLexerPython *pyLexer =
new QgsQsciLexerPython(
this );
65 pyLexer->setIndentationWarning( QsciLexerPython::Inconsistent );
66 pyLexer->setFoldComments(
true );
67 pyLexer->setFoldQuotes(
true );
69 pyLexer->setDefaultFont( font );
72 pyLexer->setFont( font, -1 );
74 font.setItalic(
true );
75 pyLexer->setFont( font, QsciLexerPython::Comment );
76 pyLexer->setFont( font, QsciLexerPython::CommentBlock );
78 font.setItalic(
false );
80 pyLexer->setFont( font, QsciLexerPython::SingleQuotedString );
81 pyLexer->setFont( font, QsciLexerPython::DoubleQuotedString );
83 pyLexer->setColor(
defaultColor, QsciLexerPython::Default );
98 QsciAPIs *apis =
new QsciAPIs( pyLexer );
102 if ( mAPISFilesList.isEmpty() )
104 if ( settings.
value( QStringLiteral(
"pythonConsole/preloadAPI" ),
true ).toBool() )
107 apis->loadPrepared( mPapFile );
109 else if ( settings.
value( QStringLiteral(
"pythonConsole/usePreparedAPIFile" ),
false ).toBool() )
111 apis->loadPrepared( settings.
value( QStringLiteral(
"pythonConsole/preparedAPIFile" ) ).toString() );
115 const QStringList apiPaths = settings.
value( QStringLiteral(
"pythonConsole/userAPI" ) ).toStringList();
116 for (
const QString &path : apiPaths )
118 if ( !QFileInfo::exists( path ) )
120 QgsDebugMsg( QStringLiteral(
"The apis file %1 was not found" ).arg( path ) );
128 pyLexer->setAPIs( apis );
131 else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == QLatin1String(
"pap" ) )
133 if ( !QFileInfo::exists( mAPISFilesList[0] ) )
135 QgsDebugMsg( QStringLiteral(
"The apis file %1 not found" ).arg( mAPISFilesList.at( 0 ) ) );
138 mPapFile = mAPISFilesList[0];
139 apis->loadPrepared( mPapFile );
143 for (
const QString &path : mAPISFilesList )
145 if ( !QFileInfo::exists( path ) )
147 QgsDebugMsg( QStringLiteral(
"The apis file %1 was not found" ).arg( path ) );
155 pyLexer->setAPIs( apis );
159 const int threshold = settings.
value( QStringLiteral(
"pythonConsole/autoCompThreshold" ), 2 ).toInt();
160 setAutoCompletionThreshold( threshold );
161 if ( !settings.
value(
"pythonConsole/autoCompleteEnabled",
true ).toBool() )
163 setAutoCompletionSource( AcsNone );
167 const QString autoCompleteSource = settings.
value( QStringLiteral(
"pythonConsole/autoCompleteSource" ), QStringLiteral(
"fromAPI" ) ).toString();
168 if ( autoCompleteSource == QLatin1String(
"fromDoc" ) )
169 setAutoCompletionSource( AcsDocument );
170 else if ( autoCompleteSource == QLatin1String(
"fromDocAPI" ) )
171 setAutoCompletionSource( AcsAll );
173 setAutoCompletionSource( AcsAPIs );
177 setIndentationsUseTabs(
false );
178 setIndentationGuides(
true );
234 if ( !hasSelectedText() )
237 QString text = selectedText();
238 text = text.replace( QLatin1String(
">>> " ), QString() ).replace( QLatin1String(
"... " ), QString() ).trimmed();
239 const QString version = QString(
Qgis::version() ).split(
'.' ).mid( 0, 2 ).join(
'.' );
240 QDesktopServices::openUrl( QUrl( QStringLiteral(
"https://qgis.org/pyqgis/%1/search.html?q=%2" ).arg( version, text ) ) );