Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Oct 7, 2024
1 parent b8bd03c commit 03fbd6e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 70 deletions.
3 changes: 1 addition & 2 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,8 @@ def showApiDocumentation(self, text, force_search=False):
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")

embedded = pythonSettingsTreeNode.childSetting('context-help-embedded').value()
api = "pyqgis" if pythonSettingsTreeNode.childSetting('context-help-pyqgis').value() else "qgis"

self._interpreter.execCommandImpl(f'_help({repr(text)}, api="{api}", embedded={embedded}, force_search={force_search})', show_input=False)
self._interpreter.execCommandImpl(f'_help({repr(text)}, api="pyqgis", embedded={embedded}, force_search={force_search})', show_input=False)

def showApi(self, api):
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
Expand Down
10 changes: 6 additions & 4 deletions python/console/console_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,16 @@ def saveSettings(self):

settings.setValue("pythonConsole/formatOnSave", self.formatOnSave.isChecked())

pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
codeEditorTreeNode = QgsSettingsTree.node("gui").childNode("code-editor")
pythonSettingsTreeNode = codeEditorTreeNode.childNode("python")
pythonSettingsTreeNode.childSetting("sort-imports").setValue(self.sortImports.isChecked())
pythonSettingsTreeNode.childSetting("formatter").setValue(self.formatter.currentText())
pythonSettingsTreeNode.childSetting("autopep8-level").setValue(self.autopep8Level.value())
pythonSettingsTreeNode.childSetting("black-normalize-quotes").setValue(self.blackNormalizeQuotes.isChecked())
pythonSettingsTreeNode.childSetting("max-line-length").setValue(self.maxLineLength.value())
pythonSettingsTreeNode.childSetting('external-editor').setValue(self.externalEditor.text())
pythonSettingsTreeNode.childSetting('context-help-embedded').setValue(self.contextHelpBrowser.currentIndex() == 0)
pythonSettingsTreeNode.childSetting('context-help-pyqgis').setValue(self.contextHelpApi.currentIndex() == 0)
codeEditorTreeNode.childSetting('context-help-hover').setValue(self.contextHelpHover.isChecked())

def restoreSettings(self):
settings = QgsSettings()
Expand All @@ -245,7 +246,8 @@ def restoreSettings(self):
self.autoSurround.setChecked(settings.value("pythonConsole/autoSurround", True, type=bool))
self.autoInsertImport.setChecked(settings.value("pythonConsole/autoInsertImport", False, type=bool))

pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
codeEditorTreeNode = QgsSettingsTree.node("gui").childNode("code-editor")
pythonSettingsTreeNode = codeEditorTreeNode.childNode("python")

self.formatOnSave.setChecked(settings.value("pythonConsole/formatOnSave", False, type=bool))
self.sortImports.setChecked(pythonSettingsTreeNode.childSetting("sort-imports").value())
Expand All @@ -254,7 +256,7 @@ def restoreSettings(self):
self.blackNormalizeQuotes.setChecked(pythonSettingsTreeNode.childSetting("black-normalize-quotes").value())
self.maxLineLength.setValue(pythonSettingsTreeNode.childSetting("max-line-length").value())
self.contextHelpBrowser.setCurrentIndex(0 if pythonSettingsTreeNode.childSetting('context-help-embedded').value() else 1)
self.contextHelpApi.setCurrentIndex(0 if pythonSettingsTreeNode.childSetting('context-help-pyqgis').value() else 1)
self.contextHelpHover.setChecked(codeEditorTreeNode.childSetting('context-help-hover').value())

if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
self.autoCompFromDoc.setChecked(True)
Expand Down
23 changes: 4 additions & 19 deletions python/console/console_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<x>0</x>
<y>0</y>
<width>739</width>
<height>1242</height>
<height>1240</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -619,27 +619,13 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="contextHelpHover">
<property name="text">
<string>API</string>
<string>F1 works on hovered words</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="contextHelpApi">
<item>
<property name="text">
<string>PyQGIS</string>
</property>
</item>
<item>
<property name="text">
<string>C++ QGIS</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -677,7 +663,6 @@
<tabstop>autoSurround</tabstop>
<tabstop>autoInsertImport</tabstop>
<tabstop>contextHelpBrowser</tabstop>
<tabstop>contextHelpApi</tabstop>
<tabstop>formatOnSave</tabstop>
<tabstop>sortImports</tabstop>
<tabstop>maxLineLength</tabstop>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ QgsDocumentationPanelWidget::QgsDocumentationPanelWidget( QWidget *parent )
{
setupUi( this );

connect( mPythonHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( QStringLiteral( "pyqgis" ), true );} );
connect( mCppHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( QStringLiteral( "qgis" ), true );} );
connect( mPyQgisHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( QStringLiteral( "pyqgis" ), true );} );
connect( mQtHomeButton, &QToolButton::clicked, this, [] {QgisApp::instance()->showApiDocumentation( QStringLiteral( "qt" ), true );} );
connect( mOpenUrlButton, &QToolButton::clicked, this, [this] {QgisApp::instance()->openURL( mWebView->url().toString(), false );} );

