Skip to content

Commit

Permalink
Create a new abtract base class for file content caches (e.g. QgsSvgC…
Browse files Browse the repository at this point in the history
…ache)

Generalise QgsSvgCache and split off into a common base class so
that we can re-use code with alternative similar caches, e.g. a
raster image cache.
  • Loading branch information
nyalldawson authored and nirvn committed Dec 5, 2018
1 parent d79cee1 commit 22496dc
Show file tree
Hide file tree
Showing 5 changed files with 747 additions and 0 deletions.
129 changes: 129 additions & 0 deletions python/core/auto_generated/qgsabstractcontentcache.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsabstractcontentcache.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAbstractContentCacheEntry
{
%Docstring
Base class for entries in a QgsAbstractContentCache.

Subclasses must take care to correctly implement the isEqual() method, applying their
own logic for testing extra cache properties (e.g. image size for an image-based cache).

.. versionadded:: 3.6
%End

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

QgsAbstractContentCacheEntry( const QString &path );
%Docstring
Constructor for QgsAbstractContentCacheEntry for an entry relating to the specified ``path``.
%End

virtual ~QgsAbstractContentCacheEntry();



QString path;

QDateTime fileModified;

QElapsedTimer fileModifiedLastCheckTimer;

int mFileModifiedCheckTimeout;

QgsAbstractContentCacheEntry *nextEntry;

QgsAbstractContentCacheEntry *previousEntry;

bool operator==( const QgsAbstractContentCacheEntry &other ) const;

virtual int dataSize() const = 0;
%Docstring
Returns the memory usage in bytes for the entry.
%End

virtual void dump() const = 0;
%Docstring
Dumps debugging strings containing the item's properties. For testing purposes only.
%End

protected:

virtual bool isEqual( const QgsAbstractContentCacheEntry *other ) const = 0;
%Docstring
Tests whether this entry matches another entry. Subclasses must take care to check
that the type of ``other`` is of a matching class, and then test extra cache-specific
properties, such as image size.
%End

private:
QgsAbstractContentCacheEntry( const QgsAbstractContentCacheEntry &rh );
};

class QgsAbstractContentCacheBase: QObject
{
%Docstring

A QObject derived base class for :py:class:`QgsAbstractContentCache`.

Required because template based class (such as :py:class:`QgsAbstractContentCache`) cannot use the Q_OBJECT macro.

.. versionadded:: 3.6
%End

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

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

signals:

void remoteContentFetched( const QString &url );
%Docstring
Emitted when the cache has finished retrieving content from a remote ``url``.
%End

protected:

virtual bool checkReply( QNetworkReply *reply, const QString &path ) const;
%Docstring
Runs additional checks on a network ``reply`` to ensure that the reply content is
consistent with that required by the cache.
%End

protected slots:

virtual void onRemoteContentFetched( const QString &url, bool success );
%Docstring
Triggered after remote content (i.e. HTTP linked content at the given ``url``) has been fetched.

The ``success`` argument will be true if the content was successfully fetched, or false if
it was not fetched successfully.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsabstractcontentcache.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
%Include auto_generated/geocms/geonode/qgsgeonodeconnection.sip
%Include auto_generated/gps/qgsqtlocationconnection.sip
%Include auto_generated/gps/qgsgpsconnectionregistry.sip
%Include auto_generated/qgsabstractcontentcache.sip
%Include auto_generated/qgsapplication.sip
%Include auto_generated/qgsactionscoperegistry.sip
%Include auto_generated/qgsanimatedicon.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ SET(QGIS_CORE_SRCS
scalebar/qgsticksscalebarrenderer.cpp

qgis.cpp
qgsabstractcontentcache.cpp
qgsapplication.cpp
qgsaction.cpp
qgsactionscope.cpp
Expand Down Expand Up @@ -586,6 +587,7 @@ ELSE(NOT MSVC)
ENDIF(NOT MSVC)

SET(QGIS_CORE_MOC_HDRS
qgsabstractcontentcache.h
qgsapplication.h
qgsactionmanager.h
qgsactionscoperegistry.h
Expand Down
48 changes: 48 additions & 0 deletions src/core/qgsabstractcontentcache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
QgsAbstractContentCache.cpp
-----------------
begin : December 2018
copyright : (C) 2018 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 "qgsabstractcontentcache.h"

//
// QgsAbstractContentCacheEntry
//

QgsAbstractContentCacheEntry::QgsAbstractContentCacheEntry( const QString &path )
: path( path )
, fileModified( QFileInfo( path ).lastModified() )
{
fileModifiedLastCheckTimer.start();
}

//
// QgsAbstractContentCacheBase
//

QgsAbstractContentCacheBase::QgsAbstractContentCacheBase( QObject *parent )
: QObject( parent )
{}


void QgsAbstractContentCacheBase::onRemoteContentFetched( const QString &, bool )
{

}





Loading

0 comments on commit 22496dc

Please sign in to comment.