diff --git a/python/PyQt6/gui/auto_additions/qgscodeeditorpython.py b/python/PyQt6/gui/auto_additions/qgscodeeditorpython.py index 9c88d2341847..2eb36412b7ec 100644 --- a/python/PyQt6/gui/auto_additions/qgscodeeditorpython.py +++ b/python/PyQt6/gui/auto_additions/qgscodeeditorpython.py @@ -1,5 +1,6 @@ # The following has been generated automatically from src/gui/codeeditors/qgscodeeditorpython.h try: + QgsCodeEditorPython.hasWebEngine = staticmethod(QgsCodeEditorPython.hasWebEngine) QgsCodeEditorPython.__group__ = ['codeeditors'] except NameError: pass diff --git a/python/PyQt6/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in b/python/PyQt6/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in index e42a32690ce3..a7cbd9dd0ba3 100644 --- a/python/PyQt6/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in +++ b/python/PyQt6/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in @@ -87,6 +87,13 @@ Updates the editor capabilities. virtual bool checkSyntax(); + static bool hasWebEngine(); +%Docstring +Checks whether QWebEngineView is available to display context help + +.. versionadded:: 3.42 +%End + public slots: void searchSelectedTextInPyQGISDocs(); diff --git a/python/console/console_sci.py b/python/console/console_sci.py index ccff0305449b..6a361bddf22d 100644 --- a/python/console/console_sci.py +++ b/python/console/console_sci.py @@ -112,7 +112,6 @@ def _help(object=None, api=Qgis.DocumentationApi.PyQgis, force_search=False): If the object is not part of the QGIS API but is a Qt object the Qt documentation is opened. ''' - pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python") browserName = pythonSettingsTreeNode.childSetting('context-help-browser').valueAsVariant() try: @@ -123,22 +122,26 @@ def _help(object=None, api=Qgis.DocumentationApi.PyQgis, force_search=False): if not object: return iface.showApiDocumentation(api, browser=browser) - embedded = browser == Qgis.DocumentationBrowser.DeveloperToolsPanel + def search_or_home(object_str): + if not object_str: + return iface.showApiDocumentation(api, browser=browser) + if browser == Qgis.DocumentationBrowser.DeveloperToolsPanel and not QgsCodeEditorPython.hasWebEngine(): + if force_search: + return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=Qgis.DocumentationBrowser.SystemWebBrowser) + else: + return iface.showApiDocumentation(api, browser=browser) + else: + return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=browser) + if isinstance(object, str): try: object = eval(object) except (SyntaxError, NameError): - if embedded and not force_search: - return iface.showApiDocumentation(api, browser=browser) - else: - return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=Qgis.DocumentationBrowser.SystemWebBrowser) + return search_or_home(object) obj_info = __parse_object(object) if not obj_info: - if force_search or isinstance(object, str) and not embedded: - return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=Qgis.DocumentationBrowser.SystemWebBrowser) - else: - return iface.showApiDocumentation(api, browser=browser) + return search_or_home(object if isinstance(object, str) else None) obj_type, module, class_name = obj_info if obj_type == "qt": diff --git a/python/gui/auto_additions/qgscodeeditorpython.py b/python/gui/auto_additions/qgscodeeditorpython.py index 9c88d2341847..2eb36412b7ec 100644 --- a/python/gui/auto_additions/qgscodeeditorpython.py +++ b/python/gui/auto_additions/qgscodeeditorpython.py @@ -1,5 +1,6 @@ # The following has been generated automatically from src/gui/codeeditors/qgscodeeditorpython.h try: + QgsCodeEditorPython.hasWebEngine = staticmethod(QgsCodeEditorPython.hasWebEngine) QgsCodeEditorPython.__group__ = ['codeeditors'] except NameError: pass diff --git a/python/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in b/python/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in index e42a32690ce3..a7cbd9dd0ba3 100644 --- a/python/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in +++ b/python/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in @@ -87,6 +87,13 @@ Updates the editor capabilities. virtual bool checkSyntax(); + static bool hasWebEngine(); +%Docstring +Checks whether QWebEngineView is available to display context help + +.. versionadded:: 3.42 +%End + public slots: void searchSelectedTextInPyQGISDocs(); diff --git a/src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp b/src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp index 15841a37e6a6..2adf06981b96 100644 --- a/src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp +++ b/src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp @@ -14,10 +14,16 @@ ***************************************************************************/ #include "qgsdocumentationpanelwidget.h" -#include "qgswebview.h" #include "qgisapp.h" #include +#ifdef HAVE_WEBENGINE +#include +#else +#include "qgswebview.h" +#endif + + // // QgsDocumentationPanelWidget // @@ -26,6 +32,13 @@ QgsDocumentationPanelWidget::QgsDocumentationPanelWidget( QWidget *parent ) : QgsDevToolWidget( parent ) { setupUi( this ); +#ifdef HAVE_WEBENGINE + mWebView = new QWebEngineView( this ); +#else + mWebView = new QgsWebView( this ); +#endif + + mWebViewContainer->layout()->addWidget( mWebView ); connect( mPyQgisHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( Qgis::DocumentationApi::PyQgis, Qgis::DocumentationBrowser::DeveloperToolsPanel );} ); connect( mQtHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( Qgis::DocumentationApi::Qt, Qgis::DocumentationBrowser::DeveloperToolsPanel );} ); diff --git a/src/app/devtools/documentation/qgsdocumentationpanelwidget.h b/src/app/devtools/documentation/qgsdocumentationpanelwidget.h index 76a4f84a326b..75038ad8cb64 100644 --- a/src/app/devtools/documentation/qgsdocumentationpanelwidget.h +++ b/src/app/devtools/documentation/qgsdocumentationpanelwidget.h @@ -16,8 +16,15 @@ #define QGSDOCUMENTATIONPANELWIDGET_H #include "qgsdevtoolwidget.h" +#include "qgsconfig.h" #include "ui_qgsdocumentationpanelbase.h" +#ifdef HAVE_WEBENGINE +class QWebEngineView; +#else +class QgsWebView; +#endif + /** * \ingroup app * \class QgsDocumentationPanelWidget @@ -39,6 +46,15 @@ class QgsDocumentationPanelWidget : public QgsDevToolWidget, private Ui::QgsDocu void showUrl( const QUrl &url ); + private: + +#ifdef HAVE_WEBENGINE + QWebEngineView *mWebView = nullptr; +#else + QgsWebView *mWebView = nullptr; +#endif + + }; diff --git a/src/gui/codeeditors/qgscodeeditorpython.cpp b/src/gui/codeeditors/qgscodeeditorpython.cpp index b8913726c084..7a0467090158 100644 --- a/src/gui/codeeditors/qgscodeeditorpython.cpp +++ b/src/gui/codeeditors/qgscodeeditorpython.cpp @@ -720,6 +720,15 @@ bool QgsCodeEditorPython::checkSyntax() } } +bool QgsCodeEditorPython::hasWebEngine() +{ +#ifdef HAVE_WEBENGINE + return true; +#else + return false; +#endif +} + void QgsCodeEditorPython::searchSelectedTextInPyQGISDocs() { showApiDocumentation( selectedText() ); diff --git a/src/gui/codeeditors/qgscodeeditorpython.h b/src/gui/codeeditors/qgscodeeditorpython.h index f0c9efc6bc9e..0039607c9b4b 100644 --- a/src/gui/codeeditors/qgscodeeditorpython.h +++ b/src/gui/codeeditors/qgscodeeditorpython.h @@ -122,6 +122,13 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor bool checkSyntax() override; + /** + * Checks whether QWebEngineView is available to display context help + * + * \since QGIS 3.42 + */ + static bool hasWebEngine(); + public slots: /** diff --git a/src/ui/qgsdocumentationpanelbase.ui b/src/ui/qgsdocumentationpanelbase.ui index 409e3a3c9f18..37f35dd0abb3 100644 --- a/src/ui/qgsdocumentationpanelbase.ui +++ b/src/ui/qgsdocumentationpanelbase.ui @@ -96,13 +96,27 @@ - + 0 0 + + + 0 + + + 0 + + + 0 + + + 0 + + @@ -114,12 +128,6 @@
qgspanelwidget.h
1 - - QgsWebView - QWidget -
qgswebview.h
- 1 -