diff --git a/examples/Axis/Chart/mainwindow.h b/examples/Axis/Chart/mainwindow.h
index 1ea13af..7c5b06d 100644
--- a/examples/Axis/Chart/mainwindow.h
+++ b/examples/Axis/Chart/mainwindow.h
@@ -1,47 +1,47 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart
{
class Chart;
class BarDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private:
KChart::Chart* m_chart;
TableModel m_model;
KChart::BarDiagram* m_lines;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Axis/Labels/AdjustedCartesianAxis.h b/examples/Axis/Labels/AdjustedCartesianAxis.h
index ed85bfa..7acbe22 100644
--- a/examples/Axis/Labels/AdjustedCartesianAxis.h
+++ b/examples/Axis/Labels/AdjustedCartesianAxis.h
@@ -1,50 +1,50 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef ADJUSTED_CARTESIAN_AXIS_H
#define ADJUSTED_CARTESIAN_AXIS_H
#include
#include
class AdjustedCartesianAxis: public KChart::CartesianAxis
{
Q_OBJECT
Q_DISABLE_COPY( AdjustedCartesianAxis )
public:
- explicit AdjustedCartesianAxis( KChart::AbstractCartesianDiagram* diagram = 0 );
+ explicit AdjustedCartesianAxis( KChart::AbstractCartesianDiagram* diagram = nullptr );
const QString customizedLabel( const QString& label ) const Q_DECL_OVERRIDE;
void setBounds( qreal lower, qreal upper ) {
m_lowerBound = lower;
m_upperBound = upper;
}
qreal lowerBound() const { return m_lowerBound; }
qreal upperBound() const { return m_upperBound; }
private:
qreal m_lowerBound;
qreal m_upperBound;
};
#endif // ADJUSTED_CARTESIAN_AXIS_H
diff --git a/examples/Axis/Labels/mainwindow.h b/examples/Axis/Labels/mainwindow.h
index 548d902..c6d79f6 100644
--- a/examples/Axis/Labels/mainwindow.h
+++ b/examples/Axis/Labels/mainwindow.h
@@ -1,56 +1,56 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class LineDiagram;
class CartesianAxis;
class Legend;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void annotationsToggled( bool );
void gridLinesOnAnnotationsToggled( bool );
private:
KChart::Chart* m_chart;
KChart::CartesianAxis* m_xAxis;
TableModel m_model;
KChart::DatasetProxyModel* m_datasetProxy;
KChart::LineDiagram* m_lines;
KChart::Legend* m_legend;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Axis/Parameters/mainwindow.h b/examples/Axis/Parameters/mainwindow.h
index 9a48b94..329afba 100644
--- a/examples/Axis/Parameters/mainwindow.h
+++ b/examples/Axis/Parameters/mainwindow.h
@@ -1,73 +1,73 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class LineDiagram;
class LineAttributes;
class CartesianAxis;
class Legend;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_lineTypeCB_currentIndexChanged( const QString & text );
void on_paintLegendCB_toggled( bool checked );
void on_paintValuesCB_toggled( bool checked );
void on_paintMarkersCB_toggled( bool checked );
void on_markersStyleCB_currentIndexChanged( const QString & text );
void on_markersWidthSB_valueChanged( int i );
void on_markersHeightSB_valueChanged( int i);
void on_displayAreasCB_toggled( bool checked );
void on_transparencySB_valueChanged( int i );
void on_zoomFactorSB_valueChanged( double factor );
void on_hSBar_valueChanged( int value );
void on_vSBar_valueChanged( int value );
private:
KChart::Chart* m_chart;
TableModel m_model;
KChart::DatasetProxyModel* m_datasetProxy;
KChart::LineDiagram* m_lines;
KChart::Legend* m_legend;
// mutable KChart::CartesianAxis xAxis;
//mutable KChart::CartesianAxis yAxis;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Background/main.cpp b/examples/Background/main.cpp
index 83e39eb..851c9d4 100644
--- a/examples/Background/main.cpp
+++ b/examples/Background/main.cpp
@@ -1,125 +1,125 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 3; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+1 * column) );
}
}
QPixmap* pixmap = new QPixmap ( "background.png" );
BarDiagram* diagram = new BarDiagram;
diagram->setModel(&m_model);
m_chart.coordinatePlane()->replaceDiagram(diagram);
// Add at one Header and set it up
HeaderFooter* header = new HeaderFooter( &m_chart );
header->setPosition( Position::North );
header->setText( "A Simple Bar Chart" );
m_chart.addHeaderFooter( header );
// Configure the Header text attributes
TextAttributes hta;
hta.setPen( QPen( Qt::blue ) );
// let the header resize itself
// together with the widget.
// so-called relative size
Measure m( 35.0 );
m.setRelativeMode( header->autoReferenceArea(),
KChartEnums::MeasureOrientationMinimum );
hta.setFontSize( m );
// min font size
m.setValue( 3.0 );
m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
hta.setMinimalFontSize( m );
header->setTextAttributes( hta );
// Configure the plane's Background
BackgroundAttributes pba;
pba.setPixmap( *pixmap );
pba.setPixmapMode( BackgroundAttributes::BackgroundPixmapModeStretched );
pba.setVisible( true );
diagram->coordinatePlane()->setBackgroundAttributes( pba );
// Configure the Header's Background
BackgroundAttributes hba;
hba.setBrush( Qt::white );
hba.setVisible( true );
header->setBackgroundAttributes( hba );
// Configure the plane Frame attributes
FrameAttributes pfa;
pfa.setPen( QPen ( QBrush( Qt::blue ), 2 ) );
pfa.setVisible( true );
diagram->coordinatePlane()->setFrameAttributes( pfa );
// Configure the header Frame attributes
FrameAttributes hfa;
hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) );
hfa.setPadding( 2 );
hfa.setVisible( true );
header->setFrameAttributes( hfa );
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
QPixmap pixmap;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Bars/Advanced/mainwindow.cpp b/examples/Bars/Advanced/mainwindow.cpp
index 3acd1ec..9697ab1 100644
--- a/examples/Bars/Advanced/mainwindow.cpp
+++ b/examples/Bars/Advanced/mainwindow.cpp
@@ -1,231 +1,231 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent )
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
m_chart = new Chart();
chartLayout->addWidget( m_chart );
m_model.loadFromCSV( ":/data" );
// Set up the diagram
m_bars = new BarDiagram();
m_bars->setModel( &m_model );
// define custom color for the borders of the bars
QPen pen( m_bars->pen() );
pen.setColor( Qt::black );
pen.setWidth( 0 );
m_bars->setPen( pen );
m_chart->coordinatePlane()->replaceDiagram( m_bars );
// define custom colours for the bars
QList bcolor;
bcolor.append(Qt::darkGreen);
bcolor.append(Qt::green);
bcolor.append(Qt::darkRed);
bcolor.append(Qt::red);
for (int row=0; row < m_model.columnCount(); ++row) {
m_bars->setBrush(row, QBrush(bcolor[row]));
}
// Configure the plane's Background
BackgroundAttributes pba;
//pba.setBrush( QBrush(QColor(0x20,0x20,0x60)) );
pba.setVisible( true );
m_chart->coordinatePlane()->setBackgroundAttributes( pba );
m_chart->setGlobalLeadingTop( 20 );
}
void MainWindow::on_barTypeCB_currentIndexChanged( const QString & text )
{
if ( text == "Normal" )
m_bars->setType( BarDiagram::Normal );
else if ( text == "Stacked" )
m_bars->setType( BarDiagram::Stacked );
else if ( text == "Percent" )
m_bars->setType( BarDiagram::Percent );
else
qWarning (" Does not match any type");
m_chart->update();
}
void MainWindow::on_barOrientationCB_currentIndexChanged(const QString & text)
{
if ( text == "Vertical" )
m_bars->setOrientation( Qt::Vertical );
else if ( text == "Horizontal" )
m_bars->setOrientation( Qt::Horizontal );
else
qWarning (" Does not match any orientation");
m_chart->update();
}
void MainWindow::on_paintValuesCB_toggled( bool checked )
{
Q_UNUSED( checked );
// We set the DataValueAttributes on a per-column basis here,
// because we want the texts to be printed in different
// colours - according to their respective dataset's colour.
const QFont font(QFont( "Comic", 10 ));
const int colCount = m_bars->model()->columnCount();
for ( int iColumn = 0; iColumnbrush( iColumn ) );
DataValueAttributes a( m_bars->dataValueAttributes( iColumn ) );
TextAttributes ta( a.textAttributes() );
ta.setRotation( 0 );
ta.setFont( font );
ta .setPen( QPen( brush.color() ) );
if ( checked )
ta.setVisible( true );
else
ta.setVisible( false );
a.setTextAttributes( ta );
a.setVisible( true );
m_bars->setDataValueAttributes( iColumn, a);
}
m_chart->update();
}
void MainWindow::on_paintThreeDBarsCB_toggled( bool checked )
{
ThreeDBarAttributes td( m_bars->threeDBarAttributes() );
qreal defaultDepth = td.depth();
if ( checked ) {
td.setEnabled( true );
if ( threeDDepthCB->isChecked() )
td.setDepth( depthSB->value() );
else
td.setDepth( defaultDepth );
} else {
td.setEnabled( false );
}
m_bars->setThreeDBarAttributes( td );
m_chart->update();
}
void MainWindow::on_markColumnCB_toggled( bool checked )
{
const int column = markColumnSB->value();
QPen pen( m_bars->pen( column ) );
if ( checked ) {
pen.setColor( Qt::yellow );
pen.setStyle( Qt::DashLine );
pen.setWidth( 3 );
} else {
pen.setColor( Qt::black );
pen.setStyle( Qt::SolidLine );
pen.setWidth( 1 );
}
m_bars->setPen( column, pen );
m_chart->update();
}
void MainWindow::on_depthSB_valueChanged( int i )
{
Q_UNUSED( i );
if ( threeDDepthCB->isChecked() && paintThreeDBarsCB->isChecked() )
on_paintThreeDBarsCB_toggled( true );
}
void MainWindow::on_threeDDepthCB_toggled( bool checked )
{
Q_UNUSED( checked );
if ( paintThreeDBarsCB->isChecked() )
on_paintThreeDBarsCB_toggled( true );
}
void MainWindow::on_markColumnSB_valueChanged( int i )
{
QPen pen( m_bars->pen( i ) );
markColumnCB->setChecked( pen.color() == Qt::yellow );
}
void MainWindow::on_widthSB_valueChanged( int value )
{
if ( widthCB->isChecked() ) {
BarAttributes ba( m_bars->barAttributes() );
ba.setFixedBarWidth( value );
ba.setUseFixedBarWidth( true );
m_bars->setBarAttributes( ba );
}
m_chart->update();
}
void MainWindow::on_widthCB_toggled( bool checked )
{
if ( checked ) {
on_widthSB_valueChanged( widthSB->value() );
} else {
BarAttributes ba( m_bars->barAttributes() );
ba.setUseFixedBarWidth( false );
m_bars->setBarAttributes( ba );
m_chart->update();
}
}
void MainWindow::on_fixPlaneSizeCB_toggled( bool checked )
{
CartesianCoordinatePlane* plane =
qobject_cast( m_chart->coordinatePlane() );
- if ( plane == 0 )
+ if ( plane == nullptr )
return;
plane->setFixedDataCoordinateSpaceRelation( checked );
// just a little adjustment:
// Reset the zoom settings to their initial values
// when the releation-adjust checkbox is unchecked:
if ( ! checked ) {
m_chart->coordinatePlane()->setZoomFactorX( 1.0 );
m_chart->coordinatePlane()->setZoomFactorY( 1.0 );
m_chart->coordinatePlane()->setZoomCenter( QPointF(0.5, 0.5) );
}
m_chart->update();
}
diff --git a/examples/Bars/Advanced/mainwindow.h b/examples/Bars/Advanced/mainwindow.h
index 8fd24ae..7b0519e 100644
--- a/examples/Bars/Advanced/mainwindow.h
+++ b/examples/Bars/Advanced/mainwindow.h
@@ -1,60 +1,60 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class BarDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_barTypeCB_currentIndexChanged( const QString & text );
void on_barOrientationCB_currentIndexChanged( const QString & text );
void on_paintValuesCB_toggled( bool checked );
void on_paintThreeDBarsCB_toggled( bool checked );
void on_markColumnCB_toggled( bool checked );
void on_markColumnSB_valueChanged( int i );
void on_threeDDepthCB_toggled( bool checked );
void on_depthSB_valueChanged( int i );
void on_widthCB_toggled( bool checked );
void on_widthSB_valueChanged( int i );
void on_fixPlaneSizeCB_toggled( bool checked );
private:
KChart::Chart* m_chart;
KChart::BarDiagram* m_bars;
TableModel m_model;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Bars/Parameters/main.cpp b/examples/Bars/Parameters/main.cpp
index ba538d9..d2f00a1 100644
--- a/examples/Bars/Parameters/main.cpp
+++ b/examples/Bars/Parameters/main.cpp
@@ -1,108 +1,108 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget
{
Q_OBJECT
public:
- explicit ChartWidget( QWidget *parent = 0 );
+ explicit ChartWidget( QWidget *parent = nullptr );
private:
Chart m_chart;
QStandardItemModel m_model;
};
ChartWidget::ChartWidget( QWidget *parent )
: QWidget( parent )
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for ( int row = 0; row < 3; ++row ) {
for ( int column = 0; column < 3; ++column ) {
QModelIndex index = m_model.index( row, column, QModelIndex() );
m_model.setData(index, row * 3 + column );
}
}
BarDiagram* diagram = new KChart::BarDiagram;
diagram->setModel( &m_model );
BarAttributes ba( diagram->barAttributes() );
//set the bar width and enable it
ba.setFixedBarWidth( 140 );
ba.setUseFixedBarWidth( true );
//configure gap between values
//and blocks
ba.setGroupGapFactor( 0.50 );
ba.setBarGapFactor( 0.125 );
//assign to the diagram
diagram->setBarAttributes( ba );
// display the values
DataValueAttributes dva( diagram->dataValueAttributes() );
TextAttributes ta( dva.textAttributes() );
//rotate if you wish
//ta.setRotation( 0 );
ta.setFont( QFont( "Comic", 9 ) );
ta .setPen( QPen( QColor( Qt::darkGreen ) ) );
ta.setVisible( true );
dva.setTextAttributes( ta );
dva.setVisible( true );
diagram->setDataValueAttributes( dva );
//draw a surrounding line around bars
QPen linePen;
linePen.setColor( Qt::magenta );
linePen.setWidth( 4 );
linePen.setStyle( Qt::DotLine );
//draw only around a dataset
//to draw around all the bars
// call setPen( myPen );
diagram->setPen( 1, linePen );
m_chart.coordinatePlane()->replaceDiagram( diagram );
m_chart.setGlobalLeadingTop( 40 );
QVBoxLayout *l = new QVBoxLayout( this );
l->addWidget( &m_chart );
setLayout( l );
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Bars/Simple/main.cpp b/examples/Bars/Simple/main.cpp
index 7ba1d2e..59119aa 100644
--- a/examples/Bars/Simple/main.cpp
+++ b/examples/Bars/Simple/main.cpp
@@ -1,106 +1,106 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 3; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+1 * column) );
/*
// show tooltips:
m_model.setData(index,
QString(""
"Row | Column | Value |
"
"%1 | %2 | %3 |
---|
")
.arg(row).arg(column).arg(row+1 * column), Qt::ToolTipRole );
*/
}
}
/*
{
// show a comment at one data item:
const int row = 0;
const int column = 2;
const QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(
index,
QString("Value %1/%2: %3")
.arg( row )
.arg( column )
.arg( m_model.data( index ).toInt() ),
KChart::CommentRole );
}
*/
KChart::BarDiagram* diagram = new KChart::BarDiagram;
diagram->setModel(&m_model);
diagram->setPen( QPen( Qt::black, 0 ) );
m_chart.coordinatePlane()->replaceDiagram(diagram);
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
/*
// render chart to a SVG
QSvgGenerator generator;
generator.setFileName("/home/kdab/chart.svg");
generator.setSize(QSize(300, 300));
generator.setViewBox(QRect(0, 0, 300, 300));
generator.setTitle(tr("SVG Chart"));
QPainter painter;
painter.begin(&generator);
painter.setRenderHint(QPainter::Antialiasing);
m_chart.paint(&painter, generator.viewBox());
painter.end();
*/
}
private:
KChart::Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/DataValueTexts/mainwindow.h b/examples/DataValueTexts/mainwindow.h
index cc10cf9..da7dc58 100644
--- a/examples/DataValueTexts/mainwindow.h
+++ b/examples/DataValueTexts/mainwindow.h
@@ -1,83 +1,83 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
#include
namespace KChart {
class Chart;
class BarDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_scopeOneBarRB_toggled( bool checked );
void on_scopeBarDatasetSB_valueChanged( int i );
void on_scopeBarItemSB_valueChanged( int i );
void on_scopeDatasetRB_toggled( bool checked );
void on_scopeDatasetSB_valueChanged( int i );
void on_scopeCommonRB_toggled( bool checked );
void on_paintValuesCB_toggled( bool checked );
void on_fontCombo_currentIndexChanged( const QString & text );
void on_relativeSizeSB_valueChanged( int i );
void on_minimumSizeSB_valueChanged( int i );
void on_rotationSB_valueChanged( int i );
void on_posPosCombo_currentIndexChanged( const QString & text );
void on_posAlignCombo_currentIndexChanged( const QString & text );
void on_posPadHoriSB_valueChanged( int i );
void on_posPadVertSB_valueChanged( int i );
void on_negPosCombo_currentIndexChanged( const QString & text );
void on_negAlignCombo_currentIndexChanged( const QString & text );
void on_negPadHoriSB_valueChanged( int i );
void on_negPadVertSB_valueChanged( int i );
void on_labelLE_textEdited( const QString & text );
void on_prefixLE_textEdited( const QString & text );
void on_suffixLE_textEdited( const QString & text );
private:
const QModelIndex currentIndex() const;
const KChart::DataValueAttributes attributes() const;
const char* positionToScreenName( const KChart::Position& pos ) const;
const Qt::Alignment alignmentFromScreeName( const QString& name ) const;
const QString alignmentToScreenName( const Qt::Alignment& align ) const;
void populateWidgets();
void setAttributes( const KChart::DataValueAttributes& da );
KChart::Chart* m_chart;
KChart::BarDiagram* m_bars;
TableModel m_model;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/DrawIntoPainter/framewidget.cpp b/examples/DrawIntoPainter/framewidget.cpp
index dca4bf4..4e37e0f 100644
--- a/examples/DrawIntoPainter/framewidget.cpp
+++ b/examples/DrawIntoPainter/framewidget.cpp
@@ -1,77 +1,77 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "framewidget.h"
#include
#include
#include
FrameWidget::FrameWidget( QWidget* parent, Qt::WindowFlags f )
: QWidget( parent, f )
- , mChart( 0 )
+ , mChart( nullptr )
{
// this bloc left empty intentionally
}
void FrameWidget::setChart( KChart::Chart* chart )
{
mChart = chart;
// This is necessary because Chart can't automatically schedule somebody else (this object) to
// call its custom paint method.
connect( mChart, SIGNAL(propertiesChanged()), SLOT(update()) );
}
void FrameWidget::paintEvent( QPaintEvent* e )
{
if ( !mChart ) {
QWidget::paintEvent( e );
} else {
QPainter painter( this );
const int wid = 64;
const QRect r( rect() );
const QPen oldPen( painter.pen() );
const QBrush oldBrush( painter.brush() );
// paint below the chart
painter.setPen( QPen( Qt::NoPen ) );
painter.setBrush( QBrush( QColor( 0xd0, 0xd0, 0xff ) ) );
painter.drawEllipse( r.left(), r.top(), wid, wid );
painter.drawEllipse( r.left() + r.width() - wid - 1, r.top(), wid, wid );
painter.drawEllipse( r.left(), r.top() + r.height() - wid - 1, wid, wid );
painter.drawEllipse( r.left() + r.width() - wid - 1, r.top() + r.height() - wid - 1, wid, wid );
painter.setBrush( oldBrush );
painter.setPen( oldPen );
// paint the chart
mChart->paint( &painter, QRect( r.left() + wid / 2, r.top() + wid / 2,
r.width() - wid, r.height() - wid ) );
// paint over the chart
painter.setPen( QPen( Qt::NoPen ) );
painter.setBrush( QBrush( QColor( 0xd0, 0xff, 0xff ) ) );
const int wid2 = 40;
const int gap = ( wid - wid2 ) / 2;
painter.drawEllipse( r.left() + gap, r.top() + gap, wid2, wid2 );
painter.drawEllipse( r.left() + r.width() - wid + gap - 1, r.top() + gap, wid2, wid2 );
painter.drawEllipse( r.left() + gap, r.top() + r.height() - wid + gap - 1, wid2, wid2 );
painter.drawEllipse( r.left() + r.width() - wid + gap - 1, r.top() + r.height() - wid + gap - 1, wid2, wid2 );
painter.setBrush( oldBrush );
painter.setPen( oldPen );
}
}
diff --git a/examples/DrawIntoPainter/framewidget.h b/examples/DrawIntoPainter/framewidget.h
index 5623150..10d74f6 100644
--- a/examples/DrawIntoPainter/framewidget.h
+++ b/examples/DrawIntoPainter/framewidget.h
@@ -1,47 +1,47 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef FRAMEWIDGET_H
#define FRAMEWIDGET_H
#include
namespace KChart {
class Chart;
}
class FrameWidget : public QWidget
{
Q_OBJECT
public:
- explicit FrameWidget( QWidget * parent = 0, Qt::WindowFlags f = Qt::WindowFlags() );
+ explicit FrameWidget( QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
void paintEvent( QPaintEvent* ) Q_DECL_OVERRIDE;
void setChart( KChart::Chart* chart );
private:
KChart::Chart* mChart;
};
#endif /* FRAMEWIDGET_H */
diff --git a/examples/DrawIntoPainter/mainwindow.cpp b/examples/DrawIntoPainter/mainwindow.cpp
index a4d0e58..787e69f 100644
--- a/examples/DrawIntoPainter/mainwindow.cpp
+++ b/examples/DrawIntoPainter/mainwindow.cpp
@@ -1,411 +1,411 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include "framewidget.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
static QPixmap drawIntoPixmap( const QSize& size, KChart::Chart* chart )
{
QPixmap pix( size );
pix.fill( Qt::white );
QPainter painter( &pix );
chart->paint( &painter, QRect( 0, 0, size.width(), size.height() ) );
return pix;
}
// When set, this example uses FrameWidget which uses Chart::paint to paint itself.
// When not set, this example uses a Chart widget directly.
#define USE_FRAME_WIDGET 1
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent )
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
#ifdef USE_FRAME_WIDGET
FrameWidget* chartFrameWidget = new FrameWidget();
chartLayout->addWidget( chartFrameWidget );
#endif
hSBar->setVisible( false );
vSBar->setVisible( false );
m_model.loadFromCSV( ":/data" );
// Set up the diagram
m_lines = new LineDiagram();
m_lines->setModel( &m_model );
CartesianAxis *xAxis = new CartesianAxis( m_lines );
CartesianAxis *yAxis = new CartesianAxis( m_lines );
CartesianAxis *axisTop = new CartesianAxis( m_lines );
CartesianAxis *axisRight = new CartesianAxis( m_lines );
xAxis->setPosition( KChart::CartesianAxis::Bottom );
yAxis->setPosition( KChart::CartesianAxis::Left );
axisTop->setPosition( KChart::CartesianAxis::Top );
axisRight->setPosition( KChart::CartesianAxis::Right );
m_lines->addAxis( xAxis );
m_lines->addAxis( yAxis );
m_lines->addAxis( axisTop );
m_lines->addAxis( axisRight );
m_chart = new Chart();
//m_chart->setGlobalLeading(10,10,10,10); // by default there is no leading
#ifdef USE_FRAME_WIDGET
chartFrameWidget->setChart( m_chart );
// make sure, we re-draw after changing one of the chart's properties
connect( m_chart, SIGNAL(propertiesChanged()),
chartFrameWidget, SLOT(update()) ) ;
#else
chartLayout->addWidget( m_chart );
#endif
m_chart->coordinatePlane()->replaceDiagram( m_lines );
for ( int iColumn = 0; iColumn < m_lines->model()->columnCount(); ++iColumn ) {
QPen pen(m_lines->pen( iColumn ));
pen.setWidth(4);
m_lines->setPen( iColumn, pen );
}
FrameAttributes faChart( m_chart->frameAttributes() );
faChart.setVisible( true );
faChart.setPen( QPen(QColor( 0x60, 0x60, 0xb0 ), 8 ) );
m_chart->setFrameAttributes( faChart );
BackgroundAttributes baChart( m_chart->backgroundAttributes() );
baChart.setVisible( true );
baChart.setBrush( QColor( 0xd0, 0xd0, 0xff ) );
m_chart->setBackgroundAttributes( baChart );
// Set up the legend
m_legend = new Legend( m_lines, m_chart );
m_legend->setPosition( Position::South );
m_legend->setAlignment( Qt::AlignRight );
m_legend->setShowLines( false );
m_legend->setTitleText( tr( "Legend" ) );
m_legend->setOrientation( Qt::Horizontal );
// setting the legend frame and background to the same color:
const QColor legendColor( 0xff, 0xe0, 0x80 );
FrameAttributes faLegend( m_legend->frameAttributes() );
faLegend.setVisible( true );
faLegend.setPen( QPen( legendColor, 1 ) );
m_legend->setFrameAttributes( faLegend );
BackgroundAttributes baLegend( m_legend->backgroundAttributes() );
baLegend.setVisible( true );
baLegend.setBrush( legendColor );
m_legend->setBackgroundAttributes( baLegend );
m_chart->addLegend( m_legend );
// for illustration we paint the same chart at different sizes:
QSize size1 = QSize( 200, 200 );
QSize size2 = QSize( 800, 800 );
m_pix1 = drawIntoPixmap( size1, m_chart );
m_pix2 = drawIntoPixmap( size2, m_chart );
m_pix2 = m_pix2.scaled( size1 );
m_smallChart1 = new QLabel( this );
m_smallChart1->setWindowTitle( "200x200" );
m_smallChart1->setPixmap( m_pix1 );
m_smallChart1->setFixedSize( m_pix1.size() );
m_smallChart1->move( width() - m_pix1.width() * 2,
height() / 2 - m_pix1.height() - 5 );
m_smallChart1->show();
m_smallChart2 = new QLabel( this );
m_smallChart2->setWindowTitle( "800x800 scaled down" );
m_smallChart2->setPixmap( m_pix2 );
m_smallChart2->setFixedSize( m_pix2.size() );
m_smallChart2->move( width() - m_pix2.width() * 2,
height() / 2 + 5 );
m_smallChart2->show();
faChart.setPen( QPen( QColor( 0xb0, 0xb0, 0xff ), 8 ) );
m_chart->setFrameAttributes( faChart );
// initialize attributes; this is necessary because we need to enable data value attributes before
// any of them (e.g. only markers) can be displayed. but if we enable data value attributs, a default
// data value text is included, even if we only wanted to set markers. so we enable DVA and then
// individually disable the parts we don't want.
on_paintValuesCB_toggled( false );
on_paintMarkersCB_toggled( false );
}
void MainWindow::on_lineTypeCB_currentIndexChanged( const QString & text )
{
if ( text == "Normal" )
m_lines->setType( LineDiagram::Normal );
else if ( text == "Stacked" )
m_lines->setType( LineDiagram::Stacked );
else if ( text == "Percent" )
m_lines->setType( LineDiagram::Percent );
else
qWarning (" Does not match any type");
}
void MainWindow::on_paintLegendCB_toggled( bool checked )
{
KChart::Legend* legend = m_chart->legend();
- if ( checked != ( legend != 0 ) ) {
+ if ( checked != ( legend != nullptr ) ) {
if ( checked )
m_chart->addLegend( m_legend );
else
m_chart->takeLegend( legend );
}
}
void MainWindow::on_paintValuesCB_toggled( bool checked )
{
const int colCount = m_lines->model()->columnCount();
for ( int iColumn = 0; iColumn < colCount; ++iColumn ) {
DataValueAttributes a = m_lines->dataValueAttributes( iColumn );
a.setVisible( true );
TextAttributes ta = a.textAttributes();
ta.setRotation( 0 );
ta.setFont( QFont( "Comic", 10 ) );
ta.setPen( m_lines->brush( iColumn ).color() );
ta.setVisible( checked );
a.setTextAttributes( ta );
m_lines->setDataValueAttributes( iColumn, a );
}
}
void MainWindow::on_paintMarkersCB_toggled( bool checked )
{
paintMarkers( checked, QSize() );
}
void MainWindow::on_markersStyleCB_currentIndexChanged( const QString & text )
{
Q_UNUSED( text );
on_paintMarkersCB_toggled( paintMarkersCB->isChecked() );
}
void MainWindow::on_markersWidthSB_valueChanged( int i )
{
Q_UNUSED( i );
markersHeightSB->setValue( markersWidthSB->value() );
on_paintMarkersCB_toggled( paintMarkersCB->isChecked() );
}
void MainWindow::on_markersHeightSB_valueChanged( int i )
{
Q_UNUSED( i );
markersWidthSB->setValue( markersHeightSB->value() );
on_paintMarkersCB_toggled( paintMarkersCB->isChecked() );
}
void MainWindow::on_displayAreasCB_toggled( bool checked )
{
const int colCount = m_lines->model()->columnCount();
for ( int iColumn = 0; iColumn < colCount; ++iColumn ) {
LineAttributes la( m_lines->lineAttributes( iColumn ) );
la.setDisplayArea( checked );
if ( checked )
la.setTransparency( transparencySB->value() );
m_lines->setLineAttributes( iColumn, la );
}
}
void MainWindow::on_transparencySB_valueChanged( int alpha )
{
Q_UNUSED( alpha );
if ( !displayAreasCB->isChecked() )
displayAreasCB->setChecked( true );
else
on_displayAreasCB_toggled( true );
}
void MainWindow::on_zoomFactorSB_valueChanged( qreal factor )
{
const bool isZoomedIn = factor > 1.0f;
hSBar->setVisible( isZoomedIn );
vSBar->setVisible( isZoomedIn );
if ( !isZoomedIn ) {
hSBar->setValue( 500 );
vSBar->setValue( 500 );
}
m_chart->coordinatePlane()->setZoomFactorX( factor );
m_chart->coordinatePlane()->setZoomFactorY( factor );
}
void MainWindow::on_hSBar_valueChanged( int hPos )
{
m_chart->coordinatePlane()->setZoomCenter( QPointF( hPos / 1000.0, vSBar->value() / 1000.0 ) );
m_chart->update();
}
void MainWindow::on_vSBar_valueChanged( int vPos )
{
m_chart->coordinatePlane()->setZoomCenter( QPointF( hSBar->value() / 1000.0, vPos / 1000.0 ) );
}
// since DataValue markers have no relative sizing mode we need to scale them for printing
void MainWindow::paintMarkers( bool checked, const QSize& printSize )
{
MarkerAttributes::MarkerStylesMap map;
map.insert( 0, MarkerAttributes::MarkerSquare );
map.insert( 1, MarkerAttributes::MarkerCircle );
map.insert( 2, MarkerAttributes::MarkerRing );
map.insert( 3, MarkerAttributes::MarkerCross );
map.insert( 4, MarkerAttributes::MarkerDiamond );
// next: Specify column- / cell-specific attributes!
const int colCount = m_lines->model()->columnCount();
for ( int iColumn = 0; iColumn < colCount; ++iColumn ) {
DataValueAttributes dva = m_lines->dataValueAttributes( iColumn );
dva.setVisible( true );
MarkerAttributes ma( dva.markerAttributes() );
switch ( markersStyleCB->currentIndex() ) {
case 0:
ma.setMarkerStyle( MarkerAttributes::MarkerSquare );
break;
case 1:
// Column-specific attributes
ma.setMarkerStyle( map.value( iColumn ) );
break;
case 2:
ma.setMarkerStyle( MarkerAttributes::MarkerCircle );
break;
case 3:
ma.setMarkerStyle( MarkerAttributes::MarkerDiamond );
break;
case 4:
ma.setMarkerStyle( MarkerAttributes::Marker1Pixel );
break;
case 5:
ma.setMarkerStyle( MarkerAttributes::Marker4Pixels );
break;
case 6:
ma.setMarkerStyle( MarkerAttributes::MarkerRing );
break;
case 7:
ma.setMarkerStyle( MarkerAttributes::MarkerCross );
break;
case 8:
ma.setMarkerStyle( MarkerAttributes::MarkerFastCross );
break;
default:
Q_ASSERT( false );
}
ma.setVisible( checked );
qreal factorWidth = printSize.isValid() ? ( printSize.width() / m_chart->rect().width() ) : 1.0f;
qreal factorHeight = printSize.isValid() ? ( printSize.height() / m_chart->rect().height() ) : 1.0f;
ma.setMarkerSize( QSize( markersWidthSB->value() * factorWidth, markersHeightSB->value() * factorHeight ) );
dva.setMarkerAttributes( ma );
m_lines->setDataValueAttributes( iColumn, dva );
// make a special one for certain values
DataValueAttributes yellowAttributes( dva );
MarkerAttributes yellowMarker( yellowAttributes.markerAttributes() );
yellowMarker.setMarkerColor( Qt::yellow );
yellowAttributes.setMarkerAttributes( yellowMarker );
const int rowCount = m_lines->model()->rowCount();
for ( int j = 0; j < rowCount; ++j ) {
QModelIndex index = m_lines->model()->index( j, iColumn, QModelIndex() );
QBrush brush = m_lines->model()->headerData( iColumn, Qt::Vertical, DatasetBrushRole ).value();
qreal value = m_lines->model()->data( index ).toReal();
/* Set a specific color - marker for a specific value */
if ( value == 13 ) {
m_lines->setDataValueAttributes( index, yellowAttributes );
}
}
}
}
void MainWindow::on_savePB_clicked()
{
const QString file = QFileDialog::getSaveFileName( this, tr( "Choose PNG File..." ) );
if ( file.isEmpty() )
return;
qDebug() << "Painting into PNG";
QPixmap qpix( 600, 600 );
QPainter painter( &qpix );
painter.setBrush( Qt::white );
painter.fillRect( 0, 0, 600, 600, Qt::white);
m_chart->paint( &painter,
QRect( 100, 100, 400, 400 ) );
painter.end();
qpix.save( file, "PNG" );
qDebug() << "Painting into PNG - done";
}
void MainWindow::on_savePDF_clicked()
{
const QString file = QFileDialog::getSaveFileName( this, tr( "Choose PDF File..." ) );
if ( file.isEmpty() )
return;
qDebug() << "Painting into PDF";
QPrinter printer( QPrinter::HighResolution );
printer.setOrientation( QPrinter::Landscape );
printer.setOutputFormat( QPrinter::PdfFormat );
printer.setOutputFileName( file );
paintMarkers( paintMarkersCB->isChecked(), printer.pageRect().size() );
QPainter painter;
painter.begin( &printer );
m_chart->paint( &painter, printer.pageRect() );
painter.end();
paintMarkers( paintMarkersCB->isChecked(), m_chart->geometry().size() );
qDebug() << "Painting into PDF - done";
}
void MainWindow::resizeEvent( QResizeEvent * )
{
m_smallChart1->move( width() - m_pix1.width() * 2,
height() / 2 - m_pix1.height() - 5 );
m_smallChart2->move( width() - m_pix2.width() * 2,
height() / 2 + 5 );
}
diff --git a/examples/DrawIntoPainter/mainwindow.h b/examples/DrawIntoPainter/mainwindow.h
index c7242a8..4a75993 100644
--- a/examples/DrawIntoPainter/mainwindow.h
+++ b/examples/DrawIntoPainter/mainwindow.h
@@ -1,83 +1,83 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class LineDiagram;
class Legend;
}
QT_BEGIN_NAMESPACE
class QLabel;
QT_END_NAMESPACE
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
protected:
/**
* Adjusts the two small charts when the window is resized.
*/
/* reimp */ void resizeEvent ( QResizeEvent * ) Q_DECL_OVERRIDE;
private slots:
void on_lineTypeCB_currentIndexChanged( const QString & text );
void on_paintLegendCB_toggled( bool checked );
void on_paintValuesCB_toggled( bool checked );
void on_paintMarkersCB_toggled( bool checked );
void on_markersStyleCB_currentIndexChanged( const QString & text );
void on_markersWidthSB_valueChanged( int i );
void on_markersHeightSB_valueChanged( int i);
void on_displayAreasCB_toggled( bool checked );
void on_transparencySB_valueChanged( int i );
void on_zoomFactorSB_valueChanged( qreal factor );
void on_hSBar_valueChanged( int value );
void on_vSBar_valueChanged( int value );
void on_savePB_clicked();
void on_savePDF_clicked();
private:
void paintMarkers( bool checked, const QSize& printSize );
private:
KChart::Chart* m_chart;
TableModel m_model;
KChart::DatasetProxyModel* m_datasetProxy;
KChart::LineDiagram* m_lines;
KChart::Legend* m_legend;
QPixmap m_pix1, m_pix2;
QLabel* m_smallChart1;
QLabel* m_smallChart2;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/EmptyValues/mainwindow.h b/examples/EmptyValues/mainwindow.h
index 76d71d2..d446611 100644
--- a/examples/EmptyValues/mainwindow.h
+++ b/examples/EmptyValues/mainwindow.h
@@ -1,47 +1,47 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
namespace KChart {
class Chart;
class BarDiagram;
}
class MainWindow : public QWidget
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
virtual ~MainWindow() { }
private:
KChart::Chart* m_chart;
KChart::BarDiagram* m_bars;
TableModel m_model;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Gantt/legend_example/entrydelegate.h b/examples/Gantt/legend_example/entrydelegate.h
index 458833c..80fed80 100644
--- a/examples/Gantt/legend_example/entrydelegate.h
+++ b/examples/Gantt/legend_example/entrydelegate.h
@@ -1,42 +1,42 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef ENTRYDELEGATE_H
#define ENTRYDELEGATE_H
#include
namespace KGantt {
class ConstraintModel;
}
class EntryDelegate : public QItemDelegate {
public:
- explicit EntryDelegate( KGantt::ConstraintModel* constraintModel, QObject* parent = 0 );
+ explicit EntryDelegate( KGantt::ConstraintModel* constraintModel, QObject* parent = nullptr );
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) Q_DECL_OVERRIDE;
private:
void addConstraint(const QModelIndex & index1, const QModelIndex & index2);
void setReadOnly(const QModelIndex & index, bool readOnly);
KGantt::ConstraintModel* constraintModel;
};
#endif /* ENTRYDELEGATE_H */
diff --git a/examples/Gantt/legend_example/entrydialog.h b/examples/Gantt/legend_example/entrydialog.h
index 10d9a3a..a99a4c9 100644
--- a/examples/Gantt/legend_example/entrydialog.h
+++ b/examples/Gantt/legend_example/entrydialog.h
@@ -1,68 +1,68 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef ENTRYDIALOG_H
#define ENTRYDIALOG_H
#include
#include
#include
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
namespace Ui {
class EntryDialog;
}
QT_END_NAMESPACE
namespace KGantt {
class ConstraintModel;
}
class EntryDialog : public QDialog {
Q_OBJECT
public:
- explicit EntryDialog( const QAbstractItemModel* model, QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags() );
+ explicit EntryDialog( const QAbstractItemModel* model, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
void initFrom( const QModelIndex& index, const KGantt::ConstraintModel* constraintModel );
QString name() const;
int type() const;
QDateTime startDate() const;
QDateTime endDate() const;
int completion() const;
bool readOnly() const;
QModelIndex depends() const;
QString legend() const;
private slots:
void updateEndDate( const QDateTime& startDate );
void disableEditing( bool disable );
void typeChanged( int index );
private:
void init();
void addDependItem( const QAbstractItemModel* model, const QModelIndex& index, int indent = 0 );
QList indexList;
const QAbstractItemModel* model;
Ui::EntryDialog* ui;
};
#endif /* ENTRYDIALOG_H */
diff --git a/examples/Gantt/legend_example/mainwindow.cpp b/examples/Gantt/legend_example/mainwindow.cpp
index 3a42068..27e4d5c 100644
--- a/examples/Gantt/legend_example/mainwindow.cpp
+++ b/examples/Gantt/legend_example/mainwindow.cpp
@@ -1,390 +1,390 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "entrydelegate.h"
#include "entrydialog.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class MyStandardItem : public QStandardItem {
public:
MyStandardItem( const QVariant& v ) : QStandardItem()
{
setData( v, Qt::DisplayRole );
}
MyStandardItem( const QString& v ) : QStandardItem()
{
setData( v, Qt::DisplayRole );
}
};
MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags ),
- smallLegend( 0 ),
- detailedLegend( 0 ),
+ smallLegend( nullptr ),
+ detailedLegend( nullptr ),
ui( new Ui::MainWindow )
{
ui->setupUi( this );
initModel();
initActions();
initItemDelegate();
initGrid();
QTreeView* leftView = qobject_cast( ui->ganttView->leftView() );
Q_ASSERT( leftView );
leftView->setColumnHidden( 1, true );
leftView->setColumnHidden( 2, true );
leftView->setColumnHidden( 3, true );
leftView->setColumnHidden( 4, true );
leftView->setColumnHidden( 5, true );
leftView->header()->setStretchLastSection( true );
connect( ui->ganttView->leftView(), SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(showContextMenu(QPoint)) );
connect( ui->ganttView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(enableActions(QItemSelection)) );
}
MainWindow::~MainWindow()
{
}
void MainWindow::closeEvent(QCloseEvent *event)
{
delete smallLegend;
delete detailedLegend;
event->accept();
}
void MainWindow::initModel()
{
model = new QStandardItemModel( 0, 6, this );
model->setHeaderData( 0, Qt::Horizontal, tr( "Tree View of Entries" ) );
ui->ganttView->setModel( model );
QStandardItemModel* lmodel = new QStandardItemModel;
lmodel->appendRow( QList()
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( KGantt::TypeEvent )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QString::fromLatin1("Event") ) );
lmodel->appendRow( QList()
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( KGantt::TypeTask )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QString::fromLatin1("Task") ) );
lmodel->appendRow( QList()
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( KGantt::TypeSummary )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QVariant() )
<< new MyStandardItem( QString::fromLatin1("Summary") ) );
smallLegend = new KGantt::Legend();
smallLegend->setWindowTitle( tr( "Legend" ) );
smallLegend->show();
smallLegend->setModel( lmodel );
detailedLegend = new KGantt::Legend();
detailedLegend->setWindowTitle( tr( "List" ) );
detailedLegend->show();
detailedLegend->setModel( model );
constraintModel = new KGantt::ConstraintModel( this );
ui->ganttView->setConstraintModel( constraintModel );
}
void MainWindow::initActions()
{
newEntryAction = new QAction( tr( "New entry" ), this );
newEntryAction->setShortcut( QKeySequence::New );
connect( newEntryAction, SIGNAL(triggered()), this, SLOT(addNewEntry()) );
removeEntryAction = new QAction( tr( "Remove entry" ), this );
removeEntryAction->setShortcut( QKeySequence::Delete );
connect( removeEntryAction, SIGNAL(triggered()), this, SLOT(removeEntry()) );
zoomInAction = new QAction( tr( "Zoom In" ), this );
zoomInAction->setShortcut( QKeySequence::ZoomIn );
connect( zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()) );
zoomOutAction = new QAction( tr( "Zoom Out" ), this );
zoomOutAction->setShortcut( QKeySequence::ZoomOut );
connect( zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()) );
zoomFitAction = new QAction( tr( "Zoom to Fit" ), this );
connect( zoomFitAction, SIGNAL(triggered()), this, SLOT(zoomFit()) );
ui->ganttView->leftView()->setContextMenuPolicy( Qt::CustomContextMenu );
ui->ganttView->leftView()->addAction( newEntryAction );
ui->ganttView->leftView()->addAction( removeEntryAction );
QMenu* entryMenu = menuBar()->addMenu( tr( "Entry" ) );
entryMenu->addAction( newEntryAction );
entryMenu->addAction( removeEntryAction );
QMenu* zoomMenu = menuBar()->addMenu( tr( "Zoom" ) );
zoomMenu->addAction( zoomInAction );
zoomMenu->addAction( zoomOutAction );
zoomMenu->addAction( zoomFitAction );
QMenu* scaleMenu = menuBar()->addMenu( tr( "Scale" ) );
scaleMenu->addAction( tr( "Auto" ), this, SLOT(scaleAuto()) );
scaleMenu->addAction( tr( "Hour" ), this, SLOT(scaleHour()) );
scaleMenu->addAction( tr( "Day" ), this, SLOT(scaleDay()) );
scaleMenu->addAction( tr( "Week" ), this, SLOT(scaleWeek()) );
scaleMenu->addAction( tr( "Month" ), this, SLOT(scaleMonth()) );
enableActions( QItemSelection() );
}
void MainWindow::initItemDelegate()
{
EntryDelegate* delegate = new EntryDelegate( constraintModel, this );
ui->ganttView->leftView()->setItemDelegate( delegate );
}
void MainWindow::initGrid()
{
grid = new KGantt::DateTimeGrid();
grid->setDayWidth( 70 );
ui->ganttView->setGrid( grid );
}
void MainWindow::showContextMenu( const QPoint& pos )
{
if ( !ui->ganttView->leftView()->indexAt( pos ).isValid() )
ui->ganttView->selectionModel()->clearSelection();
QMenu menu( ui->ganttView->leftView() );
menu.addAction( newEntryAction );
menu.addAction( removeEntryAction );
menu.exec( ui->ganttView->leftView()->viewport()->mapToGlobal( pos ) );
}
void MainWindow::enableActions(const QItemSelection & selected)
{
if ( selected.indexes().isEmpty() ) {
newEntryAction->setEnabled( true );
removeEntryAction->setEnabled( false );
return;
}
QModelIndex selectedIndex = selected.indexes()[0];
if ( model->data( model->index( selectedIndex.row(), 1 ) ) == KGantt::TypeEvent ||
model->data( model->index( selectedIndex.row(), 1 ) ) == KGantt::TypeTask ) {
newEntryAction->setEnabled( false );
removeEntryAction->setEnabled( true );
return;
}
newEntryAction->setEnabled( true );
removeEntryAction->setEnabled( true );
}
void MainWindow::addNewEntry()
{
QPointer dialog = new EntryDialog( model );
dialog->setWindowTitle( tr( "New Entry") );
if ( dialog->exec() == QDialog::Rejected || !dialog ) {
delete dialog;
return;
}
QModelIndexList selectedIndexes = ui->ganttView->selectionModel()->selectedIndexes();
const QModelIndex parent = selectedIndexes.value( 0 );
if ( !model->insertRow( model->rowCount( parent ), parent ) )
return;
int row = model->rowCount( parent ) - 1;
if ( row == 0 && parent.isValid() )
model->insertColumns( model->columnCount( parent ), 5, parent );
model->setData( model->index( row, 0, parent ), dialog->name() );
model->setData( model->index( row, 1, parent ), dialog->type() );
if ( dialog->type() != KGantt::TypeSummary ) {
model->setData( model->index( row, 2, parent ), dialog->startDate(), KGantt::StartTimeRole );
model->setData( model->index( row, 3, parent ), dialog->endDate(), KGantt::EndTimeRole );
}
model->setData( model->index( row, 4, parent ), dialog->completion() );
const QString legend( dialog->legend() );
if ( ! legend.isEmpty() )
model->setData( model->index( row, 5, parent ), legend );
addConstraint( dialog->depends(), model->index( row, 0, parent ) );
setReadOnly( model->index( row, 0, parent ), dialog->readOnly() );
delete dialog;
}
void MainWindow::setReadOnly(const QModelIndex & index, bool readOnly)
{
int row = index.row();
const QModelIndex parent = index.parent();
QStandardItem* item;
item = model->itemFromIndex( model->index( row, 0, parent ) );
item->setFlags( readOnly ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
item = model->itemFromIndex( model->index( row, 1, parent ) );
item->setFlags( readOnly ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
item = model->itemFromIndex( model->index( row, 2, parent ) );
item->setFlags( readOnly ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
item = model->itemFromIndex( model->index( row, 3, parent ) );
item->setFlags( readOnly ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
item = model->itemFromIndex( model->index( row, 4, parent ) );
item->setFlags( readOnly ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
}
void MainWindow::addConstraint(const QModelIndex & index1, const QModelIndex & index2)
{
if ( !index1.isValid() || !index2.isValid() )
return;
KGantt::Constraint c( index1, index2 );
ui->ganttView->constraintModel()->addConstraint( c );
}
void MainWindow::removeEntry()
{
QModelIndexList selectedIndexes = ui->ganttView->selectionModel()->selectedIndexes();
QModelIndex index = selectedIndexes.value( 0 );
if ( !index.isValid() )
return;
model->removeRow( index.row(), index.parent() );
}
void MainWindow::zoomIn()
{
qreal dayWidth = grid->dayWidth() + 10;
if ( dayWidth > 400 )
grid->setScale( KGantt::DateTimeGrid::ScaleHour );
grid->setDayWidth( dayWidth );
}
void MainWindow::zoomOut()
{
qreal dayWidth = grid->dayWidth() - 10;
if ( dayWidth < 10 )
dayWidth = 10;
if ( dayWidth <= 400 )
grid->setScale( KGantt::DateTimeGrid::ScaleDay );
grid->setDayWidth( dayWidth );
}
void MainWindow::zoomFit()
{
QModelIndexList selectedIndexes = ui->ganttView->selectionModel()->selectedIndexes();
if ( selectedIndexes.isEmpty() ) {
return;
}
KGantt::Span span;
Q_FOREACH( QModelIndex idx, selectedIndexes ) {
const KGantt::Span s = grid->mapToChart( grid->model()->index( idx.row(), 0 ) );
if ( span.isValid() ) {
span = span.expandedTo( s );
} else {
span = s;
}
}
span.setLength( span.length()+20 );
span.setStart( span.start()-10 );
qDebug() << selectedIndexes << span;
const qreal view_width = ui->ganttView->graphicsView()->viewport()->width();
const QDateTime start = grid->mapFromChart( span.start() ).value();
const QDateTime end = grid->mapFromChart( span.end() ).value();
qreal delta = start.date().daysTo(end.date());
delta += start.time().msecsTo(end.time())/( 1000.*24.*60.*60. );
qDebug() << view_width << "/" << delta;
grid->setDayWidth( view_width/( std::max( 1., delta ) ) );
qDebug() << "daywidth set to" << grid->dayWidth();
qDebug() << "start scroll to" << grid->mapToChart( start );
ui->ganttView->graphicsView()->horizontalScrollBar()->setValue( grid->mapToChart( start ) );
}
void MainWindow::scaleAuto()
{
KGantt::DateTimeGrid* grid = static_cast(ui->ganttView->grid());
grid->setScale( KGantt::DateTimeGrid::ScaleAuto );
}
void MainWindow::scaleHour()
{
KGantt::DateTimeGrid* grid = static_cast(ui->ganttView->grid());
grid->setScale( KGantt::DateTimeGrid::ScaleHour );
}
void MainWindow::scaleDay()
{
KGantt::DateTimeGrid* grid = static_cast(ui->ganttView->grid());
grid->setScale( KGantt::DateTimeGrid::ScaleDay );
}
void MainWindow::scaleWeek()
{
KGantt::DateTimeGrid* grid = static_cast(ui->ganttView->grid());
grid->setScale( KGantt::DateTimeGrid::ScaleWeek );
}
void MainWindow::scaleMonth()
{
KGantt::DateTimeGrid* grid = static_cast(ui->ganttView->grid());
grid->setScale( KGantt::DateTimeGrid::ScaleMonth );
}
diff --git a/examples/Gantt/legend_example/mainwindow.h b/examples/Gantt/legend_example/mainwindow.h
index b305095..37b1f5c 100644
--- a/examples/Gantt/legend_example/mainwindow.h
+++ b/examples/Gantt/legend_example/mainwindow.h
@@ -1,86 +1,86 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
QT_BEGIN_NAMESPACE
class QStandardItemModel;
class QCloseEvent;
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
namespace KGantt {
class ConstraintModel;
class DateTimeGrid;
class Legend;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- explicit MainWindow( QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags() );
+ explicit MainWindow( QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
virtual ~MainWindow();
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private slots:
void addNewEntry();
void removeEntry();
void showContextMenu( const QPoint& );
void enableActions( const QItemSelection& selected );
void zoomIn();
void zoomOut();
void zoomFit();
void scaleAuto();
void scaleHour();
void scaleDay();
void scaleWeek();
void scaleMonth();
private:
void initModel();
void initActions();
void initItemDelegate();
void initGrid();
void setReadOnly( const QModelIndex& index, bool readOnly );
void addConstraint( const QModelIndex& index1, const QModelIndex& index2 );
QStandardItemModel* model;
KGantt::ConstraintModel* constraintModel;
KGantt::DateTimeGrid* grid;
KGantt::Legend* smallLegend;
KGantt::Legend* detailedLegend;
QAction* newEntryAction;
QAction* removeEntryAction;
QAction* zoomInAction;
QAction* zoomOutAction;
QAction* zoomFitAction;
Ui::MainWindow* ui;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Gantt/project/mainwindow.cpp b/examples/Gantt/project/mainwindow.cpp
index d408fc4..3038082 100644
--- a/examples/Gantt/project/mainwindow.cpp
+++ b/examples/Gantt/project/mainwindow.cpp
@@ -1,478 +1,478 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include "projectmodel.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class ItemTypeComboBox : public QComboBox {
Q_OBJECT
Q_PROPERTY( KGantt::ItemType itemType READ itemType WRITE setItemType )
public:
- explicit ItemTypeComboBox( QWidget* parent=0 );
+ explicit ItemTypeComboBox( QWidget* parent = nullptr );
KGantt::ItemType itemType() const;
public slots:
void setItemType( KGantt::ItemType typ );
};
ItemTypeComboBox::ItemTypeComboBox( QWidget* parent )
: QComboBox( parent )
{
addItem( tr( "Task" ), QVariant( KGantt::TypeTask ) );
addItem( tr( "Event" ), QVariant( KGantt::TypeEvent ) );
addItem( tr( "Summary" ), QVariant( KGantt::TypeSummary ) );
}
KGantt::ItemType ItemTypeComboBox::itemType() const
{
return static_cast( itemData( currentIndex() ).toInt() );
}
void ItemTypeComboBox::setItemType( KGantt::ItemType typ )
{
setCurrentIndex( typ-1 );
}
class MyItemDelegate : public KGantt::ItemDelegate {
public:
- explicit MyItemDelegate( QObject* parent=0 );
+ explicit MyItemDelegate( QObject* parent = nullptr );
/*reimp*/ QWidget* createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& idx ) const Q_DECL_OVERRIDE;
/*reimp*/ void setEditorData( QWidget* editor, const QModelIndex& index ) const Q_DECL_OVERRIDE;
/*reimp*/ void setModelData( QWidget* editor, QAbstractItemModel* model,
const QModelIndex & index ) const Q_DECL_OVERRIDE;
protected:
/*reimp*/void drawDisplay( QPainter* painter, const QStyleOptionViewItem & option,
const QRect& rect, const QString& text ) const Q_DECL_OVERRIDE;
};
MyItemDelegate::MyItemDelegate( QObject* parent )
: KGantt::ItemDelegate( parent )
{
}
QWidget* MyItemDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& idx ) const
{
qDebug() << "MyItemDelegate::createEditor("<(editor)) && index.isValid() ) {
c->setItemType(static_cast(index.data(Qt::EditRole).toInt()));
} else {
ItemDelegate::setEditorData(editor,index);
}
}
void MyItemDelegate::setModelData ( QWidget* editor, QAbstractItemModel* model,
const QModelIndex & index ) const
{
ItemTypeComboBox* c;
if ( (c = qobject_cast(editor)) && index.isValid() ) {
model->setData(index,c->itemType());
} else {
ItemDelegate::setModelData(editor,model,index);
}
}
void MyItemDelegate::drawDisplay( QPainter* painter, const QStyleOptionViewItem& option,
const QRect& rect, const QString& text ) const
{
//qDebug() << "MyItemDelegate::drawDisplay(" <(text.toInt());
QString str;
switch (typ) {
case KGantt::TypeTask: str = tr("Task"); break;
case KGantt::TypeEvent: str = tr("Event"); break;
case KGantt::TypeSummary: str = tr("Summary"); break;
default: str = tr("None"); break;
}
ItemDelegate::drawDisplay(painter,option,rect,str);
}
///////////////////////////////////////////////////////////////////////////////
// Provide custom background and foreground
///////////////////////////////////////////////////////////////////////////////
class DateTimeGrid : public KGantt::DateTimeGrid
{
public:
- DateTimeGrid(QObject* parent=0) {
+ DateTimeGrid(QObject* parent = nullptr) {
setParent(parent);
setFreeDays( QSet() );
setFreeDaysBrush( QBrush( Qt::NoBrush ) );
}
~DateTimeGrid() { }
//virtual void paintUserDefinedHeader(QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, const KGantt::DateTimeScaleFormatter* formatter, QWidget* widget = 0);
void drawBackground(QPainter* painter, const QRectF& rect) Q_DECL_OVERRIDE;
void drawForeground(QPainter* painter, const QRectF& rect) Q_DECL_OVERRIDE;
};
void DateTimeGrid::drawBackground(QPainter* painter, const QRectF& rect)
{
QLinearGradient grad;
grad.setCoordinateMode( QGradient::ObjectBoundingMode );
grad.setStart( 0.5, 0.5 );
grad.setFinalStop( 0.5, 0.0 );
grad.setSpread( QGradient::ReflectSpread );
// grad.setCenter( 0.5, 0.5 );
// grad.setFocalPoint( 0.5, 0.5 );
// grad.setRadius( 0.5 );
QColor currentColor = Qt::blue;
for ( qreal i = 0; i <= 1.0; i += 0.1 )
{
currentColor = currentColor.lighter( 100 + 20 * i );
grad.setColorAt( i, currentColor );
}
QBrush brush( grad);
//brush.setColor(Qt::lightGray);
QRectF r = computeRect(QDateTime::currentDateTime(),
QDateTime::currentDateTime().addDays(2),
rect);
painter->fillRect(r, brush);
}
void DateTimeGrid::drawForeground(QPainter* painter, const QRectF& rect)
{
painter->save();
QRectF r = computeRect(QDateTime::currentDateTime(),
QDateTime::currentDateTime().addDays(2),
rect);
static QString text("Holiday");
QFont font = painter->font();
font.setPixelSize(r.width()/5);
QFontMetrics fm(font);
int width = fm.width(text);
int height = fm.boundingRect(text).height();
painter->translate(r.center());
painter->translate(-width/2, height/2);
painter->setFont(font);
painter->drawText(0, 0, text);
painter->restore();
}
/*
void DateTimeGrid::paintUserDefinedHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, const KGantt::DateTimeScaleFormatter* formatter, QWidget* widget)
{
const QStyle* const style = widget ? widget->style() : QApplication::style();
QDateTime dt = formatter->currentRangeBegin( mapToDateTime( offset + exposedRect.left() ) ).toUTC();
qreal x = mapFromDateTime( dt );
while ( x < exposedRect.right() + offset ) {
const QDateTime next = formatter->nextRangeBegin( dt );
const qreal nextx = mapFromDateTime( next );
QStyleOptionHeader opt;
if ( widget ) opt.init( widget );
opt.rect = QRectF( x - offset+1, headerRect.top(), qMax( 1., nextx-x-1 ), headerRect.height() ).toAlignedRect();
//opt.state = QStyle::State_Raised | QStyle::State_Enabled;
opt.textAlignment = formatter->alignment();
opt.text = formatter->text( dt );
// use white text on black background
opt.palette.setColor(QPalette::Window, QColor("black"));
opt.palette.setColor(QPalette::ButtonText, QColor("white"));
style->drawControl( QStyle::CE_Header, &opt, painter, widget );
dt = next;
x = nextx;
}
}
*/
MainWindow::MainWindow( QWidget* parent )
: QMainWindow( parent ),
m_model( new ProjectModel( this ) ),
m_view( new KGantt::View )
{
m_view->setModel( m_model );
m_view->setSelectionModel( new QItemSelectionModel(m_model));
// slotToolsNewItem();
m_view->leftView()->setItemDelegateForColumn( 1, new MyItemDelegate( this ) );
m_view->leftView()->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_view->graphicsView()->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
m_view->setGrid(new DateTimeGrid(this));
//QItemEditorCreatorBase *creator = new QItemEditorCreator("itemType");
//QItemEditorFactory* factory = new QItemEditorFactory;
//factory->registerEditor( QVariant( KGantt::TypeTask ).type(), creator );
//m_view->itemDelegate()->setItemEditorFactory( factory );
setCentralWidget( m_view );
QMenuBar* mb = menuBar();
QMenu* fileMenu = new QMenu( tr( "&File" ) );
#ifndef QT_NO_PRINTER
fileMenu->addAction( tr( "&Save as PDF..." ), this, SLOT(slotFileSavePdf()) );
fileMenu->addAction( tr( "&Print..." ), this, SLOT(slotFilePrint()) );
#endif
fileMenu->addSeparator();
fileMenu->addAction( tr( "&Quit" ), this, SLOT(slotFileQuit()) );
mb->addMenu( fileMenu );
QMenu* toolsMenu = new QMenu( tr( "&Tools" ) );
toolsMenu->addAction( tr( "&New Item" ), this, SLOT(slotToolsNewItem()) );
toolsMenu->addAction( tr( "&Add Item" ), this, SLOT(slotToolsAppendItem()) );
toolsMenu->addSeparator();
QMenu *alignMenu = toolsMenu->addMenu( tr( "Ali&gn" ) );
alignMenu->addAction( tr( "&Left" ), this, SLOT(slotAlignLeft()) );
alignMenu->addAction( tr( "&Center" ), this, SLOT(slotAlignCenter()) );
alignMenu->addAction( tr( "&Right" ), this, SLOT(slotAlignRight()) );
alignMenu->addAction( tr( "&Hidden" ), this, SLOT(slotAlignHidden()) );
toolsMenu->addSeparator();
toolsMenu->addAction( tr( "&Collapse All" ), this, SLOT(slotCollapseAll()) );
toolsMenu->addAction( tr( "&Expand All" ), this, SLOT(slotExpandAll()) );
mb->addMenu( toolsMenu );
/*
slotToolsNewItem();
slotToolsNewItem();
slotToolsNewItem();
for (int i = 0; i < 3; ++i) {
m_model->setData(m_model->index(i,2,QModelIndex()), qVariantFromValue(QDateTime::currentDateTime().addDays(i)), KGantt::StartTimeRole);
m_model->setData(m_model->index(i,3,QModelIndex()), qVariantFromValue(QDateTime::currentDateTime().addDays(i+1)), KGantt::EndTimeRole);
}
m_view->setConstraintModel(new KGantt::ConstraintModel(m_view));
m_view->constraintModel()->addConstraint(KGantt::Constraint(m_model->index(0,0,QModelIndex()),m_model->index(1,0,QModelIndex())));
m_view->constraintModel()->addConstraint(KGantt::Constraint(m_model->index(1,0,QModelIndex()),m_model->index(2,0,QModelIndex())));
*/
}
SavePdfDialog::SavePdfDialog(QWidget *parent)
: QDialog(parent)
{
setModal(true);
setWindowTitle(tr("Save as PDF"));
QVBoxLayout *l = new QVBoxLayout(this);
setLayout(l);
QHBoxLayout *fileLayout = new QHBoxLayout(this);
l->addLayout(fileLayout);
QLabel *fileLabel = new QLabel(tr("File:"), this);
fileLayout->addWidget(fileLabel);
m_fileEdit = new QLineEdit(this);
fileLabel->setBuddy(m_fileEdit);
m_fileEdit->setText(QFileInfo(QDir::homePath(), "gantt.pdf").absoluteFilePath());
fileLayout->addWidget(m_fileEdit);
QPushButton *m_fileButton = new QPushButton("...", this);
connect(m_fileButton, SIGNAL(clicked()), this, SLOT(fileButtonClicked()));
fileLayout->addWidget(m_fileButton);
m_rowLabels = new QCheckBox(tr("Row Header"), this);
m_rowLabels->setChecked(true);
l->addWidget(m_rowLabels);
m_columnLabels = new QCheckBox(tr("Column Header"), this);
m_columnLabels->setChecked(true);
l->addWidget(m_columnLabels);
QDialogButtonBox *btnBox = new QDialogButtonBox(this);
btnBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
connect(btnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(btnBox, SIGNAL(rejected()), this, SLOT(reject()));
l->addWidget(btnBox);
resize(QSize(400, 100).expandedTo(minimumSizeHint()));
}
void SavePdfDialog::fileButtonClicked()
{
const QString file = QFileDialog::getSaveFileName(this, tr("Choose PDF File..."), QString(), tr("PDF files (*.pdf)"));
if (!file.isEmpty())
m_fileEdit->setText(file);
}
void MainWindow::slotFileSavePdf()
{
#ifndef QT_NO_PRINTER
SavePdfDialog dialog(this);
if (dialog.exec() != QDialog::Accepted)
return;
const QString file = dialog.m_fileEdit->text();
if (file.isEmpty())
return;
const bool drawRowLabels = dialog.m_rowLabels->isChecked();
const bool drawColumnLabels = dialog.m_columnLabels->isChecked();
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
printer.setColorMode(QPrinter::Color);
printer.setPageMargins(0.2, 0.2, 0.2, 0.2, QPrinter::Point);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(file);
m_view->print(&printer, drawRowLabels, drawColumnLabels);
#endif
}
void MainWindow::slotFilePrint()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
printer.setColorMode(QPrinter::Color);
QPrintDialog dialog(&printer, this);
if (dialog.exec() != QDialog::Accepted)
return;
m_view->print(&printer);
#endif
}
void MainWindow::slotFileQuit()
{
// TODO
QApplication::instance()->quit();
}
void MainWindow::slotToolsNewItem()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
qDebug() << "MainWindow::slotToolsNewItem" << idx;
m_model->insertRows( 0, 1, m_model->index( idx.row(),0,idx.parent() ) );
} else {
m_model->insertRows( 0, 1, m_view->rootIndex() );
}
}
void MainWindow::slotToolsAppendItem()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
qDebug() << "MainWindow::slotToolsAppendItem" << idx;
m_model->insertRows( m_model->rowCount( idx ), 1, m_model->index( idx.row(),0,idx.parent() ) );
} else {
m_model->insertRows( m_model->rowCount( m_view->rootIndex() ), 1, m_view->rootIndex() );
}
}
void MainWindow::slotCollapseAll()
{
// don't use the treeview's collapseAll/expandAll methods but use the one provided by the
// view cause that one will take care to update everyt6hing as needed.
//QTreeView* view = qobject_cast( m_view->leftView() );
//view->collapseAll();
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() )
m_view->collapseAll();
}
void MainWindow::slotExpandAll()
{
// don't use the treeview's collapseAll/expandAll methods but use the one provided by the
// view cause that one will take care to update everyt6hing as needed.
//QTreeView* view = qobject_cast( m_view->leftView() );
//view->expandAll();
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() )
m_view->expandAll();
}
void MainWindow::slotAlignLeft()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
m_model->setData( idx, KGantt::StyleOptionGanttItem::Left, KGantt::TextPositionRole );
}
}
void MainWindow::slotAlignCenter()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
m_model->setData( idx, KGantt::StyleOptionGanttItem::Center, KGantt::TextPositionRole );
}
}
void MainWindow::slotAlignRight()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
m_model->setData( idx, KGantt::StyleOptionGanttItem::Right, KGantt::TextPositionRole );
}
}
void MainWindow::slotAlignHidden()
{
QModelIndex idx = m_view->selectionModel()->currentIndex();
if ( idx.isValid() ) {
m_model->setData( idx, KGantt::StyleOptionGanttItem::Hidden, KGantt::TextPositionRole );
}
}
#include "mainwindow.moc"
diff --git a/examples/Gantt/project/mainwindow.h b/examples/Gantt/project/mainwindow.h
index e246ea7..e74a909 100644
--- a/examples/Gantt/project/mainwindow.h
+++ b/examples/Gantt/project/mainwindow.h
@@ -1,71 +1,71 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
class QLineEdit;
class QCheckBox;
namespace KGantt {
class View;
}
class ProjectModel;
class SavePdfDialog : public QDialog
{
Q_OBJECT
public:
QLineEdit *m_fileEdit;
QCheckBox *m_rowLabels;
QCheckBox *m_columnLabels;
- SavePdfDialog(QWidget *parent = 0);
+ SavePdfDialog(QWidget *parent = nullptr);
private slots:
void fileButtonClicked();
};
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- explicit MainWindow( QWidget* parent = 0 );
+ explicit MainWindow( QWidget* parent = nullptr );
private slots:
void slotFileSavePdf();
void slotFilePrint();
void slotFileQuit();
void slotToolsNewItem();
void slotToolsAppendItem();
void slotCollapseAll();
void slotExpandAll();
void slotAlignLeft();
void slotAlignCenter();
void slotAlignRight();
void slotAlignHidden();
private:
ProjectModel* m_model;
KGantt::View* m_view;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Gantt/project/projectmodel.cpp b/examples/Gantt/project/projectmodel.cpp
index eb892ba..3f9ac4c 100644
--- a/examples/Gantt/project/projectmodel.cpp
+++ b/examples/Gantt/project/projectmodel.cpp
@@ -1,357 +1,357 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "projectmodel.h"
#include
#include
#include
#include
#include
#include
#include
typedef QAbstractItemModel BASE;
class ProjectModel::Node {
public:
- explicit Node( Node* parent = 0 );
+ explicit Node( Node* parent = nullptr );
virtual ~Node();
void addChild( Node* );
void insertChild( int i, Node* );
void removeChild( Node* );
Node* parent() const { return m_parent; }
int childCount() const { return m_children.count(); }
int childNumber( Node* n ) const { return m_children.indexOf( n ); }
Node* child( int i ) const {
return m_children.at( i );
}
void setParent( Node* p ) {
m_parent = p;
}
void setStart( const QDateTime& dt ) {
m_bStart = m_start;
m_start = dt;
}
void setEnd( const QDateTime& dt ) {
if ( m_end.isValid() )
m_bEnd = m_end;
m_end = dt;
}
void setLabel( const QString& str ) {
m_label = str;
}
void setType( int t ) {
m_type = static_cast( t );
if ( !m_start.isValid() )
m_start = m_bStart;
if ( !m_end.isValid() )
m_end = m_bEnd;
}
void setCompletion( int c ) {
m_completion = c;
}
void setPosition( KGantt::StyleOptionGanttItem::Position p ) {
m_position = p;
}
QDateTime start() const { return m_start; }
QDateTime end() const { return m_end; }
QString label() const { return m_label; }
KGantt::ItemType type() const { return m_type; }
int completion() const { return m_completion; }
KGantt::StyleOptionGanttItem::Position position() const { return m_position; }
private:
Node* m_parent;
QList m_children;
KGantt::ItemType m_type;
QDateTime m_start, m_end;
QDateTime m_bStart, m_bEnd;
QString m_label;
int m_completion;
KGantt::StyleOptionGanttItem::Position m_position;
};
static int unnamed_count = 0;
ProjectModel::Node::Node( Node* parent )
: m_parent( parent ),
m_type( KGantt::TypeTask ),
m_start( QDateTime::currentDateTime() ),
m_end( QDateTime::currentDateTime().addDays( 1 ) ),
m_label( tr( "Unnamed task %1" ).arg( ++unnamed_count ) ),
m_completion( -1 ),
m_position( KGantt::StyleOptionGanttItem::Right )
{
if ( m_parent ) m_parent->addChild( this );
}
ProjectModel::Node::~Node()
{
while ( !m_children.isEmpty() ) delete m_children.front();
if ( m_parent ) m_parent->removeChild( this );
}
void ProjectModel::Node::addChild( Node* child )
{
child->setParent( this );
m_children.push_back( child );
}
void ProjectModel::Node::insertChild( int i, Node* child )
{
child->setParent( this );
m_children.insert( i, child );
}
void ProjectModel::Node::removeChild( Node* child )
{
- child->setParent( 0 );
+ child->setParent( nullptr );
m_children.removeAll( child );
}
ProjectModel::ProjectModel( QObject* parent )
: QAbstractItemModel( parent ), m_root( new Node )
{
}
ProjectModel::~ProjectModel()
{
delete m_root;
}
bool ProjectModel::load( const QString& filename )
{
Q_UNUSED(filename)
// TODO: read data
delete m_root;
m_root = new Node;
return true;
}
bool ProjectModel::save( const QString& filename )
{
Q_UNUSED(filename);
return true;
}
int ProjectModel::rowCount( const QModelIndex& idx ) const
{
if ( idx.isValid() ) return static_cast( idx.internalPointer() )->childCount();
else return m_root->childCount();
}
int ProjectModel::columnCount( const QModelIndex& idx ) const
{
Q_UNUSED(idx);
return 5;
}
QModelIndex ProjectModel::index( int row, int col, const QModelIndex& parent ) const
{
Node* p = m_root;
if ( parent.isValid() ) {
p = static_cast( parent.internalPointer() );
}
if ( row < 0 || row >= p->childCount() ) return QModelIndex();
else return createIndex( row, col, p->child( row ) );
}
QModelIndex ProjectModel::parent( const QModelIndex& idx ) const
{
if ( !idx.isValid() ) return QModelIndex();
Node* n = static_cast( idx.internalPointer() );
assert( n );
Node* p = n->parent();
if ( p==m_root )return QModelIndex();
Node* pp = p->parent();
assert( pp );
return createIndex( pp->childNumber( p ), 0, p );
}
QVariant ProjectModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation != Qt::Horizontal || role != Qt::DisplayRole ) return QVariant();
switch ( section ) {
case 0: return tr( "Name" );
case 1: return tr( "Type" );
case 2: return tr( "Start" );
case 3: return tr( "End" );
case 4: return tr( "Completion %" );
default: return QVariant();
}
}
QVariant ProjectModel::data( const QModelIndex& idx, int role ) const
{
if ( !idx.isValid() ) return QVariant();
Node* n = static_cast( idx.internalPointer() );
assert( n );
if ( idx.column() == 0 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
return n->label();
case KGantt::TextPositionRole:
return n->position();
}
} else if ( idx.column() == 1 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
return qVariantFromValue( n->type() );
}
} else if ( idx.column() == 2 ) {
switch ( role ) {
case Qt::DisplayRole:
return n->start().date().toString("dd-MM-yyyy");
case Qt::EditRole:
case KGantt::StartTimeRole:
return n->start();
}
} else if ( idx.column() == 3 ) {
switch ( role ) {
case Qt::DisplayRole:
return n->end().date().toString("dd-MM-yyyy");
case Qt::EditRole:
case KGantt::EndTimeRole:
return n->end();
}
} else if ( idx.column() == 4 && n->completion() >= 0 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
return n->completion();
}
} else if ( idx.column() == 5 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
return n->label();
case KGantt::ItemTypeRole:
return n->type();
case KGantt::StartTimeRole:
return n->start();
case KGantt::EndTimeRole:
return n->end();
case KGantt::TaskCompletionRole:
if ( n->completion() >= 0 )
return n->completion();
break;
}
}
return QVariant();
}
bool ProjectModel::setData( const QModelIndex& idx, const QVariant& value,
int role )
{
if ( !idx.isValid() ) return false;
qDebug() << "ProjectModel::setData" << idx.column() << role << value;
Node* n = static_cast( idx.internalPointer() );
assert( n );
if ( idx.column() == 0 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
n->setLabel( value.toString() );
emit dataChanged( idx, idx );
break;
case KGantt::TextPositionRole:
n->setPosition( static_cast(value.toInt()) );
emit dataChanged( idx, idx );
break;
}
} else if ( idx.column() == 1 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
n->setType( value.toInt() );
emit dataChanged( idx, idx );
break;
}
} else if ( idx.column() == 2 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
case KGantt::StartTimeRole:
n->setStart(value.toDateTime());
emit dataChanged( idx, idx );
break;
}
} else if ( idx.column() == 3 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
case KGantt::EndTimeRole:
n->setEnd(value.toDateTime());
emit dataChanged( idx, idx );
break;
}
} else if ( idx.column() == 4 ) {
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
n->setCompletion(value.toInt());
emit dataChanged( idx, idx );
break;
}
}
return true;
}
bool ProjectModel::insertRows( int row, int count, const QModelIndex& parent )
{
beginInsertRows( parent, row, row+count-1 );
Node* p = m_root;
if ( parent.isValid() ) p = static_cast( parent.internalPointer() );
assert( p );
for ( int i = 0; i < count; ++i ) {
Node* n = new Node;
p->insertChild( row+i, n );
}
endInsertRows();
return true;
}
Qt::ItemFlags ProjectModel::flags( const QModelIndex& idx ) const
{
return BASE::flags( idx ) | Qt::ItemIsEditable;
}
diff --git a/examples/Gantt/project/projectmodel.h b/examples/Gantt/project/projectmodel.h
index 29b3660..8d18b82 100644
--- a/examples/Gantt/project/projectmodel.h
+++ b/examples/Gantt/project/projectmodel.h
@@ -1,56 +1,56 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KGantt library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef PROJECTMODEL_H
#define PROJECTMODEL_H
#include
class ProjectModel : public QAbstractItemModel {
Q_OBJECT
public:
- explicit ProjectModel( QObject* parent = 0 );
+ explicit ProjectModel( QObject* parent = nullptr );
virtual ~ProjectModel();
/*reimp*/ int rowCount( const QModelIndex& idx ) const Q_DECL_OVERRIDE;
/*reimp*/ int columnCount( const QModelIndex& idx ) const Q_DECL_OVERRIDE;
/*reimp*/ QModelIndex index( int row, int col, const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE;
/*reimp*/ QModelIndex parent( const QModelIndex& idx ) const Q_DECL_OVERRIDE;
/*reimp*/QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
/*reimp*/ QVariant data( const QModelIndex& idx, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
/*reimp*/ bool setData( const QModelIndex& idx, const QVariant& value,
int role = Qt::DisplayRole ) Q_DECL_OVERRIDE;
/*reimp*/ bool insertRows( int row, int count, const QModelIndex& parent = QModelIndex() ) Q_DECL_OVERRIDE;
/*reimp*/ Qt::ItemFlags flags( const QModelIndex& ) const Q_DECL_OVERRIDE;
bool load( const QString& filename );
bool save( const QString& filename );
private:
class Node;
Node* m_root;
};
#endif /* PROJECTMODEL_H */
diff --git a/examples/Grids/CartesianGrid/main.cpp b/examples/Grids/CartesianGrid/main.cpp
index 45f4230..8626caa 100644
--- a/examples/Grids/CartesianGrid/main.cpp
+++ b/examples/Grids/CartesianGrid/main.cpp
@@ -1,188 +1,188 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 6, QModelIndex() );
m_model.insertColumns( 0, 4, QModelIndex() );
for (int row = 0; row < 6; ++row) {
for (int column = 0; column < 4; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row*0.5 + column) );
}
}
LineDiagram* diagram = new LineDiagram;
diagram->setModel(&m_model);
CartesianAxis *xAxis = new CartesianAxis( diagram );
CartesianAxis *yAxis = new CartesianAxis ( diagram );
xAxis->setPosition ( KChart::CartesianAxis::Bottom );
yAxis->setPosition ( KChart::CartesianAxis::Left );
diagram->addAxis( xAxis );
diagram->addAxis( yAxis );
m_chart.coordinatePlane()->replaceDiagram(diagram);
/* Header */
// Add at one Header and set it up
HeaderFooter* header = new HeaderFooter( &m_chart );
header->setPosition( Position::North );
header->setText( "A Line Chart with Grid Configured" );
m_chart.addHeaderFooter( header );
// Configure the Header text attributes
TextAttributes hta;
hta.setPen( QPen( Qt::red ) );
// let the header resize itself
// together with the widget.
// so-called relative size
Measure m( 35.0 );
m.setRelativeMode( header->autoReferenceArea(),
KChartEnums::MeasureOrientationMinimum );
hta.setFontSize( m );
// min font size
m.setValue( 3.0 );
m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
hta.setMinimalFontSize( m );
header->setTextAttributes( hta );
// Configure the Header's Background
BackgroundAttributes hba;
hba.setBrush( Qt::white );
hba.setVisible( true );
header->setBackgroundAttributes( hba );
// Configure the header Frame attributes
FrameAttributes hfa;
hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) );
hfa.setPadding( 2 );
hfa.setVisible( true );
header->setFrameAttributes( hfa );
// diagram->coordinatePlane returns an abstract plane one.
// if we want to specify the orientation we need to cast
// as follow
CartesianCoordinatePlane* plane = static_cast
( diagram->coordinatePlane() );
/* Configure grid steps and pen */
// Vertical
GridAttributes gv ( plane->gridAttributes( Qt::Vertical ) );
// Configure a grid pen
// I know it is horrible
// just for demo'ing
QPen gridPen( Qt::gray );
gridPen.setWidth( 2 );
gv.setGridPen( gridPen );
// Configure a sub-grid pen
QPen subGridPen( Qt::darkGray );
subGridPen.setStyle( Qt::DotLine );
gv.setSubGridPen( subGridPen );
// Display a blue zero line
gv.setZeroLinePen( QPen( Qt::blue ) );
// change step and substep width
// or any of those.
gv.setGridStepWidth( 1.0 );
gv.setGridSubStepWidth( 0.5 );
gv.setGridVisible( true );
gv.setSubGridVisible( true );
// Horizontal
GridAttributes gh = plane->gridAttributes( Qt::Horizontal );
gh.setGridPen( gridPen );
gh.setGridStepWidth( 0.5 );
gh.setSubGridPen( subGridPen );
gh.setGridSubStepWidth( 0.1 );
plane->setGridAttributes( Qt::Vertical, gv );
plane->setGridAttributes( Qt::Horizontal, gh );
// Data Values Display and position
const int colCount = diagram->model()->columnCount(diagram->rootIndex());
for ( int iColumn = 0; iColumndataValueAttributes( iColumn ) );
RelativePosition pos ( a.position( true ) );
pos.setAlignment( Qt::AlignRight );
a.setPositivePosition( pos );
QBrush brush( diagram->brush( iColumn ) );
TextAttributes ta( a.textAttributes() );
ta.setRotation( 0 );
ta.setFont( QFont( "Comic", 10 ) );
ta.setPen( QPen( brush.color() ) );
ta.setVisible( true );
a.setVisible( true );
a.setTextAttributes( ta );
diagram->setDataValueAttributes( iColumn, a );
}
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
m_chart.setGlobalLeadingRight( 20 );
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
QPixmap pixmap;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Grids/PolarGrid/mainwindow.h b/examples/Grids/PolarGrid/mainwindow.h
index 9afc193..d3bd7d1 100644
--- a/examples/Grids/PolarGrid/mainwindow.h
+++ b/examples/Grids/PolarGrid/mainwindow.h
@@ -1,74 +1,74 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class PolarDiagram;
class PolarCoordinatePlane;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
// start position of circular grid
void on_startPositionSB_valueChanged( double pos );
void on_startPositionSL_valueChanged( int pos );
// show grid
void on_circularGridCB_toggled( bool toggle );
void on_sagittalGridCB_toggled( bool toggle );
/* planned for future release:
// show axes
void on_circularAxisCB_toggled( bool toggle );
void on_sagittalAxisCB_toggled( bool toggle );
*/
private:
void initKChartClasses();
void wireUpKChartClasses();
void setItemModelData();
// For a change we do not use our special TableModel here,
// but we just use the standard model that comes with Qt.
QStandardItemModel m_model;
KChart::Chart* m_chart;
KChart::PolarDiagram* m_diagram;
KChart::PolarCoordinatePlane* m_polarPlane;
int m_currentFactor;
int m_currentDirection;
int m_currentSlice;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/HeadersFooters/Advanced/mainwindow.h b/examples/HeadersFooters/Advanced/mainwindow.h
index 4eed45b..24b0692 100644
--- a/examples/HeadersFooters/Advanced/mainwindow.h
+++ b/examples/HeadersFooters/Advanced/mainwindow.h
@@ -1,61 +1,61 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include "ui_mainwindow.h"
#include "ui_addheaderdialog.h"
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class LineDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_addHeaderPB_clicked();
void on_editHeaderPB_clicked();
void on_removeHeaderPB_clicked();
void on_headersTV_itemSelectionChanged();
private:
void setupAddHeaderDialog( QDialog* dlg,
Ui::AddHeaderDialog& conf ) const;
KChart::Chart* m_chart;
TableModel m_model;
KChart::DatasetProxyModel* m_datasetProxy;
KChart::LineDiagram* m_lines;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/HeadersFooters/HeadersFootersParameters/main.cpp b/examples/HeadersFooters/HeadersFootersParameters/main.cpp
index 6551843..f81bdd5 100644
--- a/examples/HeadersFooters/HeadersFootersParameters/main.cpp
+++ b/examples/HeadersFooters/HeadersFootersParameters/main.cpp
@@ -1,106 +1,106 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 3; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+1 * column) );
}
}
BarDiagram* diagram = new BarDiagram;
diagram->setModel(&m_model);
m_chart.coordinatePlane()->replaceDiagram(diagram);
// Add at one Header and set it up
HeaderFooter* header = new HeaderFooter( &m_chart );
header->setPosition( Position::North );
header->setText( "A Simple Bar Chart" );
m_chart.addHeaderFooter( header );
// Configure the Header text attributes
TextAttributes hta;
hta.setPen( QPen( Qt::blue ) );
// let the header resize itself
// together with the widget.
// so-called relative size
Measure m( 35.0 );
m.setRelativeMode( header->autoReferenceArea(), KChartEnums::MeasureOrientationMinimum );
hta.setFontSize( m );
// min font size
m.setValue( 3.0 );
m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
hta.setMinimalFontSize( m );
header->setTextAttributes( hta );
// Configure the header Background attributes
BackgroundAttributes hba;
hba.setBrush( Qt::white );
hba.setVisible( true );
header->setBackgroundAttributes( hba );
// Configure the header Frame attributes
FrameAttributes hfa;
hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) );
hfa.setVisible( true );
header->setFrameAttributes( hfa );
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
m_chart.setGlobalLeadingTop( 10 );
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Legends/LegendAdvanced/derivedaddlegenddialog.h b/examples/Legends/LegendAdvanced/derivedaddlegenddialog.h
index b9a9c96..fd2c5d3 100644
--- a/examples/Legends/LegendAdvanced/derivedaddlegenddialog.h
+++ b/examples/Legends/LegendAdvanced/derivedaddlegenddialog.h
@@ -1,33 +1,33 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef DERIVEDADDLEGENDDIALOG_H
#define DERIVEDADDLEGENDDIALOG_H
#include "ui_addlegenddialog.h"
class DerivedAddLegendDialog : public QDialog, public Ui::AddLegendDialog
{
Q_OBJECT
public:
- DerivedAddLegendDialog( QWidget* parent = 0 );
+ DerivedAddLegendDialog( QWidget* parent = nullptr );
};
#endif // DERIVEDADDLEGENDDIALOG_H
diff --git a/examples/Legends/LegendAdvanced/mainwindow.h b/examples/Legends/LegendAdvanced/mainwindow.h
index 9d2e0ae..8f509ff 100644
--- a/examples/Legends/LegendAdvanced/mainwindow.h
+++ b/examples/Legends/LegendAdvanced/mainwindow.h
@@ -1,60 +1,60 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include "ui_mainwindow.h"
#include "derivedaddlegenddialog.h"
#include
namespace KChart {
class Chart;
class LineDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_addLegendPB_clicked();
void on_editLegendPB_clicked();
void on_removeLegendPB_clicked();
void on_legendsTV_itemSelectionChanged();
private:
void initAddLegendDialog( DerivedAddLegendDialog& conf,
Qt::Alignment alignment ) const;
KChart::Chart* m_chart;
TableModel m_model;
KChart::LineDiagram* m_lines;
QMap alignmentMap;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Legends/LegendParameters/main.cpp b/examples/Legends/LegendParameters/main.cpp
index d4e5658..1021fba 100644
--- a/examples/Legends/LegendParameters/main.cpp
+++ b/examples/Legends/LegendParameters/main.cpp
@@ -1,132 +1,132 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 3; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+1 * column) );
}
}
BarDiagram* diagram = new BarDiagram;
diagram->setModel(&m_model);
m_chart.coordinatePlane()->replaceDiagram(diagram);
// Add at one legend and set it up
Legend* legend = new Legend( diagram, &m_chart );
legend->setPosition( Position::North );
legend->setAlignment( Qt::AlignCenter );
legend->setShowLines( true );
legend->setSpacing( 5 );
legend->setTitleText( tr( "Legend" ) );
legend->setOrientation( Qt::Horizontal );
m_chart.addLegend( legend );
// Configure the items markers
MarkerAttributes lma ( legend->markerAttributes( 0 ) );
lma.setMarkerStyle( MarkerAttributes::MarkerDiamond );
legend->setMarkerAttributes( 0, lma );
lma.setMarkerStyle( MarkerAttributes::MarkerCircle );
legend->setMarkerAttributes( 1, lma );
// Configure Legend Title and labels
legend->setTitleText( "Bars" );
legend->setText( 0, "Series 1" );
legend->setText( 1, "Series 2" );
legend->setText( 2, "Series 3" );
// adjust the legend item's font:
TextAttributes lta( legend->textAttributes() );
lta.setPen( QPen( Qt::darkGray ) );
Measure me( lta.fontSize() );
me.setValue( me.value() * 1.5 );
lta.setFontSize( Measure( 9, KChartEnums::MeasureCalculationModeAbsolute ) );
legend->setTextAttributes( lta );
// adjust the legend title's font:
lta = legend->titleTextAttributes();
lta.setPen( QPen( Qt::darkGray ) );
me = lta.fontSize();
me.setValue( me.value() * 1.5 );
lta.setFontSize( me );
legend->setTitleTextAttributes( lta );
// Configure a pen to surround
// the markers with a border
QPen markerPen;
markerPen.setColor( Qt::darkGray );
markerPen.setWidth( 2 );
// Pending Michel use datasetCount() here as soon
// as it is fixed
for ( uint i = 0; i < /*legend->datasetCount()*/ 3; i++ )
legend->setPen( i, markerPen );
// Add a background to your legend
BackgroundAttributes ba;
ba.setBrush( Qt::white );
ba.setVisible( true );
legend->setBackgroundAttributes( ba );
FrameAttributes fa;
fa.setPen( markerPen );
fa.setVisible( true );
legend->setFrameAttributes( fa );
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
m_chart.setGlobalLeadingTop( 10 );
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Lines/Advanced/mainwindow.h b/examples/Lines/Advanced/mainwindow.h
index 50df12d..4fc8467 100644
--- a/examples/Lines/Advanced/mainwindow.h
+++ b/examples/Lines/Advanced/mainwindow.h
@@ -1,71 +1,71 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class LineDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private:
bool eventFilter(QObject* target, QEvent* event) Q_DECL_OVERRIDE;
private slots:
void on_lineTypeCB_currentIndexChanged( const QString & text );
void on_paintValuesCB_toggled( bool checked );
void on_centerDataPointsCB_toggled( bool checked );
void on_threeDModeCB_toggled( bool checked );
void on_depthSB_valueChanged( int i );
void on_animateAreasCB_toggled( bool checked );
void on_highlightAreaCB_toggled( bool checked );
void on_highlightAreaSB_valueChanged( int i );
void setHighlightArea( int row, int column, int opacity,
bool checked, bool doUpdate );
void on_trackAreasCB_toggled( bool checked );
void on_trackAreasSB_valueChanged( int i );
void setTrackedArea( int column, bool checked, bool doUpdate );
void slot_timerFired();
void on_reverseHorizontalCB_toggled( bool checked );
void on_reverseVerticalCB_toggled( bool checked );
private:
KChart::Chart* m_chart;
KChart::LineDiagram* m_lines;
TableModel m_model;
int m_curRow;
int m_curColumn;
int m_curOpacity;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Lines/AreaPerCell/main.cpp b/examples/Lines/AreaPerCell/main.cpp
index ac00a5a..b4a2b0e 100644
--- a/examples/Lines/AreaPerCell/main.cpp
+++ b/examples/Lines/AreaPerCell/main.cpp
@@ -1,81 +1,81 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0,6, QModelIndex() );
m_model.insertColumns( 0,1, QModelIndex() );
m_model.setData( m_model.index( 0, 0, QModelIndex()), 15);
m_model.setData( m_model.index( 1, 0, QModelIndex()), 11);
m_model.setData( m_model.index( 2, 0, QModelIndex()), 7);
m_model.setData( m_model.index( 3, 0, QModelIndex()), 3);
m_model.setData( m_model.index( 4, 0, QModelIndex()), -1);
m_model.setData( m_model.index( 5, 0, QModelIndex()), -5);
LineDiagram* diagram = new LineDiagram;
diagram->setModel(&m_model);
m_chart.coordinatePlane()->replaceDiagram(diagram);
// paint the areas in a few cells
// using different brushes
LineAttributes la3(diagram->lineAttributes(m_model.index(3,0,QModelIndex())));
la3.setDisplayArea( true );
la3.setTransparency( 150 );
diagram->setBrush(m_model.index(1,0,QModelIndex()),QBrush(Qt::green));
diagram->setLineAttributes( m_model.index( 1, 0, QModelIndex()),la3);
diagram->setBrush(m_model.index(3,0,QModelIndex()),QBrush(Qt::yellow));
diagram->setLineAttributes(m_model.index(3,0,QModelIndex()),la3);
diagram->setBrush(m_model.index(4,0,QModelIndex()),QBrush(Qt::red));
diagram->setLineAttributes(m_model.index(4,0,QModelIndex()),la3);
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Lines/Parameters/main.cpp b/examples/Lines/Parameters/main.cpp
index 7f2deb8..72a615d 100644
--- a/examples/Lines/Parameters/main.cpp
+++ b/examples/Lines/Parameters/main.cpp
@@ -1,124 +1,124 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0,5, QModelIndex() );
m_model.insertColumns( 0,5, QModelIndex() );
qreal increase = 1.15;
for ( int i = 0; i < 5; ++i ) {
increase += 0.06;
for ( int j = 0; j < 5; ++j ) {
m_model.setData( m_model.index( i,j,QModelIndex() ),
( increase + i ) * j * (1.0 + 0.1 * (rand() % 10)) );
}
}
LineDiagram* diagram = new LineDiagram;
diagram->setModel(&m_model);
// Display values
// 1 - Call the relevant attributes
DataValueAttributes dva( diagram->dataValueAttributes() );
// 2 - We want to configure the font and colors
// for the data values text.
TextAttributes ta( dva.textAttributes() );
dva.setDecimalDigits( 2 );
// Append a prefix/suffix to the
// data value labels being displayed
//
//dva.setPrefix( "* " );
dva.setSuffix( " Ohm" );
//rotate if you wish
//ta.setRotation( 0 );
// 3 - Set up your text attributes
ta.setFont( QFont( "Comic") );
ta .setPen( QPen( QColor( Qt::darkGreen ) ) );
ta.setVisible( true );
// font size
Measure me( ta.fontSize() );
me.setValue( me.value() * 0.25 );
ta.setFontSize( me );
// 4 - Assign the text attributes to your
// DataValuesAttributes
dva.setTextAttributes( ta );
dva.setVisible( true );
// 5 - Assign to the diagram
diagram->setDataValueAttributes( dva );
// Set thick line widths for all datasets
for ( int i = 0; i < m_model.rowCount(); ++i ) {
QPen pen( diagram->pen( i ) );
pen.setWidth( 17 );
diagram->setPen( i, pen );
}
// Draw one of the sections of a line differently.
// 1 - Retrieve the pen for the dataset and change
// its style.
// This allow us to keep the line original color.
QPen linePen( diagram->pen( 1 ) );
linePen.setColor( Qt::yellow );
linePen.setWidth( 7 );
linePen.setStyle( Qt::DashLine );
// 2 - Change the Pen for a section within a line
// while assigning it to the diagram
diagram->setPen( m_model.index( 1, 1, QModelIndex() ), linePen );
// 3 - Assign to the chart
m_chart.coordinatePlane()->replaceDiagram(diagram);
m_chart.setGlobalLeadingRight( 50 );
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv )
{
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Lines/PointChart/mainwindow.h b/examples/Lines/PointChart/mainwindow.h
index a38b87b..f5d511e 100644
--- a/examples/Lines/PointChart/mainwindow.h
+++ b/examples/Lines/PointChart/mainwindow.h
@@ -1,62 +1,62 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class LineDiagram;
}
QT_BEGIN_NAMESPACE
class QPainterPath;
QT_END_NAMESPACE
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
~MainWindow();
private slots:
void on_lineTypeCB_currentIndexChanged( const QString & text );
void on_paintValuesCB_toggled( bool checked );
void on_paintMarkersCB_toggled( bool checked );
void on_paintLinesCB_toggled( bool checked );
void on_markersStyleCB_currentIndexChanged( const QString & text );
void on_markersWidthSB_valueChanged( int i );
void on_markersHeightSB_valueChanged( int i);
private:
KChart::Chart* m_chart;
KChart::LineDiagram* m_lines;
TableModel m_model;
QPainterPath* path;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/ModelView/HidingData/mainwindow.h b/examples/ModelView/HidingData/mainwindow.h
index b2b5fad..bf98cf3 100644
--- a/examples/ModelView/HidingData/mainwindow.h
+++ b/examples/ModelView/HidingData/mainwindow.h
@@ -1,56 +1,56 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
QT_END_NAMESPACE
namespace KChart {
class Chart;
class LineDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_showDataset1CB_toggled( bool checked );
void on_showDataset2CB_toggled( bool checked );
void on_showDataset3CB_toggled( bool checked );
void setHidden( int dataset, bool hidden );
void openFile(const QString &path);
private:
KChart::Chart * m_chart;
KChart::LineDiagram * m_lines;
QAbstractItemModel * m_model;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/NoValues/mainwindow.cpp b/examples/NoValues/mainwindow.cpp
index f482fd9..bdc10b1 100644
--- a/examples/NoValues/mainwindow.cpp
+++ b/examples/NoValues/mainwindow.cpp
@@ -1,125 +1,125 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class EmptyModel : public QAbstractItemModel
{
public:
- EmptyModel( QObject* parent = 0 )
+ EmptyModel( QObject* parent = nullptr )
: QAbstractItemModel( parent )
{
//qDebug() << "EmptyModel::EmptyModel()";
}
~EmptyModel()
{
//qDebug() << "EmptyModel::~EmptyModel()";
}
int columnCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE
{
Q_UNUSED( parent );
//qDebug() << "EmptyModel::columnCount(...)";
return 0;
}
int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE
{
Q_UNUSED( parent );
//qDebug() << "EmptyModel::rowCount(...)";
return 0;
}
// NOTE: The following method will not be called by KD Chart,
// because the model is returning 0 for columnCount() / rowCount().
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE
{
Q_UNUSED( role );
qDebug() << "EmptyModel::data(" << index.row() << index.column() << ")";
Q_ASSERT_X( false, "EmptyModel::data", "We should not end here..." );
return QVariant();
}
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE
{
Q_UNUSED( row );
Q_UNUSED( column );
Q_UNUSED( parent );
//qDebug() << "EmptyModel::index(" << row << column << ")";
return QModelIndex();
}
QModelIndex parent( const QModelIndex& parent ) const Q_DECL_OVERRIDE
{
Q_UNUSED( parent );
//qDebug() << "EmptyModel::parent(...)";
return QModelIndex();
}
};
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent )
{
QHBoxLayout* chartLayout = new QHBoxLayout( this );
m_chart = new Chart();
m_chart->setGlobalLeading( 5, 5, 5, 5 );
chartLayout->addWidget( m_chart );
m_model = new EmptyModel( this ); // model contains no data at all
// Set up the diagram
m_bars = new LineDiagram();
m_bars->setModel( m_model );
CartesianAxis *xAxis = new CartesianAxis( m_bars );
CartesianAxis *yAxis = new CartesianAxis ( m_bars );
xAxis->setPosition ( KChart::CartesianAxis::Bottom );
yAxis->setPosition ( KChart::CartesianAxis::Left );
xAxis->setTitleText ( "Abscissa axis at the bottom" );
yAxis->setTitleText ( "Ordinate axis at the left side" );
m_bars->addAxis( xAxis );
m_bars->addAxis( yAxis );
m_chart->coordinatePlane()->replaceDiagram( m_bars );
Legend* legend = new Legend( m_bars, m_chart );
legend->setPosition( Position::South );
legend->setAlignment( Qt::AlignCenter );
legend->setShowLines( true );
legend->setTitleText("This is the legend - showing no data either");
legend->setOrientation( Qt::Horizontal );
legend->addDiagram( m_bars );
m_chart->addLegend( legend );
}
diff --git a/examples/NoValues/mainwindow.h b/examples/NoValues/mainwindow.h
index 31d7a96..f2bd402 100644
--- a/examples/NoValues/mainwindow.h
+++ b/examples/NoValues/mainwindow.h
@@ -1,48 +1,48 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
namespace KChart {
class Chart;
class BarDiagram;
class LineDiagram;
}
class MainWindow : public QWidget
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
virtual ~MainWindow() { }
private:
KChart::Chart* m_chart;
KChart::LineDiagram* m_bars;
QAbstractItemModel* m_model;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Pie/Advanced/mainwindow.h b/examples/Pie/Advanced/mainwindow.h
index baa5992..48dcced 100644
--- a/examples/Pie/Advanced/mainwindow.h
+++ b/examples/Pie/Advanced/mainwindow.h
@@ -1,71 +1,71 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE
namespace KChart {
class Chart;
class PieDiagram;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
// start position
void on_startPositionSB_valueChanged( double pos );
void on_startPositionSL_valueChanged( int pos );
// explode
void on_explodeSubmitPB_clicked();
void on_animateExplosionCB_toggled( bool toggle );
void setExplodeFactor( int column, qreal value );
// animation
void slotNextFrame();
// 3D
void on_threeDGB_toggled( bool toggle );
void on_threeDFactorSB_valueChanged( int factor );
private:
KChart::Chart* m_chart;
TableModel m_model;
KChart::PieDiagram* m_pie;
QTimer* m_timer;
int m_currentFactor;
int m_currentDirection;
int m_currentSlice;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Pie/Parameters/main.cpp b/examples/Pie/Parameters/main.cpp
index 74e02ac..2176ccf 100644
--- a/examples/Pie/Parameters/main.cpp
+++ b/examples/Pie/Parameters/main.cpp
@@ -1,132 +1,132 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 1, QModelIndex() );
m_model.insertColumns( 0, 6, QModelIndex() );
for (int row = 0; row < 1; ++row) {
for (int column = 0; column < 6; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+1 * column+1) );
// this shows the index as static comments:
// m_model.setData(index, QString("row: %1, column: %2").arg(row).arg(column), KChart::CommentRole);
// this shows the index as volatile tooltips:
m_model.setData(index, QString("row: %1, column: %2").arg(row).arg(column), Qt::ToolTipRole);
}
}
// We need a Polar plane for the Pie type
PolarCoordinatePlane* polarPlane = new PolarCoordinatePlane( &m_chart );
// replace the default Cartesian plane with
// our Polar plane
m_chart.replaceCoordinatePlane( polarPlane );
// assign the model to our pie diagram
PieDiagram* diagram = new PieDiagram;
diagram->setModel(&m_model);
// Configure some Pie specifical attributes
// explode a section
PieAttributes pa( diagram->pieAttributes() );
pa.setExplodeFactor( 0.1 );
// Assign the attributes
// to the diagram
diagram->setPieAttributes( 1, pa );
// Configure a generic attribute
// available to all chart types
QPen sectionPen;
sectionPen.setWidth( 5 );
sectionPen.setStyle( Qt::DashLine );
sectionPen.setColor( Qt::magenta );
diagram->setPen( 1, sectionPen );
// Display data values
// not implemented yet - disable for now
const QFont font(QFont( "Comic", 10 ));
const int colCount = diagram->model()->columnCount();
for ( int iColumn = 0; iColumndataValueAttributes( iColumn ) );
TextAttributes ta( dva.textAttributes() );
ta.setRotation( 0 );
ta.setFont( font );
ta .setPen( QPen( Qt::darkBlue ) );
ta.setVisible( true );
dva.setTextAttributes( ta );
BackgroundAttributes back( dva.backgroundAttributes() );
back.setBrush( QBrush( QColor(255,0,0) ) );
back.setVisible( true );
dva.setBackgroundAttributes( back );
RelativePosition posPos( dva.positivePosition() );
posPos.setReferencePosition( KChart::Position::North );
posPos.setAlignment( Qt::AlignCenter );
posPos.setHorizontalPadding( KChart::Measure(0.0) );
posPos.setVerticalPadding( KChart::Measure(-1000.0) );
dva.setPositivePosition( posPos );
dva.setVisible( true );
diagram->setDataValueAttributes( iColumn, dva);
}
// Assign our diagram to the Chart
m_chart.coordinatePlane()->replaceDiagram(diagram);
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Plane/AdjustedBoundaries/main.cpp b/examples/Plane/AdjustedBoundaries/main.cpp
index 20a20f6..458c4ce 100644
--- a/examples/Plane/AdjustedBoundaries/main.cpp
+++ b/examples/Plane/AdjustedBoundaries/main.cpp
@@ -1,204 +1,204 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class ChartWidget : public QWidget {
Q_OBJECT
public:
- explicit ChartWidget(QWidget* parent=0)
+ explicit ChartWidget(QWidget* parent = nullptr)
: QWidget(parent)
{
m_model.insertRows( 0, 2, QModelIndex() );
m_model.insertColumns( 0, 3, QModelIndex() );
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 3; ++column) {
QModelIndex index = m_model.index(row, column, QModelIndex());
m_model.setData(index, QVariant(row+10 * column) );
}
}
BarDiagram* diagram = new BarDiagram;
diagram->setModel(&m_model);
/*
* AXIS
*/
CartesianAxis *xAxis = new CartesianAxis( diagram );
CartesianAxis *yAxis = new CartesianAxis ( diagram );
xAxis->setPosition ( KChart::CartesianAxis::Bottom );
yAxis->setPosition ( KChart::CartesianAxis::Left );
diagram->addAxis( xAxis );
diagram->addAxis( yAxis );
/*
* AXIS LABELS
*/
// set the following to 0, to see the default Abscissa labels
// (== X headers, as read from the data file)
#if 1
QStringList months;
months << "January" << "February";
xAxis->setLabels( months );
QStringList shortMonths;
shortMonths << "Jan" << "Feb";
xAxis->setShortLabels( shortMonths );
#endif
/*
* DATA VALUES SETTINGS
*/
// We set the DataValueAttributes on a per-column basis here,
// because we want the texts to be printed in different
//colours - according to their respective dataset's colour.
const QFont font(QFont( "Comic", 10 ));
const int colCount = diagram->model()->columnCount();
for ( int iColumn = 0; iColumnbrush( iColumn ) );
DataValueAttributes a( diagram->dataValueAttributes( iColumn ) );
TextAttributes ta( a.textAttributes() );
ta.setRotation( 0 );
ta.setFont( font );
ta .setPen( QPen( brush.color() ) );
ta.setVisible( true );
a.setTextAttributes( ta );
a.setSuffix( "%" );
a.setVisible( true );
diagram->setDataValueAttributes( iColumn, a);
}
/*
* VERTICAL RANGE SETTINGS
*/
// m_chart.coordinatePlane() returns an abstract plane.
// We need to cast in order to be able set our own boundaries.
CartesianCoordinatePlane* plane1 =
static_cast (m_chart.coordinatePlane());
plane1->setVerticalRange( QPair( 0.0, 100.0 ) );
plane1->replaceDiagram(diagram);
/*
* HEADER SETTINGS
*/
// Add at one Header and set it up
HeaderFooter* header = new HeaderFooter( &m_chart );
header->setPosition( Position::North );
header->setText( "A Bar Chart with Adjusted Vertical Range" );
m_chart.addHeaderFooter( header );
// Configure the Header text attributes
TextAttributes hta;
hta.setPen( QPen( Qt::red ) );
// let the header resize itself
// together with the widget.
// so-called relative size
Measure m( 35.0 );
m.setRelativeMode( header->autoReferenceArea(),
KChartEnums::MeasureOrientationMinimum );
hta.setFontSize( m );
// min font size
m.setValue( 3.0 );
m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
hta.setMinimalFontSize( m );
header->setTextAttributes( hta );
// Configure the Header's Background
BackgroundAttributes hba;
hba.setBrush( Qt::white );
hba.setVisible( true );
header->setBackgroundAttributes( hba );
// Configure the header Frame attributes
FrameAttributes hfa;
hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) );
hfa.setPadding( 2 );
hfa.setVisible( true );
header->setFrameAttributes( hfa );
/*
* GRIDS SETTINGS
*/
// retrieve your grid attributes
// display grid and sub-grid
GridAttributes ga ( plane1->gridAttributes( Qt::Vertical ) );
// Configure a sub-grid pen
QPen subGridPen( Qt::darkGray );
subGridPen.setStyle( Qt::DotLine );
ga.setSubGridPen( subGridPen );
// change step and substep width
// to fit the boundaries
ga.setGridStepWidth( 10.0 );
ga.setGridSubStepWidth( 5.0 );
ga.setGridVisible( true );
ga.setSubGridVisible( true );
// Assign your grid to the plane
plane1->setGridAttributes( Qt::Vertical, ga );
QVBoxLayout* l = new QVBoxLayout(this);
m_chart.setGlobalLeadingTop( 5 );
l->addWidget(&m_chart);
setLayout(l);
}
private:
Chart m_chart;
QStandardItemModel m_model;
QPixmap pixmap;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Plane/OverlayedPlanes/mainwindow.h b/examples/Plane/OverlayedPlanes/mainwindow.h
index c4f0d77..02655a7 100644
--- a/examples/Plane/OverlayedPlanes/mainwindow.h
+++ b/examples/Plane/OverlayedPlanes/mainwindow.h
@@ -1,62 +1,62 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include
namespace KChart {
class Chart;
class DatasetProxyModel;
class LineDiagram;
class LineAttributes;
class CartesianAxis;
class CartesianCoordinatePlane;
}
class MainWindow : public QWidget, private Ui::MainWindow
{
Q_OBJECT
public:
- MainWindow( QWidget* parent = 0 );
+ MainWindow( QWidget* parent = nullptr );
private slots:
void on_displayGrid1CB_toggled( bool checked );
void on_displayGrid2CB_toggled( bool checked );
private:
void init();
KChart::Chart* m_chart;
TableModel m_model;
TableModel m_model2;
KChart::DatasetProxyModel* m_datasetProxy;
KChart::LineDiagram* m_lines;
KChart::LineDiagram* m_lines2;
KChart::CartesianCoordinatePlane* plane2;
};
#endif /* MAINWINDOW_H */
diff --git a/examples/Plotter/BubbleChart/mainwindow.cpp b/examples/Plotter/BubbleChart/mainwindow.cpp
index 153d998..7349f23 100644
--- a/examples/Plotter/BubbleChart/mainwindow.cpp
+++ b/examples/Plotter/BubbleChart/mainwindow.cpp
@@ -1,160 +1,160 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
static const int nBubbles = 7;
// we display seven bubbles using the following data structure:
// 0: Y
// 1: X
// 2: size
struct DataType{
DataType( qreal x_,
qreal y_,
qreal size_ )
: x(x_)
, y(y_)
, size(size_)
{}
qreal x;
qreal y;
qreal size;
};
static const DataType bubblesData[nBubbles] = {
DataType(0.5, 1.0, 100),
DataType(1.0, 0.5, 60 ),
DataType(1.6, 2.0, 28 ),
DataType(0.7, 0.3, 55 ),
DataType(1.3, 2.0, 95 ),
DataType(2.0, 1.0, 75 ),
DataType(1.4, 1.1, 85 )
};
#define ROLE_SIZE Qt::UserRole + 1
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent ),
- m_model(0)
+ m_model(nullptr)
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
m_chart = new Chart();
chartLayout->addWidget( m_chart );
// Set up the data
initializeDataModel();
// Set up the diagram
m_plotter = new Plotter();
// Register the data model at the diagram
m_plotter->setModel( m_model );
// Add axes to the diagram
CartesianAxis *xAxis = new CartesianAxis( m_plotter );
CartesianAxis *xAxis2 = new CartesianAxis( m_plotter );
CartesianAxis *yAxis = new CartesianAxis ( m_plotter );
CartesianAxis *yAxis2 = new CartesianAxis ( m_plotter );
xAxis->setPosition ( KChart::CartesianAxis::Bottom );
xAxis2->setPosition( KChart::CartesianAxis::Top );
yAxis->setPosition ( KChart::CartesianAxis::Left );
yAxis2->setPosition( KChart::CartesianAxis::Right );
m_plotter->addAxis( xAxis );
m_plotter->addAxis( xAxis2 );
m_plotter->addAxis( yAxis );
m_plotter->addAxis( yAxis2 );
connect( threeDEnabled, SIGNAL(toggled(bool)), this, SLOT(setMarkerAttributes()) );
m_chart->coordinatePlane()->replaceDiagram( m_plotter );
m_chart->setGlobalLeading( 20, 20, 20, 20 );
setMarkerAttributes();
}
void MainWindow::initializeDataModel()
{
m_model = new QStandardItemModel( nBubbles, 2 );
m_model->setHeaderData(0, Qt::Horizontal, tr("Some Bubbles"));
for ( int i=0; i < nBubbles; ++i ) {
const QModelIndex indexX = m_model->index(i, 0);
const QModelIndex indexY = m_model->index(i, 1);
m_model->setData(indexX, QVariant( bubblesData[i].x ), Qt::DisplayRole);
m_model->setData(indexY, QVariant( bubblesData[i].y ), Qt::DisplayRole);
m_model->setData(indexY, bubblesData[i].size, ROLE_SIZE );
}
}
void MainWindow::setMarkerAttributes()
{
// disable the connecting line
KChart::LineAttributes la = m_plotter->lineAttributes();
la.setVisible(false);
m_plotter->setLineAttributes(la);
for ( int iRow = 0; iRowmodel()->index(iRow, 0);
const QModelIndex indexY = m_plotter->model()->index(iRow, 1);
DataValueAttributes dva( m_plotter->dataValueAttributes( indexX ) );
dva.setVisible( true );
TextAttributes ta( dva.textAttributes() );
ta.setVisible( false );
MarkerAttributes ma( dva.markerAttributes() );
ma.setVisible( true );
ma.setMarkerStyle( MarkerAttributes::MarkerCircle );
ma.setThreeD( threeDEnabled->isChecked() );
// set the size
const qreal d = m_model->data( indexY, ROLE_SIZE ).toReal();
ma.setMarkerSize( QSizeF(d,d) );
RelativePosition pos( dva.positivePosition() );
pos.setAlignment( Qt::AlignCenter );
pos.setHorizontalPadding(0);
dva.setPositivePosition( pos );
dva.setMarkerAttributes( ma );
dva.setTextAttributes( ta );
// note: The KChart::Plotter looks at the X cell
// for data value attributes,
// any attrs set at the Y cell are ignored.
m_plotter->setDataValueAttributes( indexX, dva );
}
m_chart->update();
}
diff --git a/examples/Plotter/BubbleChart/mainwindow.h b/examples/Plotter/BubbleChart/mainwindow.h
index 31c10b3..53547ff 100644
--- a/examples/Plotter/BubbleChart/mainwindow.h
+++ b/examples/Plotter/BubbleChart/mainwindow.h
@@ -1,53 +1,53 @@
/**
* Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
*
* This file is part of the KD Chart library.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see