File indexing completed on 2024-11-24 03:57:50

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 <QStandardItemModel>
0010 #include <KChartChart>
0011 #include <KChartLineDiagram>
0012 #include <QApplication>
0013 
0014 using namespace KChart;
0015 
0016 class ChartWidget : public QWidget {
0017   Q_OBJECT
0018 public:
0019 
0020   explicit ChartWidget(QWidget* parent = nullptr)
0021     : QWidget(parent)
0022   {
0023 
0024     m_model.insertRows( 0,6, QModelIndex() );
0025     m_model.insertColumns( 0,1, QModelIndex() );
0026 
0027     m_model.setData( m_model.index( 0, 0, QModelIndex()),  15);
0028     m_model.setData( m_model.index( 1, 0, QModelIndex()),  11);
0029     m_model.setData( m_model.index( 2, 0, QModelIndex()),  7);
0030     m_model.setData( m_model.index( 3, 0, QModelIndex()),  3);
0031     m_model.setData( m_model.index( 4, 0, QModelIndex()),  -1);
0032     m_model.setData( m_model.index( 5, 0, QModelIndex()),  -5);
0033 
0034     LineDiagram* diagram = new LineDiagram;
0035     diagram->setModel(&m_model);
0036 
0037     m_chart.coordinatePlane()->replaceDiagram(diagram);
0038 
0039     // paint the areas in a few cells
0040     // using different brushes
0041     LineAttributes la3(diagram->lineAttributes(m_model.index(3,0,QModelIndex())));
0042     la3.setDisplayArea(  true );
0043     la3.setTransparency( 150 );
0044     diagram->setBrush(m_model.index(1,0,QModelIndex()),QBrush(Qt::green));
0045     diagram->setLineAttributes( m_model.index( 1, 0,  QModelIndex()),la3);
0046     diagram->setBrush(m_model.index(3,0,QModelIndex()),QBrush(Qt::yellow));
0047     diagram->setLineAttributes(m_model.index(3,0,QModelIndex()),la3);
0048     diagram->setBrush(m_model.index(4,0,QModelIndex()),QBrush(Qt::red));
0049     diagram->setLineAttributes(m_model.index(4,0,QModelIndex()),la3);
0050 
0051     QVBoxLayout* l = new QVBoxLayout(this);
0052     l->addWidget(&m_chart);
0053     setLayout(l);
0054   }
0055 
0056 private:
0057   Chart m_chart;
0058   QStandardItemModel m_model;
0059 };
0060 
0061 int main( int argc, char** argv ) {
0062     QApplication app( argc, argv );
0063 
0064     ChartWidget w;
0065     w.show();
0066 
0067     return app.exec();
0068 }
0069 
0070 #include "main.moc"