Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add stored query support to Execute SQL window #60761

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@
<file>themes/default/stacked-diagram.svg</file>
<file>themes/default/mIconStac.svg</file>
<file>themes/default/mIconQt.svg</file>
<file>themes/default/mIconStoredQueries.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mIconStoredQueries.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6187,6 +6187,19 @@
Qgis.HistoryProviderBackends = lambda flags=0: Qgis.HistoryProviderBackend(flags)
Qgis.HistoryProviderBackends.baseClass = Qgis
HistoryProviderBackends = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.QueryStorageBackend.LocalProfile.__doc__ = "Local user profile"
Qgis.QueryStorageBackend.CurrentProject.__doc__ = "Current QGIS project"
Qgis.QueryStorageBackend.__doc__ = """Stored query storage backends.

.. versionadded:: 3.44

* ``LocalProfile``: Local user profile
* ``CurrentProject``: Current QGIS project

"""
# --
Qgis.QueryStorageBackend.baseClass = Qgis
QgsProcessing.SourceType = Qgis.ProcessingSourceType
# monkey patching scoped based enum
QgsProcessing.TypeMapLayer = Qgis.ProcessingSourceType.MapLayer
Expand Down
6 changes: 6 additions & 0 deletions python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,12 @@ The development version
typedef QFlags<Qgis::HistoryProviderBackend> HistoryProviderBackends;


enum class QueryStorageBackend /BaseType=IntEnum/
{
LocalProfile,
CurrentProject,
};

