Skip to content
Permalink
Browse files
Implement framework for history providers
  • Loading branch information
nyalldawson committed Dec 21, 2021
1 parent 0d332d3 commit 6783347896c50ba9ea14985e1a4aa4eae8871b8f
@@ -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
@@ -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
@@ -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;
@@ -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);




@@ -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 *
************************************************************************/
@@ -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 *
************************************************************************/
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.