|
40 | 40 | #include "qgsmessagelog.h"
|
41 | 41 | #include "qgsnetworkaccessmanager.h"
|
42 | 42 | #include "qgsnetworkreplyparser.h"
|
| 43 | +#include "qgstilecache.h" |
43 | 44 | #include "qgsgml.h"
|
44 | 45 | #include "qgsgmlschema.h"
|
45 | 46 | #include "qgswmscapabilities.h"
|
@@ -501,35 +502,6 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
|
501 | 502 | return draw( viewExtent, pixelWidth, pixelHeight, nullptr );
|
502 | 503 | }
|
503 | 504 |
|
504 |
| -#include <QCache> |
505 |
| -static QCache<QUrl, QImage> sTileCache( 256 ); |
506 |
| -static QMutex sTileCacheMutex; |
507 |
| - |
508 |
| -static bool _fetchCachedTileImage( const QUrl& url, QImage& localImage ) |
509 |
| -{ |
510 |
| - QMutexLocker locker( &sTileCacheMutex ); |
511 |
| - if ( QImage* i = sTileCache.object( url ) ) |
512 |
| - { |
513 |
| - localImage = *i; |
514 |
| - return true; |
515 |
| - } |
516 |
| - else if ( QgsNetworkAccessManager::instance()->cache()->metaData( url ).isValid() ) |
517 |
| - { |
518 |
| - if ( QIODevice* data = QgsNetworkAccessManager::instance()->cache()->data( url ) ) |
519 |
| - { |
520 |
| - QByteArray imageData = data->readAll(); |
521 |
| - delete data; |
522 |
| - |
523 |
| - localImage = QImage::fromData( imageData ); |
524 |
| - |
525 |
| - // cache it as well (mutex is already locked) |
526 |
| - sTileCache.insert( url, new QImage( localImage ) ); |
527 |
| - |
528 |
| - return true; |
529 |
| - } |
530 |
| - } |
531 |
| - return false; |
532 |
| -} |
533 | 505 |
|
534 | 506 | static bool _fuzzyContainsRect( const QRectF& r1, const QRectF& r2 )
|
535 | 507 | {
|
@@ -581,7 +553,7 @@ void QgsWmsProvider::fetchOtherResTiles( QgsTileMode tileMode, const QgsRectangl
|
581 | 553 | Q_FOREACH ( const TileRequest& r, requests )
|
582 | 554 | {
|
583 | 555 | QImage localImage;
|
584 |
| - if ( !_fetchCachedTileImage( r.url, localImage ) ) |
| 556 | + if ( ! QgsTileCache::tile( r.url, localImage ) ) |
585 | 557 | continue;
|
586 | 558 |
|
587 | 559 | double cr = viewExtent.width() / imageWidth;
|
@@ -785,7 +757,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
|
785 | 757 | Q_FOREACH ( const TileRequest& r, requests )
|
786 | 758 | {
|
787 | 759 | QImage localImage;
|
788 |
| - if ( _fetchCachedTileImage( r.url, localImage ) ) |
| 760 | + if ( QgsTileCache::tile( r.url, localImage ) ) |
789 | 761 | {
|
790 | 762 | double cr = viewExtent.width() / image->width();
|
791 | 763 |
|
@@ -880,7 +852,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
|
880 | 852 | handler.downloadBlocking();
|
881 | 853 | }
|
882 | 854 |
|
883 |
| - qDebug( "TILE CACHE total: %d / %d ", sTileCache.totalCost(), sTileCache.maxCost() ); |
| 855 | + qDebug( "TILE CACHE total: %d / %d ", QgsTileCache::totalCost(), QgsTileCache::maxCost() ); |
884 | 856 |
|
885 | 857 | #if 0
|
886 | 858 | const QgsWmsStatistics::Stat& stat = QgsWmsStatistics::statForUri( dataSourceUri() );
|
@@ -3909,9 +3881,7 @@ void QgsWmsTiledImageDownloadHandler::tileReplyFinished()
|
3909 | 3881 | .arg( r.width() ).arg( r.height() ) );
|
3910 | 3882 | #endif
|
3911 | 3883 |
|
3912 |
| - sTileCacheMutex.lock(); |
3913 |
| - sTileCache.insert( reply->url(), new QImage( myLocalImage ) ); |
3914 |
| - sTileCacheMutex.unlock(); |
| 3884 | + QgsTileCache::insertTile( reply->url(), myLocalImage ); |
3915 | 3885 |
|
3916 | 3886 | if ( mFeedback )
|
3917 | 3887 | mFeedback->onNewData();
|
|
0 commit comments