File indexing completed on 2024-05-12 15:53:53
0001 /** 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include <QtTest/QtTest> 0021 0022 #include <KChartBarDiagram> 0023 #include <KChartLineDiagram> 0024 #include <KChartPieDiagram> 0025 #include <KChartPieAttributes> 0026 #include <KChartThreeDPieAttributes> 0027 #include <KChartThreeDBarAttributes> 0028 #include <KChartPolarDiagram> 0029 #include <KChartRingDiagram> 0030 #include <KChartHeaderFooter> 0031 #include <KChartLegend> 0032 0033 using namespace KChart; 0034 0035 class TestCloning: public QObject { 0036 Q_OBJECT 0037 private Q_SLOTS: 0038 0039 void initTestCase() 0040 { 0041 } 0042 0043 void testCloningBarDiagram() 0044 { 0045 BarDiagram* diagram = new BarDiagram(); 0046 diagram->setType( BarDiagram::Stacked ); 0047 CartesianAxis *axis = new CartesianAxis; 0048 diagram->addAxis( axis ); 0049 QCOMPARE( diagram->axes().count(), 1 ); 0050 BarAttributes attrs; 0051 attrs.setFixedDataValueGap( 3.0 ); 0052 attrs.setFixedBarWidth( 30.0 ); 0053 attrs.setDrawSolidExcessArrows( false ); 0054 diagram->setBarAttributes( attrs ); 0055 attrs.setDrawSolidExcessArrows( true ); 0056 diagram->setBarAttributes( 0, attrs ); 0057 attrs.setDrawSolidExcessArrows( false ); 0058 ThreeDBarAttributes threeDAttrs; 0059 threeDAttrs.setUseShadowColors( false ); 0060 diagram->setThreeDBarAttributes( threeDAttrs ); 0061 BarDiagram* clone = diagram->clone(); 0062 QCOMPARE( diagram->type(), clone->type() ); 0063 // We do not clone the axes. 0064 QCOMPARE( clone->axes().count(), 0 ); 0065 // And neither the reference diagram. 0066 QCOMPARE( clone->referenceDiagram(), (AbstractCartesianDiagram*)nullptr ); 0067 QCOMPARE( clone->referenceDiagramOffset(), QPointF() ); 0068 // And neither the plane. 0069 QCOMPARE( clone->coordinatePlane(), (AbstractCoordinatePlane*)nullptr ); 0070 QCOMPARE( diagram->allowOverlappingDataValueTexts(), clone->allowOverlappingDataValueTexts() ); 0071 QCOMPARE( diagram->antiAliasing(), clone->antiAliasing() ); 0072 QCOMPARE( diagram->percentMode(), clone->percentMode() ); 0073 QCOMPARE( diagram->datasetDimension(), clone->datasetDimension() ); 0074 QCOMPARE( diagram->barAttributes(), clone->barAttributes() ); 0075 QCOMPARE( diagram->threeDBarAttributes(), clone->threeDBarAttributes() ); 0076 0077 QVERIFY( diagram->attributesModel() != clone->attributesModel() ); 0078 } 0079 0080 void testCloningLineDiagram() 0081 { 0082 LineDiagram* diagram = new LineDiagram(); 0083 diagram->setType( LineDiagram::Percent ); 0084 LineAttributes attrs; 0085 attrs.setMissingValuesPolicy( LineAttributes::MissingValuesShownAsZero ); 0086 diagram->setLineAttributes( attrs ); 0087 LineDiagram* clone = diagram->clone(); 0088 QCOMPARE( diagram->type(), clone->type() ); 0089 QCOMPARE( diagram->lineAttributes(), clone->lineAttributes() ); 0090 0091 // the rest is already tested in testCloningBarDiagram() 0092 } 0093 0094 void testCloningPieDiagram() 0095 { 0096 // commenting those tests - Deprecated method 0097 // will make new test for that in PolarCoordinatePlane 0098 // do we want the warning ? 0099 // if yes - we just need to un-comment 0100 PieDiagram* diagram = new PieDiagram(); 0101 //diagram->coordinatePlane()->setStartPosition( 15.0 ); 0102 diagram->setGranularity( 1.5 ); 0103 PieAttributes attrs; 0104 attrs.setExplode( true ); 0105 attrs.setExplodeFactor( 1.5 ); 0106 ThreeDPieAttributes threeDAttrs; 0107 threeDAttrs.setUseShadowColors( false ); 0108 PieDiagram* clone = diagram->clone(); 0109 //QCOMPARE( diagram->startPosition(), clone->startPosition() ); 0110 QCOMPARE( diagram->granularity(), clone->granularity() ); 0111 QCOMPARE( diagram->pieAttributes(), clone->pieAttributes() ); 0112 QCOMPARE( diagram->threeDPieAttributes(), clone->threeDPieAttributes() ); 0113 0114 // the rest is already tested in testCloningBarDiagram() 0115 } 0116 0117 void testCloningPolarDiagram() 0118 { 0119 // commenting those tests - Deprecated method 0120 // will make new test for that in PolarCoordinatePlane 0121 // do we want the warning ? 0122 // if yes - we just need to un-comment 0123 PolarDiagram* diagram = new PolarDiagram(); 0124 //diagram->setZeroDegreePosition( 5 ); 0125 diagram->setRotateCircularLabels( true ); 0126 diagram->setShowDelimitersAtPosition( Position::North, false ); 0127 diagram->setShowDelimitersAtPosition( Position::South, true ); 0128 diagram->setShowLabelsAtPosition( Position::North, true ); 0129 diagram->setShowLabelsAtPosition( Position::South, false ); 0130 PolarDiagram* clone = diagram->clone(); 0131 //QCOMPARE( diagram->zeroDegreePosition(), clone->zeroDegreePosition() ); 0132 QCOMPARE( diagram->rotateCircularLabels(), clone->rotateCircularLabels() ); 0133 QCOMPARE( diagram->showDelimitersAtPosition( Position::North ), 0134 clone->showDelimitersAtPosition( Position::North ) ); 0135 QCOMPARE( diagram->showDelimitersAtPosition( Position::South ), clone->showDelimitersAtPosition( Position::South ) ); 0136 QCOMPARE( diagram->showLabelsAtPosition( Position::North ), clone->showLabelsAtPosition( Position::North ) ); 0137 QCOMPARE( diagram->showLabelsAtPosition( Position::South ), clone->showLabelsAtPosition( Position::South ) ); 0138 0139 // the rest is already tested in testCloningBarDiagram() 0140 } 0141 void testCloningRingDiagram() 0142 { 0143 RingDiagram* diagram = new RingDiagram(); 0144 diagram->setRelativeThickness( true ); 0145 RingDiagram* clone = diagram->clone(); 0146 QCOMPARE( diagram->relativeThickness(), clone->relativeThickness() ); 0147 // the rest is already tested in testCloningBarDiagram() 0148 // and testCloningPieDiagram() 0149 } 0150 0151 void testCloningHeaderFooter() 0152 { 0153 HeaderFooter* headerFooter = new HeaderFooter(); 0154 headerFooter->setType( HeaderFooter::Footer ); 0155 TextAttributes attrs; 0156 attrs.setPen( QPen(Qt::red) ); 0157 headerFooter->setTextAttributes( attrs ); 0158 HeaderFooter* clone = headerFooter->clone(); 0159 QCOMPARE( headerFooter->type(), clone->type() ); 0160 QCOMPARE( headerFooter->textAttributes(), clone->textAttributes() ); 0161 } 0162 0163 void testCloningLegends() 0164 { 0165 Legend* legend = new Legend(); 0166 TextAttributes attrs; 0167 attrs.setPen( QPen(Qt::red) ); 0168 legend->setTextAttributes( attrs ); 0169 legend->setShowLines( true ); 0170 legend->setPosition( Position::North ); 0171 Legend* clone = legend->clone(); 0172 QCOMPARE( legend->textAttributes(), clone->textAttributes() ); 0173 QCOMPARE( legend->showLines(), clone->showLines() ); 0174 QCOMPARE( legend->position(), clone->position() ); 0175 } 0176 0177 void cleanupTestCase() 0178 { 0179 } 0180 0181 0182 private: 0183 }; 0184 0185 QTEST_MAIN(TestCloning) 0186 0187 #include "main.moc"