aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-09-05 13:51:52 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-10-18 09:45:59 +0000
commitf82c4de515223574bcc510de0d993426b22bccbe (patch)
tree502580beddf2cb874fc285b3cf5308b17a00e309 /examples/quick
parent32b73196594ade358e7b419b0a7563abcfe7266e (diff)
Qt Quick examples: Introduce QCommandLineParser
Task-number: QTBUG-60630 Change-Id: Iaf24e09fdec92f8af495a1288685f266c39be4a7 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/main.cpp20
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp8
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h3
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp24
-rw-r--r--examples/quick/rendercontrol/main.cpp16
-rw-r--r--examples/quick/scenegraph/rendernode/main.cpp16
6 files changed, 76 insertions, 11 deletions
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp
index 7e45e42527..848107ce71 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp
+++ b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp
@@ -39,6 +39,8 @@
****************************************************************************/
#include <QApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include "mainwindow.h"
@@ -48,8 +50,22 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
- bool transparency = QCoreApplication::arguments().contains(QStringLiteral("--transparent"));
- MainWindow widgetWindow(transparency);
+ QCoreApplication::setApplicationName("Qt QQuickView/QQuickWidget Comparison Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption noRenderAlphaOption("no-render-alpha", "Do not render Alpha");
+ parser.addOption(noRenderAlphaOption);
+ QCommandLineOption transparentOption("transparent", "Transparent window");
+ parser.addOption(transparentOption);
+
+ parser.process(app);
+
+ const bool transparency = parser.isSet(transparentOption);
+ MainWindow widgetWindow(transparency, parser.isSet(noRenderAlphaOption));
if (transparency) {
widgetWindow.setAttribute(Qt::WA_TranslucentBackground);
widgetWindow.setAttribute(Qt::WA_NoSystemBackground, false);
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
index ea6c7f2f9a..2e623464ba 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
+++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
@@ -40,7 +40,6 @@
#include "mainwindow.h"
#include "fbitem.h"
-#include <QCoreApplication>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QRadioButton>
@@ -48,10 +47,11 @@
#include <QLabel>
#include <QQuickItem>
-MainWindow::MainWindow(bool transparency)
+MainWindow::MainWindow(bool transparency, bool noRenderAlpha)
: m_currentView(0),
m_currentRootObject(0),
- m_transparent(transparency)
+ m_transparent(transparency),
+ m_noRenderAlpha(noRenderAlpha)
{
QVBoxLayout *layout = new QVBoxLayout;
@@ -178,7 +178,7 @@ void MainWindow::updateView()
if (m_currentRootObject) {
m_currentRootObject->setProperty("currentText", text);
m_currentRootObject->setProperty("multisample", m_checkboxMultiSample->isChecked());
- if (!QCoreApplication::arguments().contains(QStringLiteral("--no_render_alpha")))
+ if (!m_noRenderAlpha)
m_currentRootObject->setProperty("translucency", m_transparent);
}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h
index 5b86c93f38..e49f50cab6 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h
+++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h
@@ -53,7 +53,7 @@ QT_FORWARD_DECLARE_CLASS(QLayout)
class MainWindow : public QWidget
{
public:
- MainWindow(bool transparency);
+ explicit MainWindow(bool transparency, bool noRenderAlpha);
protected:
void resizeEvent(QResizeEvent*);
@@ -86,6 +86,7 @@ private:
QSurfaceFormat m_format;
bool m_transparent;
+ bool m_noRenderAlpha;
};
#endif
diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp
index 7cb35d7bcd..e21c1710c6 100644
--- a/examples/quick/quickwidgets/quickwidget/main.cpp
+++ b/examples/quick/quickwidgets/quickwidget/main.cpp
@@ -44,6 +44,9 @@
#include <QtWidgets>
#include "fbitem.h"
+static bool optMultipleSample = false;
+static bool optCoreProfile = false;
+
class MainWindow : public QMainWindow {
Q_OBJECT
public:
@@ -65,11 +68,11 @@ MainWindow::MainWindow()
: m_quickWidget(new QQuickWidget)
{
QSurfaceFormat format;
- if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) {
+ if (optCoreProfile) {
format.setVersion(4, 4);
format.setProfile(QSurfaceFormat::CoreProfile);
}
- if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
+ if (optMultipleSample)
format.setSamples(4);
m_quickWidget->setFormat(format);
@@ -184,6 +187,23 @@ int main(int argc, char **argv)
{
QApplication app(argc, argv);
+ QCoreApplication::setApplicationName("Qt QQuickWidget Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption multipleSampleOption("multisample", "Multisampling");
+ parser.addOption(multipleSampleOption);
+ QCommandLineOption coreProfileOption("coreprofile", "Use core profile");
+ parser.addOption(coreProfileOption);
+
+ parser.process(app);
+
+ optMultipleSample = parser.isSet(multipleSampleOption);
+ optCoreProfile = parser.isSet(coreProfileOption);
+
qmlRegisterType<FbItem>("QuickWidgetExample", 1, 0, "FbItem");
MainWindow mainWindow;
diff --git a/examples/quick/rendercontrol/main.cpp b/examples/quick/rendercontrol/main.cpp
index 6442ad92b8..7558d5ad25 100644
--- a/examples/quick/rendercontrol/main.cpp
+++ b/examples/quick/rendercontrol/main.cpp
@@ -39,6 +39,8 @@
****************************************************************************/
#include <QGuiApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include "window_singlethreaded.h"
#include "window_multithreaded.h"
@@ -46,8 +48,20 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
+ QCoreApplication::setApplicationName("Qt Render Control Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption threadedOption("threaded", "Threaded Rendering");
+ parser.addOption(threadedOption);
+
+ parser.process(app);
+
QScopedPointer<QWindow> window;
- if (QCoreApplication::arguments().contains(QLatin1String("--threaded"))) {
+ if (parser.isSet(threadedOption)) {
qWarning("Using separate Qt Quick render thread");
window.reset(new WindowMultiThreaded);
} else {
diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp
index 3e1714313e..9623a1ba8a 100644
--- a/examples/quick/scenegraph/rendernode/main.cpp
+++ b/examples/quick/scenegraph/rendernode/main.cpp
@@ -38,6 +38,8 @@
**
****************************************************************************/
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include <QGuiApplication>
#include <QQuickView>
#include "customrenderitem.h"
@@ -50,7 +52,19 @@ int main(int argc, char **argv)
QQuickView view;
- if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) {
+ QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption multipleSampleOption("multisample", "Multisampling");
+ parser.addOption(multipleSampleOption);
+
+ parser.process(app);
+
+ if (parser.isSet(multipleSampleOption)) {
QSurfaceFormat fmt;
fmt.setSamples(4);
view.setFormat(fmt);