Warning, file /graphics/kdiagram/qtests/Cloning/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 0011 #include <KChartBarDiagram> 0012 #include <KChartLineDiagram> 0013 #include <KChartPieDiagram> 0014 #include <KChartPieAttributes> 0015 #include <KChartThreeDPieAttributes> 0016 #include <KChartThreeDBarAttributes> 0017 #include <KChartPolarDiagram> 0018 #include <KChartRingDiagram> 0019 #include <KChartHeaderFooter> 0020 #include <KChartLegend> 0021 0022 using namespace KChart; 0023 0024 class TestCloning: public QObject { 0025 Q_OBJECT 0026 private Q_SLOTS: 0027 0028 void initTestCase() 0029 { 0030 } 0031 0032 void testCloningBarDiagram() 0033 { 0034 BarDiagram* diagram = new BarDiagram(); 0035 diagram->setType( BarDiagram::Stacked ); 0036 CartesianAxis *axis = new CartesianAxis; 0037 diagram->addAxis( axis ); 0038 QCOMPARE( diagram->axes().count(), 1 ); 0039 BarAttributes attrs; 0040 attrs.setFixedDataValueGap( 3.0 ); 0041 attrs.setFixedBarWidth( 30.0 ); 0042 attrs.setDrawSolidExcessArrows( false ); 0043 diagram->setBarAttributes( attrs ); 0044 attrs.setDrawSolidExcessArrows( true ); 0045 diagram->setBarAttributes( 0, attrs ); 0046 attrs.setDrawSolidExcessArrows( false ); 0047 ThreeDBarAttributes threeDAttrs; 0048 threeDAttrs.setUseShadowColors( false ); 0049 diagram->setThreeDBarAttributes( threeDAttrs ); 0050 BarDiagram* clone = diagram->clone(); 0051 QCOMPARE( diagram->type(), clone->type() ); 0052 // We do not clone the axes. 0053 QCOMPARE( clone->axes().count(), 0 ); 0054 // And neither the reference diagram. 0055 QCOMPARE( clone->referenceDiagram(), (AbstractCartesianDiagram*)nullptr ); 0056 QCOMPARE( clone->referenceDiagramOffset(), QPointF() ); 0057 // And neither the plane. 0058 QCOMPARE( clone->coordinatePlane(), (AbstractCoordinatePlane*)nullptr ); 0059 QCOMPARE( diagram->allowOverlappingDataValueTexts(), clone->allowOverlappingDataValueTexts() ); 0060 QCOMPARE( diagram->antiAliasing(), clone->antiAliasing() ); 0061 QCOMPARE( diagram->percentMode(), clone->percentMode() ); 0062 QCOMPARE( diagram->datasetDimension(), clone->datasetDimension() ); 0063 QCOMPARE( diagram->barAttributes(), clone->barAttributes() ); 0064 QCOMPARE( diagram->threeDBarAttributes(), clone->threeDBarAttributes() ); 0065 0066 QVERIFY( diagram->attributesModel() != clone->attributesModel() ); 0067 } 0068 0069 void testCloningLineDiagram() 0070 { 0071 LineDiagram* diagram = new LineDiagram(); 0072 diagram->setType( LineDiagram::Percent ); 0073 LineAttributes attrs; 0074 attrs.setMissingValuesPolicy( LineAttributes::MissingValuesShownAsZero ); 0075 diagram->setLineAttributes( attrs ); 0076 LineDiagram* clone = diagram->clone(); 0077 QCOMPARE( diagram->type(), clone->type() ); 0078 QCOMPARE( diagram->lineAttributes(), clone->lineAttributes() ); 0079 0080 // the rest is already tested in testCloningBarDiagram() 0081 } 0082 0083 void testCloningPieDiagram() 0084 { 0085 // commenting those tests - Deprecated method 0086 // will make new test for that in PolarCoordinatePlane 0087 // do we want the warning ? 0088 // if yes - we just need to un-comment 0089 PieDiagram* diagram = new PieDiagram(); 0090 //diagram->coordinatePlane()->setStartPosition( 15.0 ); 0091 diagram->setGranularity( 1.5 ); 0092 PieAttributes attrs; 0093 attrs.setExplode( true ); 0094 attrs.setExplodeFactor( 1.5 ); 0095 ThreeDPieAttributes threeDAttrs; 0096 threeDAttrs.setUseShadowColors( false ); 0097 PieDiagram* clone = diagram->clone(); 0098 //QCOMPARE( diagram->startPosition(), clone->startPosition() ); 0099 QCOMPARE( diagram->granularity(), clone->granularity() ); 0100 QCOMPARE( diagram->pieAttributes(), clone->pieAttributes() ); 0101 QCOMPARE( diagram->threeDPieAttributes(), clone->threeDPieAttributes() ); 0102 0103 // the rest is already tested in testCloningBarDiagram() 0104 } 0105 0106 void testCloningPolarDiagram() 0107 { 0108 // commenting those tests - Deprecated method 0109 // will make new test for that in PolarCoordinatePlane 0110 // do we want the warning ? 0111 // if yes - we just need to un-comment 0112 PolarDiagram* diagram = new PolarDiagram(); 0113 //diagram->setZeroDegreePosition( 5 ); 0114 diagram->setRotateCircularLabels( true ); 0115 diagram->setShowDelimitersAtPosition( Position::North, false ); 0116 diagram->setShowDelimitersAtPosition( Position::South, true ); 0117 diagram->setShowLabelsAtPosition( Position::North, true ); 0118 diagram->setShowLabelsAtPosition( Position::South, false ); 0119 PolarDiagram* clone = diagram->clone(); 0120 //QCOMPARE( diagram->zeroDegreePosition(), clone->zeroDegreePosition() ); 0121 QCOMPARE( diagram->rotateCircularLabels(), clone->rotateCircularLabels() ); 0122 QCOMPARE( diagram->showDelimitersAtPosition( Position::North ), 0123 clone->showDelimitersAtPosition( Position::North ) ); 0124 QCOMPARE( diagram->showDelimitersAtPosition( Position::South ), clone->showDelimitersAtPosition( Position::South ) ); 0125 QCOMPARE( diagram->showLabelsAtPosition( Position::North ), clone->showLabelsAtPosition( Position::North ) ); 0126 QCOMPARE( diagram->showLabelsAtPosition( Position::South ), clone->showLabelsAtPosition( Position::South ) ); 0127 0128 // the rest is already tested in testCloningBarDiagram() 0129 } 0130 void testCloningRingDiagram() 0131 { 0132 RingDiagram* diagram = new RingDiagram(); 0133 diagram->setRelativeThickness( true ); 0134 RingDiagram* clone = diagram->clone(); 0135 QCOMPARE( diagram->relativeThickness(), clone->relativeThickness() ); 0136 // the rest is already tested in testCloningBarDiagram() 0137 // and testCloningPieDiagram() 0138 } 0139 0140 void testCloningHeaderFooter() 0141 { 0142 HeaderFooter* headerFooter = new HeaderFooter(); 0143 headerFooter->setType( HeaderFooter::Footer ); 0144 TextAttributes attrs; 0145 attrs.setPen( QPen(Qt::red) ); 0146 headerFooter->setTextAttributes( attrs ); 0147 HeaderFooter* clone = headerFooter->clone(); 0148 QCOMPARE( headerFooter->type(), clone->type() ); 0149 QCOMPARE( headerFooter->textAttributes(), clone->textAttributes() ); 0150 } 0151 0152 void testCloningLegends() 0153 { 0154 Legend* legend = new Legend(); 0155 TextAttributes attrs; 0156 attrs.setPen( QPen(Qt::red) ); 0157 legend->setTextAttributes( attrs ); 0158 legend->setShowLines( true ); 0159 legend->setPosition( Position::North ); 0160 Legend* clone = legend->clone(); 0161 QCOMPARE( legend->textAttributes(), clone->textAttributes() ); 0162 QCOMPARE( legend->showLines(), clone->showLines() ); 0163 QCOMPARE( legend->position(), clone->position() ); 0164 } 0165 0166 void cleanupTestCase() 0167 { 0168 } 0169 0170 0171 private: 0172 }; 0173 0174 QTEST_MAIN(TestCloning) 0175 0176 #include "main.moc"