Skip to content

Commit

Permalink
Implement framework for history providers
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 21, 2021
1 parent 0d332d3 commit 6783347
Show file tree
Hide file tree
Showing 17 changed files with 957 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Expand Up @@ -104,6 +104,7 @@ if(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/history
${CMAKE_SOURCE_DIR}/src/gui/labeling
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/layout
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -1187,3 +1187,10 @@
Qgis.AngularDirection.__doc__ = 'Angular directions.\n\n.. versionadded:: 3.24\n\n' + '* ``Clockwise``: ' + Qgis.AngularDirection.Clockwise.__doc__ + '\n' + '* ``CounterClockwise``: ' + Qgis.AngularDirection.CounterClockwise.__doc__
# --
Qgis.AngularDirection.baseClass = Qgis
# monkey patching scoped based enum
Qgis.HistoryProviderBackend.LocalProfile.__doc__ = "Local profile"
Qgis.HistoryProviderBackend.__doc__ = 'History provider backends.\n\n.. versionadded:: 3.24\n\n' + '* ``LocalProfile``: ' + Qgis.HistoryProviderBackend.LocalProfile.__doc__
# --
Qgis.HistoryProviderBackend.baseClass = Qgis
Qgis.HistoryProviderBackends.baseClass = Qgis
HistoryProviderBackends = Qgis # dirty hack since SIP seems to introduce the flags in module
10 changes: 10 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -763,6 +763,14 @@ The development version
CounterClockwise,
};

enum class HistoryProviderBackend
{
LocalProfile,
// Project = 1 << 1, //!< QGIS Project (not yet implemented)
};
typedef QFlags<Qgis::HistoryProviderBackend> HistoryProviderBackends;


