/usr/share/qt5/doc/qtcharts/qtcharts-nesteddonuts-example.html is in qtcharts5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- examples-nesteddonuts.qdoc -->
<title>Nested Donuts Example | Qt Charts 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td >Qt 5.9</td><td ><a href="qtcharts-index.html">Qt Charts</a></td><td ><a href="qtcharts-examples.html">Qt Charts Examples</a></td><td >Nested Donuts Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#creating-nested-donut-charts">Creating Nested Donut Charts</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Nested Donuts Example</h1>
<span class="subtitle"></span>
<!-- $$$nesteddonuts-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/examples_nesteddonuts.png" alt="" /></p><a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="creating-nested-donut-charts"></a>
<h2 id="creating-nested-donut-charts">Creating Nested Donut Charts</h2>
<p>Let's start by creating a <a href="qchartview.html">QChartView</a> instance and enabling the Antialiasing on it. A <a href="qchart.html">QChart</a> object is then obtained from the <a href="qchartview.html">QChartView</a> instance. The legend is disabled and the title of the chart is set. Last line enables the animations of the chart.</p>
<pre class="cpp">
<span class="type"><a href="qchartview.html">QChartView</a></span> <span class="operator">*</span>chartView <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qchartview.html">QChartView</a></span>;
chartView<span class="operator">-</span><span class="operator">></span>setRenderHint(<span class="type">QPainter</span><span class="operator">::</span>Antialiasing);
<span class="type"><a href="qchart.html">QChart</a></span> <span class="operator">*</span>chart <span class="operator">=</span> chartView<span class="operator">-</span><span class="operator">></span>chart();
chart<span class="operator">-</span><span class="operator">></span>legend()<span class="operator">-</span><span class="operator">></span>setVisible(<span class="keyword">false</span>);
chart<span class="operator">-</span><span class="operator">></span>setTitle(<span class="string">"Nested donuts demo"</span>);
chart<span class="operator">-</span><span class="operator">></span>setAnimationOptions(<span class="type"><a href="qchart.html">QChart</a></span><span class="operator">::</span>AllAnimations);
</pre>
<p>Three variables are defined that will be used to define the donut chart. Min and max size define the relative size of the whole donut. minSize is the relative inner size of the smallest donut. maxSize is the relative outer size of the biggest donut.</p>
<pre class="cpp">
<span class="type">qreal</span> minSize <span class="operator">=</span> <span class="number">0.1</span>;
<span class="type">qreal</span> maxSize <span class="operator">=</span> <span class="number">0.9</span>;
<span class="type">int</span> donutCount <span class="operator">=</span> <span class="number">5</span>;
</pre>
<p>The following block of code defines the individual donuts and their slices. First a new <a href="qpieseries.html">QPieSeries</a> object is created. The number of slices in each donut is randomized. The internal for loop creates the slices with a random value and label same as the value. Next the label of the slice is set to be visible and its color is set to white. To make the example more interesting the hovered signal of the slice is connected to widget's slot, of which the inner workings are explained later. Finally the slice is added to the donut. The donut's size is adjusted to achieve the nesting of the donuts. Then the donut is added to the widget's list of donuts and to the chart.</p>
<pre class="cpp">
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> donutCount; i<span class="operator">+</span><span class="operator">+</span>) {
<span class="type"><a href="qpieseries.html">QPieSeries</a></span> <span class="operator">*</span>donut <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpieseries.html">QPieSeries</a></span>;
<span class="type">int</span> sliceCount <span class="operator">=</span> <span class="number">3</span> <span class="operator">+</span> qrand() <span class="operator">%</span> <span class="number">3</span>;
<span class="keyword">for</span> (<span class="type">int</span> j <span class="operator">=</span> <span class="number">0</span>; j <span class="operator"><</span> sliceCount; j<span class="operator">+</span><span class="operator">+</span>) {
<span class="type">qreal</span> value <span class="operator">=</span> <span class="number">100</span> <span class="operator">+</span> qrand() <span class="operator">%</span> <span class="number">100</span>;
<span class="type"><a href="qpieslice.html">QPieSlice</a></span> <span class="operator">*</span>slice <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpieslice.html">QPieSlice</a></span>(<span class="type">QString</span>(<span class="string">"%1"</span>)<span class="operator">.</span>arg(value)<span class="operator">,</span> value);
slice<span class="operator">-</span><span class="operator">></span>setLabelVisible(<span class="keyword">true</span>);
slice<span class="operator">-</span><span class="operator">></span>setLabelColor(<span class="type">Qt</span><span class="operator">::</span>white);
slice<span class="operator">-</span><span class="operator">></span>setLabelPosition(<span class="type"><a href="qpieslice.html">QPieSlice</a></span><span class="operator">::</span>LabelInsideTangential);
connect(slice<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qpieslice.html">QPieSlice</a></span><span class="operator">::</span>hovered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Widget<span class="operator">::</span>explodeSlice);
donut<span class="operator">-</span><span class="operator">></span>append(slice);
donut<span class="operator">-</span><span class="operator">></span>setHoleSize(minSize <span class="operator">+</span> i <span class="operator">*</span> (maxSize <span class="operator">-</span> minSize) <span class="operator">/</span> donutCount);
donut<span class="operator">-</span><span class="operator">></span>setPieSize(minSize <span class="operator">+</span> (i <span class="operator">+</span> <span class="number">1</span>) <span class="operator">*</span> (maxSize <span class="operator">-</span> minSize) <span class="operator">/</span> donutCount);
}
m_donuts<span class="operator">.</span>append(donut);
chartView<span class="operator">-</span><span class="operator">></span>chart()<span class="operator">-</span><span class="operator">></span>addSeries(donut);
}
</pre>
<p>Finally the widget is placed in a layout used by the application.</p>
<pre class="cpp">
<span class="type">QGridLayout</span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QGridLayout</span>;
mainLayout<span class="operator">-</span><span class="operator">></span>addWidget(chartView<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
setLayout(mainLayout);
</pre>
<p>To make the example more interesting the donuts are rotated randomly every 1.25 sec.</p>
<pre class="cpp">
updateTimer <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QTimer</span>(<span class="keyword">this</span>);
connect(updateTimer<span class="operator">,</span> <span class="operator">&</span><span class="type">QTimer</span><span class="operator">::</span>timeout<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Widget<span class="operator">::</span>updateRotation);
updateTimer<span class="operator">-</span><span class="operator">></span>start(<span class="number">1250</span>);
</pre>
<p>The widget's updatedRotation slot is defined below. It goes through all of the donuts and modifies their current rotation by a random value.</p>
<pre class="cpp">
<span class="type">void</span> Widget<span class="operator">::</span>updateRotation()
{
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> m_donuts<span class="operator">.</span>count(); i<span class="operator">+</span><span class="operator">+</span>) {
<span class="type"><a href="qpieseries.html">QPieSeries</a></span> <span class="operator">*</span>donut <span class="operator">=</span> m_donuts<span class="operator">.</span>at(i);
<span class="type">qreal</span> phaseShift <span class="operator">=</span> <span class="operator">-</span><span class="number">50</span> <span class="operator">+</span> qrand() <span class="operator">%</span> <span class="number">100</span>;
donut<span class="operator">-</span><span class="operator">></span>setPieStartAngle(donut<span class="operator">-</span><span class="operator">></span>pieStartAngle() <span class="operator">+</span> phaseShift);
donut<span class="operator">-</span><span class="operator">></span>setPieEndAngle(donut<span class="operator">-</span><span class="operator">></span>pieEndAngle() <span class="operator">+</span> phaseShift);
}
}
</pre>
<p>The earlier mentioned explodeSlice slot code is provided below. If the slice is set to exploded, then stop the timer that controls the donuts rotation. Then the slice's start and end angles are obtained from the slice. To highlight the selected slice all the other donuts that lie outward from the one that contains the selected slice have their start and end angles modified so that they wouldn't "block" the way for the hightlighted slice. If the slice is no longer selected return to the original state.</p>
<pre class="cpp">
<span class="type">void</span> Widget<span class="operator">::</span>explodeSlice(bool exploded)
{
<span class="type"><a href="qpieslice.html">QPieSlice</a></span> <span class="operator">*</span>slice <span class="operator">=</span> qobject_cast<span class="operator"><</span><span class="type"><a href="qpieslice.html">QPieSlice</a></span> <span class="operator">*</span><span class="operator">></span>(sender());
<span class="keyword">if</span> (exploded) {
updateTimer<span class="operator">-</span><span class="operator">></span>stop();
<span class="type">qreal</span> sliceStartAngle <span class="operator">=</span> slice<span class="operator">-</span><span class="operator">></span>startAngle();
<span class="type">qreal</span> sliceEndAngle <span class="operator">=</span> slice<span class="operator">-</span><span class="operator">></span>startAngle() <span class="operator">+</span> slice<span class="operator">-</span><span class="operator">></span>angleSpan();
<span class="type"><a href="qpieseries.html">QPieSeries</a></span> <span class="operator">*</span>donut <span class="operator">=</span> slice<span class="operator">-</span><span class="operator">></span>series();
<span class="type">qreal</span> seriesIndex <span class="operator">=</span> m_donuts<span class="operator">.</span>indexOf(donut);
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> seriesIndex <span class="operator">+</span> <span class="number">1</span>; i <span class="operator"><</span> m_donuts<span class="operator">.</span>count(); i<span class="operator">+</span><span class="operator">+</span>) {
m_donuts<span class="operator">.</span>at(i)<span class="operator">-</span><span class="operator">></span>setPieStartAngle(sliceEndAngle);
m_donuts<span class="operator">.</span>at(i)<span class="operator">-</span><span class="operator">></span>setPieEndAngle(<span class="number">360</span> <span class="operator">+</span> sliceStartAngle);
}
} <span class="keyword">else</span> {
<span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> m_donuts<span class="operator">.</span>count(); i<span class="operator">+</span><span class="operator">+</span>) {
m_donuts<span class="operator">.</span>at(i)<span class="operator">-</span><span class="operator">></span>setPieStartAngle(<span class="number">0</span>);
m_donuts<span class="operator">.</span>at(i)<span class="operator">-</span><span class="operator">></span>setPieEndAngle(<span class="number">360</span>);
}
updateTimer<span class="operator">-</span><span class="operator">></span>start();
}
slice<span class="operator">-</span><span class="operator">></span>setExploded(exploded);
}
</pre>
<p>Files:</p>
<ul>
<li><a href="qtcharts-nesteddonuts-widget-cpp.html">nesteddonuts/widget.cpp</a></li>
<li><a href="qtcharts-nesteddonuts-widget-h.html">nesteddonuts/widget.h</a></li>
<li><a href="qtcharts-nesteddonuts-main-cpp.html">nesteddonuts/main.cpp</a></li>
<li><a href="qtcharts-nesteddonuts-nesteddonuts-pro.html">nesteddonuts/nesteddonuts.pro</a></li>
</ul>
</div>
<!-- @@@nesteddonuts -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|