File indexing completed on 2024-05-12 15:53:55

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 #include <QStandardItemModel>
0022 
0023 #include <KChartChart>
0024 #include <KChartGlobal>
0025 #include <KChartPieDiagram>
0026 #include <KChartPolarDiagram>
0027 #include <KChartPolarCoordinatePlane>
0028 #include <KChartAbstractCoordinatePlane>
0029 #include <KChartLegend>
0030 #include <KChartGridAttributes>
0031 
0032 #include <TableModel.h>
0033 
0034 using namespace KChart;
0035 
0036 class TestPolarPlanes: public QObject {
0037     Q_OBJECT
0038 private Q_SLOTS:
0039 
0040     void initTestCase()
0041     {
0042         m_chart = new Chart(nullptr);
0043         m_tableModel = new TableModel( this );
0044         m_tableModel->loadFromCSV( ":/data" );
0045         m_pie = new PieDiagram();
0046         m_pie->setModel( m_tableModel );
0047         m_polar = new PolarDiagram();
0048         m_polar->setModel( m_tableModel );
0049         m_plane = new PolarCoordinatePlane();
0050         m_chart->addCoordinatePlane( m_plane );
0051         m_plane->setReferenceCoordinatePlane( m_chart->coordinatePlane() );
0052     }
0053 
0054     void testIntialOwnership()
0055     {
0056         AbstractCoordinatePlane *plane = m_chart->coordinatePlane();
0057         QCOMPARE( m_plane->referenceCoordinatePlane(), m_chart->coordinatePlane() );
0058         m_chart->takeCoordinatePlane( nullptr );
0059         delete plane;
0060         QCOMPARE( m_plane->referenceCoordinatePlane(), (AbstractCoordinatePlane*)nullptr );
0061     }
0062 
0063     void testStartPositionSettings()
0064     {
0065         m_plane->addDiagram(  m_pie );
0066         QVERIFY( m_plane->startPosition() ==  0.0 );
0067         qreal pos = 45;
0068         m_plane->addDiagram(  m_pie );
0069         m_plane->setStartPosition( pos );
0070         QVERIFY( m_plane->startPosition() ==  pos );
0071         m_plane->takeDiagram(  m_pie );
0072     }
0073 
0074       void testZoomFactorsSettings()
0075     {
0076         m_plane->addDiagram(  m_pie );
0077         QCOMPARE( m_plane->zoomFactorX(),  1.0 );
0078         QCOMPARE( m_plane->zoomFactorY(),  1.0 );
0079         QCOMPARE( m_plane->zoomCenter(), QPointF( 0.5, 0.5 ) );
0080         m_plane->setZoomFactorX( 1.5 );
0081         m_plane->setZoomFactorY( 1.5 );
0082         m_plane->setZoomCenter( QPointF ( 1.0, 1.0 ) );
0083         QCOMPARE( m_plane->zoomFactorX(),  1.5 );
0084         QCOMPARE( m_plane->zoomFactorY(),  1.5 );
0085         QCOMPARE( m_plane->zoomCenter(),  QPointF( 1.0, 1.0 ) );
0086         m_plane->takeDiagram(  m_pie );
0087     }
0088 
0089     void testDiagramOwnership()
0090     {
0091 
0092         QCOMPARE( m_plane->diagrams().size(),  1 );
0093         m_plane->addDiagram(  m_polar );
0094         QCOMPARE( m_plane->diagrams().size(),  2 );
0095         QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()),  m_pie );
0096         m_plane->takeDiagram( m_pie );
0097         QCOMPARE( m_plane->diagrams().size(),  1 );
0098         QCOMPARE( dynamic_cast< PolarDiagram * >(m_plane->diagram()),  m_polar );
0099         m_plane->replaceDiagram( m_pie,  m_polar );
0100         QCOMPARE( m_plane->diagrams().size(),  1 );
0101         QCOMPARE( dynamic_cast< PieDiagram * >(m_plane->diagram()),  m_pie );
0102         m_plane->takeDiagram( m_pie );
0103         QCOMPARE( m_plane->diagrams().size(),  0 );
0104         delete m_pie;
0105     }
0106 
0107     void testGlobalGridAttributesSettings()
0108     {
0109         GridAttributes ga = m_plane->globalGridAttributes();
0110         QVERIFY( ga.isGridVisible() == true );
0111         ga.setGridVisible(  false );
0112         m_plane->setGlobalGridAttributes(  ga );
0113         QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false );
0114         //reset to normal
0115         ga.setGridVisible(  true );
0116         QVERIFY( m_plane->globalGridAttributes().isGridVisible() == false );
0117         m_plane->setGlobalGridAttributes(  ga );
0118         QVERIFY( m_plane->globalGridAttributes().isGridVisible() == true );
0119     }
0120 
0121       void testGridAttributesSettings()
0122     {
0123         GridAttributes gcircular = m_plane->gridAttributes( true );
0124         GridAttributes gsagittal = m_plane->gridAttributes( false );
0125         QVERIFY( gcircular.isGridVisible() == true );
0126         gcircular.setGridVisible( false );
0127         m_plane->setGridAttributes( true, gcircular );
0128         QVERIFY( m_plane->hasOwnGridAttributes( true ) == true );
0129         QVERIFY( m_plane->hasOwnGridAttributes( false ) == false );
0130         QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false );
0131         QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true );
0132         gsagittal.setGridVisible( false );
0133         m_plane->setGridAttributes( false, gsagittal );
0134         QVERIFY( m_plane->hasOwnGridAttributes( true ) == true );
0135         QVERIFY( m_plane->hasOwnGridAttributes( true ) == true );
0136         QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == false );
0137         QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == false );
0138         m_plane->resetGridAttributes( true );
0139         m_plane->resetGridAttributes( false );
0140         QVERIFY( m_plane->gridAttributes( true ).isGridVisible() == true );
0141         QVERIFY( m_plane->gridAttributes( false ).isGridVisible() == true );
0142         QVERIFY( m_plane->hasOwnGridAttributes( true ) == false );
0143         QVERIFY( m_plane->hasOwnGridAttributes( false ) == false );
0144     }
0145 
0146     void cleanupTestCase()
0147     {
0148     }
0149 
0150 private:
0151     Chart *m_chart;
0152     PieDiagram *m_pie;
0153     PolarDiagram *m_polar;
0154     PolarCoordinatePlane *m_plane;
0155     TableModel *m_tableModel;
0156 
0157 };
0158 
0159 QTEST_MAIN(TestPolarPlanes)
0160 
0161 #include "main.moc"