Expand Down
47 changes: 45 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,44 @@ class QTreeWidgetItem;
class QgsUserProfileManager;
class QgsUserProfile;



class TestAction: public QWidgetAction
{
public:
TestAction( QObject *parent = nullptr ): QWidgetAction( parent ) {};
virtual QToolButton *createToolButton() = 0;

QWidget *createWidget( QWidget *parent )
{
auto widget = createToolButton();
widget->setParent( parent );
if ( dynamic_cast<QMenu *>( parent ) )
{

widget->setText( QStringLiteral( " " ) + widget->text() );
widget->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
}
return widget;
}
};

class MapThemeAction: public TestAction
{
public:
MapThemeAction( QObject *parent = nullptr ): TestAction( parent ) {};
QToolButton *createToolButton() override
{
QToolButton *btnVisibilityPresets = new QToolButton();
btnVisibilityPresets->setAutoRaise( true );
btnVisibilityPresets->setText( tr( "Manage Map Themes" ) );
btnVisibilityPresets->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowAllLayers.svg" ) ) );
btnVisibilityPresets->setPopupMode( QToolButton::InstantPopup );
btnVisibilityPresets->setMenu( QgsMapThemes::instance()->menu() );
return btnVisibilityPresets;
}
};

/**
* Set the application title bar text
*/
Expand Down Expand Up @@ -4960,12 +4998,15 @@ void QgisApp::initLayerTreeView()
connect( actionAddGroup, &QAction::triggered, mLayerTreeView->defaultActions(), &QgsLayerTreeViewDefaultActions::addGroup );

// visibility groups tool button

QWidgetAction *btnVisibilityPresetsAction = new QWidgetAction( this );
QToolButton *btnVisibilityPresets = new QToolButton;
btnVisibilityPresets->setAutoRaise( true );
btnVisibilityPresets->setToolTip( tr( "Manage Map Themes" ) );
btnVisibilityPresets->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowAllLayers.svg" ) ) );
btnVisibilityPresets->setPopupMode( QToolButton::InstantPopup );
btnVisibilityPresets->setMenu( QgsMapThemes::instance()->menu() );
btnVisibilityPresetsAction->setDefaultWidget( btnVisibilityPresets );

// filter legend actions
mFilterLegendToolButton = new QToolButton( this );
Expand Down Expand Up @@ -5015,7 +5056,9 @@ void QgisApp::initLayerTreeView()
toolbar->setIconSize( iconSize( true ) );
toolbar->addAction( mActionStyleDock );
toolbar->addAction( actionAddGroup );
toolbar->addWidget( btnVisibilityPresets );
toolbar->addAction( btnVisibilityPresetsAction );
auto aa = new MapThemeAction( this );
toolbar->addAction( aa );
toolbar->addWidget( mFilterLegendToolButton );
toolbar->addWidget( mLegendExpressionFilterButton );
toolbar->addAction( actionExpandAll );
Expand Down Expand Up @@ -12943,7 +12986,7 @@ void QgisApp::apiDocumentation()
showApiDocumentation( "qgis", false );
}

void QgisApp::pyQgisApiDocumentation()
void QgisApp::pyQgisApiDocumentation( )
{
showApiDocumentation( "pyqgis", false );
}
Expand Down
9 changes: 8 additions & 1 deletion src/gui/codeeditors/qgscodeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgscodeeditorhistorydialog.h"
#include "qgsstringutils.h"
#include "qgsfontutils.h"
#include "qgssettingsentryimpl.h"

#include <QLabel>
#include <QWidget>
Expand All @@ -36,6 +37,12 @@
#include <QScrollBar>
#include <QMessageBox>

///@cond PRIVATE
const QgsSettingsEntryBool *QgsCodeEditor::settingContextHelpHover = new QgsSettingsEntryBool( QStringLiteral( "context-help-hover" ), sTreeCodeEditor, false, QStringLiteral( "Whether the context help should works on hovered words" ) );
///@endcond PRIVATE



