##// END OF EJS Templates
Copyright header changes...
Copyright header changes Copyright header changes for Qt 5.5. Change-Id: I2b8e9356997de2c87a7436bcefd4d0948d566259 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>

File last commit:

r2776:bc1f6aa59d42
r2776:bc1f6aa59d42
Show More
widget.cpp
126 lines | 3.9 KiB | text/x-c | CppLexer
Jani Honkonen
add missing license statements
r1916 /****************************************************************************
**
Titta Heikkala
Copyright header changes...
r2776 ** Copyright (C) 2015 The Qt Company Ltd
Jani Honkonen
add missing license statements
r1916 ** All rights reserved.
Titta Heikkala
Copyright header changes...
r2776 ** For any questions to The Qt Company, please use contact form at http://qt.io
Jani Honkonen
add missing license statements
r1916 **
Titta Heikkala
Updated license headers...
r2740 ** This file is part of the Qt Charts module.
Jani Honkonen
add missing license statements
r1916 **
Titta Heikkala
Updated license headers...
r2740 ** Licensees holding valid commercial license for Qt may use this file in
** accordance with the Qt License Agreement provided with the Software
** or, alternatively, in accordance with the terms contained in a written
Titta Heikkala
Copyright header changes...
r2776 ** agreement between you and The Qt Company.
Jani Honkonen
add missing license statements
r1916 **
** If you have questions regarding the use of this file, please use
Titta Heikkala
Updated license headers...
r2740 ** contact form at http://qt.io
Jani Honkonen
add missing license statements
r1916 **
****************************************************************************/
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 #include "widget.h"
Titta Heikkala
Fix include syntax...
r2714 #include <QtCharts/QChartView>
#include <QtCharts/QChart>
#include <QtCharts/QLegend>
#include <QtCharts/QPieSeries>
#include <QtCharts/QPieSlice>
#include <QtCore/QTime>
#include <QtWidgets/QGridLayout>
#include <QtCore/QTimer>
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_USE_NAMESPACE
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
Widget::Widget(QWidget *parent)
: QWidget(parent)
Jani Honkonen
coding style fixes for demos
r2099 {
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 setMinimumSize(800, 600);
Jani Honkonen
coding style fixes for demos
r2099 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
Marek Rosa
Documented the donut example
r1713 //! [1]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 QChartView *chartView = new QChartView;
chartView->setRenderHint(QPainter::Antialiasing);
Jani Honkonen
coding style fixes for demos
r2099 QChart *chart = chartView->chart();
Marek Rosa
Donut support simplified. Examples updated
r1838 chart->legend()->setVisible(false);
Jani Honkonen
Moved 'donut' example to demos 'nesteddonuts'
r1877 chart->setTitle("Nested donuts demo");
Marek Rosa
Nesteddonuts chart docs updated
r1985 chart->setAnimationOptions(QChart::AllAnimations);
Marek Rosa
Documented the donut example
r1713 //! [1]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
Marek Rosa
Documented the donut example
r1713 //! [2]
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 qreal minSize = 0.1;
qreal maxSize = 0.9;
Marek Rosa
Donut support simplified. Examples updated
r1838 int donutCount = 5;
Marek Rosa
Documented the donut example
r1713 //! [2]
//! [3]
Marek Rosa
Donut support simplified. Examples updated
r1838 for (int i = 0; i < donutCount; i++) {
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 QPieSeries *donut = new QPieSeries;
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 int sliceCount = 3 + qrand() % 3;
for (int j = 0; j < sliceCount; j++) {
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 qreal value = 100 + qrand() % 100;
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
Marek Rosa
Documented the donut example
r1713 slice->setLabelVisible(true);
slice->setLabelColor(Qt::white);
slice->setLabelPosition(QPieSlice::LabelInsideTangential);
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool)));
donut->append(slice);
Marek Rosa
Donut support simplified. Examples updated
r1838 donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount);
donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount);
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 }
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 m_donuts.append(donut);
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 chartView->chart()->addSeries(donut);
}
Marek Rosa
Documented the donut example
r1713 //! [3]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
// create main layout
Marek Rosa
Documented the donut example
r1713 //! [4]
Jani Honkonen
coding style fixes for demos
r2099 QGridLayout *mainLayout = new QGridLayout;
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 mainLayout->addWidget(chartView, 1, 1);
setLayout(mainLayout);
Marek Rosa
Documented the donut example
r1713 //! [4]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693
Marek Rosa
Documented the donut example
r1713 //! [5]
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 updateTimer = new QTimer(this);
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateRotation()));
Marek Rosa
Documented the donut example
r1713 updateTimer->start(1250);
//! [5]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 }
Widget::~Widget()
{
Jani Honkonen
coding style fixes for demos
r2099
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 }
Jani Honkonen
coding style fixes for demos
r2099 //! [6]
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 void Widget::updateRotation()
{
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 for (int i = 0; i < m_donuts.count(); i++) {
QPieSeries *donut = m_donuts.at(i);
Marek Rosa
Added insert, remove and other common methodds to QDonutGroup. Donut example added
r1693 qreal phaseShift = -50 + qrand() % 100;
donut->setPieStartAngle(donut->pieStartAngle() + phaseShift);
donut->setPieEndAngle(donut->pieEndAngle() + phaseShift);
}
}
Jani Honkonen
coding style fixes for demos
r2099 //! [6]
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697
Jani Honkonen
coding style fixes for demos
r2099 //! [7]
Marek Rosa
Removed QDonutGroup class. Added Donut Drill down example
r1697 void Widget::explodeSlice(bool exploded)
{
QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
if (exploded) {
updateTimer->stop();
qreal sliceStartAngle = slice->startAngle();
qreal sliceEndAngle = slice->startAngle() + slice->angleSpan();
QPieSeries *donut = slice->series();
qreal seriesIndex = m_donuts.indexOf(donut);
for (int i = seriesIndex + 1; i < m_donuts.count(); i++) {
m_donuts.at(i)->setPieStartAngle(sliceEndAngle);
m_donuts.at(i)->setPieEndAngle(360 + sliceStartAngle);
}
} else {
for (int i = 0; i < m_donuts.count(); i++) {
m_donuts.at(i)->setPieStartAngle(0);
m_donuts.at(i)->setPieEndAngle(360);
}
updateTimer->start();
}
slice->setExploded(exploded);
}
Jani Honkonen
coding style fixes for demos
r2099 //! [7]