<?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>main.qml Example File | Qt Data Visualization 5.11</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 ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtdatavisualization-index.html">Qt Data Visualization</a></td><td ><a href="qtdatavisualization-qmlmultigraph-example.html">Qt Quick 2 Multiple Graphs Example</a></td><td >main.qml Example File</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.11.2 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">main.qml Example File</h1> <span class="subtitle">qmlmultigraph/qml/qmlmultigraph/main.qml</span> <!-- $$$qmlmultigraph/qml/qmlmultigraph/main.qml-description --> <div class="descr"> <a name="details"></a> <pre class="qml"> <span class="comment">/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Data Visualization 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> import QtQuick 2.1 import QtQuick.Layouts 1.0 import QtDataVisualization 1.0 import "." <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">id</span>: <span class="name">mainView</span> <span class="name">width</span>: <span class="number">800</span> <span class="name">height</span>: <span class="number">600</span> <span class="type">Data</span> { <span class="name">id</span>: <span class="name">data</span> } <span class="type"><a href="../qtquick/qml-qtquick-layouts-gridlayout.html">GridLayout</a></span> { <span class="name">id</span>: <span class="name">gridLayout</span> <span class="name">columns</span>: <span class="number">2</span> <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">anchors</span>.top: <span class="name">mainView</span>.<span class="name">top</span> <span class="name">anchors</span>.bottom: <span class="name">mainView</span>.<span class="name">bottom</span> <span class="name">anchors</span>.left: <span class="name">mainView</span>.<span class="name">left</span> <span class="name">anchors</span>.right: <span class="name">mainView</span>.<span class="name">right</span> <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">border</span>.color: <span class="name">surfaceGraph</span>.<span class="name">theme</span>.<span class="name">gridLineColor</span> <span class="name">border</span>.width: <span class="number">2</span> <span class="type"><a href="qml-qtdatavisualization-surface3d.html">Surface3D</a></span> { <span class="name">id</span>: <span class="name">surfaceGraph</span> <span class="name">anchors</span>.fill: <span class="name">parent</span> <span class="name">anchors</span>.margins: <span class="name">parent</span>.<span class="name">border</span>.<span class="name">width</span> <span class="name">theme</span>: <span class="name">Theme3D</span> { <span class="name">type</span>: <span class="name">Theme3D</span>.<span class="name">ThemePrimaryColors</span> <span class="name">font</span>.pointSize: <span class="number">60</span> } <span class="name">scene</span>.activeCamera.cameraPreset: <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="type"><a href="qml-qtdatavisualization-surface3dseries.html">Surface3DSeries</a></span> { <span class="name">itemLabelFormat</span>: <span class="string">"Pop density at (@xLabel N, @zLabel E): @yLabel"</span> <span class="type"><a href="qml-qtdatavisualization-itemmodelsurfacedataproxy.html">ItemModelSurfaceDataProxy</a></span> { <span class="name">itemModel</span>: <span class="name">data</span>.<span class="name">sharedData</span> <span class="comment">// The surface data points are not neatly lined up in rows and columns,</span> <span class="comment">// so we define explicit row and column roles.</span> <span class="name">rowRole</span>: <span class="string">"row"</span> <span class="name">columnRole</span>: <span class="string">"col"</span> <span class="name">xPosRole</span>: <span class="string">"latitude"</span> <span class="name">zPosRole</span>: <span class="string">"longitude"</span> <span class="name">yPosRole</span>: <span class="string">"pop_density"</span> } } } } <span class="comment">// We'll use one grid cell for buttons</span> <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="type"><a href="../qtquick/qml-qtquick-layouts-gridlayout.html">GridLayout</a></span> { <span class="name">anchors</span>.right: <span class="name">parent</span>.<span class="name">right</span> <span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span> <span class="name">anchors</span>.top: <span class="name">parent</span>.<span class="name">top</span> <span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span> <span class="name">columns</span>: <span class="number">2</span> <span class="type">NewButton</span> { <span class="name">Layout</span>.minimumWidth: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">/</span> <span class="number">2</span> <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">text</span>: <span class="string">"Clear Selections"</span> <span class="name">onClicked</span>: <span class="name">clearSelections</span>() <span class="comment">// call a helper function to keep button itself simpler</span> } <span class="type">NewButton</span> { <span class="name">Layout</span>.minimumWidth: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">/</span> <span class="number">2</span> <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">text</span>: <span class="string">"Quit"</span> <span class="name">onClicked</span>: <span class="name">Qt</span>.<span class="name">quit</span>(<span class="number">0</span>); } <span class="type">NewButton</span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">text</span>: <span class="string">"Reset Cameras"</span> <span class="name">onClicked</span>: <span class="name">resetCameras</span>() <span class="comment">// call a helper function to keep button itself simpler</span> } <span class="type">NewButton</span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">text</span>: <span class="string">"Toggle Mesh Styles"</span> <span class="name">onClicked</span>: <span class="name">toggleMeshStyle</span>() <span class="comment">// call a helper function to keep button itself simpler</span> } } } <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">border</span>.color: <span class="name">scatterGraph</span>.<span class="name">theme</span>.<span class="name">gridLineColor</span> <span class="name">border</span>.width: <span class="number">2</span> <span class="type"><a href="qml-qtdatavisualization-scatter3d.html">Scatter3D</a></span> { <span class="name">id</span>: <span class="name">scatterGraph</span> <span class="name">anchors</span>.fill: <span class="name">parent</span> <span class="name">anchors</span>.margins: <span class="name">parent</span>.<span class="name">border</span>.<span class="name">width</span> <span class="name">theme</span>: <span class="name">Theme3D</span> { <span class="name">type</span>: <span class="name">Theme3D</span>.<span class="name">ThemeDigia</span> <span class="name">font</span>.pointSize: <span class="number">60</span> } <span class="name">scene</span>.activeCamera.cameraPreset: <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="type"><a href="qml-qtdatavisualization-scatter3dseries.html">Scatter3DSeries</a></span> { <span class="name">itemLabelFormat</span>: <span class="string">"Pop density at (@xLabel N, @zLabel E): @yLabel"</span> <span class="type"><a href="qml-qtdatavisualization-itemmodelscatterdataproxy.html">ItemModelScatterDataProxy</a></span> { <span class="name">itemModel</span>: <span class="name">data</span>.<span class="name">sharedData</span> <span class="comment">// Mapping model roles to scatter series item coordinates.</span> <span class="name">xPosRole</span>: <span class="string">"latitude"</span> <span class="name">zPosRole</span>: <span class="string">"longitude"</span> <span class="name">yPosRole</span>: <span class="string">"pop_density"</span> } } } } <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">Layout</span>.fillHeight: <span class="number">true</span> <span class="name">Layout</span>.fillWidth: <span class="number">true</span> <span class="name">border</span>.color: <span class="name">barGraph</span>.<span class="name">theme</span>.<span class="name">gridLineColor</span> <span class="name">border</span>.width: <span class="number">2</span> <span class="type"><a href="qml-qtdatavisualization-bars3d.html">Bars3D</a></span> { <span class="name">id</span>: <span class="name">barGraph</span> <span class="name">anchors</span>.fill: <span class="name">parent</span> <span class="name">anchors</span>.margins: <span class="name">parent</span>.<span class="name">border</span>.<span class="name">width</span> <span class="name">theme</span>: <span class="name">Theme3D</span> { <span class="name">type</span>: <span class="name">Theme3D</span>.<span class="name">ThemeQt</span> <span class="name">font</span>.pointSize: <span class="number">60</span> } <span class="name">selectionMode</span>: <span class="name">AbstractGraph3D</span>.<span class="name">SelectionItemAndRow</span> <span class="operator">|</span> <span class="name">AbstractGraph3D</span>.<span class="name">SelectionSlice</span> <span class="name">scene</span>.activeCamera.cameraPreset: <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="type"><a href="qml-qtdatavisualization-bar3dseries.html">Bar3DSeries</a></span> { <span class="name">itemLabelFormat</span>: <span class="string">"@seriesName: @valueLabel"</span> <span class="name">name</span>: <span class="string">"Population density"</span> <span class="type"><a href="qml-qtdatavisualization-itemmodelbardataproxy.html">ItemModelBarDataProxy</a></span> { <span class="name">itemModel</span>: <span class="name">data</span>.<span class="name">sharedData</span> <span class="comment">// Mapping model roles to bar series rows, columns, and values.</span> <span class="name">rowRole</span>: <span class="string">"row"</span> <span class="name">columnRole</span>: <span class="string">"col"</span> <span class="name">valueRole</span>: <span class="string">"pop_density"</span> } } } } } <span class="keyword">function</span> <span class="name">clearSelections</span>() { <span class="name">barGraph</span>.<span class="name">clearSelection</span>() <span class="name">scatterGraph</span>.<span class="name">clearSelection</span>() <span class="name">surfaceGraph</span>.<span class="name">clearSelection</span>() } <span class="keyword">function</span> <span class="name">resetCameras</span>() { <span class="name">surfaceGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">cameraPreset</span> <span class="operator">=</span> <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="name">scatterGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">cameraPreset</span> <span class="operator">=</span> <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="name">barGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">cameraPreset</span> <span class="operator">=</span> <span class="name">Camera3D</span>.<span class="name">CameraPresetIsometricLeftHigh</span> <span class="name">surfaceGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">zoomLevel</span> <span class="operator">=</span> <span class="number">100.0</span> <span class="name">scatterGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">zoomLevel</span> <span class="operator">=</span> <span class="number">100.0</span> <span class="name">barGraph</span>.<span class="name">scene</span>.<span class="name">activeCamera</span>.<span class="name">zoomLevel</span> <span class="operator">=</span> <span class="number">100.0</span> } <span class="keyword">function</span> <span class="name">toggleMeshStyle</span>() { <span class="keyword">if</span> (<span class="name">barGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">meshSmooth</span> <span class="operator">===</span> <span class="number">true</span>) { <span class="name">barGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">meshSmooth</span> <span class="operator">=</span> <span class="number">false</span> <span class="keyword">if</span> (<span class="name">surfaceGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">flatShadingSupported</span>) <span class="name">surfaceGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">flatShadingEnabled</span> <span class="operator">=</span> <span class="number">true</span> <span class="name">scatterGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">meshSmooth</span> <span class="operator">=</span> <span class="number">false</span> } <span class="keyword">else</span> { <span class="name">barGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">meshSmooth</span> <span class="operator">=</span> <span class="number">true</span> <span class="name">surfaceGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">flatShadingEnabled</span> <span class="operator">=</span> <span class="number">false</span> <span class="name">scatterGraph</span>.<span class="name">seriesList</span>[<span class="number">0</span>].<span class="name">meshSmooth</span> <span class="operator">=</span> <span class="number">true</span> } } } </pre> </div> <!-- @@@qmlmultigraph/qml/qmlmultigraph/main.qml --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2018 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>