Skip to content

Commit

Permalink
Switch to QWebEngineView if available
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Oct 31, 2024
1 parent 5057238 commit 4789e4b
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 18 deletions.
1 change: 1 addition & 0 deletions python/PyQt6/gui/auto_additions/qgscodeeditorpython.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 13 additions & 10 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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":
Expand Down
1 change: 1 addition & 0 deletions python/gui/auto_additions/qgscodeeditorpython.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
***************************************************************************/

#include "qgsdocumentationpanelwidget.h"
#include "qgswebview.h"
#include "qgisapp.h"
#include <QVBoxLayout>

#ifdef HAVE_WEBENGINE
#include <QWebEngineView>
#else
#include "qgswebview.h"
#endif


//
// QgsDocumentationPanelWidget
//
Expand All @@ -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 );} );
Expand Down
16 changes: 16 additions & 0 deletions src/app/devtools/documentation/qgsdocumentationpanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


};


Expand Down
9 changes: 9 additions & 0 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@ bool QgsCodeEditorPython::checkSyntax()
}
}

bool QgsCodeEditorPython::hasWebEngine()
{
#ifdef HAVE_WEBENGINE
return true;
#else
return false;
#endif
}

void QgsCodeEditorPython::searchSelectedTextInPyQGISDocs()
{
showApiDocumentation( selectedText() );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/codeeditors/qgscodeeditorpython.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down
22 changes: 15 additions & 7 deletions src/ui/qgsdocumentationpanelbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,27 @@
</layout>
</item>
<item>
<widget class="QgsWebView" name="mWebView" native="true">
<widget class="QWidget" name="mWebViewContainer" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
Expand All @@ -114,12 +128,6 @@
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsWebView</class>
<extends>QWidget</extends>
<header>qgswebview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 4789e4b

Please sign in to comment.