File indexing completed on 2024-05-12 04:20:16
0001 /** 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include <QtTest/QtTest> 0010 #include <QStandardItemModel> 0011 0012 #include <KChartChart> 0013 #include <KChartGlobal> 0014 #include <KChartPieDiagram> 0015 #include <KChartPolarDiagram> 0016 #include <KChartPolarCoordinatePlane> 0017 #include <KChartAbstractCoordinatePlane> 0018 #include <KChartLegend> 0019 #include <KChartGridAttributes> 0020 0021 #include <TableModel.h> 0022 0023 using namespace KChart; 0024 0025 class TestPolarPlanes: public QObject { 0026 Q_OBJECT 0027 private Q_SLOTS: 0028 0029 void initTestCase() 0030 { 0031 m_chart = new Chart(nullptr); 0032 m_tableModel = new TableModel( this ); 0033 m_tableModel->loadFromCSV( ":/data" ); 0034 m_pie = new PieDiagram(); 0035 m_pie->setModel( m_tableModel ); 0036 m_polar = new PolarDiagram(); 0037 m_polar->setModel( m_tableModel ); 0038 m_plane = new PolarCoordinatePlane(); 0039 m_chart->addCoordinatePlane( m_plane ); 0040 m_plane->setReferenceCoordinatePlane( m_chart->coordinatePlane() ); 0041 } 0042 0043 void testIntialOwnership() 0044 { 0045 AbstractCoordinatePlane *plane = m_chart->coordinatePlane(); 0046 QCOMPARE( m_plane->referenceCoordinatePlane(), m_chart->coordinatePlane() ); 0047 m_chart->takeCoordinatePlane( nullptr ); 0048 delete plane; 0049 QCOMPARE( m_plane->referenceCoordinatePlane(), (AbstractCoordinatePlane*)nullptr ); 0050 } 0051 0052 void testStartPositionSettings() 0053 { 0054 m_plane->addDiagram( m_pie ); 0055 QVERIFY( m_plane->startPosition() == 0.0 ); 0056 qreal pos = 45; 0057 m_plane->addDiagram( m_pie ); 0058 m_plane->setStartPosition( pos ); 0059 QVERIFY( m_plane->startPosition() == pos ); 0060 m_plane->takeDiagram( m_pie ); 0061 } 0062 0063 void testZoomFactorsSettings() 0064 { 0065 m_plane->addDiagram( m_pie ); 0066 QCOMPARE( m_plane->zoomFactorX(), 1.0 ); 0067 QCOMPARE( m_plane->zoomFactorY(), 1.0 ); 0068 QCOMPARE( m_plane->zoomCenter(), QPointF( 0.5, 0.5 ) ); 0069 m_plane->setZoomFactorX( 1.5 ); 0070 m_plane->setZoomFactorY( 1.5 ); 0071 m_plane->setZoomCenter( QPointF ( 1.0, 1.0 ) ); 0072 QCOMPARE( m_plane->zoomFactorX(), 1.5 ); 0073 QCOMPARE( m_plane->zoomFactorY(), 1.5 ); 0074 QCOMPARE( m_plane->zoomCenter(), QPointF( 1.0, 1.0 ) ); 0075 m_plane->takeDiagram( m_pie ); 0076 } 0077 0078 void testDiagramOwnership() 0079 { 0080 0081 QCOMPARE( m_plane->diagrams().size(), 1 ); 0082 m_plane->addDiagram( m_polar ); 0083 QCOMPARE( m_plane->diagrams().size(), 2 ); 0084 QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()), m_pie ); 0085 m_plane->takeDiagram( m_pie ); 0086 QCOMPARE( m_plane->diagrams().size(), 1 ); 0087 QCOMPARE( dynamic_cast< PolarDiagram * >(m_plane->diagram()), m_polar ); 0088 m_plane->replaceDiagram( m_pie, m_polar ); 0089 QCOMPARE( m_plane->diagrams().size(), 1 ); 0090 QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()), m_pie ); 0091 m_plane->takeDiagram( m_pie ); 0092 QCOMPARE( m_plane->diagrams().size(), 0 ); 0093 delete m_pie; 0094 } 0095 0096 void testGlobalGridAttributesSettings() 0097 { 0098 GridAttributes ga = m_plane->globalGridAttributes(); 0099 QVERIFY( ga.isGridVisible() == true ); 0100 ga.setGridVisible( false ); 0101 m_plane->setGlobalGridAttributes( ga ); 0102 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false ); 0103 //reset to normal 0104 ga.setGridVisible( true ); 0105 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false ); 0106 m_plane->setGlobalGridAttributes( ga ); 0107 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == true ); 0108 } 0109 0110 void testGridAttributesSettings() 0111 { 0112 GridAttributes gcircular = m_plane->gridAttributes( true ); 0113 GridAttributes gsagittal = m_plane->gridAttributes( false ); 0114 QVERIFY( gcircular.isGridVisible() == true ); 0115 gcircular.setGridVisible( false ); 0116 m_plane->setGridAttributes( true, gcircular ); 0117 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 0118 QVERIFY( m_plane->hasOwnGridAttributes( false ) == false ); 0119 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false ); 0120 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true ); 0121 gsagittal.setGridVisible( false ); 0122 m_plane->setGridAttributes( false, gsagittal ); 0123 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 0124 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 0125 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false ); 0126 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == false ); 0127 m_plane->resetGridAttributes( true ); 0128 m_plane->resetGridAttributes( false ); 0129 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == true ); 0130 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true ); 0131 QVERIFY( m_plane->hasOwnGridAttributes( true ) == false ); 0132 QVERIFY( m_plane->hasOwnGridAttributes( false ) == false ); 0133 } 0134 0135 void cleanupTestCase() 0136 { 0137 } 0138 0139 private: 0140 Chart *m_chart; 0141 PieDiagram *m_pie; 0142 PolarDiagram *m_polar; 0143 PolarCoordinatePlane *m_plane; 0144 TableModel *m_tableModel; 0145 0146 }; 0147 0148 QTEST_MAIN(TestPolarPlanes) 0149 0150 #include "main.moc"