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 <KChartChart> 0011 #include <KChartGlobal> 0012 #include <KChartPieDiagram> 0013 #include <KChartPieAttributes> 0014 #include <KChartThreeDPieAttributes> 0015 #include <KChartPolarCoordinatePlane> 0016 0017 #include <TableModel.h> 0018 0019 using namespace KChart; 0020 0021 class TestPieDiagrams: public QObject { 0022 Q_OBJECT 0023 private Q_SLOTS: 0024 0025 void initTestCase() 0026 { 0027 m_chart = new Chart(nullptr); 0028 PolarCoordinatePlane* polarPlane = new PolarCoordinatePlane( m_chart ); 0029 m_chart->replaceCoordinatePlane( polarPlane ); 0030 m_model = new TableModel( this ); 0031 m_model->loadFromCSV( ":/data" ); 0032 m_pie = new PieDiagram(); 0033 m_pie->setModel( m_model ); 0034 m_chart->coordinatePlane()->replaceDiagram( m_pie ); 0035 } 0036 0037 void testPieDiagramsSettings() 0038 { 0039 QVERIFY( m_pie->granularity() == 1 ); 0040 m_pie->setGranularity( 2 ); 0041 QVERIFY( m_pie->granularity() == 2 ); 0042 } 0043 0044 0045 void testPieAttributesLevelSettings() 0046 { 0047 //check segments 0048 const int cols = m_pie->model()->columnCount(); 0049 QCOMPARE( m_pie->columnCount(), cols ); 0050 // create attribute 0051 PieAttributes pa( m_pie->pieAttributes() ); 0052 PieAttributes paCol( m_pie->pieAttributes() ); 0053 0054 // modify at different level and compare 0055 paCol.setExplode ( true ); 0056 m_pie->setPieAttributes( pa ); 0057 m_pie->setPieAttributes( cols-2, paCol ); 0058 0059 QVERIFY( m_pie->pieAttributes() != m_pie->pieAttributes(cols-2) ); 0060 0061 QCOMPARE( m_pie->pieAttributes(), pa ); 0062 QCOMPARE( m_pie->pieAttributes( cols - 2 ), paCol ); 0063 0064 // try and override the cols and index level - should not work 0065 m_pie->setPieAttributes( pa ); 0066 QVERIFY( m_pie->pieAttributes().explode() == false ); 0067 QVERIFY( m_pie->pieAttributes( cols-2 ).explode() == true ); 0068 0069 } 0070 0071 void testPieAttributesValueSettings() 0072 { 0073 PieAttributes pa( m_pie->pieAttributes() ); 0074 0075 // check default values 0076 QVERIFY( pa.explode() == false ); 0077 QVERIFY( pa.explodeFactor() == 0.0 ); 0078 //change settings 0079 pa.setExplode ( true ); 0080 pa.setExplodeFactor( 0.2 ); 0081 m_pie->setPieAttributes( pa ); 0082 // get new values 0083 QVERIFY( m_pie->pieAttributes().explode() == true ); 0084 QVERIFY( m_pie->pieAttributes().explodeFactor() == 0.2 ); 0085 } 0086 0087 void testThreeDPieAttributesLevelSettings() 0088 { 0089 //check segments 0090 const int cols = m_pie->model()->columnCount(); 0091 QCOMPARE( m_pie->columnCount(), cols ); 0092 0093 // create attribute 0094 ThreeDPieAttributes td( m_pie->threeDPieAttributes() ); 0095 ThreeDPieAttributes tdCol( m_pie->threeDPieAttributes() ); 0096 // modify at different level and compare 0097 tdCol.setDepth(25 ); 0098 m_pie->setThreeDPieAttributes( td ); 0099 m_pie->setThreeDPieAttributes( cols-2, tdCol ); 0100 QVERIFY( m_pie->threeDPieAttributes() != 0101 m_pie->threeDPieAttributes(cols-2) ); 0102 QCOMPARE( m_pie->threeDPieAttributes(), td ); 0103 QCOMPARE( m_pie->threeDPieAttributes( cols - 2 ), tdCol ); 0104 // try and override the cols and index level - should not work 0105 m_pie->setThreeDPieAttributes( td ); 0106 QVERIFY( m_pie->threeDPieAttributes().depth() == -10 ); 0107 QVERIFY( m_pie->threeDPieAttributes( cols-2 ).depth() == 25 ); 0108 } 0109 0110 0111 void testThreeDPieAttributesValueSettings() 0112 { 0113 ThreeDPieAttributes td( m_pie->threeDPieAttributes() ); 0114 //check default values 0115 QVERIFY( td.isEnabled() == false ); 0116 QVERIFY( td.depth() == -10 ); 0117 QVERIFY( td.validDepth() == 0.0 ); 0118 //pie specifics 0119 QVERIFY( td.useShadowColors() == true ); 0120 0121 //set new values 0122 td.setEnabled( true ); 0123 td.setDepth( 40 ); 0124 td.setUseShadowColors( false ); // not implemented yet 0125 m_pie->setThreeDPieAttributes( td ); 0126 0127 //get new values 0128 QVERIFY( m_pie->threeDPieAttributes().isEnabled() == true ); 0129 QVERIFY( m_pie->threeDPieAttributes().depth() == 40 ); 0130 QVERIFY( m_pie->threeDPieAttributes().validDepth() == 40 ); 0131 QVERIFY( m_pie->threeDPieAttributes().useShadowColors() == false ); 0132 } 0133 0134 void cleanupTestCase() 0135 { 0136 } 0137 0138 private: 0139 Chart *m_chart; 0140 PieDiagram *m_pie; 0141 TableModel *m_model; 0142 0143 }; 0144 0145 QTEST_MAIN(TestPieDiagrams) 0146 0147 #include "main.moc"