From 4fe99d8d6ca8a7ab9e8a7c791d2a2f05241d4ea2 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 23 Mar 2021 14:12:06 +1000 Subject: [PATCH] Add better __repr__ methods for QgsDateTimeRange, QgsDateRange --- python/core/__init__.py.in | 3 +++ python/core/additions/ranges.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 python/core/additions/ranges.py diff --git a/python/core/__init__.py.in b/python/core/__init__.py.in index 59b16954078..77e240a5559 100644 --- a/python/core/__init__.py.in +++ b/python/core/__init__.py.in @@ -38,6 +38,7 @@ from .additions.qgstaskwrapper import QgsTaskWrapper from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory from .additions.runtimeprofiler import ScopedRuntimeProfileContextManager from .additions.validitycheck import check +from .additions.ranges import datetime_range_repr, date_range_repr # Injections into classes QgsFeature.__geo_interface__ = property(mapping_feature) @@ -53,6 +54,8 @@ QgsSettings.enumValue = _qgssettings_enum_value QgsSettings.setEnumValue = _qgssettings_set_enum_value QgsSettings.flagValue = _qgssettings_flag_value QgsTask.fromFunction = fromFunction +QgsDateTimeRange.__repr__ = datetime_range_repr +QgsDateRange.__repr__ = date_range_repr # Classes patched using a derived class QgsProviderMetadata = PyProviderMetadata diff --git a/python/core/additions/ranges.py b/python/core/additions/ranges.py new file mode 100644 index 00000000000..40985f0b721 --- /dev/null +++ b/python/core/additions/ranges.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + ranges.py + --------------------- + Date : Mar 2021 + Copyright : (C) 2021 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. * +* * +*************************************************************************** +""" +from qgis.PyQt.QtCore import Qt + + +# add some __repr__ methods to QGIS range classes. We can't do this via sip because they are template based classes + + +def datetime_range_repr(self): + return f"" + + +def date_range_repr(self): + return f""