File indexing completed on 2024-06-16 04:08:59
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 <KChartPolarDiagram> 0014 #include <KChartTextAttributes> 0015 #include <KChartDataValueAttributes> 0016 #include <KChartGridAttributes> 0017 #include <KChartMarkerAttributes> 0018 #include <KChartLegend> 0019 0020 #include <QDebug> 0021 #include <QPainter> 0022 0023 using namespace KChart; 0024 0025 MainWindow::MainWindow( QWidget* parent ) : 0026 QWidget( parent ), m_currentFactor( 0 ), m_currentDirection( 1 ), m_currentSlice( 0 ) 0027 { 0028 setupUi( this ); 0029 0030 // instantiate the KD Chart classes 0031 initKChartClasses(); 0032 0033 // insert the KChart::Chart into Qt's layout 0034 QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); 0035 m_chart->setGlobalLeading( 2, 2, 2, 2 ); 0036 chartLayout->addWidget( m_chart ); 0037 0038 // wire up the KD Chart classes 0039 wireUpKChartClasses(); 0040 0041 // initialize the ItemModel and fill in some data 0042 m_model.insertRows( 0, 40 ); 0043 m_model.insertColumns( 0, 5 ); 0044 setItemModelData(); 0045 } 0046 0047 0048 void MainWindow::initKChartClasses() 0049 { 0050 m_chart = new Chart(); 0051 m_diagram = new PolarDiagram(); 0052 m_polarPlane = new PolarCoordinatePlane(); 0053 } 0054 0055 void MainWindow::wireUpKChartClasses() 0056 { 0057 m_chart->replaceCoordinatePlane( m_polarPlane ); 0058 //note: We need to set a valid item model to the diagram, 0059 // before we can add it to the coordinate plane. 0060 m_diagram->setModel( &m_model ); 0061 m_chart->coordinatePlane()->replaceDiagram( m_diagram ); 0062 } 0063 0064 void MainWindow::setItemModelData() 0065 { 0066 // For a change we do not read data from a resource file here, 0067 // but we just fill in the cells manually 0068 int value = 0; 0069 for ( int column = 0; column < m_model.columnCount(); ++column ) { 0070 for ( int row = 0; row < m_model.rowCount(); ++row ) { 0071 QModelIndex index = m_model.index( row, column ); 0072 m_model.setData( index, QVariant( value++ ) ); 0073 } 0074 } 0075 } 0076 0077 0078 void MainWindow::on_startPositionSB_valueChanged( double pos ) 0079 { 0080 const int intValue = static_cast<int>( pos ); 0081 startPositionSL->blockSignals( true ); 0082 startPositionSL->setValue( intValue ); 0083 startPositionSL->blockSignals( false ); 0084 // note: We use the global getter method here, it will fall back 0085 // automatically to return the default settings. 0086 static_cast<PolarCoordinatePlane*>(m_chart->coordinatePlane())->setStartPosition( pos ); 0087 update(); 0088 } 0089 0090 void MainWindow::on_startPositionSL_valueChanged( int pos ) 0091 { 0092 qreal qrealValue = static_cast<qreal>( pos ); 0093 startPositionSB->blockSignals( true ); 0094 startPositionSB->setValue( qrealValue ); 0095 startPositionSB->blockSignals( false ); 0096 // note: We use the global getter method here, it will fall back 0097 // automatically to return the default settings. 0098 static_cast<PolarCoordinatePlane*>(m_chart->coordinatePlane())->setStartPosition( pos ); 0099 update(); 0100 } 0101 0102 void MainWindow::on_circularGridCB_toggled( bool toggle ) 0103 { 0104 GridAttributes attrs( m_polarPlane->gridAttributes( true ) ); 0105 attrs.setGridVisible( toggle ); 0106 m_polarPlane->setGridAttributes( true, attrs ); 0107 update(); 0108 } 0109 void MainWindow::on_sagittalGridCB_toggled( bool toggle ) 0110 { 0111 GridAttributes attrs( m_polarPlane->gridAttributes( false ) ); 0112 attrs.setGridVisible( toggle ); 0113 m_polarPlane->setGridAttributes( false, attrs ); 0114 update(); 0115 } 0116 /* planned for future release: 0117 void MainWindow::on_circularAxisCB_toggled( bool toggle ) 0118 { 0119 Q_UNUSED( toggle ); 0120 update(); 0121 } 0122 void MainWindow::on_sagittalAxisCB_toggled( bool toggle ) 0123 { 0124 Q_UNUSED( toggle ); 0125 update(); 0126 } 0127 */