diff --git a/examples/Bars/Advanced/mainwindow.cpp b/examples/Bars/Advanced/mainwindow.cpp index 76a9f24..5c6fa8a 100644 --- a/examples/Bars/Advanced/mainwindow.cpp +++ b/examples/Bars/Advanced/mainwindow.cpp @@ -1,231 +1,247 @@ /** * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. * * This file is part of the KD Chart library. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "mainwindow.h" #include #include #include #include #include #include #include #include #include #include using namespace KChart; MainWindow::MainWindow( QWidget* parent ) : QWidget( parent ) { setupUi( this ); QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); m_chart = new Chart(); chartLayout->addWidget( m_chart ); m_model.loadFromCSV( ":/data" ); // Set up the diagram m_bars = new BarDiagram(); m_bars->setModel( &m_model ); // define custom color for the borders of the bars QPen pen( m_bars->pen() ); pen.setColor( Qt::black ); pen.setWidth( 0 ); m_bars->setPen( pen ); m_chart->coordinatePlane()->replaceDiagram( m_bars ); // define custom colours for the bars QList bcolor; bcolor.append(Qt::darkGreen); bcolor.append(Qt::green); bcolor.append(Qt::darkRed); bcolor.append(Qt::red); for (int row=0; row < m_model.columnCount(); ++row) { m_bars->setBrush(row, QBrush(bcolor[row])); } // Configure the plane's Background BackgroundAttributes pba; //pba.setBrush( QBrush(QColor(0x20,0x20,0x60)) ); pba.setVisible( true ); m_chart->coordinatePlane()->setBackgroundAttributes( pba ); m_chart->setGlobalLeadingTop( 20 ); + + connect(reverse, SIGNAL(toggled(bool)), this, SLOT(setReverseDirection(bool))); } void MainWindow::on_barTypeCB_currentIndexChanged( const QString & text ) { if ( text == "Normal" ) m_bars->setType( BarDiagram::Normal ); else if ( text == "Stacked" ) m_bars->setType( BarDiagram::Stacked ); else if ( text == "Percent" ) m_bars->setType( BarDiagram::Percent ); else qWarning (" Does not match any type"); m_chart->update(); } void MainWindow::on_barOrientationCB_currentIndexChanged(const QString & text) { if ( text == "Vertical" ) m_bars->setOrientation( Qt::Vertical ); else if ( text == "Horizontal" ) m_bars->setOrientation( Qt::Horizontal ); else qWarning (" Does not match any orientation"); m_chart->update(); } void MainWindow::on_paintValuesCB_toggled( bool checked ) { Q_UNUSED( checked ); // We set the DataValueAttributes on a per-column basis here, // because we want the texts to be printed in different // colours - according to their respective dataset's colour. const QFont font(QFont( "Comic", 10 )); const int colCount = m_bars->model()->columnCount(); for ( int iColumn = 0; iColumnbrush( iColumn ) ); DataValueAttributes a( m_bars->dataValueAttributes( iColumn ) ); TextAttributes ta( a.textAttributes() ); ta.setRotation( 0 ); ta.setFont( font ); ta .setPen( QPen( brush.color() ) ); if ( checked ) ta.setVisible( true ); else ta.setVisible( false ); a.setTextAttributes( ta ); a.setVisible( true ); m_bars->setDataValueAttributes( iColumn, a); } m_chart->update(); } void MainWindow::on_paintThreeDBarsCB_toggled( bool checked ) { ThreeDBarAttributes td( m_bars->threeDBarAttributes() ); qreal defaultDepth = td.depth(); if ( checked ) { td.setEnabled( true ); if ( threeDDepthCB->isChecked() ) td.setDepth( depthSB->value() ); else td.setDepth( defaultDepth ); } else { td.setEnabled( false ); } m_bars->setThreeDBarAttributes( td ); m_chart->update(); } void MainWindow::on_markColumnCB_toggled( bool checked ) { const int column = markColumnSB->value(); QPen pen( m_bars->pen( column ) ); if ( checked ) { pen.setColor( Qt::yellow ); pen.setStyle( Qt::DashLine ); pen.setWidth( 3 ); } else { pen.setColor( Qt::black ); pen.setStyle( Qt::SolidLine ); pen.setWidth( 1 ); } m_bars->setPen( column, pen ); m_chart->update(); } void MainWindow::on_depthSB_valueChanged( int i ) { Q_UNUSED( i ); if ( threeDDepthCB->isChecked() && paintThreeDBarsCB->isChecked() ) on_paintThreeDBarsCB_toggled( true ); } void MainWindow::on_threeDDepthCB_toggled( bool checked ) { Q_UNUSED( checked ); if ( paintThreeDBarsCB->isChecked() ) on_paintThreeDBarsCB_toggled( true ); } void MainWindow::on_markColumnSB_valueChanged( int i ) { QPen pen( m_bars->pen( i ) ); markColumnCB->setChecked( pen.color() == Qt::yellow ); } void MainWindow::on_widthSB_valueChanged( int value ) { if ( widthCB->isChecked() ) { BarAttributes ba( m_bars->barAttributes() ); ba.setFixedBarWidth( value ); ba.setUseFixedBarWidth( true ); m_bars->setBarAttributes( ba ); } m_chart->update(); } void MainWindow::on_widthCB_toggled( bool checked ) { if ( checked ) { on_widthSB_valueChanged( widthSB->value() ); } else { BarAttributes ba( m_bars->barAttributes() ); ba.setUseFixedBarWidth( false ); m_bars->setBarAttributes( ba ); m_chart->update(); } } void MainWindow::on_fixPlaneSizeCB_toggled( bool checked ) { CartesianCoordinatePlane* plane = qobject_cast( m_chart->coordinatePlane() ); if ( plane == nullptr ) return; plane->setFixedDataCoordinateSpaceRelation( checked ); // just a little adjustment: // Reset the zoom settings to their initial values // when the releation-adjust checkbox is unchecked: if ( ! checked ) { m_chart->coordinatePlane()->setZoomFactorX( 1.0 ); m_chart->coordinatePlane()->setZoomFactorY( 1.0 ); m_chart->coordinatePlane()->setZoomCenter( QPointF(0.5, 0.5) ); } m_chart->update(); } + +void MainWindow::setReverseDirection(bool reverse) +{ + CartesianCoordinatePlane* plane = + qobject_cast( m_chart->coordinatePlane() ); + if ( plane == nullptr ) + return; + + if (axes->currentIndex() == 0) { + plane->setHorizontalRangeReversed(reverse); + } else if (axes->currentIndex() == 1) { + plane->setVerticalRangeReversed(reverse); + } +} diff --git a/examples/Bars/Advanced/mainwindow.h b/examples/Bars/Advanced/mainwindow.h index e1299fc..99e9a46 100644 --- a/examples/Bars/Advanced/mainwindow.h +++ b/examples/Bars/Advanced/mainwindow.h @@ -1,60 +1,62 @@ /** * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. * * This file is part of the KD Chart library. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include "ui_mainwindow.h" #include namespace KChart { class Chart; class BarDiagram; } class MainWindow : public QWidget, private Ui::MainWindow { Q_OBJECT public: MainWindow( QWidget* parent = nullptr ); private slots: void on_barTypeCB_currentIndexChanged( const QString & text ); void on_barOrientationCB_currentIndexChanged( const QString & text ); void on_paintValuesCB_toggled( bool checked ); void on_paintThreeDBarsCB_toggled( bool checked ); void on_markColumnCB_toggled( bool checked ); void on_markColumnSB_valueChanged( int i ); void on_threeDDepthCB_toggled( bool checked ); void on_depthSB_valueChanged( int i ); void on_widthCB_toggled( bool checked ); void on_widthSB_valueChanged( int i ); void on_fixPlaneSizeCB_toggled( bool checked ); + void setReverseDirection(bool); + private: KChart::Chart* m_chart; KChart::BarDiagram* m_bars; TableModel m_model; }; #endif /* MAINWINDOW_H */ diff --git a/examples/Bars/Advanced/mainwindow.ui b/examples/Bars/Advanced/mainwindow.ui index 87a4917..220cd20 100644 --- a/examples/Bars/Advanced/mainwindow.ui +++ b/examples/Bars/Advanced/mainwindow.ui @@ -1,273 +1,319 @@ MainWindow 0 0 692 - 424 + 598 Bar Chart - - + .. - - - - - Data / plane space relation fixed - - - - - - - Qt::Vertical - - - - 171 - 51 - - - - - - - - Qt::Horizontal - - - - - - - 6 - + + + - + - Configure Width + Display Data Values - + + + Qt::Horizontal + + + + + 6 - + - Bars Width + Bar Chart Type - + + + + Normal + + + + + Stacked + + + + + Percent + + + + + + + + Bar Orientation + + + + + + + + Vertical + + + + + Horizontal + + + - - - - - - Qt::Horizontal - - - - - - - 6 - - - - Paint ThreeD Bars + + + Qt::Horizontal - - - ThreeD + + + 6 + + + + + Pen Settings + + + + + + + 6 + + + + + Mark Column + + + + + + + 3 + + + + + + + + + + + Qt::Horizontal - + 6 - + - Bars Depth + Paint ThreeD Bars - - - 20 + + + ThreeD + + + + 6 + + + + + Bars Depth + + + + + + + 20 + + + + + - - - - - - Qt::Horizontal - - - - - - - 6 - - - - Pen Settings + + + Qt::Horizontal - + 6 - + - Mark Column + Configure Width - - - 3 + + + 6 - + + + + Bars Width + + + + + + + - - - - - - Qt::Horizontal - - - - - - - 6 - - - - Bar Chart Type + + + Qt::Horizontal - + - - Normal - - - - - Stacked - + + + Axis Direction + + - - Percent - + + + + + + X Axis + + + + + Y Axis + + + + + + + + Reverse + + + + + + + + + + Qt::Horizontal + - + - Bar Orientation + Data / plane space relation fixed - - - - Vertical - - - - - Horizontal - - - + + + Qt::Vertical + + + + 171 + 51 + + + - - - - Qt::Horizontal - - - - - - - Display Data Values - - - - + Qt::Horizontal 300 400 QFrame::StyledPanel QFrame::Raised