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 Nov 5, 2024
1 parent ac3a01f commit a2c9374
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 37 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,7 @@ if(WITH_CORE)

set (WITH_QTWEBENGINE FALSE CACHE BOOL "Enable QtWebEngine support")
if (WITH_QTWEBENGINE)
if(BUILD_WITH_QT6)
find_package(${QT_VERSION_BASE} COMPONENTS WebEngineCore REQUIRED)
else()
# QWebEnginePage is only available in widgets module in Qt5
find_package(${QT_VERSION_BASE} COMPONENTS WebEngineCore WebEngineWidgets REQUIRED)
endif()

find_package(${QT_VERSION_BASE} COMPONENTS WebEngineCore WebEngineWidgets REQUIRED)
message(STATUS "QtWebEngine support enabled")
set(HAVE_WEBENGINE TRUE) # used in qgsconfig.h
else()
Expand Down
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
16 changes: 15 additions & 1 deletion src/app/devtools/documentation/qgsdocumentationpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
***************************************************************************/

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

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


//
// QgsDocumentationPanelWidget
//
Expand All @@ -26,6 +33,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
2 changes: 1 addition & 1 deletion src/app/qgsdevtoolspanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void QgsDevToolsPanelWidget::showApiDocumentation(
}
#ifndef HAVE_WEBENGINE
// QWebView does not support the search function from the PyQGIS documentation homepage
if ( api == QStringLiteral( "pyqgis-search" ) )
if ( api == Qgis::DocumentationApi::PyQgisSearch )
{
browser = Qgis::DocumentationBrowser::SystemWebBrowser;
}
Expand Down
15 changes: 4 additions & 11 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2612,17 +2612,10 @@ if (WITH_PDAL)
endif()

if (WITH_QTWEBENGINE)
if(BUILD_WITH_QT6)
target_link_libraries(qgis_core
${QT_VERSION_BASE}::WebEngineCore
)
else()
# QWebEnginePage is in WebEngineWidgets for Qt5
target_link_libraries(qgis_core
${QT_VERSION_BASE}::WebEngineCore
${QT_VERSION_BASE}::WebEngineWidgets
)
endif()
target_link_libraries(qgis_core
${QT_VERSION_BASE}::WebEngineCore
${QT_VERSION_BASE}::WebEngineWidgets
)
endif()

if (FORCE_STATIC_LIBS)
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 @@ -721,6 +721,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 a2c9374

Please sign in to comment.