File indexing completed on 2024-11-24 03:57:53
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 <KChartWidget> 0012 #include <KChartAbstractDiagram> 0013 #include <QDebug> 0014 #include <QMessageBox> 0015 0016 using namespace KChart; 0017 0018 MainWindow::MainWindow( QWidget* parent ) 0019 : QWidget( parent ), datasetCount( 3 ) 0020 { 0021 setupUi( this ); 0022 0023 QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); 0024 widget = new Widget( chartFrame ); 0025 chartLayout->addWidget( widget ); 0026 0027 typeSelector->setCurrentIndex(1); // we start by LineDiagram 0028 0029 connect( typeSelector, SIGNAL(activated(int)), SLOT(changeType()) ); 0030 0031 connect( btnAddDataset, SIGNAL(clicked()), SLOT(addDataset()) ); 0032 0033 connect( leadingSelector, SIGNAL(valueChanged(int)), 0034 this, SLOT(changeLeading(int)) ); 0035 } 0036 0037 void MainWindow::changeType() 0038 { 0039 QString text = typeSelector->currentText(); 0040 if ( text == "Widget::Bar" ) 0041 widget->setType( Widget::Bar ); 0042 else if ( text == "Widget::Line" ) 0043 widget->setType( Widget::Line ); 0044 else if ( text == "Widget::Pie" ) 0045 widget->setType( Widget::Pie ); 0046 else if ( text == "Widget::Polar" ) 0047 widget->setType( Widget::Polar ); 0048 else 0049 widget->setType( Widget::NoType ); 0050 } 0051 0052 void MainWindow::changeLeading( int leading ) 0053 { 0054 widget->setGlobalLeading( leading, leading, leading, leading ); 0055 } 0056 0057 void MainWindow::addDataset() 0058 { 0059 const QStringList parts = lineAddDataset->text().split( ';' ); 0060 bool ok; 0061 QVector< qreal > vec; 0062 for ( const QString &str : parts ) { 0063 const qreal val = str.toDouble( &ok ); 0064 if ( ok ) 0065 vec.append( val ); 0066 } 0067 const int rows = widget->diagram()->model()->rowCount(); 0068 if ( vec.count() != rows ) { 0069 QMessageBox::warning( this, "Wrong number of values entered!", 0070 QString( "You have entered %1 values,<br>but the data model needs %2 ones." 0071 "<br><br>Note: Use <b>;</b> to separate the values!" ) 0072 .arg(vec.count()).arg(rows)); 0073 } else { 0074 widget->setDataset( datasetCount++, vec, "user data" ); 0075 } 0076 }