File indexing completed on 2024-05-12 04:20:15
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 <KChartLineDiagram> 0013 #include <KChartThreeDLineAttributes> 0014 #include <KChartCartesianCoordinatePlane> 0015 0016 #include <TableModel.h> 0017 0018 using namespace KChart; 0019 0020 class TestLineDiagrams: public QObject { 0021 Q_OBJECT 0022 private Q_SLOTS: 0023 0024 void initTestCase() 0025 { 0026 m_chart = new Chart(nullptr); 0027 m_model = new TableModel( this ); 0028 m_model->loadFromCSV( ":/data" ); 0029 m_lines = new LineDiagram(); 0030 m_lines->setModel( m_model ); 0031 m_chart->coordinatePlane()->replaceDiagram( m_lines ); 0032 } 0033 0034 void testLineDiagramType() 0035 { 0036 QCOMPARE( m_lines->type(), LineDiagram::Normal ); 0037 m_lines->setType( LineDiagram::Stacked ); 0038 QCOMPARE( m_lines->type(), LineDiagram::Stacked ); 0039 m_lines->setType( LineDiagram::Percent ); 0040 QCOMPARE( m_lines->type(), LineDiagram::Percent ); 0041 //reset to normal 0042 m_lines->setType( LineDiagram::Normal ); 0043 } 0044 0045 void testLineAttributesLevelSettings() 0046 { 0047 //check segments 0048 const int rows = m_lines->model()->rowCount(); 0049 QCOMPARE( m_lines->numberOfAbscissaSegments(), rows ); 0050 const int cols = m_lines->model()->columnCount(); 0051 QCOMPARE( m_lines->numberOfOrdinateSegments(), cols ); 0052 QModelIndex idx = m_model->index(rows-3, cols-3, QModelIndex()); 0053 // create attribute 0054 LineAttributes la( m_lines->lineAttributes() ); 0055 LineAttributes laCol( m_lines->lineAttributes() ); 0056 LineAttributes laIndex( m_lines->lineAttributes() ); 0057 0058 // modify at different level and compare 0059 laCol.setMissingValuesPolicy ( LineAttributes::MissingValuesHideSegments ); 0060 laIndex.setMissingValuesPolicy ( LineAttributes::MissingValuesShownAsZero ); 0061 m_lines->setLineAttributes( la ); 0062 m_lines->setLineAttributes( cols-2, laCol ); 0063 m_lines->setLineAttributes( idx, laIndex ); 0064 QVERIFY( m_lines->lineAttributes() != m_lines->lineAttributes(cols-2) ); 0065 QVERIFY( m_lines->lineAttributes() != m_lines->lineAttributes(idx) ); 0066 QVERIFY( m_lines->lineAttributes(cols-2) != m_lines->lineAttributes(idx) ); 0067 QCOMPARE( m_lines->lineAttributes(), la ); 0068 QCOMPARE( m_lines->lineAttributes( cols - 2 ), laCol ); 0069 QCOMPARE( m_lines->lineAttributes( idx ), laIndex ); 0070 // try and override the cols and index level - should not work 0071 m_lines->setLineAttributes( la ); 0072 QVERIFY( m_lines->lineAttributes().missingValuesPolicy() == 0073 LineAttributes::MissingValuesAreBridged ); 0074 QVERIFY( m_lines->lineAttributes( cols-2 ).missingValuesPolicy() == 0075 LineAttributes::MissingValuesHideSegments ); 0076 QVERIFY( m_lines->lineAttributes( idx ).missingValuesPolicy() == 0077 LineAttributes::MissingValuesShownAsZero ); 0078 } 0079 0080 void testLineAttributesValueSettings() 0081 { 0082 LineAttributes la( m_lines->lineAttributes() ); 0083 0084 // check default values 0085 QVERIFY( la.missingValuesPolicy() == LineAttributes::MissingValuesAreBridged ); 0086 QVERIFY( la.displayArea() == false ); 0087 QVERIFY( la.transparency() == 255 ); 0088 //change settings 0089 la.setMissingValuesPolicy ( LineAttributes::MissingValuesShownAsZero ); 0090 la.setDisplayArea( true ); 0091 la.setTransparency( 100 ); 0092 m_lines->setLineAttributes( la ); 0093 // get new values 0094 QVERIFY( m_lines->lineAttributes().missingValuesPolicy() == 0095 LineAttributes::MissingValuesShownAsZero ); 0096 QVERIFY( m_lines->lineAttributes().displayArea() == true ); 0097 QVERIFY( m_lines->lineAttributes().transparency() == 100 ); 0098 } 0099 0100 void testThreeDLineAttributesLevelSettings() 0101 { 0102 //check segments 0103 const int rows = m_lines->model()->rowCount(); 0104 QCOMPARE( m_lines->numberOfAbscissaSegments(), rows ); 0105 const int cols = m_lines->model()->columnCount(); 0106 QCOMPARE( m_lines->numberOfOrdinateSegments(), cols ); 0107 QModelIndex idx = m_model->index(rows-3, cols-3, QModelIndex()); 0108 // create attribute 0109 ThreeDLineAttributes td( m_lines->threeDLineAttributes() ); 0110 ThreeDLineAttributes tdCol( m_lines->threeDLineAttributes() ); 0111 ThreeDLineAttributes tdIndex( m_lines->threeDLineAttributes() ); 0112 // modify at different level and compare 0113 tdCol.setDepth(25 ); 0114 tdIndex.setDepth( 30 ); 0115 m_lines->setThreeDLineAttributes( td ); 0116 m_lines->setThreeDLineAttributes( cols-2, tdCol ); 0117 m_lines->setThreeDLineAttributes( idx, tdIndex ); 0118 QVERIFY( m_lines->threeDLineAttributes() != 0119 m_lines->threeDLineAttributes(cols-2) ); 0120 QVERIFY( m_lines->threeDLineAttributes() != 0121 m_lines->threeDLineAttributes(idx) ); 0122 QVERIFY( m_lines->threeDLineAttributes(cols-2) != 0123 m_lines->threeDLineAttributes(idx) ); 0124 QCOMPARE( m_lines->threeDLineAttributes(), td ); 0125 QCOMPARE( m_lines->threeDLineAttributes( cols - 2 ), tdCol ); 0126 QCOMPARE( m_lines->threeDLineAttributes( idx ), tdIndex ); 0127 // try and override the cols and index level - should not work 0128 m_lines->setThreeDLineAttributes( td ); 0129 QVERIFY( m_lines->threeDLineAttributes().depth() == 20 ); 0130 QVERIFY( m_lines->threeDLineAttributes( cols-2 ).depth() == 25 ); 0131 QVERIFY( m_lines->threeDLineAttributes( idx ).depth() == 30 ); 0132 } 0133 0134 void testThreeDLineAttributesValueSettings() 0135 { 0136 ThreeDLineAttributes td( m_lines->threeDLineAttributes() ); 0137 0138 //check default values 0139 //generics == AbstractThreeD 0140 QVERIFY( td.isEnabled() == false ); 0141 QVERIFY( td.depth() == 20 ); 0142 QVERIFY( td.validDepth() == 0.0 ); 0143 //bars specifics 0144 QVERIFY( td.lineXRotation() == 15 ); 0145 QVERIFY( td.lineYRotation() == 15 ); 0146 0147 //set new values 0148 td.setEnabled( true ); 0149 td.setDepth( 40 ); 0150 td.setLineXRotation( 20 ); 0151 td.setLineYRotation( 25 ); 0152 m_lines->setThreeDLineAttributes( td ); 0153 0154 //get new values 0155 QVERIFY( m_lines->threeDLineAttributes().isEnabled() == true ); 0156 QVERIFY( m_lines->threeDLineAttributes().depth() == 40 ); 0157 QVERIFY( m_lines->threeDLineAttributes().validDepth() == 40 ); 0158 QVERIFY( m_lines->threeDLineAttributes().lineXRotation() == 20 ); 0159 QVERIFY( m_lines->threeDLineAttributes().lineYRotation() == 25 ); 0160 } 0161 0162 void cleanupTestCase() 0163 { 0164 } 0165 0166 private: 0167 Chart *m_chart; 0168 LineDiagram *m_lines; 0169 TableModel *m_model; 0170 0171 }; 0172 0173 QTEST_MAIN(TestLineDiagrams) 0174 0175 #include "main.moc"