static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down Expand Up @@ -866,6 +874,8 @@ QFlags<Qgis::MarkerLinePlacement> operator|(Qgis::MarkerLinePlacement f1, QFlags

QFlags<Qgis::TextRendererFlag> operator|(Qgis::TextRendererFlag f1, QFlags<Qgis::TextRendererFlag> f2);

QFlags<Qgis::HistoryProviderBackend> operator|(Qgis::HistoryProviderBackend f1, QFlags<Qgis::HistoryProviderBackend> f2);




Expand Down
45 changes: 45 additions & 0 deletions python/gui/auto_generated/history/qgshistoryprovider.sip.in
@@ -0,0 +1,45 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAbstractHistoryProvider
{
%Docstring(signature="appended")
Abstract base class for objects which track user history (i.e. operations performed through the GUI).

:py:class:`QgsAbstractHistoryProvider` subclasses are accessible through the :py:class:`QgsHistoryProviderRegistry` class.

.. versionadded:: 3.24
%End

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

virtual ~QgsAbstractHistoryProvider();

virtual QString id() const = 0;
%Docstring
Returns the provider's unique id, which is used to associate existing history entries with the provider.
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
163 changes: 163 additions & 0 deletions python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in
@@ -0,0 +1,163 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsHistoryEntry
{
%Docstring(signature="appended")
Encapsulates a history entry.

.. versionadded:: 3.24
%End

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

QgsHistoryEntry( const QString &providerId, const QDateTime &timestamp, const QVariantMap &entry );
%Docstring
Constructor for QgsHistoryEntry ``entry``, with the specified ``providerId`` and ``timestamp``.
%End

QgsHistoryEntry( const QVariantMap &entry );
%Docstring
Constructor for QgsHistoryEntry ``entry``.

The entry timestamp will be automatically set to the current date/time.
%End

QDateTime timestamp;

QString providerId;

QVariantMap entry;

SIP_PYOBJECT __repr__();
%MethodCode
const QString str = QStringLiteral( "<QgsHistoryEntry: %1 %2>" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};

class QgsHistoryProviderRegistry : QObject
{
%Docstring(signature="appended")
The :py:class:`QgsHistoryProviderRegistry` is a registry for objects which track user history (i.e. operations performed through the GUI).

:py:class:`QgsHistoryProviderRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsGui.historyProviderRegistry()`.

.. versionadded:: 3.24
%End

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

QgsHistoryProviderRegistry( QObject *parent = 0, bool useMemoryDatabase = false );
%Docstring
Creates a new empty history provider registry.

QgsHistoryProviderRegistry is not usually directly created, but rather accessed through
:py:func:`QgsGui.historyProviderRegistry()`.
%End

~QgsHistoryProviderRegistry();

bool addProvider( QgsAbstractHistoryProvider *provider /Transfer/ );
%Docstring
Adds a ``provider`` to the registry. Ownership of the provider is
transferred to the registry.

Returns ``True`` if the provider was successfully added.
%End

QgsAbstractHistoryProvider *providerById( const QString &id );
%Docstring
Returns the provider with matching ``id``, or ``None`` if no matching
provider is registered.
%End

bool removeProvider( const QString &id );
%Docstring
Removes the provider with matching ``id``.

The provider will be deleted.

Returns ``True`` if the provider was successfully removed.
%End

QStringList providerIds() const;
%Docstring
Returns a list of the registered provider IDs.
%End

class HistoryEntryOptions
{
%Docstring(signature="appended")
Contains options for storing history entries.

.. versionadded:: 3.24
%End

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

HistoryEntryOptions();
%Docstring
Constructor for HistoryEntryOptions.
%End

Qgis::HistoryProviderBackends storageBackends;
};

bool addEntry( const QString &providerId, const QVariantMap &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
%Docstring
Adds an ``entry`` to the history logs.

The entry will be tagged with the current date/time as the timestamp.

The ``providerId`` specifies the history provider responsible for this entry.
Entry options are specified via the ``options`` argument.
%End

bool addEntry( const QgsHistoryEntry &entry, QgsHistoryProviderRegistry::HistoryEntryOptions options = QgsHistoryProviderRegistry::HistoryEntryOptions() );
%Docstring
Adds an ``entry`` to the history logs.
%End

QList< QgsHistoryEntry > queryEntries( const QDateTime &start = QDateTime(), const QDateTime &end = QDateTime(),
const QString &providerId = QString(), Qgis::HistoryProviderBackends backends = Qgis::HistoryProviderBackend::LocalProfile ) const;
%Docstring
Queries history entries which occurred between the specified ``start`` and ``end`` times.

The optional ``providerId`` and ``backends`` arguments can be used to filter entries.
%End

static QString userHistoryDbPath();
%Docstring
Returns the path to user's local history database.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
8 changes: 8 additions & 0 deletions python/gui/auto_generated/qgsgui.sip.in
Expand Up @@ -153,6 +153,14 @@ Returns the global relation widget registry, used for managing all known relatio
.. versionadded:: 3.18
%End


static QgsHistoryProviderRegistry *historyProviderRegistry() /KeepReference/;
%Docstring
Returns the global history provider registry, used for tracking history providers.

.. versionadded:: 3.24
%End

static void enableAutoGeometryRestore( QWidget *widget, const QString &key = QString() );
%Docstring
Register the widget to allow its position to be automatically saved and restored when open and closed.
Expand Down
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -317,6 +317,8 @@
%Include auto_generated/effects/qgseffectstackpropertieswidget.sip
%Include auto_generated/effects/qgspainteffectpropertieswidget.sip
%Include auto_generated/effects/qgspainteffectwidget.sip
%Include auto_generated/history/qgshistoryprovider.sip
%Include auto_generated/history/qgshistoryproviderregistry.sip
%Include auto_generated/labeling/qgslabellineanchorwidget.sip
%Include auto_generated/labeling/qgslabelobstaclesettingswidget.sip
%Include auto_generated/labeling/qgslabelsettingswidgetbase.sip
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgis.h
Expand Up @@ -1248,6 +1248,20 @@ class CORE_EXPORT Qgis
};
Q_ENUM( AngularDirection )

/**
* History provider backends.
*
* \since QGIS 3.24
*/
enum class HistoryProviderBackend : int
{
LocalProfile = 1 << 0, //!< Local profile
// Project = 1 << 1, //!< QGIS Project (not yet implemented)
};
Q_ENUM( HistoryProviderBackend )
Q_DECLARE_FLAGS( HistoryProviderBackends, HistoryProviderBackend )
Q_FLAG( HistoryProviderBackends )

/**
* Identify search radius in mm
* \since QGIS 2.3
Expand Down Expand Up @@ -1380,6 +1394,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::RenderContextFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::VectorLayerTypeFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::MarkerLinePlacements )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::TextRendererFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::HistoryProviderBackends )


// hack to workaround warnings when casting void pointers
Expand Down
7 changes: 7 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -212,6 +212,9 @@ set(QGIS_GUI_SRCS
editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp
editorwidgets/qgsvaluerelationwidgetfactory.cpp

history/qgshistoryprovider.cpp
history/qgshistoryproviderregistry.cpp

labeling/qgslabelengineconfigdialog.cpp
labeling/qgslabelinggui.cpp
labeling/qgslabelingwidget.cpp
Expand Down Expand Up @@ -1033,6 +1036,9 @@ set(QGIS_GUI_HDRS
effects/qgspainteffectpropertieswidget.h
effects/qgspainteffectwidget.h

history/qgshistoryprovider.h
history/qgshistoryproviderregistry.h

labeling/qgslabelengineconfigdialog.h
labeling/qgslabelinggui.h
labeling/qgslabelingwidget.h
Expand Down Expand Up @@ -1449,6 +1455,7 @@ target_include_directories(qgis_gui PUBLIC
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/history
${CMAKE_SOURCE_DIR}/src/gui/labeling
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/layout
Expand Down
19 changes: 19 additions & 0 deletions src/gui/history/qgshistoryprovider.cpp
@@ -0,0 +1,19 @@
/***************************************************************************
qgshistoryprovider.cpp
-------------------------
begin : April 2019
copyright : (C) 2019 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgshistoryprovider.h"

QgsAbstractHistoryProvider::~QgsAbstractHistoryProvider() = default;

0 comments on commit 6783347

Please sign in to comment.