Skip to content
Permalink
Browse files

Move more code to QgsCodeEditorPython base class

  • Loading branch information
nyalldawson committed Oct 5, 2020
1 parent 96db7ad commit d9782a12f5eea5e8fcf15be196f88122be27279d
@@ -122,13 +122,6 @@ def setLexers(self):

self.setLexer(self.lexer)

def searchPyQGIS(self):
if self.hasSelectedText():
text = self.selectedText()
text = text.replace('>>> ', '').replace('... ', '').strip() # removing prompts
version = '.'.join(Qgis.QGIS_VERSION.split('.')[0:2])
QDesktopServices.openUrl(QUrl('https://qgis.org/pyqgis/' + version + '/search.html?q=' + text))


if __name__ == "__main__":
pass
@@ -235,7 +235,7 @@ def contextMenuEvent(self, e):
self.runSelectedCode, 'Ctrl+E') # spellok
pyQGISHelpAction = menu.addAction(self.iconPyQGISHelp,
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
self.searchPyQGIS)
self.searchSelectedTextInPyQGISDocs)
menu.addAction(self.iconRunScript,
QCoreApplication.translate("PythonConsole", "Run Script"),
self.runScriptCode, 'Shift+Ctrl+E')
@@ -189,7 +189,7 @@ def contextMenuEvent(self, e):
self.clearConsole)
pyQGISHelpAction = menu.addAction(self.iconPyQGISHelp,
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
self.searchPyQGIS)
self.searchSelectedTextInPyQGISDocs)
menu.addSeparator()
copyAction = menu.addAction(
self.iconCopy,
@@ -446,7 +446,7 @@ def contextMenuEvent(self, e):
self.paste, QKeySequence.Paste)
pyQGISHelpAction = menu.addAction(self.iconPyQGISHelp,
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
self.searchPyQGIS)
self.searchSelectedTextInPyQGISDocs)
copyAction.setEnabled(False)
pasteAction.setEnabled(False)
pyQGISHelpAction.setEnabled(False)
@@ -50,6 +50,15 @@ Load APIs from one or more files
Load a script file

:param script: The script file to load
%End

public slots:

void searchSelectedTextInPyQGISDocs();
%Docstring
Searches the selected text in the official PyQGIS online documentation.

.. versionadded:: 3.16
%End

protected:
@@ -25,6 +25,7 @@
#include <QMessageBox>
#include <QTextStream>
#include <Qsci/qscilexerpython.h>
#include <QDesktopServices>

QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames )
: QgsCodeEditor( parent )
@@ -139,3 +140,14 @@ bool QgsCodeEditorPython::loadScript( const QString &script )
initializeLexer();
return true;
}

void QgsCodeEditorPython::searchSelectedTextInPyQGISDocs()
{
if ( !hasSelectedText() )
return;

QString text = selectedText();
text = text.replace( QStringLiteral( ">>> " ), QString() ).replace( QStringLiteral( "... " ), QString() ).trimmed(); // removing prompts
const QString version = QString( Qgis::version() ).split( '.' ).mid( 0, 2 ).join( '.' );
QDesktopServices::openUrl( QUrl( QStringLiteral( "https://qgis.org/pyqgis/%1/search.html?q=%2" ).arg( version, text ) ) );
}
@@ -57,6 +57,15 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
*/
bool loadScript( const QString &script );

public slots:

/**
* Searches the selected text in the official PyQGIS online documentation.
*
* \since QGIS 3.16
*/
void searchSelectedTextInPyQGISDocs();

protected:

void initializeLexer() override;

0 comments on commit d9782a1

Please sign in to comment.
You can’t perform that action at this time.