enum class ProcessingSourceType /BaseType=IntEnum/
{
MapLayer,
Expand Down
1 change: 1 addition & 0 deletions python/PyQt6/gui/auto_additions/qgsgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _force_int(v): return int(v.value) if isinstance(v, Enum) else v
QgsGui.windowManager = staticmethod(QgsGui.windowManager)
QgsGui.setWindowManager = staticmethod(QgsGui.setWindowManager)
QgsGui.inputControllerManager = staticmethod(QgsGui.inputControllerManager)
QgsGui.storedQueryManager = staticmethod(QgsGui.storedQueryManager)
QgsGui.higFlags = staticmethod(QgsGui.higFlags)
QgsGui.sampleColor = staticmethod(QgsGui.sampleColor)
QgsGui.findScreenAt = staticmethod(QgsGui.findScreenAt)
Expand Down
10 changes: 10 additions & 0 deletions python/PyQt6/gui/auto_additions/qgsstoredquerymanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The following has been generated automatically from src/gui/qgsstoredquerymanager.h
try:
QgsStoredQueryManager.QueryDetails.__attribute_docs__ = {'name': 'Name of the query.', 'definition': 'Query definition.', 'backend': 'Storage backend.'}
except (NameError, AttributeError):
pass
try:
QgsStoredQueryManager.__attribute_docs__ = {'queryAdded': 'Emitted when a query is added to the manager.\n', 'queryChanged': 'Emitted when an existing query is changed in the manager.\n', 'queryRemoved': 'Emitted when a query is removed from the manager.\n'}
QgsStoredQueryManager.__signal_arguments__ = {'queryAdded': ['name: str', 'backend: Qgis.QueryStorageBackend'], 'queryChanged': ['name: str', 'backend: Qgis.QueryStorageBackend'], 'queryRemoved': ['name: str', 'backend: Qgis.QueryStorageBackend']}
except (NameError, AttributeError):
pass
7 changes: 7 additions & 0 deletions python/PyQt6/gui/auto_generated/qgsgui.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta
Returns the global input controller manager.

.. versionadded:: 3.32
%End

static QgsStoredQueryManager *storedQueryManager() /KeepReference/;
%Docstring
Returns the global stored SQL query manager.

.. versionadded:: 3.44
%End

enum HigFlag /BaseType=IntEnum/
Expand Down
120 changes: 120 additions & 0 deletions python/PyQt6/gui/auto_generated/qgsstoredquerymanager.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsstoredquerymanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/



class QgsStoredQueryManager : QObject
{
%Docstring(signature="appended")
A manager for stored SQL queries.

:py:class:`QgsStoredQueryManager` is not usually directly created, instead
use the instance accessible through :py:func:`QgsGui.storedQueryManager()`.

.. versionadded:: 3.44
%End

%TypeHeaderCode
#include "qgsstoredquerymanager.h"
%End
public:

QgsStoredQueryManager( QObject *parent = 0 );
%Docstring
Constructor for QgsStoredQueryManager, with the specified
``parent`` object.
%End

void storeQuery( const QString &name, const QString &query, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile );
%Docstring
Saves a query to the manager.

If a query with the same ``name`` already exists it will be overwritten with the new definition.

:param name: user-set, unique name for the query.
:param query: query definition to store
:param backend: storage backend for query

.. seealso:: :py:func:`queryAdded`

.. seealso:: :py:func:`queryChanged`
%End

void removeQuery( const QString &name, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile );
%Docstring
Removes the stored query with matching ``name``.

:param name: name of query to remove
:param backend: storage backend for query

.. seealso:: :py:func:`queryRemoved`
%End

QStringList allQueryNames( Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile ) const;
%Docstring
Returns a list of the names of all stored queries for the specified ``backend``.
%End

QString query( const QString &name, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile ) const;
%Docstring
Returns the query definition with matching ``name``, from the specified ``backend``.
%End

class QueryDetails
{
%Docstring(signature="appended")
Contains details about a stored query.

.. versionadded:: 3.44
%End

%TypeHeaderCode
#include "qgsstoredquerymanager.h"
%End
public:
QString name;

QString definition;

Qgis::QueryStorageBackend backend;
};

QList< QgsStoredQueryManager::QueryDetails > allQueries() const;
%Docstring
Returns details of all queries stored in the manager.

Queries will be sorted by name.
%End

signals:

void queryAdded( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when a query is added to the manager.
%End

void queryChanged( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when an existing query is changed in the manager.
%End

void queryRemoved( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when a query is removed from the manager.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsstoredquerymanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
1 change: 1 addition & 0 deletions python/PyQt6/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
%Include auto_generated/qgssourceselectprovider.sip
%Include auto_generated/qgssourceselectproviderregistry.sip
%Include auto_generated/qgsstatusbar.sip
%Include auto_generated/qgsstoredquerymanager.sip
%Include auto_generated/qgsstyleitemslistwidget.sip
%Include auto_generated/qgssublayersdialog.sip
%Include auto_generated/qgssubstitutionlistwidget.sip
Expand Down
13 changes: 13 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6128,6 +6128,19 @@
Qgis.HistoryProviderBackend.baseClass = Qgis
Qgis.HistoryProviderBackends.baseClass = Qgis
HistoryProviderBackends = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.QueryStorageBackend.LocalProfile.__doc__ = "Local user profile"
Qgis.QueryStorageBackend.CurrentProject.__doc__ = "Current QGIS project"
Qgis.QueryStorageBackend.__doc__ = """Stored query storage backends.

.. versionadded:: 3.44

* ``LocalProfile``: Local user profile
* ``CurrentProject``: Current QGIS project

"""
# --
Qgis.QueryStorageBackend.baseClass = Qgis
QgsProcessing.SourceType = Qgis.ProcessingSourceType
# monkey patching scoped based enum
QgsProcessing.TypeMapLayer = Qgis.ProcessingSourceType.MapLayer
Expand Down
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,12 @@ The development version
typedef QFlags<Qgis::HistoryProviderBackend> HistoryProviderBackends;


enum class QueryStorageBackend
{
LocalProfile,
CurrentProject,
};

enum class ProcessingSourceType
{
MapLayer,
Expand Down
1 change: 1 addition & 0 deletions python/gui/auto_additions/qgsgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
QgsGui.windowManager = staticmethod(QgsGui.windowManager)
QgsGui.setWindowManager = staticmethod(QgsGui.setWindowManager)
QgsGui.inputControllerManager = staticmethod(QgsGui.inputControllerManager)
QgsGui.storedQueryManager = staticmethod(QgsGui.storedQueryManager)
QgsGui.higFlags = staticmethod(QgsGui.higFlags)
QgsGui.sampleColor = staticmethod(QgsGui.sampleColor)
QgsGui.findScreenAt = staticmethod(QgsGui.findScreenAt)
Expand Down
10 changes: 10 additions & 0 deletions python/gui/auto_additions/qgsstoredquerymanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The following has been generated automatically from src/gui/qgsstoredquerymanager.h
try:
QgsStoredQueryManager.QueryDetails.__attribute_docs__ = {'name': 'Name of the query.', 'definition': 'Query definition.', 'backend': 'Storage backend.'}
except (NameError, AttributeError):
pass
try:
QgsStoredQueryManager.__attribute_docs__ = {'queryAdded': 'Emitted when a query is added to the manager.\n', 'queryChanged': 'Emitted when an existing query is changed in the manager.\n', 'queryRemoved': 'Emitted when a query is removed from the manager.\n'}
QgsStoredQueryManager.__signal_arguments__ = {'queryAdded': ['name: str', 'backend: Qgis.QueryStorageBackend'], 'queryChanged': ['name: str', 'backend: Qgis.QueryStorageBackend'], 'queryRemoved': ['name: str', 'backend: Qgis.QueryStorageBackend']}
except (NameError, AttributeError):
pass
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsgui.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta
Returns the global input controller manager.

.. versionadded:: 3.32
%End

static QgsStoredQueryManager *storedQueryManager() /KeepReference/;
%Docstring
Returns the global stored SQL query manager.

.. versionadded:: 3.44
%End

enum HigFlag
Expand Down
120 changes: 120 additions & 0 deletions python/gui/auto_generated/qgsstoredquerymanager.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsstoredquerymanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/



class QgsStoredQueryManager : QObject
{
%Docstring(signature="appended")
A manager for stored SQL queries.

:py:class:`QgsStoredQueryManager` is not usually directly created, instead
use the instance accessible through :py:func:`QgsGui.storedQueryManager()`.

.. versionadded:: 3.44
%End

%TypeHeaderCode
#include "qgsstoredquerymanager.h"
%End
public:

QgsStoredQueryManager( QObject *parent = 0 );
%Docstring
Constructor for QgsStoredQueryManager, with the specified
``parent`` object.
%End

void storeQuery( const QString &name, const QString &query, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile );
%Docstring
Saves a query to the manager.

If a query with the same ``name`` already exists it will be overwritten with the new definition.

:param name: user-set, unique name for the query.
:param query: query definition to store
:param backend: storage backend for query

.. seealso:: :py:func:`queryAdded`

.. seealso:: :py:func:`queryChanged`
%End

void removeQuery( const QString &name, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile );
%Docstring
Removes the stored query with matching ``name``.

:param name: name of query to remove
:param backend: storage backend for query

.. seealso:: :py:func:`queryRemoved`
%End

QStringList allQueryNames( Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile ) const;
%Docstring
Returns a list of the names of all stored queries for the specified ``backend``.
%End

QString query( const QString &name, Qgis::QueryStorageBackend backend = Qgis::QueryStorageBackend::LocalProfile ) const;
%Docstring
Returns the query definition with matching ``name``, from the specified ``backend``.
%End

class QueryDetails
{
%Docstring(signature="appended")
Contains details about a stored query.

.. versionadded:: 3.44
%End

%TypeHeaderCode
#include "qgsstoredquerymanager.h"
%End
public:
QString name;

QString definition;

Qgis::QueryStorageBackend backend;
};

QList< QgsStoredQueryManager::QueryDetails > allQueries() const;
%Docstring
Returns details of all queries stored in the manager.

Queries will be sorted by name.
%End

signals:

void queryAdded( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when a query is added to the manager.
%End

void queryChanged( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when an existing query is changed in the manager.
%End

void queryRemoved( const QString &name, Qgis::QueryStorageBackend backend );
%Docstring
Emitted when a query is removed from the manager.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsstoredquerymanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
Loading