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