File indexing completed on 2025-01-26 04:02:42

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 "mainwindow.h"
0010 
0011 #include <KChartChart>
0012 #include <KChartAbstractCoordinatePlane>
0013 #include <KChartLineDiagram>
0014 #include <KChartGridAttributes>
0015 
0016 #include <QDebug>
0017 #include <QPainter>
0018 
0019 using namespace KChart;
0020 
0021 MainWindow::MainWindow( QWidget* parent ) :
0022     QWidget( parent )
0023 {
0024     setupUi( this );
0025 
0026     QHBoxLayout *chartLayout = new QHBoxLayout( chartFrame );
0027     m_chart = new Chart();
0028     chartLayout->addWidget( m_chart );
0029 
0030     m_model.loadFromCSV( ":/data" );
0031     m_model2.loadFromCSV( ":/data2" );
0032 
0033     // Set up the diagram
0034     m_lines = new LineDiagram();
0035     m_lines->setModel( &m_model );
0036 
0037     m_lines2 = new LineDiagram();
0038     m_lines2->setModel( &m_model2 );
0039 
0040     // We call this "plane2" just for remembering, that we use it
0041     // in addition to the plane, that's built-in by default.
0042     plane2 = new CartesianCoordinatePlane( m_chart );
0043 
0044     plane2->setReferenceCoordinatePlane( m_chart->coordinatePlane() );
0045 
0046     CartesianAxis *xAxis = new CartesianAxis( m_lines2 );
0047     CartesianAxis *yAxis = new CartesianAxis( m_lines );
0048     CartesianAxis *yAxis2 = new CartesianAxis( m_lines2 );
0049 
0050     xAxis->setPosition( KChart::CartesianAxis::Top );
0051     yAxis->setPosition( KChart::CartesianAxis::Left );
0052     yAxis2->setPosition( KChart::CartesianAxis::Left );
0053 
0054     m_lines->addAxis( yAxis );
0055 
0056     m_lines2->addAxis( xAxis );
0057     m_lines2->addAxis( yAxis2 );
0058 
0059     m_chart->coordinatePlane()->replaceDiagram( m_lines );
0060     plane2->replaceDiagram( m_lines2 );
0061     m_chart->addCoordinatePlane( plane2/*, 1*/ );
0062     m_chart->setGlobalLeading( 20, 20, 20, 20 );
0063     init();
0064 }
0065 
0066 void MainWindow::init()
0067 {
0068     on_displayGrid2CB_toggled( false );
0069 }
0070 
0071 
0072 void MainWindow::on_displayGrid1CB_toggled( bool checked )
0073 {
0074     CartesianCoordinatePlane* plane = qobject_cast< CartesianCoordinatePlane * >( m_chart->coordinatePlane() );
0075 
0076     // disable grid for plane
0077     GridAttributes gv( plane->gridAttributes( Qt::Vertical) );
0078     gv.setGridVisible( checked );
0079     plane->setGridAttributes( Qt::Vertical, gv );
0080     plane->setGridAttributes( Qt::Horizontal, gv );
0081 }
0082 
0083 void MainWindow::on_displayGrid2CB_toggled( bool checked )
0084 {
0085     // disable grid for plane2
0086     GridAttributes gv( plane2->gridAttributes( Qt::Vertical ) );
0087     gv.setGridVisible( checked );
0088     plane2->setGridAttributes( Qt::Vertical, gv );
0089     plane2->setGridAttributes( Qt::Horizontal, gv );
0090 }