Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 19952c5e751bf7e3108c3c59625b0f35 > files > 357

qtcharts5-doc-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>tablewidget.cpp Example File | 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-modeldata-example.html">Model Data Example</a></td><td >tablewidget.cpp Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">tablewidget.cpp Example File</h1>
<span class="subtitle">modeldata/tablewidget.cpp</span>
<!-- $$$modeldata/tablewidget.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the Qt Charts module of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:GPL$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** GNU General Public License Usage
  ** Alternatively, this file may be used under the terms of the GNU
  ** General Public License version 3 or (at your option) any later version
  ** approved by the KDE Free Qt Foundation. The licenses are as published by
  ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  ** included in the packaging of this file. Please review the following
  ** information to ensure the GNU General Public License requirements will
  ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;tablewidget.h&quot;</span>
  <span class="preprocessor">#include &quot;customtablemodel.h&quot;</span>
  <span class="preprocessor">#include &lt;QtWidgets/QGridLayout&gt;</span>
  <span class="preprocessor">#include &lt;QtWidgets/QTableView&gt;</span>
  <span class="preprocessor">#include &lt;QtCharts/QChart&gt;</span>
  <span class="preprocessor">#include &lt;QtCharts/QChartView&gt;</span>
  <span class="preprocessor">#include &lt;QtCharts/QLineSeries&gt;</span>
  <span class="preprocessor">#include &lt;QtCharts/QVXYModelMapper&gt;</span>
  <span class="preprocessor">#include &lt;QtWidgets/QHeaderView&gt;</span>

  QT_CHARTS_USE_NAMESPACE

  TableWidget<span class="operator">::</span>TableWidget(<span class="type">QWidget</span> <span class="operator">*</span>parent)
      : <span class="type">QWidget</span>(parent)
  {
      <span class="comment">// create simple model for storing data</span>
      <span class="comment">// user's table data model</span>
      CustomTableModel <span class="operator">*</span>model <span class="operator">=</span> <span class="keyword">new</span> CustomTableModel;

      <span class="comment">// create table view and add model to it</span>
      <span class="type">QTableView</span> <span class="operator">*</span>tableView <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QTableView</span>;
      tableView<span class="operator">-</span><span class="operator">&gt;</span>setModel(model);
      tableView<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="type">QHeaderView</span><span class="operator">::</span>Stretch);
      tableView<span class="operator">-</span><span class="operator">&gt;</span>verticalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="type">QHeaderView</span><span class="operator">::</span>Stretch);

      <span class="type"><a href="qchart.html">QChart</a></span> <span class="operator">*</span>chart <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qchart.html">QChart</a></span>;
      chart<span class="operator">-</span><span class="operator">&gt;</span>setAnimationOptions(<span class="type"><a href="qchart.html">QChart</a></span><span class="operator">::</span>AllAnimations);

      <span class="comment">// series 1</span>
      <span class="type"><a href="qlineseries.html">QLineSeries</a></span> <span class="operator">*</span>series <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineseries.html">QLineSeries</a></span>;
      series<span class="operator">-</span><span class="operator">&gt;</span>setName(<span class="string">&quot;Line 1&quot;</span>);
      <span class="type"><a href="qvxymodelmapper.html">QVXYModelMapper</a></span> <span class="operator">*</span>mapper <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvxymodelmapper.html">QVXYModelMapper</a></span>(<span class="keyword">this</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setXColumn(<span class="number">0</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setYColumn(<span class="number">1</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setSeries(series);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setModel(model);
      chart<span class="operator">-</span><span class="operator">&gt;</span>addSeries(series);

      <span class="comment">// for storing color hex from the series</span>
      <span class="type">QString</span> seriesColorHex <span class="operator">=</span> <span class="string">&quot;#000000&quot;</span>;

      <span class="comment">// get the color of the series and use it for showing the mapped area</span>
      seriesColorHex <span class="operator">=</span> <span class="string">&quot;#&quot;</span> <span class="operator">+</span> <span class="type">QString</span><span class="operator">::</span>number(series<span class="operator">-</span><span class="operator">&gt;</span>pen()<span class="operator">.</span>color()<span class="operator">.</span>rgb()<span class="operator">,</span> <span class="number">16</span>)<span class="operator">.</span>right(<span class="number">6</span>)<span class="operator">.</span>toUpper();
      model<span class="operator">-</span><span class="operator">&gt;</span>addMapping(seriesColorHex<span class="operator">,</span> <span class="type">QRect</span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> model<span class="operator">-</span><span class="operator">&gt;</span>rowCount()));

      <span class="comment">// series 2</span>
      series <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineseries.html">QLineSeries</a></span>;
      series<span class="operator">-</span><span class="operator">&gt;</span>setName(<span class="string">&quot;Line 2&quot;</span>);

      mapper <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvxymodelmapper.html">QVXYModelMapper</a></span>(<span class="keyword">this</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setXColumn(<span class="number">2</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setYColumn(<span class="number">3</span>);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setSeries(series);
      mapper<span class="operator">-</span><span class="operator">&gt;</span>setModel(model);
      chart<span class="operator">-</span><span class="operator">&gt;</span>addSeries(series);

      <span class="comment">// get the color of the series and use it for showing the mapped area</span>
      seriesColorHex <span class="operator">=</span> <span class="string">&quot;#&quot;</span> <span class="operator">+</span> <span class="type">QString</span><span class="operator">::</span>number(series<span class="operator">-</span><span class="operator">&gt;</span>pen()<span class="operator">.</span>color()<span class="operator">.</span>rgb()<span class="operator">,</span> <span class="number">16</span>)<span class="operator">.</span>right(<span class="number">6</span>)<span class="operator">.</span>toUpper();
      model<span class="operator">-</span><span class="operator">&gt;</span>addMapping(seriesColorHex<span class="operator">,</span> <span class="type">QRect</span>(<span class="number">2</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> model<span class="operator">-</span><span class="operator">&gt;</span>rowCount()));

      chart<span class="operator">-</span><span class="operator">&gt;</span>createDefaultAxes();
      <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>(chart);
      chartView<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type">QPainter</span><span class="operator">::</span>Antialiasing);
      chartView<span class="operator">-</span><span class="operator">&gt;</span>setMinimumSize(<span class="number">640</span><span class="operator">,</span> <span class="number">480</span>);

      <span class="comment">// create main layout</span>
      <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">&gt;</span>addWidget(tableView<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(chartView<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>setColumnStretch(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      setLayout(mainLayout);
  }

</pre>
</div>
<!-- @@@modeldata/tablewidget.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>