QMap< QgsCodeEditorColorScheme::ColorRole, QString > QgsCodeEditor::sColorRoleToSettingsKey
{
{QgsCodeEditorColorScheme::ColorRole::Default, QStringLiteral( "defaultFontColor" ) },
Expand Down Expand Up @@ -198,7 +205,7 @@ void QgsCodeEditor::keyPressEvent( QKeyEvent *event )
QString text = selectedText();

// Check if mouse is hovering over a word
if ( text.isEmpty() )
if ( text.isEmpty() && settingContextHelpHover->value() )
{
text = wordAtPoint( mapFromGlobal( QCursor::pos() ) );
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/codeeditors/qgscodeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class QgsFilterLineEdit;
class QToolButton;
class QCheckBox;
class QgsSettingsEntryBool;

SIP_IF_MODULE( HAVE_QSCI_SIP )

Expand Down Expand Up @@ -107,6 +108,7 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
#ifndef SIP_RUN

static inline QgsSettingsTreeNode *sTreeCodeEditor = QgsSettingsTree::sTreeGui->createChildNode( QStringLiteral( "code-editor" ) );
static const QgsSettingsEntryBool *settingContextHelpHover;
#endif

/**
Expand Down
24 changes: 3 additions & 21 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const QgsSettingsEntryInteger *QgsCodeEditorPython::settingAutopep8Level = new Q
const QgsSettingsEntryBool *QgsCodeEditorPython::settingBlackNormalizeQuotes = new QgsSettingsEntryBool( QStringLiteral( "black-normalize-quotes" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether quotes should be normalized when auto-formatting code using black" ) );
const QgsSettingsEntryString *QgsCodeEditorPython::settingExternalPythonEditorCommand = new QgsSettingsEntryString( QStringLiteral( "external-editor" ), sTreePythonCodeEditor, QString(), QStringLiteral( "Command to launch an external Python code editor. Use the token <file> to insert the filename, <line> to insert line number, and <col> to insert the column number." ) );
const QgsSettingsEntryBool *QgsCodeEditorPython::settingContextHelpEmbedded = new QgsSettingsEntryBool( QStringLiteral( "context-help-embedded" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether the context help should be displayed in an embedded webview in the devtools panel" ) );
const QgsSettingsEntryBool *QgsCodeEditorPython::settingContextHelpPyQgis = new QgsSettingsEntryBool( QStringLiteral( "context-help-pyqgis" ), sTreePythonCodeEditor, true, QStringLiteral( "Whether the context help should use the PyQGIS api instead of the C++ API" ) );
///@endcond PRIVATE


Expand Down Expand Up @@ -741,34 +740,17 @@ void QgsCodeEditorPython::showApiDocumentation( const QString &text )
{
QString searchText = text;
searchText = searchText.replace( QLatin1String( ">>> " ), QString() ).replace( QLatin1String( "... " ), QString() ).trimmed(); // removing prompts
QRegularExpression qgisExpression( "^Qgs[A-Z][a-zA-Z]" );

QRegularExpression qtExpression( "^Q[A-Z][a-zA-Z]" );

bool pyQgis = QgsCodeEditorPython::settingContextHelpPyQgis->value();

const QString qgisVersion = QString( Qgis::version() ).split( '.' ).mid( 0, 2 ).join( '.' );
const QString qtVersion = QString( qVersion() ).split( '.' ).mid( 0, 2 ).join( '.' );

QgsSettings settings;

if ( qgisExpression.match( searchText ).hasMatch() )
{
if ( !pyQgis )
{

QString baseUrl = settings.value( QStringLiteral( "qgis/QgisApiUrl" ),
QString( "https://qgis.org/api/%1" ).arg( qgisVersion ) ).toString();
QDesktopServices::openUrl( QUrl( QString( "%1/class%2.html" ).arg( baseUrl, searchText ) ) );
return;
}
}
else if ( qtExpression.match( searchText ).hasMatch() )
if ( qtExpression.match( searchText ).hasMatch() )
{
const QString qtVersion = QString( qVersion() ).split( '.' ).mid( 0, 2 ).join( '.' );
QString baseUrl = QString( "https://doc.qt.io/qt-%1" ).arg( qtVersion );
QDesktopServices::openUrl( QUrl( QStringLiteral( "%1/%2.html" ).arg( baseUrl, searchText.toLower() ) ) );
return;
}
const QString qgisVersion = QString( Qgis::version() ).split( '.' ).mid( 0, 2 ).join( '.' );
QDesktopServices::openUrl( QUrl( QStringLiteral( "https://qgis.org/pyqgis/%1/search.html?q=%2" ).arg( qgisVersion, searchText ) ) );
}

Expand Down
1 change: 0 additions & 1 deletion src/gui/codeeditors/qgscodeeditorpython.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
static const QgsSettingsEntryBool *settingBlackNormalizeQuotes;
static const QgsSettingsEntryString *settingExternalPythonEditorCommand;
static const QgsSettingsEntryBool *settingContextHelpEmbedded;
static const QgsSettingsEntryBool *settingContextHelpPyQgis;
///@endcond PRIVATE
#endif

Expand Down
19 changes: 1 addition & 18 deletions src/ui/qgsdocumentationpanelbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,10 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="mPythonHomeButton">
<widget class="QToolButton" name="mPyQgisHomeButton">
<property name="toolTip">
<string>PyQGIS API Documentation</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mIconPythonFile.svg</normaloff>:/images/themes/default/mIconPythonFile.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mCppHomeButton">
<property name="toolTip">
<string>C++ API documentation</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/icons/qgis_icon.svg</normaloff>:/images/icons/qgis_icon.svg</iconset>
Expand Down

0 comments on commit 03fbd6e

Please sign in to comment.