1 /** 2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 3 * 4 * This file is part of the KD Chart library. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #include <QtTest/QtTest> 21 #include <QStandardItemModel> 22 23 #include <KChartChart> 24 #include <KChartGlobal> 25 #include <KChartPieDiagram> 26 #include <KChartPolarDiagram> 27 #include <KChartPolarCoordinatePlane> 28 #include <KChartAbstractCoordinatePlane> 29 #include <KChartLegend> 30 #include <KChartGridAttributes> 31 32 #include <TableModel.h> 33 34 using namespace KChart; 35 36 class TestPolarPlanes: public QObject { 37 Q_OBJECT 38 private Q_SLOTS: 39 initTestCase()40 void initTestCase() 41 { 42 m_chart = new Chart(nullptr); 43 m_tableModel = new TableModel( this ); 44 m_tableModel->loadFromCSV( ":/data" ); 45 m_pie = new PieDiagram(); 46 m_pie->setModel( m_tableModel ); 47 m_polar = new PolarDiagram(); 48 m_polar->setModel( m_tableModel ); 49 m_plane = new PolarCoordinatePlane(); 50 m_chart->addCoordinatePlane( m_plane ); 51 m_plane->setReferenceCoordinatePlane( m_chart->coordinatePlane() ); 52 } 53 testIntialOwnership()54 void testIntialOwnership() 55 { 56 AbstractCoordinatePlane *plane = m_chart->coordinatePlane(); 57 QCOMPARE( m_plane->referenceCoordinatePlane(), m_chart->coordinatePlane() ); 58 m_chart->takeCoordinatePlane( nullptr ); 59 delete plane; 60 QCOMPARE( m_plane->referenceCoordinatePlane(), (AbstractCoordinatePlane*)nullptr ); 61 } 62 testStartPositionSettings()63 void testStartPositionSettings() 64 { 65 m_plane->addDiagram( m_pie ); 66 QVERIFY( m_plane->startPosition() == 0.0 ); 67 qreal pos = 45; 68 m_plane->addDiagram( m_pie ); 69 m_plane->setStartPosition( pos ); 70 QVERIFY( m_plane->startPosition() == pos ); 71 m_plane->takeDiagram( m_pie ); 72 } 73 testZoomFactorsSettings()74 void testZoomFactorsSettings() 75 { 76 m_plane->addDiagram( m_pie ); 77 QCOMPARE( m_plane->zoomFactorX(), 1.0 ); 78 QCOMPARE( m_plane->zoomFactorY(), 1.0 ); 79 QCOMPARE( m_plane->zoomCenter(), QPointF( 0.5, 0.5 ) ); 80 m_plane->setZoomFactorX( 1.5 ); 81 m_plane->setZoomFactorY( 1.5 ); 82 m_plane->setZoomCenter( QPointF ( 1.0, 1.0 ) ); 83 QCOMPARE( m_plane->zoomFactorX(), 1.5 ); 84 QCOMPARE( m_plane->zoomFactorY(), 1.5 ); 85 QCOMPARE( m_plane->zoomCenter(), QPointF( 1.0, 1.0 ) ); 86 m_plane->takeDiagram( m_pie ); 87 } 88 testDiagramOwnership()89 void testDiagramOwnership() 90 { 91 92 QCOMPARE( m_plane->diagrams().size(), 1 ); 93 m_plane->addDiagram( m_polar ); 94 QCOMPARE( m_plane->diagrams().size(), 2 ); 95 QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()), m_pie ); 96 m_plane->takeDiagram( m_pie ); 97 QCOMPARE( m_plane->diagrams().size(), 1 ); 98 QCOMPARE( dynamic_cast< PolarDiagram * >(m_plane->diagram()), m_polar ); 99 m_plane->replaceDiagram( m_pie, m_polar ); 100 QCOMPARE( m_plane->diagrams().size(), 1 ); 101 QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()), m_pie ); 102 m_plane->takeDiagram( m_pie ); 103 QCOMPARE( m_plane->diagrams().size(), 0 ); 104 delete m_pie; 105 } 106 testGlobalGridAttributesSettings()107 void testGlobalGridAttributesSettings() 108 { 109 GridAttributes ga = m_plane->globalGridAttributes(); 110 QVERIFY( ga.isGridVisible() == true ); 111 ga.setGridVisible( false ); 112 m_plane->setGlobalGridAttributes( ga ); 113 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false ); 114 //reset to normal 115 ga.setGridVisible( true ); 116 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false ); 117 m_plane->setGlobalGridAttributes( ga ); 118 QVERIFY( m_plane->globalGridAttributes().isGridVisible() == true ); 119 } 120 testGridAttributesSettings()121 void testGridAttributesSettings() 122 { 123 GridAttributes gcircular = m_plane->gridAttributes( true ); 124 GridAttributes gsagittal = m_plane->gridAttributes( false ); 125 QVERIFY( gcircular.isGridVisible() == true ); 126 gcircular.setGridVisible( false ); 127 m_plane->setGridAttributes( true, gcircular ); 128 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 129 QVERIFY( m_plane->hasOwnGridAttributes( false ) == false ); 130 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false ); 131 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true ); 132 gsagittal.setGridVisible( false ); 133 m_plane->setGridAttributes( false, gsagittal ); 134 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 135 QVERIFY( m_plane->hasOwnGridAttributes( true ) == true ); 136 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false ); 137 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == false ); 138 m_plane->resetGridAttributes( true ); 139 m_plane->resetGridAttributes( false ); 140 QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == true ); 141 QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true ); 142 QVERIFY( m_plane->hasOwnGridAttributes( true ) == false ); 143 QVERIFY( m_plane->hasOwnGridAttributes( false ) == false ); 144 } 145 cleanupTestCase()146 void cleanupTestCase() 147 { 148 } 149 150 private: 151 Chart *m_chart; 152 PieDiagram *m_pie; 153 PolarDiagram *m_polar; 154 PolarCoordinatePlane *m_plane; 155 TableModel *m_tableModel; 156 157 }; 158 159 QTEST_MAIN(TestPolarPlanes) 160 161 #include "main.moc" 162