-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SvgSelectorWidget): Correctly use QPixmapCache
With previous code, pixmap was never taken from cache
- Loading branch information
Showing
4 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*************************************************************************** | ||
testqgssvgselectorwidget.cpp | ||
--------------------- | ||
begin : 2024/09/25 | ||
copyright : (C) 2024 by Julien Cabieces | ||
email : julien dot cabieces at oslandia 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 <QPixmapCache> | ||
#include <QTemporaryFile> | ||
|
||
#include "qgstest.h" | ||
#include "qgssvgselectorwidget.h" | ||
|
||
class TestQgsSvgSelectorWidget : public QgsTest | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
TestQgsSvgSelectorWidget() : QgsTest( QStringLiteral( "SVG Selector Widget Tests" ) ) {} | ||
|
||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase();// will be called after the last testfunction was executed. | ||
void init();// will be called before each testfunction is executed. | ||
void cleanup();// will be called after every testfunction. | ||
void testPixmapCache(); | ||
}; | ||
|
||
void TestQgsSvgSelectorWidget::initTestCase() | ||
{ | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
} | ||
|
||
void TestQgsSvgSelectorWidget::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsSvgSelectorWidget::init() | ||
{ | ||
} | ||
|
||
void TestQgsSvgSelectorWidget::cleanup() | ||
{ | ||
} | ||
|
||
void TestQgsSvgSelectorWidget::testPixmapCache() | ||
{ | ||
// We want to check that QPixmapCache is correctly used | ||
// So we force a cache image different from the one we set to the model to check that this is | ||
// the cache image returned, not the model svg one | ||
|
||
const QPixmap cachePixmap( QStringLiteral( "%1/rgb256x256.png" ).arg( TEST_DATA_DIR ) ); | ||
const QString sampleSvg = QStringLiteral( "%1/sample_svg.svg" ).arg( TEST_DATA_DIR ); | ||
QPixmapCache::insert( sampleSvg, cachePixmap ); | ||
|
||
QgsSvgSelectorListModel model( nullptr ); | ||
model.addSvgs( QStringList() << sampleSvg ); | ||
|
||
const QPixmap pixmap = model.data( model.index( 0, 0 ), Qt::DecorationRole ).value<QPixmap>(); | ||
QVERIFY( !pixmap.isNull() ); | ||
|
||
QCOMPARE( pixmap, cachePixmap ); | ||
} | ||
|
||
|
||
QGSTEST_MAIN( TestQgsSvgSelectorWidget ) | ||
#include "testqgssvgselectorwidget.moc" |