File indexing completed on 2022-10-04 14:00:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0004 //
0005 
0006 
0007 #include "BillboardGraphicsItem.h"
0008 
0009 #include "FrameGraphicsItem.h"
0010 #include "MarbleGraphicsGridLayout.h"
0011 #include "ViewportParams.h"
0012 
0013 #include <QImage>
0014 #include <QPainter>
0015 #include <QTest>
0016 
0017 namespace Marble
0018 {
0019 
0020 class BillboardGraphicsItemTest : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 private Q_SLOTS:
0025     void defaultConstructorValues();
0026 
0027     void paintEvent();
0028 };
0029 
0030 void BillboardGraphicsItemTest::defaultConstructorValues()
0031 {
0032     const BillboardGraphicsItem item;
0033 
0034     // MarbleGraphicsItem
0035     QCOMPARE( item.layout(), static_cast<AbstractMarbleGraphicsLayout *>( nullptr ) );
0036     QCOMPARE( item.cacheMode(), BillboardGraphicsItem::NoCache );
0037     QCOMPARE( item.visible(), true );
0038     QCOMPARE( item.size(), QSizeF() );
0039     QCOMPARE( item.contentSize(), QSizeF() );
0040 
0041     // BillboardGraphicsItem
0042     QCOMPARE( item.coordinate(), GeoDataCoordinates() );
0043     QCOMPARE( item.alignment(), Qt::AlignHCenter | Qt::AlignVCenter );
0044     QCOMPARE( item.positions(), QVector<QPointF>() );
0045     QCOMPARE( item.boundingRects(), QVector<QRectF>() );
0046 }
0047 
0048 void BillboardGraphicsItemTest::paintEvent()
0049 {
0050     BillboardGraphicsItem item;
0051     item.setCoordinate( GeoDataCoordinates( 0, 0 ) );
0052 
0053     MarbleGraphicsGridLayout *topLayout = new MarbleGraphicsGridLayout( 1, 1 );
0054     item.setLayout( topLayout );
0055 
0056     FrameGraphicsItem frameItem( &item );
0057     frameItem.setSize( QSizeF( 11.2, 11.3 ) );
0058     topLayout->addItem( &frameItem, 0, 0 );
0059 
0060     QCOMPARE( item.positions(), QVector<QPointF>() );
0061     QCOMPARE( item.size(), QSizeF() );
0062 
0063     QImage paintDevice( 100, 100, QImage::Format_ARGB32_Premultiplied );
0064     QPainter painter( &paintDevice );
0065 
0066     const ViewportParams viewport( Mercator, 0, 0, 20, paintDevice.size() );
0067 
0068     item.paintEvent( &painter, &viewport );
0069 
0070     QCOMPARE( item.size(), frameItem.size() );
0071     QCOMPARE( item.positions().size(), 1 );
0072     QCOMPARE( item.positions()[0], QPointF( 44, 44 ) );
0073 }
0074 
0075 }
0076 
0077 QTEST_MAIN( Marble::BillboardGraphicsItemTest )
0078 
0079 #include "BillboardGraphicsItemTest.moc"