From 58f8a29f8860db774e05a87378b8ee1acd306ea6 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 13 Feb 2014 14:58:19 +0200 Subject: Fix qmlscatter example docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3994aac8c744252e28f93df83ad968e3479cdd01 Reviewed-by: Tomi Korpipää --- .../doc/images/qmlscatter-newproject.png | Bin 37045 -> 0 bytes .../qmlscatter/doc/src/qmlscatter.qdoc | 66 +++++++++------------ examples/datavisualization/qmlscatter/main.cpp | 19 ++++-- 3 files changed, 41 insertions(+), 44 deletions(-) delete mode 100644 examples/datavisualization/qmlscatter/doc/images/qmlscatter-newproject.png (limited to 'examples/datavisualization/qmlscatter') diff --git a/examples/datavisualization/qmlscatter/doc/images/qmlscatter-newproject.png b/examples/datavisualization/qmlscatter/doc/images/qmlscatter-newproject.png deleted file mode 100644 index 7c81cae8..00000000 Binary files a/examples/datavisualization/qmlscatter/doc/images/qmlscatter-newproject.png and /dev/null differ diff --git a/examples/datavisualization/qmlscatter/doc/src/qmlscatter.qdoc b/examples/datavisualization/qmlscatter/doc/src/qmlscatter.qdoc index 236238e1..ec11970f 100644 --- a/examples/datavisualization/qmlscatter/doc/src/qmlscatter.qdoc +++ b/examples/datavisualization/qmlscatter/doc/src/qmlscatter.qdoc @@ -27,45 +27,31 @@ For instructions about how to interact with the graph, see \l{Qt Data Visualization Interacting with Data}{this page}. - \image qmlscatter-example.png - - \section1 Creating the application - - The application main is created by creating a new Qt Quick Application project in QtCreator. - The dialog shown here is from QtCreator 3.0.0, and it may look a bit different in other - versions: + For instructions how to create a new Qt Quick 2 application of your own, see Qt Creator help. - \image qmlscatter-newproject.png + \image qmlscatter-example.png - We'll modify the generated \c main.cpp a bit, as we want to add our \c main.qml file as a - resource. We do it by replacing + \section1 Application basics - \code viewer.setMainQmlFile(QStringLiteral("qml/qmlscatter/main.qml")); \endcode + Before diving into the QML code, let's take a look at the application \c main.cpp. - with + Anti-aliasing for Qt Data Visualization graphs in Qt Quick 2 is not supported by default due + to technological limitations. To enable anti-aliasing, a custom surface format must be set to + the QQuickWindow we are using to show the application in the application \c main.cpp: + \snippet qmlscatter/main.cpp 1 + \dots 0 \snippet qmlscatter/main.cpp 0 - This will make application deployment easier. + This will make the graphs nicer to look at. - We'll enable anti-aliasing for our application in environments that support it: + This application implements a 'Quit' button in the UI, so we want to connect the QQmlEngine::quit() + signal to our application's QWindow::close() slot: - \snippet qmlscatter/main.cpp 2 - - We'll also change the application to be shown maximized by replacing + \snippet qmlscatter/main.cpp 4 - \code viewer.showExpanded(); \endcode - - with - - \snippet qmlscatter/main.cpp 1 - - We won't look into that any closer, as we'll change nothing in the generated - \c qtquick2applicationviewer files. - - Next we'll create new qml files for data (\c Data.qml) and a QtQuick.Controls button - we want to modify a bit (\c NewButton.qml), and add them to the resource file, in addition to - main.qml: + To make deployment little simpler, we gather all of the application's \c .qml files to a resource + file (\c qmlscatter.qrc): \code @@ -77,12 +63,15 @@ \endcode - Now the base for our application is done, and we can start setting up the graph. + This also requires us to set the \c main.qml to be read from the resource (\c{qrc:}): - \section1 Setting up the graph + \snippet qmlscatter/main.cpp 3 - Let's start modifying the generated \c {main.qml}. We can remove all previous content from it, - as it has nothing we need. + Lastly, we want the application to run in a maximized window: + + \snippet qmlscatter/main.cpp 2 + + \section1 Setting up the graph First we'll import all the QML modules we need: @@ -96,12 +85,13 @@ \snippet qmlscatter/qml/qmlscatter/main.qml 1 \note The Qt Creator application wizard will set a \c Rectangle item as the main item, which - is opaque white by default. This doesn't work for us, because the graphs are rendered behind the other - QML elements. We change the main item type to \c Item, which is invisible. This way the graph is - not covered by the main item. + is opaque white by default. This doesn't work for an application using Qt Data Visualization graphs, + because the graphs are rendered behind the other QML elements. When creating a new application, + you should change the main item type to \c Item instead, which is invisible. + This way the graph is not covered by the main item. - Then we'll add another \c Item inside it, and call it \c dataView. This will be the item to hold - the Scatter3D graph. We'll anchor it to the parent bottom: + Then we'll add another \c Item inside the main \c Item, and call it \c dataView. + This will be the item to hold the Scatter3D graph. We'll anchor it to the parent bottom: \snippet qmlscatter/qml/qmlscatter/main.qml 9 diff --git a/examples/datavisualization/qmlscatter/main.cpp b/examples/datavisualization/qmlscatter/main.cpp index 3c36e3f2..425becd5 100644 --- a/examples/datavisualization/qmlscatter/main.cpp +++ b/examples/datavisualization/qmlscatter/main.cpp @@ -16,7 +16,9 @@ ** ****************************************************************************/ +//! [1] #include +//! [1] #include #include @@ -30,9 +32,9 @@ int main(int argc, char *argv[]) QQuickView viewer; // Enable antialiasing - //! [2] + //! [0] viewer.setFormat(QtDataVisualization::qDefaultSurfaceFormat()); - //! [2] + //! [0] // The following are needed to make examples run without having to install the module // in desktop environments. @@ -43,16 +45,21 @@ int main(int argc, char *argv[]) #endif viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), QString::fromLatin1("qml"))); + //! [4] QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); + //! [4] viewer.setTitle(QStringLiteral("QML scatter example")); - //! [0] + + //! [3] viewer.setSource(QUrl("qrc:/qml/qmlscatter/main.qml")); - //! [0] + //! [3] + viewer.setResizeMode(QQuickView::SizeRootObjectToView); - //! [1] + + //! [2] viewer.showMaximized(); - //! [1] + //! [2] return app.exec(); } -- cgit v1.2.3