From e5aa797837bafdd666cc9aff9cb09f0722d56214 2012-08-25 08:16:33 From: Marek Rosa Date: 2012-08-25 08:16:33 Subject: [PATCH] Added basic donut chart example. Still better data needed --- diff --git a/examples/donutchart/donutchart.pro b/examples/donutchart/donutchart.pro new file mode 100644 index 0000000..72d4ea4 --- /dev/null +++ b/examples/donutchart/donutchart.pro @@ -0,0 +1,5 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} +TARGET = donutchart +SOURCES += main.cpp diff --git a/examples/donutchart/main.cpp b/examples/donutchart/main.cpp new file mode 100644 index 0000000..ef1379b --- /dev/null +++ b/examples/donutchart/main.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + +//![1] + QPieSeries *series = new QPieSeries(); + series->setHoleSize(0.35); + series->append("Jane", 1); + series->append("Joe", 2); + series->append("Andy", 3); + series->append("Barbara", 4); + series->append("Axel", 5); +//![1] + +//![2] + QPieSlice *slice = series->slices().at(1); + slice->setExploded(); + slice->setLabelVisible(); + slice->setPen(QPen(Qt::darkGreen, 2)); + slice->setBrush(Qt::green); +//![2] + +//![3] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple donutchart example"); +//![3] + +//![4] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![4] + +//![5] + QMainWindow window; + window.setCentralWidget(chartView); + window.resize(400, 300); + window.show(); +//![5] + + return a.exec(); +} diff --git a/examples/examples.pro b/examples/examples.pro index e13e5ab..612723a 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -31,4 +31,5 @@ SUBDIRS += \ donutbreakdown \ scrollchart \ datetimeaxis \ - populationpyramid + populationpyramid \ + donutchart diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index 0fc31a5..a4a9214 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -169,8 +169,17 @@ void PieSliceItem::updateGeometry() m_labelTextRect.moveBottomLeft(labelTextStart); break; case QPieSlice::LabelInsideHorizontal: - case QPieSlice::LabelInsideTangential: + case QPieSlice::LabelInsideTangential:{ + QPointF textCenter; + if (m_data.m_holeRadius > 0) + textCenter = m_data.m_center + offset(centerAngle, m_data.m_holeRadius + (m_data.m_radius - m_data.m_holeRadius) / 2); + else + textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); + m_labelTextRect.moveCenter(textCenter); + break; + } case QPieSlice::LabelInsideNormal:{ + // TODO: align the label text to the slice arc insead of half the radius QPointF textCenter; if (m_data.m_holeRadius > 0) textCenter = m_data.m_center + offset(centerAngle, m_data.m_holeRadius + (m_data.m_radius - m_data.m_holeRadius) / 2); diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index e3bc024..0f71ae1 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -741,7 +741,6 @@ QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : m_pieStartAngle(0), m_pieEndAngle(360), m_sum(0), -// m_donutChart(false), m_holeRelativeSize(0.0) { }