diff --git a/examples/Axis/Labels/mainwindow.cpp b/examples/Axis/Labels/mainwindow.cpp
index 8b6ced5..dbafb7d 100644
--- a/examples/Axis/Labels/mainwindow.cpp
+++ b/examples/Axis/Labels/mainwindow.cpp
@@ -1,127 +1,127 @@
/**
* 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 "AdjustedCartesianAxis.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent )
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( m_chartFrame );
m_chart = new KChart::Chart;
chartLayout->addWidget( m_chart );
m_model.loadFromCSV( ":/data" );
// Set up the diagram
m_lines = new KChart::LineDiagram();
m_lines->setModel( &m_model );
m_xAxis = new KChart::CartesianAxis( m_lines );
KChart::TextAttributes ta( m_xAxis->textAttributes() );
AdjustedCartesianAxis *yAxis = new AdjustedCartesianAxis( m_lines );
yAxis->setBounds( 3, 6 );
m_xAxis->setPosition( KChart::CartesianAxis::Bottom );
yAxis->setPosition( KChart::CartesianAxis::Left );
// set the following to 0, to see the default Abscissa labels (== X headers, as read from the data file)
#if 1
QStringList daysOfWeek;
daysOfWeek << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday" << "Sunday";
m_xAxis->setLabels( daysOfWeek );
//QStringList shortDays;
//shortDays << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
//m_xAxis->setShortLabels( shortDays );
#endif
// Use HTML for drawing the text in the axis labels.
#if 0
QStringList htmlStyles;
htmlStyles << "Bold" << "Italic" << "Underline" << "Red";
m_xAxis->setLabels( htmlStyles );
ta.setTextDocument(new QTextDocument);
#endif
// Illustration of custom ticks
QList ticks;
ticks.append( 0.5 );
ticks.append( 3.5 );
ticks.append( 4.2 );
ticks.append( 6.5 );
m_xAxis->setCustomTicks(ticks);
yAxis->setCustomTicks(ticks);
// rotate abscissa labels by -60 degrees:
ta.setRotation( -60 );
m_xAxis->setTextAttributes( ta );
m_lines->addAxis( m_xAxis );
m_lines->addAxis( yAxis );
m_chart->coordinatePlane()->replaceDiagram( m_lines );
// Set up the legend
m_xAxis->setCustomTickLength( 11 );
yAxis->setCustomTickLength( 11 );
m_legend = new KChart::Legend( m_lines, m_chart );
m_legend->setPosition( KChart::Position::East );
m_legend->setAlignment( Qt::AlignTop );
m_chart->addLegend( m_legend );
- connect( m_annotations, SIGNAL( toggled( bool ) ), SLOT( annotationsToggled( bool ) ) );
- connect( m_linesOnAnnotations, SIGNAL( toggled( bool ) ), SLOT( gridLinesOnAnnotationsToggled( bool ) ) );
+ connect( m_annotations, SIGNAL(toggled(bool)), SLOT(annotationsToggled(bool)) );
+ connect( m_linesOnAnnotations, SIGNAL(toggled(bool)), SLOT(gridLinesOnAnnotationsToggled(bool)) );
}
void MainWindow::annotationsToggled( bool showAnnotations )
{
QMap< qreal, QString > annotations;
if ( showAnnotations ) {
// set custom axis labels at custom positions
annotations[ 0.5 ] = "Left";
annotations[ 3.5 ] = "Center";
annotations[ 4.2 ] = "Off Center";
annotations[ 6.5 ] = "Right";
}
m_xAxis->setAnnotations( annotations );
m_chart->update();
}
void MainWindow::gridLinesOnAnnotationsToggled( bool onAnnotations )
{
// Draw grid lines where the annotations are
KChart::CartesianCoordinatePlane* plane =
static_cast< KChart::CartesianCoordinatePlane* >( m_chart->coordinatePlane() );
KChart::GridAttributes ga = plane->gridAttributes( Qt::Horizontal );
ga.setLinesOnAnnotations( onAnnotations );
plane->setGridAttributes( Qt::Horizontal, ga );
m_chart->update();
}
diff --git a/examples/DrawIntoPainter/framewidget.cpp b/examples/DrawIntoPainter/framewidget.cpp
index b134112..dca4bf4 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 )
{
// 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() ) );
+ 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/mainwindow.cpp b/examples/DrawIntoPainter/mainwindow.cpp
index 0dd6258..a4d0e58 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() ) ) ;
+ 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 )
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/Gantt/legend_example/entrydialog.cpp b/examples/Gantt/legend_example/entrydialog.cpp
index 939a95b..08c3096 100644
--- a/examples/Gantt/legend_example/entrydialog.cpp
+++ b/examples/Gantt/legend_example/entrydialog.cpp
@@ -1,175 +1,175 @@
/**
* 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 "entrydialog.h"
#include "ui_entrydialog.h"
#include
#include
#include
#include
#include
Q_DECLARE_METATYPE( QPersistentModelIndex )
EntryDialog::EntryDialog( const QAbstractItemModel* model, QWidget* parent, Qt::WindowFlags f )
: QDialog( parent, f ),
indexList( QList() ),
ui( new Ui::EntryDialog )
{
ui->setupUi( this );
this->model = model;
init();
}
void EntryDialog::init()
{
ui->type->addItem( tr( "Event" ), KGantt::TypeEvent );
ui->type->addItem( tr( "Task" ), KGantt::TypeTask );
ui->type->addItem( tr( "Summary" ), KGantt::TypeSummary );
ui->type->addItem( tr( "Multi" ), KGantt::TypeMulti );
for (int row = 0; row < model->rowCount(); ++row )
addDependItem( model, model->index( row, 0 ) );
- connect( ui->startDate, SIGNAL( dateTimeChanged( const QDateTime& ) ), this, SLOT( updateEndDate( const QDateTime& ) ) );
- connect( ui->readOnly, SIGNAL( toggled( bool ) ), this, SLOT( disableEditing( bool ) ) );
- connect( ui->type, SIGNAL( currentIndexChanged( int ) ), this, SLOT( typeChanged( int ) ) );
+ connect( ui->startDate, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateEndDate(QDateTime)) );
+ connect( ui->readOnly, SIGNAL(toggled(bool)), this, SLOT(disableEditing(bool)) );
+ connect( ui->type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int)) );
ui->startDate->setDateTime( QDateTime::currentDateTime() );
typeChanged( 0 );
}
void EntryDialog::initFrom( const QModelIndex & index, const KGantt::ConstraintModel* constraintModel )
{
int row = index.row();
const QModelIndex parent = index.parent();
ui->name->setText( model->data( model->index( row, 0, parent ) ).toString() );
ui->legend->setText( model->data( model->index( row, 5, parent ) ).toString() );
int idx = ui->type->findData( model->data( model->index( row, 1, parent ) ).toInt() );
ui->type->setCurrentIndex( idx );
ui->startDate->setDateTime( model->data( model->index( row, 2, parent ), KGantt::StartTimeRole ).toDateTime() );
ui->endDate->setDateTime( model->data( model->index( row, 3, parent ), KGantt::EndTimeRole ).toDateTime() );
ui->completion->setValue( model->data( model->index( row, 4, parent ) ).toInt() );
ui->readOnly->setChecked( !(model->flags( model->index( row, 0, parent ) ) & Qt::ItemIsEditable) );
QList constraints = constraintModel->constraintsForIndex( model->index( row, 0, parent ) );
if ( constraints.isEmpty() )
return;
QModelIndex constraintIndex;
for ( int i = 0; i < constraints.size(); ++i ) {
KGantt::Constraint constraint = constraints[i];
if ( constraint.endIndex() == index ) {
constraintIndex = constraint.startIndex();
break;
}
}
if ( !constraintIndex.isValid() )
return;
ui->depends->setCurrentIndex( indexList.indexOf( constraintIndex ) + 1 );
}
void EntryDialog::addDependItem( const QAbstractItemModel* model, const QModelIndex & index, int indent)
{
indexList << QPersistentModelIndex( index );
QString str = QString( "%1%2" ).arg( QString().fill( ' ', indent ) ).arg( model->data( index ).toString() );
ui->depends->addItem( str );
for (int row = 0; row < model->rowCount( index ); ++row )
addDependItem( model, model->index( row, 0, index ), indent + 2 );
}
QString EntryDialog::name() const
{
return ui->name->text();
}
int EntryDialog::type() const
{
return ui->type->itemData( ui->type->currentIndex() ).toInt();
}
QDateTime EntryDialog::startDate() const
{
return ui->startDate->dateTime();
}
QDateTime EntryDialog::endDate() const
{
return ui->endDate->dateTime();
}
int EntryDialog::completion() const
{
return ui->completion->value();
}
void EntryDialog::updateEndDate(const QDateTime & startDate)
{
ui->endDate->setMinimumDate( startDate.date() );
ui->endDate->setMinimumTime( startDate.time() );
}
bool EntryDialog::readOnly() const
{
return ui->readOnly->isChecked();
}
QModelIndex EntryDialog::depends() const
{
if ( ui->depends->currentIndex() == 0 )
return QModelIndex();
QPersistentModelIndex index = indexList[ ui->depends->currentIndex() - 1 ];
if ( index.isValid() )
return index;
return QModelIndex();
}
QString EntryDialog::legend() const
{
return ui->legend->text();
}
void EntryDialog::disableEditing(bool disable)
{
ui->name->setEnabled( !disable );
ui->type->setEnabled( !disable );
ui->completion->setEnabled( !disable );
ui->startDate->setEnabled( !disable );
ui->endDate->setEnabled( !disable );
ui->depends->setEnabled( !disable );
}
void EntryDialog::typeChanged(int index)
{
if ( ! index ) {
ui->label_EndDate->hide();
ui->endDate->hide();
} else {
ui->label_EndDate->show();
ui->endDate->show();
}
}
diff --git a/examples/Gantt/legend_example/mainwindow.cpp b/examples/Gantt/legend_example/mainwindow.cpp
index 0364a86..3a42068 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 ),
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( const QPoint& ) ),
- this, SLOT( showContextMenu( const QPoint& ) ) );
- connect( ui->ganttView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ),
- this, SLOT( enableActions( const QItemSelection& ) ) );
+ 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() ) );
+ 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() ) );
+ 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() ) );
+ 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() ) );
+ connect( zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()) );
zoomFitAction = new QAction( tr( "Zoom to Fit" ), this );
- connect( zoomFitAction, SIGNAL( triggered() ), this, SLOT( zoomFit() ) );
+ 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/project/mainwindow.cpp b/examples/Gantt/project/mainwindow.cpp
index 4ae115b..d408fc4 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 );
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 );
/*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) {
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() ) );
+ 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() ) );
+ 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->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() ) );
+ 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() ) );
+ 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/LeveyJennings/Simple/main.cpp b/examples/LeveyJennings/Simple/main.cpp
index 79732da..6067ca7 100644
--- a/examples/LeveyJennings/Simple/main.cpp
+++ b/examples/LeveyJennings/Simple/main.cpp
@@ -1,198 +1,198 @@
/**
* 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
class SelectionAnimator : public QObject
{
Q_OBJECT
public:
SelectionAnimator( QAbstractItemView* view )
: QObject( view ),
view( view )
{
QTimer* const t = new QTimer( this );
- connect( t, SIGNAL( timeout() ), this, SLOT( animate() ) );
+ connect( t, SIGNAL(timeout()), this, SLOT(animate()) );
t->start( 1000 );
}
protected Q_SLOTS:
void animate()
{
const int row = ( view->selectionModel()->currentIndex().row() + 1 ) % view->model()->rowCount();
view->selectionModel()->setCurrentIndex( view->model()->index( row, 0 ), QItemSelectionModel::ClearAndSelect );
}
private:
QAbstractItemView* const view;
};
#include "main.moc"
int main( int argc, char** argv )
{
QApplication app( argc, argv );
QStandardItemModel model( 14, 6 );
model.setHeaderData( 0, Qt::Horizontal, QObject::tr( "Lot" ) );
model.setHeaderData( 1, Qt::Horizontal, QObject::tr( "Value" ) );
model.setHeaderData( 2, Qt::Horizontal, QObject::tr( "OK" ) );
model.setHeaderData( 3, Qt::Horizontal, QObject::tr( "Date/Time" ) );
model.setHeaderData( 4, Qt::Horizontal, QObject::tr( "Mean Value" ) );
model.setHeaderData( 5, Qt::Horizontal, QObject::tr( "Standard Deviation" ) );
// Lot 1
model.setData( model.index( 0, 0 ), 1 ); // lot number
model.setData( model.index( 0, 1 ), 210 ); // value
model.setData( model.index( 0, 2 ), true ); // QC value ok/not ok
model.setData( model.index( 0, 3 ), QDateTime::fromString( "2007-07-06T09:00:00", Qt::ISODate ) );
model.setData( model.index( 1, 0 ), 1 );
model.setData( model.index( 1, 1 ), 9.5 );
model.setData( model.index( 1, 2 ), true );
model.setData( model.index( 1, 3 ), QDateTime::fromString( "2007-07-06T21:00:00", Qt::ISODate ) );
model.setData( model.index( 1, 4 ), 7.5 );
model.setData( model.index( 1, 5 ), 1.0 );
model.setData( model.index( 2, 0 ), 1 );
model.setData( model.index( 2, 1 ), 200 );
model.setData( model.index( 2, 2 ), true );
model.setData( model.index( 2, 3 ), QDateTime::fromString( "2007-07-07T09:00:00", Qt::ISODate ) );
// This values should be missing (lot is needed anyway)
model.setData( model.index( 3, 0 ), 1 );
model.setData( model.index( 3, 3 ), QDateTime::fromString( "2007-07-07T21:00:00", Qt::ISODate ) );
model.setData( model.index( 4, 0 ), 1 );
model.setData( model.index( 4, 1 ), 180 );
model.setData( model.index( 4, 2 ), true );
model.setData( model.index( 4, 3 ), QDateTime::fromString( "2007-07-08T09:00:00", Qt::ISODate ) );
// Lot 2
model.setData( model.index( 5, 0 ), 2 );
model.setData( model.index( 5, 1 ), 210 );
model.setData( model.index( 5, 2 ), true );
model.setData( model.index( 5, 3 ), QDateTime::fromString( "2007-07-08T21:00:00", Qt::ISODate ) );
model.setData( model.index( 6, 0 ), 2 );
model.setData( model.index( 6, 1 ), 195 );
model.setData( model.index( 6, 2 ), true );
model.setData( model.index( 6, 3 ), QDateTime::fromString( "2007-07-09T09:00:00", Qt::ISODate ) );
// this value is not OK
model.setData( model.index( 7, 0 ), 2 );
model.setData( model.index( 7, 1 ), 200 );
model.setData( model.index( 7, 2 ), false );
model.setData( model.index( 7, 3 ), QDateTime::fromString( "2007-07-09T21:00:00", Qt::ISODate ) );
model.setData( model.index( 8, 0 ), 2 );
model.setData( model.index( 8, 1 ), 210 );
model.setData( model.index( 8, 2 ), true );
model.setData( model.index( 8, 3 ), QDateTime::fromString( "2007-07-10T09:00:00", Qt::ISODate ) );
model.setData( model.index( 9, 0 ), 2 );
model.setData( model.index( 9, 1 ), 180 );
model.setData( model.index( 9, 2 ), true );
model.setData( model.index( 9, 3 ), QDateTime::fromString( "2007-07-10T21:00:00", Qt::ISODate ) );
// this values is completely out of bounds and therefore cut/truncated
model.setData( model.index( 10,0 ), 2 );
model.setData( model.index( 10,1 ), 290 );
model.setData( model.index( 10,2 ), true );
model.setData( model.index( 10,3 ), QDateTime::fromString( "2007-07-11T09:00:00", Qt::ISODate ) );
// this value is ok again
model.setData( model.index( 11,0 ), 2 );
model.setData( model.index( 11,1 ), 210 );
model.setData( model.index( 11,2 ), true );
model.setData( model.index( 11,3 ), QDateTime::fromString( "2007-07-11T21:00:00", Qt::ISODate ) );
model.setData( model.index( 12,0 ), 2 );
model.setData( model.index( 12,1 ), 205 );
model.setData( model.index( 12,2 ), true );
model.setData( model.index( 12,3 ), QDateTime::fromString( "2007-07-12T09:00:00", Qt::ISODate ) );
model.setData( model.index( 13,0 ), 2 );
model.setData( model.index( 13,1 ), 204 );
model.setData( model.index( 13,2 ), true );
model.setData( model.index( 13,3 ), QDateTime::fromString( "2007-07-12T21:00:00", Qt::ISODate ) );
KChart::Chart* chart = new KChart::Chart();
KChart::LeveyJenningsDiagram* diagram = new KChart::LeveyJenningsDiagram;
diagram->setModel( &model );
diagram->setExpectedMeanValue( 200 );
diagram->setExpectedStandardDeviation( 20 );
KChart::LeveyJenningsCoordinatePlane* plane = new KChart::LeveyJenningsCoordinatePlane;
chart->replaceCoordinatePlane( plane );
plane->replaceDiagram( diagram );
/*diagram->setLotChangedSymbolPosition( Qt::AlignBottom );
diagram->setSensorChangedSymbolPosition( Qt::AlignTop );
diagram->setFluidicsPackChangedSymbolPosition( Qt::AlignTop );*/
//diagram->setScanLinePen( QPen( Qt::green ) );
//diagram->setSymbol( KChart::LeveyJenningsDiagram::NotOkDataPoint,
// diagram->symbol( KChart::LeveyJenningsDiagram::OkDataPoint ) );
diagram->setFluidicsPackChanges( QVector< QDateTime >() << QDateTime::fromString( "2007-07-11T15:00:00", Qt::ISODate ) );
diagram->setSensorChanges( QVector< QDateTime >() << QDateTime::fromString( "2007-07-10T11:00:00", Qt::ISODate ) );
KChart::LeveyJenningsAxis* axis = new KChart::LeveyJenningsAxis( diagram );
axis->setPosition( KChart::CartesianAxis::Left );
diagram->addAxis( axis );
KChart::LeveyJenningsAxis* axis2 = new KChart::LeveyJenningsAxis( diagram );
axis2->setPosition( KChart::CartesianAxis::Right );
axis2->setType( KChart::LeveyJenningsGridAttributes::Calculated );
diagram->addAxis( axis2 );
KChart::CartesianAxis* axis3 = new KChart::LeveyJenningsAxis( diagram );
axis3->setPosition( KChart::CartesianAxis::Bottom );
diagram->addAxis( axis3 );
QTableView* tv = new QTableView;
tv->setModel( &model );
tv->setSelectionModel( diagram->selectionModel() );
QSplitter* splitter = new QSplitter;
splitter->addWidget( tv );
splitter->addWidget( chart );
splitter->show();
new SelectionAnimator( tv );//diagram );
return app.exec();
}
diff --git a/examples/Lines/Advanced/mainwindow.cpp b/examples/Lines/Advanced/mainwindow.cpp
index ec1ae88..be8dacd 100644
--- a/examples/Lines/Advanced/mainwindow.cpp
+++ b/examples/Lines/Advanced/mainwindow.cpp
@@ -1,305 +1,305 @@
/**
* 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;
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent )
{
setupUi( this );
m_curColumn = -1;
m_curOpacity = 0;
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
m_chart = new Chart();
chartLayout->addWidget( m_chart );
m_model.loadFromCSV( ":/data" );
// Set up the diagram
m_lines = new LineDiagram( this );
m_lines->setModel( &m_model );
CartesianAxis* xAxis = new CartesianAxis( m_lines );
CartesianAxis* yAxis = new CartesianAxis( m_lines );
xAxis->setPosition( KChart::CartesianAxis::Bottom );
yAxis->setPosition( KChart::CartesianAxis::Left );
m_lines->addAxis( xAxis );
m_lines->addAxis( yAxis );
m_chart->coordinatePlane()->replaceDiagram( m_lines );
m_chart->setGlobalLeading( 20, 20, 20, 20 );
// Instantiate the timer
QTimer* timer = new QTimer( this );
- connect( timer, SIGNAL( timeout() ), this, SLOT( slot_timerFired() ) );
+ connect( timer, SIGNAL(timeout()), this, SLOT(slot_timerFired()) );
timer->start( 30 );
//Change the cursor to IBeamCursor inside Chart widget.
m_chart->setCursor( Qt::IBeamCursor );
//Install event filter on Chart to get the mouse position
m_chart->installEventFilter( this );
}
/**
Event filter for getting mouse position
*/
bool MainWindow::eventFilter(QObject* target, QEvent* event)
{
if (target == m_chart) {
if (event->type() == QEvent::MouseMove) {
// When the mouse is over a data-point then fetch that data-point
// that belongs to the mouse-position and print the data value.
QMouseEvent* mouseEvent = static_cast< QMouseEvent* >( event );
QPointF pos = mouseEvent->pos();
QModelIndex index = m_lines->indexAt(pos.toPoint());
if (index.isValid()) {
qDebug() << "Mouse position" << pos << "Data:" << m_model.data(index).toDouble();
}
}
}
return QWidget::eventFilter(target, event);
}
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");
m_chart->update();
}
void MainWindow::on_paintValuesCB_toggled( bool checked )
{
const int colCount = m_lines->model()->columnCount( m_lines->rootIndex() );
for ( int iColumn = 0; iColumndataValueAttributes( iColumn ) );
QBrush brush( m_lines->brush( iColumn ) );
TextAttributes ta( a.textAttributes() );
ta.setRotation( 0 );
ta.setFont( QFont( "Comic", 10 ) );
ta.setPen( QPen( brush.color() ) );
if ( checked )
ta.setVisible( true );
else
ta.setVisible( false );
a.setVisible( true );
a.setTextAttributes( ta );
m_lines->setDataValueAttributes( iColumn, a );
}
m_chart->update();
}
void MainWindow::on_centerDataPointsCB_toggled( bool checked )
{
m_lines->setCenterDataPoints( checked );
m_chart->update();
}
void MainWindow::on_animateAreasCB_toggled( bool checked )
{
if ( checked ) {
highlightAreaCB->setCheckState( Qt::Unchecked );
m_curRow = 0;
m_curColumn = 0;
} else {
m_curColumn = -1;
}
highlightAreaCB->setEnabled( !checked );
highlightAreaSB->setEnabled( !checked );
// un-highlight all previously highlighted columns
const int rowCount = m_lines->model()->rowCount();
const int colCount = m_lines->model()->columnCount();
for ( int iColumn = 0; iColumnupdate();
m_curOpacity = 0;
}
void MainWindow::slot_timerFired()
{
if ( m_curColumn < 0 ) {
return;
}
m_curOpacity += 8;
if ( m_curOpacity > 255 ) {
setHighlightArea( m_curRow, m_curColumn, 127, false, false );
m_curOpacity = 5;
++m_curRow;
if ( m_curRow >= m_lines->model()->rowCount( m_lines->rootIndex() ) ) {
m_curRow = 0;
++m_curColumn;
if ( m_curColumn >= m_lines->model()->columnCount( m_lines->rootIndex() ) )
m_curColumn = 0;
}
}
setHighlightArea( m_curRow, m_curColumn, m_curOpacity, true, true );
}
void MainWindow::setHighlightArea( int row, int column, int opacity,
bool checked, bool doUpdate )
{
if ( row < 0 ) {
// highlight a complete dataset
LineAttributes la = m_lines->lineAttributes( column );
if ( checked ) {
la.setDisplayArea( true );
la.setTransparency( opacity );
} else {
la.setDisplayArea( false );
}
m_lines->setLineAttributes( column, la );
} else {
// highlight two segments only
if ( row ) {
QModelIndex cellIndex( m_lines->model()->index( row - 1, column,
m_lines->rootIndex() ) );
if ( checked ) {
LineAttributes la( m_lines->lineAttributes( cellIndex ) );
la.setDisplayArea( true );
la.setTransparency( 255 - opacity );
// set specific line attribute settings for this cell
m_lines->setLineAttributes( cellIndex, la );
} else {
// remove any cell-specific line attribute settings
// from the indexed cell
m_lines->resetLineAttributes( cellIndex );
}
}
if ( row < m_lines->model()->rowCount(m_lines->rootIndex() ) ) {
QModelIndex cellIndex( m_lines->model()->index( row, column, m_lines->rootIndex() ) );
if ( checked ) {
LineAttributes la( m_lines->lineAttributes( cellIndex ) );
la.setDisplayArea( true );
la.setTransparency( opacity );
// set specific line attribute settings for this cell
m_lines->setLineAttributes( cellIndex, la );
} else {
// remove any cell-specific line attribute settings
// from the indexed cell
m_lines->resetLineAttributes( cellIndex );
}
}
}
if ( doUpdate )
m_chart->update();
}
void MainWindow::on_highlightAreaCB_toggled( bool checked )
{
setHighlightArea( -1, highlightAreaSB->value(), 127, checked, true );
}
void MainWindow::on_highlightAreaSB_valueChanged( int i )
{
Q_UNUSED( i );
if ( highlightAreaCB->isChecked() )
on_highlightAreaCB_toggled( true );
else
on_highlightAreaCB_toggled( false );
}
void MainWindow::on_threeDModeCB_toggled( bool checked )
{
ThreeDLineAttributes td( m_lines->threeDLineAttributes() );
td.setDepth( depthSB->value() );
if ( checked )
td.setEnabled( true );
else
td.setEnabled( false );
m_lines->setThreeDLineAttributes( td );
m_chart->update();
}
void MainWindow::on_depthSB_valueChanged( int i )
{
Q_UNUSED( i );
if ( threeDModeCB->isChecked() )
on_threeDModeCB_toggled( true );
}
void MainWindow::on_trackAreasCB_toggled( bool checked )
{
setTrackedArea( trackAreasSB->value(), checked, true );
}
void MainWindow::on_trackAreasSB_valueChanged( int i )
{
Q_UNUSED( i );
on_trackAreasCB_toggled( trackAreasCB->isChecked() );
}
void MainWindow::setTrackedArea( int column, bool checked, bool doUpdate )
{
const int rowCount = m_model.rowCount( m_lines->rootIndex() );
const int columnCount = m_model.columnCount( m_lines->rootIndex() );
for ( int i = 0; i < rowCount; ++i ) {
for ( int j = 0; j < columnCount; ++j ) {
QModelIndex cellIndex( m_model.index( i, j,
m_lines->rootIndex() ) );
ValueTrackerAttributes va( m_lines->valueTrackerAttributes( cellIndex ) );
va.setEnabled( checked && j == column );
va.setAreaBrush( QColor( 255, 255, 0, 50 ) );
va.setOrientations( Qt::Horizontal | Qt::Vertical );
QColor color = Qt::cyan;
color.setAlphaF( 0.5 );
va.setAreaBrush( color );
m_lines->setValueTrackerAttributes( cellIndex, va );
}
}
if ( doUpdate )
m_chart->update();
}
void MainWindow::on_reverseHorizontalCB_toggled( bool checked )
{
static_cast< KChart::CartesianCoordinatePlane* >( m_chart->coordinatePlane() )
->setHorizontalRangeReversed( checked );
}
void MainWindow::on_reverseVerticalCB_toggled( bool checked )
{
static_cast< KChart::CartesianCoordinatePlane* >( m_chart->coordinatePlane() )
->setVerticalRangeReversed( checked );
}
diff --git a/examples/ModelView/TableView/mainwindow.cpp b/examples/ModelView/TableView/mainwindow.cpp
index 4ea66d2..048c21d 100644
--- a/examples/ModelView/TableView/mainwindow.cpp
+++ b/examples/ModelView/TableView/mainwindow.cpp
@@ -1,245 +1,245 @@
/**
* 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
#include
#include
#include
#include
#include
using namespace KChart;
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu( tr( "&File" ), this );
QAction *openAction = fileMenu->addAction( tr( "&Open..." ) );
openAction->setShortcut( QKeySequence( tr( "Ctrl+O" ) ) );
QAction *saveAction = fileMenu->addAction( tr( "&Save As..." ) );
saveAction->setShortcut( QKeySequence( tr( "Ctrl+S" ) ) );
QAction *quitAction = fileMenu->addAction( tr( "E&xit" ) );
quitAction->setShortcut( QKeySequence( tr( "Ctrl+Q" ) ) );
setupModel();
initializeData();
setupViews();
connect( openAction, SIGNAL(triggered()), this, SLOT(openFile()));
connect( saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
connect( quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect( m_selectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
- this, SLOT( selectionChanged( const QItemSelection &, const QItemSelection & ) ) );
+ connect( m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ this, SLOT(selectionChanged(QItemSelection,QItemSelection)) );
- connect( m_diagramView, SIGNAL( clicked( const QModelIndex& ) ), SLOT( itemClicked( const QModelIndex& ) ) );
+ connect( m_diagramView, SIGNAL(clicked(QModelIndex)), SLOT(itemClicked(QModelIndex)) );
menuBar()->addMenu( fileMenu );
statusBar();
setWindowTitle( tr( "KD Chart used as item viewer together with a QTableView" ) );
resize( 740, 480 );
}
void MainWindow::setupModel()
{
const int rowCount = 8;
const int columnCount = 3;
m_model = new QStandardItemModel( rowCount, columnCount, this );
m_model->setHeaderData( 0, Qt::Horizontal, tr( "Label" ) );
m_model->setHeaderData( 1, Qt::Horizontal, tr( "Quantity" ) );
m_model->setHeaderData( 2, Qt::Horizontal, tr( "Product A") );
}
void MainWindow::initializeData()
{
openFile(":/Charts/qtdata.cht");
}
void MainWindow::setupViews()
{
m_chart = new Chart();
m_tableView = new QTableView;
QSplitter *splitter = new QSplitter( Qt::Vertical );
splitter->addWidget( m_tableView );
splitter->addWidget( m_chart );
splitter->setStretchFactor( 0, 0 );
splitter->setStretchFactor( 1, 1 );
// Set up the diagram
m_diagramView = new BarDiagram();
DatasetDescriptionVector columnConfig( m_model->columnCount() - 1 );
for ( int iC = 1; iC <= columnConfig.size(); ++iC )
columnConfig[ iC - 1 ] = iC;
qDebug() << "(" << m_model->rowCount() << "," << m_model->columnCount() << ")";
KChart::DatasetProxyModel* dproxy = new KChart::DatasetProxyModel( this );
dproxy->setSourceModel( m_model );
dproxy->setDatasetColumnDescriptionVector( columnConfig );
m_diagramView->setModel( dproxy );
KChart::HeaderFooter* headerFooter = new KChart::HeaderFooter( m_chart );
headerFooter->setText( tr( "You can edit the table data, or select table cells with keyboard/mouse." ) );
headerFooter->setType( HeaderFooter::Header );
headerFooter->setPosition( Position::North );
m_chart->addHeaderFooter( headerFooter );
m_chart->coordinatePlane()->replaceDiagram( m_diagramView );
m_tableView->setModel( m_model );
m_selectionModel = new QItemSelectionModel( m_model );
m_tableView->setSelectionModel( m_selectionModel );
setCentralWidget( splitter );
}
void MainWindow::itemClicked( const QModelIndex& index )
{
QItemSelectionModel::SelectionFlags command = QItemSelectionModel::Clear | QItemSelectionModel::Select;
if ( QApplication::keyboardModifiers() & Qt::ControlModifier )
command = QItemSelectionModel::Toggle;
m_selectionModel->setCurrentIndex( static_cast< const QAbstractProxyModel* >( index.model() )
->mapToSource( index ), command );
}
void MainWindow::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
{
if ( deselected != selected ) {
// First we set pItemSelection to the de-selected bars
// and we use an invisible pen, then we set it to the selected ones
// using a dark blue pen:
const QItemSelection * pItemSelection = &deselected;
QPen pen( Qt::NoPen );
for ( int iItemSelection = 0; iItemSelection < 2; ++iItemSelection ) {
for ( int i = 0; i < pItemSelection->size(); ++i ) {
QItemSelectionRange range( pItemSelection->at( i ) );
for ( int iRow = range.topLeft().row(); iRow <= range.bottomRight().row(); ++iRow ) {
for ( int iColumn = range.topLeft().column(); iColumn <= range.bottomRight().column(); ++iColumn ) {
// ignore the first column: that's just the label texts to be shown in the table view
if ( iColumn )
// enable (or disable, resp.) the surrounding line around this bar
m_diagramView->setPen( m_diagramView->model()
->index( iRow, iColumn - 1, m_diagramView->rootIndex()), pen );
}
}
}
pItemSelection = &selected;
pen.setColor( Qt::darkBlue );
pen.setStyle( Qt::DashLine );
pen.setWidth( 2 );
}
m_chart->update();
}
}
void MainWindow::openFile(const QString &path)
{
QString fileName;
if ( path.isNull() )
fileName = QFileDialog::getOpenFileName( this, tr( "Choose a data file" ), "", "*.cht" );
else
fileName = path;
if ( !fileName.isEmpty() ) {
QFile file(fileName);
if ( file.open( QFile::ReadOnly | QFile::Text) ) {
QTextStream stream( &file );
QString line;
m_model->removeRows( 0, m_model->rowCount( QModelIndex() ), QModelIndex() );
int row = 0;
do {
line = stream.readLine();
if (!line.isEmpty()) {
m_model->insertRows(row, 1, QModelIndex());
QStringList pieces = line.split( ',', QString::SkipEmptyParts );
m_model->setData( m_model->index( row, 0, QModelIndex() ),
pieces.value( 0 ) );
m_model->setData( m_model->index(row, 1, QModelIndex() ),
pieces.value( 1 ) );
m_model->setData( m_model->index( row, 2, QModelIndex() ),
pieces.value( 2 ) );
m_model->setData( m_model->index(row, 0, QModelIndex()),
QColor( pieces.value( 3 ) ), Qt::DecorationRole );
++row;
}
} while ( !line.isEmpty() );
file.close();
statusBar()->showMessage( tr( "Loaded %1" ).arg( fileName ), 2000 );
}
}
}
void MainWindow::saveFile()
{
QString fileName = QFileDialog::getSaveFileName(this, tr( "Save file as" ), "", "*.cht" );
if ( !fileName.isEmpty() ) {
QFile file( fileName );
QTextStream stream( &file );
if ( file.open(QFile::WriteOnly | QFile::Text) ) {
for ( int row = 0; row < m_model->rowCount( QModelIndex() ); ++row ) {
QStringList pieces;
pieces.append( m_model->data( m_model->index( row, 0, QModelIndex() ),
Qt::DisplayRole).toString());
pieces.append( m_model->data( m_model->index( row, 1, QModelIndex() ),
Qt::DisplayRole).toString());
pieces.append( m_model->data( m_model->index( row, 2, QModelIndex() ),
Qt::DisplayRole).toString());
pieces.append( m_model->data( m_model->index( row, 0, QModelIndex() ),
Qt::DecorationRole).toString());
stream << pieces.join( "," ) << "\n";
}
}
file.close();
statusBar()->showMessage( tr( "Saved %1" ).arg( fileName ), 2000 );
}
}
diff --git a/examples/Pie/Advanced/mainwindow.cpp b/examples/Pie/Advanced/mainwindow.cpp
index a31a2e9..67666e2 100644
--- a/examples/Pie/Advanced/mainwindow.cpp
+++ b/examples/Pie/Advanced/mainwindow.cpp
@@ -1,148 +1,148 @@
/**
* 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
using namespace KChart;
MainWindow::MainWindow( QWidget* parent ) :
QWidget( parent ),
m_currentFactor( 0 ),
m_currentDirection( 1 ),
m_currentSlice( 0 )
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
m_chart = new Chart();
m_chart->setGlobalLeadingLeft( 5 );
m_chart->setGlobalLeadingRight( 5 );
chartLayout->addWidget( m_chart );
m_model.loadFromCSV( ":/data" );
explodeDatasetSB->setMaximum( m_model.columnCount() - 1 );
// Set up the diagram
PolarCoordinatePlane* polarPlane = new PolarCoordinatePlane( m_chart );
m_chart->replaceCoordinatePlane( polarPlane );
m_pie = new PieDiagram();
m_pie->setModel( &m_model );
m_chart->coordinatePlane()->replaceDiagram( m_pie );
m_timer = new QTimer( this );
- connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotNextFrame() ) );
+ connect( m_timer, SIGNAL(timeout()), this, SLOT(slotNextFrame()) );
}
void MainWindow::on_startPositionSB_valueChanged( double pos )
{
const int intValue = static_cast( pos );
startPositionSL->blockSignals( true );
startPositionSL->setValue( intValue );
startPositionSL->blockSignals( false );
static_cast( m_chart->coordinatePlane()
)->setStartPosition( pos );
m_chart->update();
}
void MainWindow::on_startPositionSL_valueChanged( int pos )
{
qreal qrealValue = static_cast( pos );
startPositionSB->blockSignals( true );
startPositionSB->setValue( qrealValue );
startPositionSB->blockSignals( false );
static_cast( m_chart->coordinatePlane()
)->setStartPosition( pos );
m_chart->update();
}
void MainWindow::on_explodeSubmitPB_clicked()
{
setExplodeFactor( explodeDatasetSB->value(), explodeFactorSB->value() );
m_chart->update();
}
void MainWindow::setExplodeFactor( int column, qreal value )
{
// Note:
// We use the per-column getter method here, it will fall back
// automatically to return the global (or even the default) settings.
PieAttributes attrs( m_pie->pieAttributes( column ) );
attrs.setExplodeFactor( value );
m_pie->setPieAttributes( column, attrs );
m_chart->update();
}
void MainWindow::on_animateExplosionCB_toggled( bool toggle )
{
if ( toggle )
m_timer->start( 100 );
else
m_timer->stop();
}
void MainWindow::slotNextFrame()
{
m_currentFactor += ( 1 * m_currentDirection );
if ( m_currentFactor == 0 || m_currentFactor == 5 )
m_currentDirection = -m_currentDirection;
if ( m_currentFactor == 0 ) {
setExplodeFactor( m_currentSlice, 0.0 );
m_currentSlice++;
if ( m_currentSlice >= m_model.columnCount() )
m_currentSlice = 0;
}
setExplodeFactor(
m_currentSlice,
static_cast( m_currentFactor ) / 10.0 );
m_chart->update();
}
void MainWindow::on_threeDGB_toggled( bool toggle )
{
// note: We use the global getter method here, it will fall back
// automatically to return the default settings.
ThreeDPieAttributes attrs( m_pie->threeDPieAttributes() );
attrs.setEnabled( toggle );
attrs.setDepth( threeDFactorSB->value() );
m_pie->setThreeDPieAttributes( attrs );
m_chart->update();
}
void MainWindow::on_threeDFactorSB_valueChanged( int factor )
{
// note: We use the global getter method here, it will fall back
// automatically to return the default settings.
ThreeDPieAttributes attrs( m_pie->threeDPieAttributes() );
attrs.setEnabled( threeDGB->isChecked() );
attrs.setDepth( factor );
m_pie->setThreeDPieAttributes( attrs );
m_chart->update();
}
diff --git a/examples/Plotter/BigDataset/MainWidget.cpp b/examples/Plotter/BigDataset/MainWidget.cpp
index 39f2ccc..31e869a 100644
--- a/examples/Plotter/BigDataset/MainWidget.cpp
+++ b/examples/Plotter/BigDataset/MainWidget.cpp
@@ -1,99 +1,99 @@
/**
* 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 "MainWidget.h"
#include "KChartAbstractDiagram_p.h"
#include "KChartChart.h"
#include "KChartPlotter.h"
#include
#include
MainWidget::MainWidget()
: m_controlsContainer( new QWidget( this ) )
{
// set up the chart
QHBoxLayout* topLayout = new QHBoxLayout( this );
m_controls.setupUi( m_controlsContainer );
topLayout->addWidget( m_controlsContainer );
KChart::Chart* chart = new KChart::Chart;
topLayout->addWidget( chart );
m_plotter = new KChart::Plotter;
m_plotter->setModel( &m_model );
KChart::AbstractDiagram::Private::get( m_plotter )->doDumpPaintTime = true;
chart->coordinatePlane()->replaceDiagram( m_plotter );
KChart::CartesianCoordinatePlane* cPlane
= qobject_cast< KChart::CartesianCoordinatePlane* >( chart->coordinatePlane() );
Q_ASSERT( cPlane );
cPlane->setVerticalRange( QPair< qreal, qreal >( -2, 2 ) );
KChart::CartesianAxis* xAxis = new KChart::CartesianAxis( m_plotter );
xAxis->setPosition( KChart::CartesianAxis::Bottom );
xAxis->setTitleText("X");
m_plotter->addAxis( xAxis );
KChart::CartesianAxis* yAxis = new KChart::CartesianAxis( m_plotter );
yAxis->setPosition( KChart::CartesianAxis::Left );
yAxis->setTitleText("Y");
m_plotter->addAxis( yAxis );
// wire up the UI
// index of elements in vector must match corresponding Model::Function enum values
m_functionSelector << m_controls.sineRadio << m_controls.triangleRadio << m_controls.squareRadio
<< m_controls.noiseRadio << m_controls.oneDivSineRadio
<< m_controls.sineOneDivRadio;
foreach ( QRadioButton* r, m_functionSelector ) {
- connect( r, SIGNAL( toggled( bool ) ), SLOT( functionToggled( bool ) ) );
+ connect( r, SIGNAL(toggled(bool)), SLOT(functionToggled(bool)) );
}
- connect( m_controls.runButton, SIGNAL( toggled( bool ) ),
- &m_model, SLOT( setRunning( bool ) ) );
+ connect( m_controls.runButton, SIGNAL(toggled(bool)),
+ &m_model, SLOT(setRunning(bool)) );
// order matters again
m_addPointsButtons << m_controls.add1kButton << m_controls.add10kButton << m_controls.add100kButton;
foreach ( QPushButton* b, m_addPointsButtons ) {
- connect( b, SIGNAL( clicked( bool ) ), SLOT( addPointsButtonClicked() ) );
+ connect( b, SIGNAL(clicked(bool)), SLOT(addPointsButtonClicked()) );
}
}
// slot
void MainWidget::functionToggled( bool checked )
{
if ( !checked ) {
return;
}
int idx = m_functionSelector.indexOf( qobject_cast< QRadioButton* >( sender() ) );
Q_ASSERT( idx >= 0 );
m_model.setFunction( static_cast< Model::Function >( idx ) );
}
// slot
void MainWidget::addPointsButtonClicked()
{
int idx = m_addPointsButtons.indexOf( qobject_cast< QPushButton* >( sender() ) );
Q_ASSERT( idx >= 0 );
m_model.appendPoints( pow( qreal( 10 ), qreal( idx + 3 ) ) );
}
diff --git a/examples/Plotter/BigDataset/Model.cpp b/examples/Plotter/BigDataset/Model.cpp
index 20b07cf..85c36a7 100644
--- a/examples/Plotter/BigDataset/Model.cpp
+++ b/examples/Plotter/BigDataset/Model.cpp
@@ -1,156 +1,156 @@
/**
* 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 "Model.h"
#include "KChartMath_p.h"
#include
#include
static const qreal s_stepWidth = 0.1;
Model::Model()
: m_x( 0 ),
m_function( SineFunction )
{
m_appendTimer.setInterval( 3 );
- connect( &m_appendTimer, SIGNAL( timeout() ), SLOT( appendPoint() ) );
+ connect( &m_appendTimer, SIGNAL(timeout()), SLOT(appendPoint()) );
// pre-fill some values
appendPoints( 100 );
}
int Model::columnCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
return 2; // row 0: x, row 1: y
}
int Model::rowCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
return m_data.count();
}
QModelIndex Model::index( int row, int column, const QModelIndex& parent ) const
{
if ( column > 1 || row >= m_data.count() || parent.isValid() ) {
return QModelIndex();
}
return createIndex( row, column );
}
QModelIndex Model::parent( const QModelIndex& index ) const
{
Q_UNUSED( index );
return QModelIndex();
}
QVariant Model::data( const QModelIndex& index, int role ) const
{
if ( role != Qt::DisplayRole || index.parent().isValid() ||
index.column() > 1 || index.row() >= m_data.count() ) {
return QVariant();
}
if ( index.column() == 0 ) {
return index.row() * s_stepWidth;
} else {
return m_data.at( index.row() );
}
}
// slot
void Model::setFunction( Function f )
{
m_function = f;
}
void Model::setRunning( bool running )
{
if ( running ) {
m_appendTimer.start();
} else {
m_appendTimer.stop();
}
}
// slot
void Model::appendPoint()
{
appendPoints( 1 );
}
void Model::appendPoints( int numPoints )
{
Q_ASSERT( numPoints >= 1);
beginInsertRows( QModelIndex(), m_data.count(), m_data.count() + numPoints - 1 );
for ( int i = 0; i < numPoints; i++ ) {
m_data.append( nextFunctionValue() );
}
QTime stopWatch;
stopWatch.start();
endInsertRows(); // this immediately triggers the signals that cause the diagram to update
qDebug() << "Adding" << numPoints << "data points to the existing" << m_data.count() - numPoints
<< "took" << stopWatch.elapsed() << "milliseconds";
}
qreal Model::nextFunctionValue()
{
qreal fx = 0.0;
switch ( m_function ) {
case SineFunction:
fx = sin( m_x );
break;
case TriangleFunction: {
qreal x = fmod( m_x + 0.5 * M_PI, 2 * M_PI ); // make it look like sine, only less round
if ( x < M_PI ) {
fx = -1.0 + x * ( 2.0 / M_PI);
} else {
fx = 3.0 - x * ( 2.0 / M_PI);
}
break; }
case SquareFunction: {
qreal x = fmod( m_x, 2 * M_PI );
fx = x < M_PI ? 1 : -1;
break; }
case NoiseFunction:
fx = -1.0 + qreal( qrand() ) * 2.0 / qreal( RAND_MAX );
break;
case SineOneDivFunction: {
// we want this repeating and we want negative arguments, too.
qreal x = fmod( m_x + 10, 20 ) - 10;
if ( qAbs( x ) < 1e-6 ) {
break;
}
fx = sin( 1.0 / x );
break; }
case OneDivSineFunction: {
qreal s = sin( m_x );
fx = qAbs( s ) > 1e-6 ? 1.0 / s : 0.0;
break; }
default:
Q_ASSERT( false );
}
m_x += s_stepWidth;
return fx;
}
diff --git a/examples/Plotter/BubbleChart/mainwindow.cpp b/examples/Plotter/BubbleChart/mainwindow.cpp
index d4d7f00..153d998 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)
{
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() ) );
+ 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/Logarithmic/main.cpp b/examples/Plotter/Logarithmic/main.cpp
index 0f4ff5f..39978af 100644
--- a/examples/Plotter/Logarithmic/main.cpp
+++ b/examples/Plotter/Logarithmic/main.cpp
@@ -1,112 +1,111 @@
/**
* 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
using namespace KChart;
int main( int argc, char** argv )
{
QApplication app( argc, argv );
const int points = 420;
const double xMin = 0;
const double xMax = 20;
const double step = ( xMax - xMin ) / ( points - 1 );
QStandardItemModel model( points, 6 );
double x = xMin;
for ( int n = 0; n < points; ++n, x += step) {
QModelIndex index = model.index( n, 0 );
model.setData( index, x );
index = model.index( n, 1 );
model.setData( index, sin( x ) * 100.0 );
index = model.index( n, 2 );
model.setData( index, x );
index = model.index( n, 3 );
model.setData( index, x );
index = model.index( n, 4 );
model.setData( index, x );
index = model.index( n, 5 );
model.setData( index, x * x * x );
}
model.setHeaderData( 0, Qt::Horizontal, QString::fromLatin1( "100 * sin(x)" ) );
model.setHeaderData( 2, Qt::Horizontal, QString::fromLatin1( "x" ) );
model.setHeaderData( 4, Qt::Horizontal, QString::fromLatin1( "x^3" ) );
KChart::Chart* chart = new KChart::Chart();
KChart::AbstractCartesianDiagram* diagram = new KChart::Plotter;
diagram->setModel( &model );
chart->coordinatePlane()->replaceDiagram( diagram );
KChart::CartesianAxis* xAxis = new KChart::CartesianAxis( diagram );
KChart::CartesianAxis* yAxis = new KChart::CartesianAxis( diagram );
xAxis->setPosition( KChart::CartesianAxis::Bottom );
yAxis->setPosition( KChart::CartesianAxis::Left );
diagram->addAxis( xAxis );
diagram->addAxis( yAxis );
KChart::Legend* legend = new KChart::Legend( diagram, chart );
KChart::FrameAttributes legendAtt = legend->frameAttributes();
legendAtt.setCornerRadius( 9 );
legend->setFrameAttributes( legendAtt );
legend->setPosition( KChart::Position::East );
legend->setAlignment( Qt::AlignCenter );
legend->setTitleText( "Legend" );
chart->addLegend( legend );
KChart::CartesianCoordinatePlane* cart_plane = dynamic_cast(chart->coordinatePlane());
Q_ASSERT(cart_plane);
cart_plane->setAxesCalcModeX(KChart::AbstractCoordinatePlane::Logarithmic);
cart_plane->setAxesCalcModeY(KChart::AbstractCoordinatePlane::Logarithmic);
// Set the vertical range from 15 to 75 - with a logarithmic axis I actually get 1 to 100
//cart_plane->setVerticalRange(QPair( 0.005, 1000 ) );
// Set the horizontal range from 1 to 9 - with a linear axis this works OK
cart_plane->setHorizontalRange(QPair( 0.001, 100 ) );
chart->show();
int ret = app.exec();
delete chart;
return ret;
}
diff --git a/examples/Plotter/Timeline/main.cpp b/examples/Plotter/Timeline/main.cpp
index 0de09b8..99c4824 100644
--- a/examples/Plotter/Timeline/main.cpp
+++ b/examples/Plotter/Timeline/main.cpp
@@ -1,148 +1,148 @@
/**
* 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 "timeaxis.h"
#include "timechartmodel.h"
class ChartWidget : public QWidget {
Q_OBJECT
public:
explicit ChartWidget(QWidget* parent = 0) : QWidget(parent), m_counter(0) {
QSplitter* splitter = new QSplitter(this);
QHBoxLayout* l = new QHBoxLayout(this);
setLayout(l);
l->addWidget( splitter );
QWidget* leftWidget = new QWidget( splitter );
QVBoxLayout* leftLayout = new QVBoxLayout(leftWidget);
leftWidget->setLayout(leftLayout);
QPushButton* button = new QPushButton("Animate", leftWidget);
leftLayout->addWidget( button );
button->setCheckable( true );
connect( button, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool)) );
QTreeView* tv = new QTreeView( leftWidget );
leftLayout->addWidget( tv );
m_chart = new KChart::Chart( splitter );
m_model = new QStandardItemModel( 365, 2, this );
for ( int i = 0; i < 365; ++i ) {
const QDateTime dt = QDateTime( QDate( 2010, 1, 1 ), QTime() );
m_model->setData( m_model->index( i, 0 ), dt.addDays( i ) );
m_model->setData( m_model->index( i, 1 ), sin( i / 10.0 ) * 10 );
}
TimeChartModel* proxy = new TimeChartModel( this );
proxy->setSourceModel( m_model );
proxy->setVisibleRange( QDateTime( QDate( 2010, 2, 1 ), QTime() ),
QDateTime( QDate( 2010, 3, 31 ), QTime() ) );
KChart::Plotter* plotter = new KChart::Plotter;
m_chart->coordinatePlane()->replaceDiagram( plotter );
tv->setModel( proxy );
tv->show();
TimeAxis* axis = new TimeAxis( plotter );
axis->setPosition( TimeAxis::Bottom );
plotter->addAxis( axis );
plotter->setModel( proxy );
- connect( proxy, SIGNAL( rowsInserted( QModelIndex, int, int ) ),
- m_chart->coordinatePlane(), SLOT( adjustRangesToData() ) );
- connect( proxy, SIGNAL( rowsRemoved( QModelIndex, int, int ) ),
- m_chart->coordinatePlane(), SLOT( adjustRangesToData() ) );
+ connect( proxy, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ m_chart->coordinatePlane(), SLOT(adjustRangesToData()) );
+ connect( proxy, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ m_chart->coordinatePlane(), SLOT(adjustRangesToData()) );
proxy->setVisibleRange( QDateTime( QDate( 2010, 3, 15 ), QTime() ),
QDateTime( QDate( 2010, 5, 18 ), QTime() ) );
qobject_cast< KChart::CartesianCoordinatePlane* >( m_chart->coordinatePlane() )->adjustRangesToData();
m_timer = new QTimer(this);
- connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotTimeout() ) );
+ connect( m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()) );
}
private slots:
void slotTimeout() {
// An ugly hack to prevent the QAbstractItemModel from emitting dataChanged
// for every single call to setData which would result in a full relayout
// every time. That is horrible for performance and what we do is to prevent
// QAbstractItemModel to emit dataChanged, collect what data changed and
// emit the signal at the end ourself.
m_model->blockSignals(true);
QModelIndexList indexes;
QVariant v1, v2;
for ( int i = 0; i < 365; ++i ) {
QModelIndex idx = m_model->index( i, 1 );
indexes.append(idx);
m_model->setData( idx, sin( i / 10.0 + m_counter ) * 10 );
}
m_model->blockSignals(false);
if (!indexes.isEmpty()) {
m_model->metaObject()->invokeMethod(m_model, "dataChanged", Qt::DirectConnection, Q_ARG(QModelIndex,indexes.first()), Q_ARG(QModelIndex,indexes.last()));
}
m_counter += 0.02;
}
void buttonToggled(bool checked) {
if (checked)
m_timer->start( 200 );
else
m_timer->stop();
}
private:
KChart::Chart* m_chart;
QStandardItemModel* m_model;
QTimer* m_timer;
qreal m_counter;
};
/**
* This example demonstrates how to use time-based plots with timestamp-value data points
* based on seconds and how to use a proxy model for defining the plotted "window" of the
* measurement data.
*/
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Plotter/Timeline/timeaxis.cpp b/examples/Plotter/Timeline/timeaxis.cpp
index b24e9e4..b2c3c0c 100644
--- a/examples/Plotter/Timeline/timeaxis.cpp
+++ b/examples/Plotter/Timeline/timeaxis.cpp
@@ -1,41 +1,41 @@
/**
* 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 "timeaxis.h"
-#include
+#include
TimeAxis::TimeAxis( KChart::AbstractCartesianDiagram* parent )
: KChart::CartesianAxis( parent )
{
// Intentionally left blank
}
const QString TimeAxis::customizedLabel( const QString& label ) const
{
// Here we are free to format the value to whatever we want. As example we
// could also return a scientific notation with something like the following
// both lines;
//const int precision = 2;
//return QString::number(label.toReal(), 'E', precision);
// Format the time-value to a nice string representation.
const QDateTime dateTime = QDateTime::fromTime_t( label.toDouble() * 3600.0 );
return dateTime.date().toString();
}
diff --git a/examples/RealTime/main.cpp b/examples/RealTime/main.cpp
index af3202c..104b44e 100644
--- a/examples/RealTime/main.cpp
+++ b/examples/RealTime/main.cpp
@@ -1,80 +1,80 @@
/**
* 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
class ChartWidget : public QWidget {
Q_OBJECT
public:
explicit ChartWidget(QWidget* parent=0)
: 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) );
}
}
KChart::BarDiagram* diagram = new KChart::BarDiagram;
diagram->setModel(&m_model);
m_chart.coordinatePlane()->replaceDiagram(diagram);
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(&m_chart);
setLayout(l);
m_timer = new QTimer(this);
- connect( m_timer, SIGNAL( timeout() ),
- this, SLOT( slotTimeout() ) );
+ connect( m_timer, SIGNAL(timeout()),
+ this, SLOT(slotTimeout()) );
m_timer->start( 200 );
}
private slots:
void slotTimeout() {
QModelIndex index = m_model.index( 0, 1, QModelIndex());
qreal value = ( m_model.data( index ).toInt() % 24 ) +1;
m_model.setData( index, value );
}
private:
KChart::Chart m_chart;
QStandardItemModel m_model;
QTimer *m_timer;
};
int main( int argc, char** argv ) {
QApplication app( argc, argv );
ChartWidget w;
w.show();
return app.exec();
}
#include "main.moc"
diff --git a/examples/Stock/Advanced/mainwindow.cpp b/examples/Stock/Advanced/mainwindow.cpp
index d9af76c..ebfd0f4 100644
--- a/examples/Stock/Advanced/mainwindow.cpp
+++ b/examples/Stock/Advanced/mainwindow.cpp
@@ -1,148 +1,148 @@
/**
* 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
using namespace KChart;
MainWindow::MainWindow( QWidget *parent )
: QWidget( parent )
, m_chart( new Chart() )
, m_diagram( m_chart )
{
setupUi( this );
m_HLCModel.loadFromCSV( ":/HLC" );
m_OHLCModel.loadFromCSV( ":/OHLC" );
m_diagram.setType( StockDiagram::HighLowClose );
m_diagram.setModel( &m_HLCModel );
m_chart->coordinatePlane()->replaceDiagram( &m_diagram );
KChart::Legend* legend = new KChart::Legend( &m_diagram, m_chart );
m_chart->addLegend( legend );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
chartLayout->addWidget( m_chart );
// Abscissa
CartesianAxis *leftAxis = new CartesianAxis( &m_diagram );
// Ordinate
CartesianAxis *bottomAxis = new CartesianAxis( &m_diagram );
leftAxis->setPosition( CartesianAxis::Left );
TextAttributes attributes = bottomAxis->textAttributes();
attributes.setRotation( 90 );
attributes.setFontSize( Measure( 7.0, KChartEnums::MeasureCalculationModeAbsolute ) );
bottomAxis->setTextAttributes( attributes );
bottomAxis->setPosition( CartesianAxis::Bottom );
m_diagram.addAxis( leftAxis );
m_diagram.addAxis( bottomAxis );
m_diagram.addAxis( bottomAxis );
applyColor( QColor( "chartreuse" ) );
- const bool connected = connect( colorChooser, SIGNAL( clicked() ), SLOT( chooseColor() ) );
+ const bool connected = connect( colorChooser, SIGNAL(clicked()), SLOT(chooseColor()) );
Q_ASSERT( connected );
Q_UNUSED( connected );
// Initialize all values for the stock chart to sane defaults
initValues();
}
void MainWindow::chooseColor()
{
applyColor( QColorDialog::getColor( m_diagram.brush().color(), this ) );
}
void MainWindow::applyColor(const QColor &color)
{
if ( color.isValid() ) {
m_diagram.setPen( 0, QPen( color.darker( 130 ) ) );
m_diagram.setBrush( 0, QBrush( color ) );
QColor inverse( 255 - color.red(), 255 - color.green(), 255 - color.blue() );
m_diagram.setPen( 1, QPen( inverse.darker( 130 ) ) );
m_diagram.setBrush( 1, QBrush( inverse ) );
QPalette pal = colorChooser->palette();
pal.setBrush( QPalette::Button, QBrush( color ) );
colorChooser->setPalette( pal );
}
}
void MainWindow::initValues()
{
m_threeDBarAttributes = m_diagram.threeDBarAttributes();
m_threeDBarAttributes.setDepth( 10.0 );
m_threeDBarAttributes.setUseShadowColors( false );
threeDProperties->setChecked( m_threeDBarAttributes.isEnabled() );
perspectiveAngle->setValue( m_threeDBarAttributes.angle() );
perspectiveDepth->setValue( (int)m_threeDBarAttributes.depth() );
useShadowColors->setChecked( m_threeDBarAttributes.useShadowColors() );
m_diagram.setThreeDBarAttributes( m_threeDBarAttributes );
}
void MainWindow::on_threeDProperties_toggled( bool checked )
{
m_threeDBarAttributes.setEnabled( checked );
m_diagram.setThreeDBarAttributes( m_threeDBarAttributes );
m_chart->update();
}
void MainWindow::on_perspectiveAngle_valueChanged( int value )
{
m_threeDBarAttributes.setAngle( value );
m_diagram.setThreeDBarAttributes( m_threeDBarAttributes );
m_chart->update();
}
void MainWindow::on_perspectiveDepth_valueChanged( int value )
{
m_threeDBarAttributes.setDepth( value );
m_diagram.setThreeDBarAttributes( m_threeDBarAttributes );
m_chart->update();
}
void MainWindow::on_useShadowColors_toggled( bool checked )
{
m_threeDBarAttributes.setUseShadowColors( checked );
m_diagram.setThreeDBarAttributes( m_threeDBarAttributes );
m_chart->update();
}
void MainWindow::on_stockTypeCB_currentIndexChanged( const QString &text )
{
// FIXME: Workaround for disappearing diagram when setting new model
m_chart->coordinatePlane()->takeDiagram( &m_diagram );
if ( text == "High-Low-Close" ) {
m_diagram.setType( StockDiagram::HighLowClose );
m_diagram.setModel( &m_HLCModel );
} else if ( text == "Open-High-Low-Close" ) {
m_diagram.setType( StockDiagram::OpenHighLowClose );
m_diagram.setModel( &m_OHLCModel );
} else if ( text == "Candlestick" ) {
m_diagram.setType( StockDiagram::Candlestick );
m_diagram.setModel( &m_OHLCModel );
}
m_chart->coordinatePlane()->replaceDiagram( &m_diagram );
}
diff --git a/examples/TernaryCharts/Advanced/mainwindow.cpp b/examples/TernaryCharts/Advanced/mainwindow.cpp
index 1f6e900..64a62d4 100644
--- a/examples/TernaryCharts/Advanced/mainwindow.cpp
+++ b/examples/TernaryCharts/Advanced/mainwindow.cpp
@@ -1,99 +1,99 @@
/**
* 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 "mainwindow.h"
MainWindow::MainWindow( QWidget* parent )
: QDialog( parent )
, m_chart( 0 )
, m_diagram( 0 )
, m_ternaryPlane( 0 )
{
setupUi( this );
// make a chart
m_chart = new KChart::Chart;
// replace the default (cartesian) coordinate plane with a ternary one
m_ternaryPlane = new KChart::TernaryCoordinatePlane;
m_chart->replaceCoordinatePlane( m_ternaryPlane );
// make a ternary line diagram
m_diagram = new KChart::TernaryPointDiagram;
// and replace the default diagram with it
m_ternaryPlane->replaceDiagram( m_diagram );
// add the three ternary axes, see the positions
KChart::TernaryAxis* axisA = new KChart::TernaryAxis( m_diagram );
axisA->setPosition( KChartEnums::PositionSouth );
KChart::TernaryAxis* axisB = new KChart::TernaryAxis( m_diagram );
axisB->setPosition( KChartEnums::PositionWest );
KChart::TernaryAxis* axisC = new KChart::TernaryAxis( m_diagram );
axisC->setPosition( KChartEnums::PositionEast );
QHBoxLayout* chartLayout = new QHBoxLayout( frame );
chartLayout->addWidget( m_chart );
setupModel();
m_diagram->setModel( &m_model );
- connect( m_diagram, SIGNAL( clicked( QModelIndex ) ),
- SLOT( indexClicked( QModelIndex ) ) );
+ connect( m_diagram, SIGNAL(clicked(QModelIndex)),
+ SLOT(indexClicked(QModelIndex)) );
}
void MainWindow::setupModel()
{
m_model.insertRows( 0, 5 );
m_model.insertColumns( 0, 3 );
const float column0Share = 1.0f/3.0f;
const float column1Share = 1.0f/3.0f;
const float column2Share = 1.0f/3.0f;
for ( int row = 0; row < m_model.rowCount(); ++row ) {
const qreal SkewX = column0Share * ( 1 - 1.0/( 5 * row*row*row + 1 ) );
const qreal SkewY = SkewX;
QModelIndex index;
index = m_model.index( row, 0 );
m_model.setData( index, QVariant( column0Share - SkewX ) );
index = m_model.index( row, 1 );
m_model.setData( index, QVariant( column1Share + SkewX - SkewY) );
index = m_model.index( row, 2 );
m_model.setData( index, QVariant( column2Share + SkewY ) );
}
}
void MainWindow::indexClicked( const QModelIndex& index )
{
qDebug() << "MainWindow::indexClicked:" << index;
if ( index.isValid() ) {
QString text;
QTextStream stream( &text );
stream << "Row: " << index.row() << " - Column: " << index.column();
label->setText( text );
}
}
diff --git a/examples/Widget/Advanced/mainwindow.cpp b/examples/Widget/Advanced/mainwindow.cpp
index 1d39d1c..9137f8d 100644
--- a/examples/Widget/Advanced/mainwindow.cpp
+++ b/examples/Widget/Advanced/mainwindow.cpp
@@ -1,87 +1,87 @@
/**
* 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
using namespace KChart;
MainWindow::MainWindow( QWidget* parent )
: QWidget( parent ), datasetCount( 3 )
{
setupUi( this );
QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
widget = new Widget( chartFrame );
chartLayout->addWidget( widget );
typeSelector->setCurrentIndex(1); // we start by LineDiagram
- connect( typeSelector, SIGNAL( activated( int ) ), SLOT( changeType() ) );
+ connect( typeSelector, SIGNAL(activated(int)), SLOT(changeType()) );
- connect( btnAddDataset, SIGNAL( clicked() ), SLOT( addDataset() ) );
+ connect( btnAddDataset, SIGNAL(clicked()), SLOT(addDataset()) );
- connect( leadingSelector, SIGNAL( valueChanged( int ) ),
- this, SLOT( changeLeading( int ) ) );
+ connect( leadingSelector, SIGNAL(valueChanged(int)),
+ this, SLOT(changeLeading(int)) );
}
void MainWindow::changeType()
{
QString text = typeSelector->currentText();
if ( text == "Widget::Bar" )
widget->setType( Widget::Bar );
else if ( text == "Widget::Line" )
widget->setType( Widget::Line );
else if ( text == "Widget::Pie" )
widget->setType( Widget::Pie );
else if ( text == "Widget::Polar" )
widget->setType( Widget::Polar );
else
widget->setType( Widget::NoType );
}
void MainWindow::changeLeading( int leading )
{
widget->setGlobalLeading( leading, leading, leading, leading );
}
void MainWindow::addDataset()
{
QStringList parts = lineAddDataset->text().split( ';' );
bool ok;
QVector< qreal > vec;
foreach ( const QString &str, parts ) {
const qreal val = str.toDouble( &ok );
if ( ok )
vec.append( val );
}
const int rows = widget->diagram()->model()->rowCount();
if ( vec.count() != rows ) {
QMessageBox::warning( this, "Wrong number of values entered!",
QString( "You have entered %1 values,
but the data model needs %2 ones."
"
Note: Use ; to separate the values!" )
.arg(vec.count()).arg(rows));
} else {
widget->setDataset( datasetCount++, vec, "user data" );
}
}
diff --git a/examples/Zoom/ScrollBars/mainwindow.cpp b/examples/Zoom/ScrollBars/mainwindow.cpp
index 275b977..c856b55 100644
--- a/examples/Zoom/ScrollBars/mainwindow.cpp
+++ b/examples/Zoom/ScrollBars/mainwindow.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 "mainwindow.h"
#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();
m_chart->setGlobalLeadingTop( 10 );
m_chart->setGlobalLeadingRight( 10 );
chartLayout->addWidget( m_chart );
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 );
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_lines->addAxis( xAxis );
m_lines->addAxis( yAxis );
m_chart->coordinatePlane()->replaceDiagram( m_lines );
- connect( m_chart, SIGNAL( propertiesChanged() ), SLOT( applyNewZoomParameters() ) );
+ connect( m_chart, SIGNAL(propertiesChanged()), SLOT(applyNewZoomParameters()) );
// Set up the legend
m_legend = new Legend( m_lines, m_chart );
m_chart->addLegend( m_legend );
m_legend->setPosition( KChartEnums::PositionEast );
m_legend->setAlignment( Qt::AlignTop );
}
void MainWindow::on_zoomFactorSB_valueChanged( double factor )
{
if ( factor > 1 ) {
hSBar->setVisible( true );
vSBar->setVisible( true );
} else {
hSBar->setValue( 500 );
vSBar->setValue( 500 );
hSBar->setVisible( false );
vSBar->setVisible( false );
}
m_chart->coordinatePlane()->setZoomFactorX( factor );
m_chart->coordinatePlane()->setZoomFactorY( factor );
m_chart->update();
}
void MainWindow::on_adjustGridCB_toggled( bool checked )
{
static_cast ( m_chart->coordinatePlane() )
->setAutoAdjustGridToZoom( checked );
m_chart->update();
}
void MainWindow::on_rubberBandZoomCB_toggled( bool checked )
{
m_chart->coordinatePlane()->setRubberBandZoomingEnabled( checked );
}
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) );
m_chart->update();
}
void MainWindow::applyNewZoomParameters()
{
hSBar->blockSignals( true );
vSBar->blockSignals( true );
hSBar->setValue( qRound( m_chart->coordinatePlane()->zoomCenter().x() * 1000 ) );
vSBar->setValue( qRound( m_chart->coordinatePlane()->zoomCenter().y() * 1000 ) );
zoomFactorSB->setValue( m_chart->coordinatePlane()->zoomFactorX() );
hSBar->blockSignals( false );
vSBar->blockSignals( false );
}
diff --git a/examples/demo/axissettings.cpp b/examples/demo/axissettings.cpp
index 26b8db9..5f8d88e 100644
--- a/examples/demo/axissettings.cpp
+++ b/examples/demo/axissettings.cpp
@@ -1,205 +1,205 @@
/**
* 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 "axissettings.h"
#include "ui_axissettings.h"
-#include
-#include
+#include
+#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class AxisSettings::Private : public QObject
{
Q_OBJECT
public:
Private( Chart* chart, AxisSettings *q );
void init();
CartesianAxis *m_currentAxis;
QHash< CartesianCoordinatePlane*, QVector< CartesianAxis* > > m_axisCache;
Chart *m_chart;
Ui::AxisSettings ui;
AxisSettings *qq;
public Q_SLOTS:
void currentIndexChanged( int index );
void setVisible( bool value );
void setShowMajorTickMarks( bool value );
void setShowMinorTickMarks( bool value );
private:
void updateUiForCurrentAxis();
};
AxisSettings::Private::Private( Chart* chart, AxisSettings *q )
: m_chart( chart )
, qq( q )
{
}
void AxisSettings::Private::init()
{
ui.axisSelection->addItem( QIcon(), tr( "Left Y-Axis" ), CartesianAxis::Left );
ui.axisSelection->addItem( QIcon(), tr( "Right Y-Axis" ), CartesianAxis::Right );
ui.axisSelection->addItem( QIcon(), tr( "Bottom X-Axis" ), CartesianAxis::Bottom );
ui.axisSelection->addItem( QIcon(), tr( "Top X-Axis" ), CartesianAxis::Top );
- connect( ui.axisSelection, SIGNAL( currentIndexChanged( int ) ), this, SLOT( currentIndexChanged( int ) ) );
- connect( ui.axisVisibility, SIGNAL( toggled( bool ) ), this, SLOT( setVisible( bool ) ) );
- connect( ui.majorTicks, SIGNAL( toggled( bool ) ), this, SLOT( setShowMajorTickMarks( bool ) ) );
- connect( ui.minorTicks, SIGNAL( toggled( bool ) ), this, SLOT( setShowMinorTickMarks( bool ) ) );
+ connect( ui.axisSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int)) );
+ connect( ui.axisVisibility, SIGNAL(toggled(bool)), this, SLOT(setVisible(bool)) );
+ connect( ui.majorTicks, SIGNAL(toggled(bool)), this, SLOT(setShowMajorTickMarks(bool)) );
+ connect( ui.minorTicks, SIGNAL(toggled(bool)), this, SLOT(setShowMinorTickMarks(bool)) );
ui.axisSelection->setCurrentIndex( 0 );
}
void AxisSettings::Private::currentIndexChanged( int index )
{
m_currentAxis = 0;
const CartesianAxis::Position pos = ( CartesianAxis::Position ) ui.axisSelection->itemData( index ).toInt();
CartesianCoordinatePlane *plane = qobject_cast< CartesianCoordinatePlane* >( m_chart->coordinatePlane() );
AbstractCartesianDiagram *diag = qobject_cast< AbstractCartesianDiagram* >( m_chart->coordinatePlane()->diagram() );
if ( plane && diag )
{
QVector< CartesianAxis* > axes = diag->axes().toVector();
Q_FOREACH( CartesianAxis *axis, axes )
{
if ( axis->position() == pos )
{
m_currentAxis = axis;
break;
}
}
}
updateUiForCurrentAxis();
}
void AxisSettings::Private::updateUiForCurrentAxis()
{
const bool prevSignalsBlocked = ui.axisVisibility->blockSignals( true );
ui.axisVisibility->setChecked( m_currentAxis );
ui.axisVisibility->blockSignals( prevSignalsBlocked );
ui.majorTicks->setEnabled( m_currentAxis );
ui.minorTicks->setEnabled( m_currentAxis );
if ( m_currentAxis )
{
const RulerAttributes rulerAttr = m_currentAxis->rulerAttributes();
ui.majorTicks->setChecked( rulerAttr.showMajorTickMarks() );
ui.minorTicks->setChecked( rulerAttr.showMinorTickMarks() );
}
else
{
ui.majorTicks->setChecked( false );
ui.minorTicks->setChecked( false );
}
}
void AxisSettings::Private::setVisible( bool value )
{
const CartesianAxis::Position pos = ( CartesianAxis::Position ) ui.axisSelection->itemData( ui.axisSelection->currentIndex() ).toInt();
CartesianCoordinatePlane *plane = qobject_cast< CartesianCoordinatePlane* >( m_chart->coordinatePlane() );
AbstractCartesianDiagram *diag = qobject_cast< AbstractCartesianDiagram* >( m_chart->coordinatePlane()->diagram() );
if ( plane && diag )
{
QVector< CartesianAxis* > axes = m_axisCache[ plane ];
bool foundAxis = false;
Q_FOREACH( CartesianAxis *axis, axes )
{
if ( axis->position() == pos )
{
foundAxis = true;
if ( !value )
{
diag->takeAxis( axis );
m_currentAxis = 0;
}
else
{
diag->addAxis( axis );
m_currentAxis = axis;
}
break;
}
}
if ( !foundAxis )
{
Q_ASSERT( value );
CartesianAxis *axis = new CartesianAxis( diag );
axis->setPosition( pos );
diag->addAxis( axis );
m_axisCache[ plane ].append( axis );
m_currentAxis = axis;
}
updateUiForCurrentAxis();
m_chart->update();
}
}
void AxisSettings::Private::setShowMajorTickMarks( bool value )
{
if ( m_currentAxis )
{
RulerAttributes attr( m_currentAxis->rulerAttributes() );
attr.setShowMajorTickMarks( value );
m_currentAxis->setRulerAttributes( attr );
m_chart->update();
}
}
void AxisSettings::Private::setShowMinorTickMarks( bool value )
{
if ( m_currentAxis )
{
RulerAttributes attr( m_currentAxis->rulerAttributes() );
attr.setShowMinorTickMarks( value );
m_currentAxis->setRulerAttributes( attr );
m_chart->update();
}
}
AxisSettings::AxisSettings( Chart *chart, QWidget *parent )
: QWidget( parent )
, d( new Private( chart, this ) )
{
d->ui.setupUi( this );
d->init();
}
AxisSettings::~AxisSettings()
{
delete d;
}
void AxisSettings::diagramTypeChanged()
{
CartesianCoordinatePlane *plane = qobject_cast< CartesianCoordinatePlane* >( d->m_chart->coordinatePlane() );
setEnabled( plane );
if ( plane )
d->currentIndexChanged( d->ui.axisSelection->currentIndex() );
}
#include "axissettings.moc"
diff --git a/examples/demo/colorslider.cpp b/examples/demo/colorslider.cpp
index 8991761..6bfff10 100644
--- a/examples/demo/colorslider.cpp
+++ b/examples/demo/colorslider.cpp
@@ -1,163 +1,163 @@
/**
* 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 "colorslider.h"
-#include
-#include
-#include
+#include
+#include
+#include
#include
class ColorSlider::Private
{
public:
Private( ColorSlider *q );
void drawSliderMarker( QPainter *painter );
QColor m_startColor;
QColor m_endColor;
bool m_dragging;
ColorSlider *qq;
};
ColorSlider::Private::Private( ColorSlider *q )
: m_dragging( false )
, qq( q )
{
}
void ColorSlider::Private::drawSliderMarker( QPainter *painter )
{
QVector< QPointF > points; points << QPointF( -0.5, 0 ) << QPointF( 0.0, 0.5 ) << QPointF( 0.5, 0 );
QPolygonF triangle( points );
painter->drawPolygon( triangle );
}
ColorSlider::ColorSlider( QWidget *parent )
: QAbstractSlider( parent )
, d( new Private( this ) )
{
setSizePolicy( QSizePolicy( QSizePolicy::Minimum ,QSizePolicy::Fixed) );
setMinimum( 0 );
setMaximum( 255 );
setValue( 25 );
}
ColorSlider::~ColorSlider()
{
delete d;
}
QColor ColorSlider::startColor() const
{
return d->m_startColor;
}
void ColorSlider::setStartColor( const QColor &color )
{
if ( d->m_startColor != color )
{
d->m_startColor = color;
Q_EMIT startColorChanged();
update();
}
}
QColor ColorSlider::endColor() const
{
return d->m_endColor;
}
void ColorSlider::setEndColor( const QColor &color )
{
if ( d->m_endColor != color )
{
d->m_endColor = color;
Q_EMIT startColorChanged();
update();
}
}
void ColorSlider::paintEvent( QPaintEvent *event )
{
QAbstractSlider::paintEvent( event );
const double percentage = value() / ( double )( maximum() - minimum() );
QPainter painter( this );
QLinearGradient gradient;
gradient.setStart( 0, 0 );
gradient.setFinalStop( 1, 0 );
gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
gradient.setColorAt( 0, d->m_startColor );
gradient.setColorAt( 1, d->m_endColor );
painter.setBrush( gradient );
painter.drawRect( event->rect() );
painter.setBrush( Qt::white );
painter.save();
painter.translate( event->rect().width() * percentage, 0 );
QPen oldPen = painter.pen();
QPen linePen = oldPen;
linePen.setColor( Qt::white );
painter.setPen( linePen );
painter.drawLine( 0, 0, 0, rect().height() );
painter.setPen( oldPen );
painter.save();
painter.translate( 0, rect().height() );
painter.rotate( 180 );
painter.scale( 15, 15 );
d->drawSliderMarker( &painter );
painter.restore();
painter.scale( 15, 15 );
d->drawSliderMarker( &painter );
painter.restore();
}
void ColorSlider::mousePressEvent(QMouseEvent *event )
{
if ( event->button() == Qt::LeftButton )
{
d->m_dragging = true;
const double relPos = qMin( 1.0, qMax( 0.0, event->localPos().x() / rect().width() ) );
setValue( (maximum() - minimum() ) * relPos );
}
}
void ColorSlider::mouseReleaseEvent(QMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
{
d->m_dragging = false;
const double relPos = qMin( 1.0, qMax( 0.0, event->localPos().x() / rect().width() ) );
setValue( (maximum() - minimum() ) * relPos );
}
}
void ColorSlider::mouseMoveEvent( QMouseEvent *event )
{
if ( d->m_dragging )
{
const double relPos = qMin( 1.0, qMax( 0.0, event->localPos().x() / rect().width() ) );
setValue( (maximum() - minimum() ) * relPos );
}
}
QSize ColorSlider::sizeHint() const
{
return QSize( 300, 50 );
}
diff --git a/examples/demo/datasetsettings.cpp b/examples/demo/datasetsettings.cpp
index 98eaa41..6eaca1b 100644
--- a/examples/demo/datasetsettings.cpp
+++ b/examples/demo/datasetsettings.cpp
@@ -1,203 +1,203 @@
/**
* 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 "datasetsettings.h"
#include "ui_datasetsettings.h"
#include
#include
#include
#include
#include
-#include
+#include
-#include
+#include
-#include
+#include
#include "gradientdialog.h"
using namespace KChart;
class DatasetSettings::Private : public QObject
{
Q_OBJECT
public:
Private( Chart *chart, DatasetSettings *q, QObject *parent );
~Private();
Ui::DatasetSettings *ui;
int m_dataset;
int m_datasetCount;
KChart::Chart *m_chart;
DatasetSettings *qq;
public Q_SLOTS:
void changeColor();
void changeOutline();
};
DatasetSettings::Private::Private( Chart *chart, DatasetSettings *q, QObject *parent )
: QObject( parent )
, ui( new Ui::DatasetSettings )
, m_dataset( 0 )
, m_datasetCount( 0 )
, m_chart( chart )
, qq( q )
{
}
DatasetSettings::Private::~Private()
{
delete ui;
}
void DatasetSettings::Private::changeColor()
{
const int index = ui->datasetSelector->currentIndex();
if ( ui->Color->isChecked() )
{
QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index );
const QColor color = QColorDialog::getColor( setBrush.color(), qq, tr( "Choose new color" ) );
if ( !color.isValid() )
return;
m_chart->coordinatePlane()->diagram()->setBrush( index, color );
QPalette palette = ui->colorDisplay->palette();
palette.setBrush( QPalette::Button, color );
ui->colorDisplay->setPalette( palette );
}
else if ( ui->textureBtn->isChecked() )
{
//QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index );
QImage texture;
const QString filename = QFileDialog::getOpenFileName( qq, tr( "Choose Texture" ), QString(), tr( "Images (*.png *.xpm *.jpg)" ) );
if ( filename.isEmpty() )
return;
texture = QImage( filename );
m_chart->coordinatePlane()->diagram()->setBrush( index, texture );
QPalette palette = ui->colorDisplay->palette();
palette.setBrush( QPalette::Button, QBrush( texture ) );
ui->colorDisplay->setPalette( palette );
}
else
{
QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index );
QGradient grad;
QLinearGradient lGrad;
lGrad.setColorAt( 0, Qt::black );
lGrad.setColorAt( 1, setBrush.color() );
grad = lGrad;
if ( setBrush.gradient() )
grad = *setBrush.gradient();
const QGradient &color = GradientDialog::getGradient( grad, qq, tr( "Choose new color" ) );
m_chart->coordinatePlane()->diagram()->setBrush( index, color );
QPalette palette = ui->colorDisplay->palette();
palette.setBrush( QPalette::Button, QBrush( color ) );
ui->colorDisplay->setPalette( palette );
}
}
void DatasetSettings::Private::changeOutline()
{
const int index = ui->datasetSelector->currentIndex();
if ( ui->Color->isChecked() )
{
QPen pen = m_chart->coordinatePlane()->diagram()->pen( index );
const QColor color = QColorDialog::getColor( pen.color(), qq, tr( "Choose new color" ) );
if ( !color.isValid() )
return;
pen.setColor( color );
m_chart->coordinatePlane()->diagram()->setPen( index, pen );
QPalette palette = ui->outlineBtn->palette();
palette.setBrush( QPalette::Button, color );
ui->outlineBtn->setPalette( palette );
}
}
DatasetSettings::DatasetSettings( Chart *chart, QWidget *parent )
: QWidget( parent )
, d( new Private( chart, this, this ) )
{
d->ui->setupUi(this);
#ifdef Q_OS_LINUX
d->ui->colorDisplay->setStyle( QStyleFactory::create( QStringLiteral( "cleanlooks" ) ) );
d->ui->outlineBtn->setStyle( QStyleFactory::create( QStringLiteral( "cleanlooks" ) ) );
#endif
- connect( d->ui->datasetSelector, SIGNAL( currentIndexChanged( int ) ), this, SLOT( indexChanged( int ) ) );
- connect( d->ui->colorDisplay, SIGNAL( clicked() ), d, SLOT( changeColor() ) );
- connect( d->ui->outlineBtn, SIGNAL( clicked() ), d, SLOT( changeOutline() ) );
+ connect( d->ui->datasetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) );
+ connect( d->ui->colorDisplay, SIGNAL(clicked()), d, SLOT(changeColor()) );
+ connect( d->ui->outlineBtn, SIGNAL(clicked()), d, SLOT(changeOutline()) );
}
DatasetSettings::~DatasetSettings()
{
delete d;
}
int DatasetSettings::datasetCount() const
{
return d->m_datasetCount;
}
void DatasetSettings::setDatasetCount( int value )
{
if ( d->m_datasetCount != value )
{
d->m_datasetCount = value;
QStringList list;
for ( int i = 0; i < value; ++i )
{
list << tr( "Dataset %1" ).arg( i );
}
d->ui->datasetSelector->clear();
d->ui->datasetSelector->addItems( list );
Q_EMIT datasetCountChanged();
}
}
void DatasetSettings::indexChanged( int index )
{
if ( d->m_chart && index >= 0 )
{
const QBrush setBrush = d->m_chart->coordinatePlane()->diagram()->brush( index );
QPalette palette = d->ui->colorDisplay->palette();
if ( setBrush.gradient() )
d->ui->radioButton_2->setChecked( true );
else if ( !setBrush.textureImage().isNull() )
d->ui->textureBtn->setChecked( true );
else
d->ui->Color->setChecked( true );
palette.setBrush( QPalette::Button, setBrush );
d->ui->colorDisplay->setPalette( palette );
const QPen pen = d->m_chart->coordinatePlane()->diagram()->pen( index );
QPalette penPalette = d->ui->outlineBtn->palette();
penPalette.setBrush( QPalette::Button, pen.color() );
d->ui->outlineBtn->setPalette( penPalette );
}
}
void DatasetSettings::diagramTypeChanged()
{
}
#include "datasetsettings.moc"
diff --git a/examples/demo/datavaluesettings.cpp b/examples/demo/datavaluesettings.cpp
index 15fb8aa..ee4669a 100644
--- a/examples/demo/datavaluesettings.cpp
+++ b/examples/demo/datavaluesettings.cpp
@@ -1,488 +1,488 @@
/**
* 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 "datavaluesettings.h"
#include "ui_datavaluesettings.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KChart;
class DataValueSettings::Private : public QObject
{
Q_OBJECT
public:
Private( KChart::Chart *chart, DataValueSettings *q );
DataValueSettings *qq;
void init();
public Q_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 );
public:
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 );
void connectWidgets();
KChart::Chart* m_chart;
Ui::DataValueSettings *ui;
};
DataValueSettings::Private::Private( KChart::Chart *chart, DataValueSettings *q )
: qq ( q )
, m_chart( chart )
, ui( new Ui::DataValueSettings )
{
}
void DataValueSettings::Private::init()
{
ui->setupUi( qq );
ui->scopeCommonRB->setFocus( Qt::OtherFocusReason );
ui->scopeCommonRB->setChecked( true );
ui->paintValuesCB->setChecked( true );
populateWidgets();
connectWidgets();
}
void DataValueSettings::Private::connectWidgets()
{
- connect( ui->scopeBarDatasetSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_scopeBarDatasetSB_valueChanged( int ) ) );
- connect( ui->scopeBarItemSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_scopeBarItemSB_valueChanged( int ) ) );
- connect( ui->scopeDatasetSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_scopeDatasetSB_valueChanged( int ) ) );
- connect( ui->scopeOneBarRB, SIGNAL( toggled( bool ) ), this, SLOT( on_scopeOneBarRB_toggled( bool ) ) );
- connect( ui->scopeDatasetRB, SIGNAL( toggled( bool ) ), this, SLOT( on_scopeDatasetRB_toggled( bool ) ) );
- connect( ui->scopeCommonRB, SIGNAL( toggled( bool ) ), this, SLOT( on_scopeCommonRB_toggled( bool ) ) );
- connect( ui->paintValuesCB, SIGNAL( toggled( bool ) ), this, SLOT( on_paintValuesCB_toggled( bool ) ) );
- connect( ui->fontCombo, SIGNAL( currentIndexChanged( QString ) ), this , SLOT( on_fontCombo_currentIndexChanged( QString ) ) );
- connect( ui->relativeSizeSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_relativeSizeSB_valueChanged( int ) ) );
- connect( ui->minimumSizeSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_minimumSizeSB_valueChanged( int ) ) );
- connect( ui->rotationSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_rotationSB_valueChanged( int ) ) );
- connect( ui->posPosCombo, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( on_posPosCombo_currentIndexChanged( QString ) ) );
- connect( ui->posAlignCombo, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( on_posAlignCombo_currentIndexChanged( QString ) ) );
- connect( ui->posPadHoriSB, SIGNAL( valueChanged(int) ), this, SLOT( on_posPadHoriSB_valueChanged(int) ) );
- connect( ui->posPadVertSB, SIGNAL( valueChanged(int) ), this, SLOT( on_posPadVertSB_valueChanged(int) ) );
- connect( ui->negPosCombo, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( on_negPosCombo_currentIndexChanged( QString ) ) );
- connect( ui->negAlignCombo, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( on_negAlignCombo_currentIndexChanged( QString ) ) );
- connect( ui->negPadHoriSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_negPadHoriSB_valueChanged( int ) ) );
- connect( ui->negPadVertSB, SIGNAL( valueChanged( int ) ), this, SLOT( on_negPadVertSB_valueChanged( int ) ) );
- connect( ui->labelLE, SIGNAL( textEdited( QString ) ), this, SLOT( on_labelLE_textEdited( QString ) ) );
- connect( ui->prefixLE, SIGNAL( textEdited( QString ) ), this, SLOT( on_prefixLE_textEdited( QString ) ) );
- connect( ui->suffixLE, SIGNAL( textEdited( QString ) ), this, SLOT( on_suffixLE_textEdited( QString ) ) );
+ connect( ui->scopeBarDatasetSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeBarDatasetSB_valueChanged(int)) );
+ connect( ui->scopeBarItemSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeBarItemSB_valueChanged(int)) );
+ connect( ui->scopeDatasetSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeDatasetSB_valueChanged(int)) );
+ connect( ui->scopeOneBarRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeOneBarRB_toggled(bool)) );
+ connect( ui->scopeDatasetRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeDatasetRB_toggled(bool)) );
+ connect( ui->scopeCommonRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeCommonRB_toggled(bool)) );
+ connect( ui->paintValuesCB, SIGNAL(toggled(bool)), this, SLOT(on_paintValuesCB_toggled(bool)) );
+ connect( ui->fontCombo, SIGNAL(currentIndexChanged(QString)), this , SLOT(on_fontCombo_currentIndexChanged(QString)) );
+ connect( ui->relativeSizeSB, SIGNAL(valueChanged(int)), this, SLOT(on_relativeSizeSB_valueChanged(int)) );
+ connect( ui->minimumSizeSB, SIGNAL(valueChanged(int)), this, SLOT(on_minimumSizeSB_valueChanged(int)) );
+ connect( ui->rotationSB, SIGNAL(valueChanged(int)), this, SLOT(on_rotationSB_valueChanged(int)) );
+ connect( ui->posPosCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_posPosCombo_currentIndexChanged(QString)) );
+ connect( ui->posAlignCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_posAlignCombo_currentIndexChanged(QString)) );
+ connect( ui->posPadHoriSB, SIGNAL(valueChanged(int)), this, SLOT(on_posPadHoriSB_valueChanged(int)) );
+ connect( ui->posPadVertSB, SIGNAL(valueChanged(int)), this, SLOT(on_posPadVertSB_valueChanged(int)) );
+ connect( ui->negPosCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_negPosCombo_currentIndexChanged(QString)) );
+ connect( ui->negAlignCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_negAlignCombo_currentIndexChanged(QString)) );
+ connect( ui->negPadHoriSB, SIGNAL(valueChanged(int)), this, SLOT(on_negPadHoriSB_valueChanged(int)) );
+ connect( ui->negPadVertSB, SIGNAL(valueChanged(int)), this, SLOT(on_negPadVertSB_valueChanged(int)) );
+ connect( ui->labelLE, SIGNAL(textEdited(QString)), this, SLOT(on_labelLE_textEdited(QString)) );
+ connect( ui->prefixLE, SIGNAL(textEdited(QString)), this, SLOT(on_prefixLE_textEdited(QString)) );
+ connect( ui->suffixLE, SIGNAL(textEdited(QString)), this, SLOT(on_suffixLE_textEdited(QString)) );
}
DataValueSettings::DataValueSettings( KChart::Chart *chart, QWidget* parent )
: QWidget( parent )
, d( new Private( chart, this ) )
{
d->init();
}
DataValueSettings::~DataValueSettings()
{
delete d;
}
void DataValueSettings::refresh()
{
d->populateWidgets();
}
void DataValueSettings::Private::on_scopeOneBarRB_toggled( bool checked )
{
if ( checked ) {
ui->scopeBarDatasetSB->setDisabled( false );
ui->scopeBarItemSB->setDisabled( false );
ui->scopeDatasetSB->setDisabled( true );
populateWidgets();
}
}
void DataValueSettings::Private::on_scopeBarDatasetSB_valueChanged( int i )
{
Q_UNUSED(i)
populateWidgets();
}
void DataValueSettings::Private::on_scopeBarItemSB_valueChanged( int i )
{
Q_UNUSED(i)
populateWidgets();
}
void DataValueSettings::Private::on_scopeDatasetRB_toggled( bool checked )
{
if ( checked ) {
ui->scopeBarDatasetSB->setDisabled( true );
ui->scopeBarItemSB->setDisabled( true );
ui->scopeDatasetSB->setDisabled( false );
populateWidgets();
}
}
void DataValueSettings::Private::on_scopeDatasetSB_valueChanged( int i )
{
Q_UNUSED(i)
populateWidgets();
}
void DataValueSettings::Private::on_scopeCommonRB_toggled( bool checked )
{
if ( checked ) {
ui->scopeBarDatasetSB->setDisabled( true );
ui->scopeBarItemSB->setDisabled( true );
ui->scopeDatasetSB->setDisabled( true );
populateWidgets();
}
}
void DataValueSettings::Private::on_paintValuesCB_toggled( bool checked )
{
DataValueAttributes da( attributes() );
da.setVisible( checked );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_fontCombo_currentIndexChanged( const QString & text )
{
DataValueAttributes da( attributes() );
TextAttributes ta( da.textAttributes() );
QFont font( text );
ta.setFont( font );
da.setTextAttributes( ta );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_relativeSizeSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
TextAttributes ta( da.textAttributes() );
Measure fs( ta.fontSize() );
fs.setValue( i );
ta.setFontSize( i );
da.setTextAttributes( ta );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_minimumSizeSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
TextAttributes ta( da.textAttributes() );
Measure fs( ta.fontSize() );
fs.setValue( i );
ta.setMinimalFontSize( i );
da.setTextAttributes( ta );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_rotationSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
TextAttributes ta( da.textAttributes() );
ta.setRotation( i );
da.setTextAttributes( ta );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_posPosCombo_currentIndexChanged( const QString & text )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.positivePosition() );
relPos.setReferencePosition( Position::fromName( qPrintable( text ) ) );
da.setPositivePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_posAlignCombo_currentIndexChanged( const QString & text )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.positivePosition() );
relPos.setAlignment( alignmentFromScreeName( text ) );
da.setPositivePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_posPadHoriSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.positivePosition() );
Measure pad( relPos.horizontalPadding() );
pad.setValue( i );
relPos.setHorizontalPadding( pad );
da.setPositivePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_posPadVertSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.positivePosition() );
Measure pad( relPos.verticalPadding() );
pad.setValue( i );
relPos.setVerticalPadding( pad );
da.setPositivePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_negPosCombo_currentIndexChanged( const QString & text )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.negativePosition() );
relPos.setReferencePosition( Position::fromName( qPrintable( text ) ) );
da.setNegativePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_negAlignCombo_currentIndexChanged( const QString & text )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.negativePosition() );
relPos.setAlignment( alignmentFromScreeName( text ) );
da.setNegativePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_negPadHoriSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.negativePosition() );
Measure pad( relPos.horizontalPadding() );
pad.setValue( i );
relPos.setHorizontalPadding( pad );
da.setNegativePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_negPadVertSB_valueChanged( int i )
{
DataValueAttributes da( attributes() );
RelativePosition relPos( da.negativePosition() );
Measure pad( relPos.verticalPadding() );
pad.setValue( i );
relPos.setVerticalPadding( pad );
da.setNegativePosition( relPos );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_labelLE_textEdited( const QString & text )
{
DataValueAttributes da( attributes() );
da.setDataLabel( text.isEmpty() ? QString() : text );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_prefixLE_textEdited( const QString & text )
{
DataValueAttributes da( attributes() );
da.setPrefix( text.isEmpty() ? QString() : text );
setAttributes( da );
m_chart->update();
}
void DataValueSettings::Private::on_suffixLE_textEdited( const QString & text )
{
DataValueAttributes da( attributes() );
da.setSuffix( text.isEmpty() ? QString() : text );
setAttributes( da );
m_chart->update();
}
const QModelIndex DataValueSettings::Private::currentIndex() const
{
const int dataset = ui->scopeBarDatasetSB->value();
const int item = ui->scopeBarItemSB->value();
Q_ASSERT( m_chart );
Q_ASSERT( m_chart->coordinatePlane() );
AbstractDiagram *diag = m_chart->coordinatePlane()->diagram();
return diag->model()->index( item, dataset, QModelIndex() );
}
const KChart::DataValueAttributes DataValueSettings::Private::attributes() const
{
Q_ASSERT( m_chart );
Q_ASSERT( m_chart->coordinatePlane() );
AbstractDiagram *diag = m_chart->coordinatePlane()->diagram();
DataValueAttributes attr = diag->dataValueAttributes();
if ( ui->scopeOneBarRB->isChecked() ) {
attr = diag->dataValueAttributes( currentIndex() );
}
else if ( ui->scopeDatasetRB->isChecked() ) {
attr = diag->dataValueAttributes( ui->scopeDatasetSB->value() );
}
attr.setShowRepetitiveDataLabels( true );
return attr;
}
void DataValueSettings::Private::setAttributes( const KChart::DataValueAttributes& da )
{
Q_ASSERT( m_chart );
Q_ASSERT( m_chart->coordinatePlane() );
AbstractDiagram *diag = m_chart->coordinatePlane()->diagram();
if ( ui->scopeOneBarRB->isChecked() )
diag->setDataValueAttributes( currentIndex(), da );
else if ( ui->scopeDatasetRB->isChecked() )
diag->setDataValueAttributes( ui->scopeDatasetSB->value(), da );
else
diag->setDataValueAttributes( da );
}
// just a convenience method:
// In the combo box we have the text "( Default Value )" instead of "Unknown Position"
// because by setting a position to unknown we get KD Chart to use the
// diagram-specific default positions.
const char* DataValueSettings::Private::positionToScreenName( const Position& pos ) const
{
static const char* defaultPositionName = "( Default Value )";
if ( pos.isUnknown() )
return defaultPositionName;
return pos.name();
}
const Qt::Alignment DataValueSettings::Private::alignmentFromScreeName( const QString& name ) const
{
if ( name == "Center" ) return Qt::AlignCenter;
if ( name == "BottomLeft" ) return Qt::AlignLeft | Qt::AlignBottom;
if ( name == "Bottom" ) return Qt::AlignHCenter | Qt::AlignBottom;
if ( name == "BottomRight" ) return Qt::AlignRight | Qt::AlignBottom;
if ( name == "Right" ) return Qt::AlignRight | Qt::AlignVCenter;
if ( name == "TopRight" ) return Qt::AlignRight | Qt::AlignTop;
if ( name == "Top" ) return Qt::AlignHCenter | Qt::AlignTop;
if ( name == "TopLeft" ) return Qt::AlignLeft | Qt::AlignTop;
if ( name == "Left" ) return Qt::AlignLeft | Qt::AlignVCenter;
return Qt::AlignCenter;
}
const QString DataValueSettings::Private::alignmentToScreenName( const Qt::Alignment& align ) const
{
if ( align == Qt::AlignCenter ) return "Center";
if ( align == (Qt::AlignLeft | Qt::AlignBottom) ) return "BottomLeft";
if ( align == (Qt::AlignHCenter | Qt::AlignBottom) ) return "Bottom";
if ( align == (Qt::AlignRight | Qt::AlignBottom) ) return "BottomRight";
if ( align == (Qt::AlignRight | Qt::AlignVCenter) ) return "Right";
if ( align == (Qt::AlignRight | Qt::AlignTop) ) return "TopRight";
if ( align == (Qt::AlignHCenter | Qt::AlignTop) ) return "Top";
if ( align == (Qt::AlignLeft | Qt::AlignTop) ) return "TopLeft";
if ( align == (Qt::AlignLeft | Qt::AlignVCenter) ) return "Left";
return "Center";
}
void DataValueSettings::Private::populateWidgets()
{
const DataValueAttributes da( attributes() );
const TextAttributes ta( da.textAttributes() );
const RelativePosition posPos( da.positivePosition() );
const RelativePosition negPos( da.negativePosition() );
ui->paintValuesCB->setChecked( da.isVisible() && ta.isVisible() );
ui->fontCombo->setCurrentFont( ta.font() );
ui->relativeSizeSB->setValue( static_cast(ta.fontSize().value()) );
ui->minimumSizeSB->setValue( static_cast(ta.minimalFontSize().value()) );
ui->rotationSB->setValue( static_cast