From e84ce19706ea8ba3dc3533c19a10235ae105b34a Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 19 Apr 2023 09:05:08 +1000 Subject: [PATCH] Move QgsHistoryEntry to separate file --- .../history/qgshistoryentry.sip.in | 69 +++++++++++++++ .../history/qgshistoryproviderregistry.sip.in | 52 ----------- python/gui/gui_auto.sip | 1 + src/gui/CMakeLists.txt | 2 + src/gui/history/qgshistoryentry.cpp | 37 ++++++++ src/gui/history/qgshistoryentry.h | 88 +++++++++++++++++++ .../history/qgshistoryproviderregistry.cpp | 31 +------ src/gui/history/qgshistoryproviderregistry.h | 61 +------------ .../qgsprocessinghistoryprovider.cpp | 2 +- src/gui/qgsgui.cpp | 1 + 10 files changed, 202 insertions(+), 142 deletions(-) create mode 100644 python/gui/auto_generated/history/qgshistoryentry.sip.in create mode 100644 src/gui/history/qgshistoryentry.cpp create mode 100644 src/gui/history/qgshistoryentry.h diff --git a/python/gui/auto_generated/history/qgshistoryentry.sip.in b/python/gui/auto_generated/history/qgshistoryentry.sip.in new file mode 100644 index 00000000000..a77be84bacf --- /dev/null +++ b/python/gui/auto_generated/history/qgshistoryentry.sip.in @@ -0,0 +1,69 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/history/qgshistoryentry.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 "qgshistoryentry.h" +%End + public: + + QgsHistoryEntry(); +%Docstring +Constructor for an invalid entry. +%End + + QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, 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 + + bool isValid() const; +%Docstring +Returns ``True`` if the entry is valid. + +.. versionadded:: 3.32 +%End + + QDateTime timestamp; + + QString providerId; + + QVariantMap entry; + + SIP_PYOBJECT __repr__(); +%MethodCode + const QString str = QStringLiteral( "" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) ); + sipRes = PyUnicode_FromString( str.toUtf8().constData() ); +%End + +}; + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/history/qgshistoryentry.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in b/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in index 3c87202953f..82492f8c41f 100644 --- a/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in +++ b/python/gui/auto_generated/history/qgshistoryproviderregistry.sip.in @@ -10,58 +10,6 @@ -class QgsHistoryEntry -{ -%Docstring(signature="appended") -Encapsulates a history entry. - -.. versionadded:: 3.24 -%End - -%TypeHeaderCode -#include "qgshistoryproviderregistry.h" -%End - public: - - QgsHistoryEntry(); -%Docstring -Constructor for an invalid entry. -%End - - QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, 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 - - bool isValid() const; -%Docstring -Returns ``True`` if the entry is valid. - -.. versionadded:: 3.32 -%End - - QDateTime timestamp; - - QString providerId; - - QVariantMap entry; - - SIP_PYOBJECT __repr__(); -%MethodCode - const QString str = QStringLiteral( "" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) ); - sipRes = PyUnicode_FromString( str.toUtf8().constData() ); -%End - -}; - - class QgsHistoryProviderRegistry : QObject { %Docstring(signature="appended") diff --git a/python/gui/gui_auto.sip b/python/gui/gui_auto.sip index d28fd64217e..00d0578e7ab 100644 --- a/python/gui/gui_auto.sip +++ b/python/gui/gui_auto.sip @@ -341,6 +341,7 @@ %Include auto_generated/effects/qgspainteffectpropertieswidget.sip %Include auto_generated/effects/qgspainteffectwidget.sip %Include auto_generated/elevation/qgselevationprofilecanvas.sip +%Include auto_generated/history/qgshistoryentry.sip %Include auto_generated/history/qgshistoryprovider.sip %Include auto_generated/history/qgshistoryproviderregistry.sip %Include auto_generated/labeling/qgslabellineanchorwidget.sip diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index a835f7338a2..2243d2e6be2 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -236,6 +236,7 @@ set(QGIS_GUI_SRCS elevation/qgselevationprofilecanvas.cpp elevation/qgselevationprofilelayertreeview.cpp + history/qgshistoryentry.cpp history/qgshistoryprovider.cpp history/qgshistoryproviderregistry.cpp @@ -1142,6 +1143,7 @@ set(QGIS_GUI_HDRS elevation/qgselevationprofilecanvas.h elevation/qgselevationprofilelayertreeview.h + history/qgshistoryentry.h history/qgshistoryprovider.h history/qgshistoryproviderregistry.h diff --git a/src/gui/history/qgshistoryentry.cpp b/src/gui/history/qgshistoryentry.cpp new file mode 100644 index 00000000000..fe8d9a2004b --- /dev/null +++ b/src/gui/history/qgshistoryentry.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + qgshistoryentry.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 "qgshistoryentry.h" + +QgsHistoryEntry::QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, const QVariantMap &entry ) + : timestamp( timestamp ) + , providerId( providerId ) + , entry( entry ) +{ + +} + +QgsHistoryEntry::QgsHistoryEntry( const QVariantMap &entry ) + : timestamp( QDateTime::currentDateTime() ) + , entry( entry ) +{ + +} + +bool QgsHistoryEntry::isValid() const +{ + return !providerId.isEmpty(); +} diff --git a/src/gui/history/qgshistoryentry.h b/src/gui/history/qgshistoryentry.h new file mode 100644 index 00000000000..25e335e2ee7 --- /dev/null +++ b/src/gui/history/qgshistoryentry.h @@ -0,0 +1,88 @@ +/*************************************************************************** + qgshistoryentry.h + -------------------------- + 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. * + * * + ***************************************************************************/ +#ifndef QGSHISTORYENTRY_H +#define QGSHISTORYENTRY_H + +#include "qgis_gui.h" +#include "qgis_sip.h" +#include "qgis.h" + +#include +#include +#include +#include + +/** + * Encapsulates a history entry. + * + * \ingroup gui + * \since QGIS 3.24 + */ +class GUI_EXPORT QgsHistoryEntry +{ + public: + + /** + * Constructor for an invalid entry. + */ + QgsHistoryEntry() = default; + + /** + * Constructor for QgsHistoryEntry \a entry, with the specified \a providerId and \a timestamp. + */ + QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, const QVariantMap &entry ); + + /** + * Constructor for QgsHistoryEntry \a entry. + * + * The entry timestamp will be automatically set to the current date/time. + */ + QgsHistoryEntry( const QVariantMap &entry ); + + /** + * Returns TRUE if the entry is valid. + * + * \since QGIS 3.32 + */ + bool isValid() const; + + //! Entry timestamp + QDateTime timestamp; + + //! Associated history provider ID + QString providerId; + + /** + * Entry details. + * + * Entries details are stored as a free-form map. Interpretation of this map is the responsibility of the + * associated history provider. + */ + QVariantMap entry; + +#ifdef SIP_RUN + SIP_PYOBJECT __repr__(); + % MethodCode + const QString str = QStringLiteral( "" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) ); + sipRes = PyUnicode_FromString( str.toUtf8().constData() ); + % End +#endif + +}; + +Q_DECLARE_METATYPE( QgsHistoryEntry ); + +#endif // QGSHISTORYENTRY diff --git a/src/gui/history/qgshistoryproviderregistry.cpp b/src/gui/history/qgshistoryproviderregistry.cpp index cbf512b3969..750e5f712be 100644 --- a/src/gui/history/qgshistoryproviderregistry.cpp +++ b/src/gui/history/qgshistoryproviderregistry.cpp @@ -15,44 +15,17 @@ ***************************************************************************/ #include "qgshistoryproviderregistry.h" -#include "history/qgshistoryprovider.h" +#include "qgshistoryprovider.h" #include "qgsapplication.h" #include "qgsruntimeprofiler.h" #include "qgslogger.h" #include "qgsxmlutils.h" #include "qgsprocessinghistoryprovider.h" +#include "qgshistoryentry.h" #include #include -// -// QgsHistoryEntry -// - -QgsHistoryEntry::QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, const QVariantMap &entry ) - : timestamp( timestamp ) - , providerId( providerId ) - , entry( entry ) -{ - -} - -QgsHistoryEntry::QgsHistoryEntry( const QVariantMap &entry ) - : timestamp( QDateTime::currentDateTime() ) - , entry( entry ) -{ - -} - -bool QgsHistoryEntry::isValid() const -{ - return !providerId.isEmpty(); -} - -// -// QgsHistoryProviderRegistry -// - QgsHistoryProviderRegistry::QgsHistoryProviderRegistry( QObject *parent, bool useMemoryDatabase ) : QObject( parent ) { diff --git a/src/gui/history/qgshistoryproviderregistry.h b/src/gui/history/qgshistoryproviderregistry.h index 9293ef2f412..d8fd193b7fb 100644 --- a/src/gui/history/qgshistoryproviderregistry.h +++ b/src/gui/history/qgshistoryproviderregistry.h @@ -30,66 +30,7 @@ #include "qgssqliteutils.h" class QgsAbstractHistoryProvider; - -/** - * Encapsulates a history entry. - * - * \ingroup gui - * \since QGIS 3.24 - */ -class GUI_EXPORT QgsHistoryEntry -{ - public: - - /** - * Constructor for an invalid entry. - */ - QgsHistoryEntry() = default; - - /** - * Constructor for QgsHistoryEntry \a entry, with the specified \a providerId and \a timestamp. - */ - QgsHistoryEntry( const QString &providerId, const QDateTime ×tamp, const QVariantMap &entry ); - - /** - * Constructor for QgsHistoryEntry \a entry. - * - * The entry timestamp will be automatically set to the current date/time. - */ - QgsHistoryEntry( const QVariantMap &entry ); - - /** - * Returns TRUE if the entry is valid. - * - * \since QGIS 3.32 - */ - bool isValid() const; - - //! Entry timestamp - QDateTime timestamp; - - //! Associated history provider ID - QString providerId; - - /** - * Entry details. - * - * Entries details are stored as a free-form map. Interpretation of this map is the responsibility of the - * associated history provider. - */ - QVariantMap entry; - -#ifdef SIP_RUN - SIP_PYOBJECT __repr__(); - % MethodCode - const QString str = QStringLiteral( "" ).arg( sipCpp->providerId, sipCpp->timestamp.toString( Qt::ISODate ) ); - sipRes = PyUnicode_FromString( str.toUtf8().constData() ); - % End -#endif - -}; - -Q_DECLARE_METATYPE( QgsHistoryEntry ); +class QgsHistoryEntry; /** * The QgsHistoryProviderRegistry is a registry for objects which track user history (i.e. operations performed through the GUI). diff --git a/src/gui/processing/qgsprocessinghistoryprovider.cpp b/src/gui/processing/qgsprocessinghistoryprovider.cpp index 3963b04d898..8ebaa86d03f 100644 --- a/src/gui/processing/qgsprocessinghistoryprovider.cpp +++ b/src/gui/processing/qgsprocessinghistoryprovider.cpp @@ -18,7 +18,7 @@ #include "qgsapplication.h" #include "qgsgui.h" #include "qgshistoryproviderregistry.h" -#include "qgssettings.h" +#include "qgshistoryentry.h" #include #include diff --git a/src/gui/qgsgui.cpp b/src/gui/qgsgui.cpp index ebd85af3469..a0c9574e89f 100644 --- a/src/gui/qgsgui.cpp +++ b/src/gui/qgsgui.cpp @@ -61,6 +61,7 @@ #include "qgshistoryproviderregistry.h" #include "qgslayermetadatasourceselectprovider.h" #include "qgssensorguiregistry.h" +#include "qgshistoryentry.h" #include #include