Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 845e36bb3ecce380666d628d88446962 > files > 228

qtdatavis3d5-doc-5.12.6-1.mga7.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" />
<!-- customitems.qdoc -->
  <title>Custom Items Example | Qt Data Visualization 5.12.6</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.12</td><td ><a href="qtdatavisualization-index.html">Qt Data Visualization</a></td><td >Custom Items Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdatavisualization-index.html">Qt Data Visualization | Commercial or GPLv3</a></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="#adding-custom-meshes-to-the-application">Adding Custom Meshes to the Application</a></li>
<li class="level1"><a href="#adding-custom-item-to-a-graph">Adding Custom Item to a Graph</a></li>
<li class="level1"><a href="#removing-custom-item-from-a-graph">Removing Custom Item from a Graph</a></li>
<li class="level1"><a href="#example-contents">Example Contents</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Custom Items Example</h1>
<span class="subtitle"></span>
<!-- $$$customitems-brief -->
<p>Adding custom items to a surface graph.</p>
<!-- @@@customitems -->
<!-- $$$customitems-description -->
<div class="descr"> <a name="details"></a>
<p>The custom items example shows how to add your own custom meshes as items to a graph, and how to remove them.</p>
<p class="centerAlign"><img src="images/customitems-example.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="adding-custom-meshes-to-the-application"></a>
<h2 id="adding-custom-meshes-to-the-application">Adding Custom Meshes to the Application</h2>
<p>We'll add the meshes in a resource file:</p>
<pre class="cpp">

  <span class="operator">&lt;</span>RCC<span class="operator">&gt;</span>
  <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  <span class="operator">&lt;</span>qresource prefix<span class="operator">=</span><span class="string">&quot;/items&quot;</span><span class="operator">&gt;</span>
      <span class="operator">&lt;</span>file<span class="operator">&gt;</span>refinery<span class="operator">.</span>obj<span class="operator">&lt;</span><span class="operator">/</span>file<span class="operator">&gt;</span>
      <span class="operator">&lt;</span>file<span class="operator">&gt;</span>oilrig<span class="operator">.</span>obj<span class="operator">&lt;</span><span class="operator">/</span>file<span class="operator">&gt;</span>
  <span class="operator">&lt;</span><span class="operator">/</span>qresource<span class="operator">&gt;</span>
  <span class="operator">&lt;</span><span class="operator">/</span>RCC<span class="operator">&gt;</span>

</pre>
<a name="adding-custom-item-to-a-graph"></a>
<h2 id="adding-custom-item-to-a-graph">Adding Custom Item to a Graph</h2>
<p>In this example we do not have specific textures for our meshes, so we'll just create a small QImage and fill it with a single color:</p>
<pre class="cpp">

  <span class="type">QImage</span> color <span class="operator">=</span> <span class="type">QImage</span>(<span class="number">2</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="type">QImage</span><span class="operator">::</span>Format_RGB32);
  color<span class="operator">.</span>fill(<span class="type">Qt</span><span class="operator">::</span>red);

</pre>
<p>Then we'll specify the position for the item in a variable. This way we'll be able to use it later for removing the correct item:</p>
<pre class="cpp">

  QVector3D positionOne <span class="operator">=</span> QVector3D(<span class="number">39.0f</span><span class="operator">,</span> <span class="number">77.0f</span><span class="operator">,</span> <span class="number">19.2f</span>);

</pre>
<p>Then we'll create a new <a href="qcustom3ditem.html">QCustom3DItem</a> with all the parameters:</p>
<pre class="cpp">

  QCustom3DItem <span class="operator">*</span>item <span class="operator">=</span> <span class="keyword">new</span> QCustom3DItem(<span class="string">&quot;:/items/oilrig.obj&quot;</span><span class="operator">,</span> positionOne<span class="operator">,</span>
                                          QVector3D(<span class="number">0.025f</span><span class="operator">,</span> <span class="number">0.025f</span><span class="operator">,</span> <span class="number">0.025f</span>)<span class="operator">,</span>
                                          <span class="type">QQuaternion</span><span class="operator">::</span>fromAxisAndAngle(<span class="number">0.0f</span><span class="operator">,</span> <span class="number">1.0f</span><span class="operator">,</span> <span class="number">0.0f</span><span class="operator">,</span> <span class="number">45.0f</span>)<span class="operator">,</span>
                                          color);

</pre>
<p>And finally we'll just add the item:</p>
<pre class="cpp">

  m_graph<span class="operator">-</span><span class="operator">&gt;</span>addCustomItem(item);

</pre>
<a name="removing-custom-item-from-a-graph"></a>
<h2 id="removing-custom-item-from-a-graph">Removing Custom Item from a Graph</h2>
<p>We'll just call <code>removeCustomItemAt()</code> with the position of the item:</p>
<pre class="cpp">

  m_graph<span class="operator">-</span><span class="operator">&gt;</span>removeCustomItemAt(positionOne);

</pre>
<p><b>Note: </b>Removing a custom item from the graph also deletes it. If you want to preserve the item, you need to use <code>releaseCustomItem()</code> method instead.</p><a name="example-contents"></a>
<h2 id="example-contents">Example Contents</h2>
<p>Files:</p>
<ul>
<li><a href="qtdatavisualization-customitems-customitemgraph-cpp.html">customitems/customitemgraph.cpp</a></li>
<li><a href="qtdatavisualization-customitems-customitemgraph-h.html">customitems/customitemgraph.h</a></li>
<li><a href="qtdatavisualization-customitems-customitems-pro.html">customitems/customitems.pro</a></li>
<li><a href="qtdatavisualization-customitems-customitems-qrc.html">customitems/customitems.qrc</a></li>
<li><a href="qtdatavisualization-customitems-main-cpp.html">customitems/main.cpp</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/customitems/layer_1.png">customitems/layer_1.png</a></li>
<li><a href="images/used-in-examples/customitems/layer_2.png">customitems/layer_2.png</a></li>
<li><a href="images/used-in-examples/customitems/layer_3.png">customitems/layer_3.png</a></li>
</ul>
</div>
<!-- @@@customitems -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>