diff options
Diffstat (limited to 'tests')
42 files changed, 1500 insertions, 63 deletions
diff --git a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp index f851688b5e..d2cfd3897a 100644 --- a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp +++ b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp @@ -89,21 +89,12 @@ public: protected: //inherited from QQmlDebugClient - void stateChanged(State state); void messageReceived(const QByteArray &data); signals: - void enabled(); void debugOutput(); }; -void QQmlDebugMsgClient::stateChanged(State state) -{ - if (state == Enabled) { - emit enabled(); - } -} - void QQmlDebugMsgClient::messageReceived(const QByteArray &data) { QPacket ds(connection()->currentDataStreamVersion(), data); diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp index 52e7f85e52..37118f4bd0 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp @@ -125,7 +125,7 @@ void tst_QQmlDebuggingEnabler::qmlscene() QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); } - QCOMPARE(m_process->state(), QLatin1String("running")); + QCOMPARE(m_process->state(), QProcess::Running); if (!blockMode) { QTRY_VERIFY_WITH_TIMEOUT(m_process->output().contains( QLatin1String("Component.onCompleted")), 15000); @@ -172,7 +172,7 @@ void tst_QQmlDebuggingEnabler::custom() QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); } - QCOMPARE(m_process->state(), QLatin1String("running")); + QCOMPARE(m_process->state(), QProcess::Running); if (!blockMode) { QTRY_VERIFY_WITH_TIMEOUT(m_process->output().contains(QLatin1String("QQmlEngine created")), 15000); diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp index 3cd359cf48..37d4ef1160 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp @@ -251,6 +251,8 @@ public: { parser = jsEngine.evaluate(QLatin1String("JSON.parse")); stringify = jsEngine.evaluate(QLatin1String("JSON.stringify")); + QObject::connect(this, &QQmlDebugClient::stateChanged, + this, &QJSDebugClient::onStateChanged); } void connect(bool redundantRefs = false, bool namesAsObjects = false); @@ -272,7 +274,7 @@ public: protected: //inherited from QQmlDebugClient - void stateChanged(State state); + void onStateChanged(State state); void messageReceived(const QByteArray &data); signals: @@ -660,7 +662,7 @@ void QJSDebugClient::disconnect() sendMessage(packMessage(DISCONNECT, json.toString().toUtf8())); } -void QJSDebugClient::stateChanged(State state) +void QJSDebugClient::onStateChanged(State state) { if (state == Enabled) flushSendBuffer(); diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp index 993a1d5f63..35bd912d9b 100644 --- a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp @@ -118,7 +118,7 @@ void tst_QQmlDebugProcess::sessionStart() QTimer::singleShot(delay, process.data(), wait); QTRY_VERIFY(done); - QVERIFY(process->state().startsWith("not running")); + QCOMPARE(process->state(), QProcess::NotRunning); } QTEST_MAIN(tst_QQmlDebugProcess) diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index 4ce0f9fd89..17a99d6a43 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -481,7 +481,7 @@ void tst_qv4debugger::conditionalBreakPoint() QVERIFY(m_debuggerAgent->m_capturedScope.size() > 1); const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedScope.at(0); - QCOMPARE(frame0.size(), 2); + QCOMPARE(frame0.size(), 3); QVERIFY(frame0.contains("i")); QCOMPARE(frame0.value("i").toInt(), 11); } @@ -540,7 +540,7 @@ void tst_qv4debugger::readArguments() QVERIFY(m_debuggerAgent->m_wasPaused); QVERIFY(m_debuggerAgent->m_capturedScope.size() > 1); const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedScope.at(0); - QCOMPARE(frame0.size(), 4); + QCOMPARE(frame0.size(), 5); QVERIFY(frame0.contains(QStringLiteral("a"))); QCOMPARE(frame0.type(QStringLiteral("a")), QStringLiteral("number")); QCOMPARE(frame0.value(QStringLiteral("a")).toDouble(), 1.0); @@ -567,7 +567,7 @@ void tst_qv4debugger::readLocals() QVERIFY(m_debuggerAgent->m_wasPaused); QVERIFY(m_debuggerAgent->m_capturedScope.size() > 1); const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedScope.at(0); - QCOMPARE(frame0.size(), 4); // locals and parameters + QCOMPARE(frame0.size(), 5); // locals and parameters QVERIFY(frame0.contains("c")); QCOMPARE(frame0.type("c"), QStringLiteral("number")); QCOMPARE(frame0.value("c").toDouble(), 3.0); @@ -592,7 +592,7 @@ void tst_qv4debugger::readObject() QVERIFY(m_debuggerAgent->m_wasPaused); QVERIFY(m_debuggerAgent->m_capturedScope.size() > 1); const TestAgent::NamedRefs &frame0 = m_debuggerAgent->m_capturedScope.at(0); - QCOMPARE(frame0.size(), 2); + QCOMPARE(frame0.size(), 3); QVERIFY(frame0.contains("b")); QCOMPARE(frame0.type("b"), QStringLiteral("object")); QJsonObject b = frame0.rawValue("b"); @@ -657,7 +657,7 @@ void tst_qv4debugger::readContextInAllFrames() for (int i = 0; i < 12; ++i) { const TestAgent::NamedRefs &scope = m_debuggerAgent->m_capturedScope.at(i); - QCOMPARE(scope.size(), 2); + QCOMPARE(scope.size(), 3); QVERIFY(scope.contains("n")); QCOMPARE(scope.type("n"), QStringLiteral("number")); QCOMPARE(scope.value("n").toDouble(), i + 1.0); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index b118b22c64..46f504f6d3 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -98,6 +98,9 @@ QString QQmlDebugTest::connectionStateString(const QQmlDebugConnection *connecti QQmlDebugTestClient::QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c) : QQmlDebugClient(s, c) { + connect(this, &QQmlDebugClient::stateChanged, this, [this](QQmlDebugClient::State newState) { + QCOMPARE(newState, state()); + }); } QByteArray QQmlDebugTestClient::waitForResponse() @@ -111,12 +114,6 @@ QByteArray QQmlDebugTestClient::waitForResponse() return lastMsg; } -void QQmlDebugTestClient::stateChanged(State stat) -{ - QCOMPARE(stat, state()); - emit stateHasChanged(); -} - void QQmlDebugTestClient::messageReceived(const QByteArray &ba) { lastMsg = ba; @@ -211,7 +208,7 @@ void QQmlDebugTest::cleanup() if (QTest::currentTestFailed()) { const QString null = QStringLiteral("null"); - qDebug() << "Process State:" << (m_process ? m_process->state() : null); + qDebug() << "Process State:" << (m_process ? m_process->stateString() : null); qDebug() << "Application Output:" << (m_process ? m_process->output() : null); qDebug() << "Connection State:" << QQmlDebugTest::connectionStateString(m_connection); for (QQmlDebugClient *client : m_clients) { diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 94ad83bfce..05665f8a28 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -88,11 +88,9 @@ public: QByteArray waitForResponse(); signals: - void stateHasChanged(); void serverMessage(const QByteArray &); protected: - virtual void stateChanged(State state); virtual void messageReceived(const QByteArray &ba); private: diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp index 201a6b1a76..0005477075 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp @@ -51,6 +51,7 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) this, [this]() { m_timer.stop(); m_eventLoop.quit(); + emit finished(); }); connect(&m_timer, &QTimer::timeout, this, &QQmlDebugProcess::timeout); @@ -61,7 +62,7 @@ QQmlDebugProcess::~QQmlDebugProcess() stop(); } -QString QQmlDebugProcess::state() +QString QQmlDebugProcess::stateString() const { QString stateStr; switch (m_process.state()) { @@ -157,6 +158,11 @@ bool QQmlDebugProcess::waitForFinished() return m_process.waitForFinished(); } +QProcess::ProcessState QQmlDebugProcess::state() const +{ + return m_process.state(); +} + QProcess::ExitStatus QQmlDebugProcess::exitStatus() const { return m_process.exitStatus(); diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h index fd2c89bb41..945cc58c85 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h @@ -52,7 +52,7 @@ public: QQmlDebugProcess(const QString &executable, QObject *parent = 0); ~QQmlDebugProcess(); - QString state(); + QString stateString() const; void addEnvironment(const QString &environment); @@ -61,6 +61,7 @@ public: int debugPort() const; bool waitForFinished(); + QProcess::ProcessState state() const; QProcess::ExitStatus exitStatus() const; QString output() const; @@ -69,6 +70,7 @@ public: signals: void readyReadStandardOutput(); + void finished(); private slots: void timeout(); diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp index 4dce07d824..896ed608fd 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp @@ -48,5 +48,4 @@ void QQmlDebugTestService::stateAboutToBeChanged(QQmlDebugService::State) void QQmlDebugTestService::stateChanged(State) { Q_ASSERT(QThread::currentThread() != thread()); - emit stateHasChanged(); } diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h index 37b4a9f98c..9c39c0893d 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h @@ -38,9 +38,6 @@ class QQmlDebugTestService : public QQmlDebugService public: QQmlDebugTestService(const QString &s, float version = 1, QObject *parent = 0); -signals: - void stateHasChanged(); - protected: virtual void messageReceived(const QByteArray &ba); virtual void stateAboutToBeChanged(State state); diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index 589f25d174..19cec5d294 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -22,12 +22,23 @@ S15.4.4.3_A3_T1 failing S15.5.4.11_A5_T1 failing S15.2.4.4_A14 failing -# Function declarations in conditionals. We allow them, because the real -# world requires them. -Sbp_12.5_A9_T3 failing -Sbp_12.6.1_A13_T3 failing -Sbp_12.6.2_A13_T3 failing -Sbp_12.6.4_A13_T3 failing +# Function declarations in conditionals. ES6 allows them, but the test +# is buggy (using a function declaration without a name) +Sbp_12.5_A9_T3 +Sbp_12.6.1_A13_T3 +Sbp_12.6.2_A13_T3 +Sbp_12.6.4_A13_T3 + +# Function declarations in blocks, allowed in ES6 +Sbp_A1_T1 failing +Sbp_A2_T1 failing +Sbp_A2_T2 failing +Sbp_A3_T1 failing +Sbp_A3_T2 failing +Sbp_A4_T1 failing +Sbp_A4_T2 failing +Sbp_A5_T2 failing + # es6: function length attributes are configurable, wasn't in es5 S15.1.2.2_A9.2 failing diff --git a/tests/auto/qml/ecmascripttests/ecmascripttests.pro b/tests/auto/qml/ecmascripttests/ecmascripttests.pro index 6d3ee12307..4298b068ca 100644 --- a/tests/auto/qml/ecmascripttests/ecmascripttests.pro +++ b/tests/auto/qml/ecmascripttests/ecmascripttests.pro @@ -8,6 +8,14 @@ DEFINES += SRCDIR=\\\"$$PWD\\\" TESTSCRIPT=$$PWD/test262.py isEmpty(V4CMD): V4CMD = qmljs +# The ES test suite takes approximately 5 mins to run, on a fairly +# vanilla developer machine, so the default watchdog timer kills the +# test some of the time. Fix by raising time-out to 400s when +# invoking tst_ecmascripttests: +checkenv.name = QTEST_FUNCTION_TIMEOUT +checkenv.value = 400000 +QT_TOOL_ENV += checkenv + checkjittarget.target = check-jit checkjittarget.commands = python $$TESTSCRIPT --command=$$V4CMD --parallel --with-test-expectations --update-expectations checkjittarget.depends = all diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index f862cdb048..0e6b77f02b 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -205,6 +205,9 @@ private slots: void scriptScopes(); + void binaryNumbers(); + void octalNumbers(); + signals: void testSignal(); }; @@ -4157,6 +4160,38 @@ void tst_QJSEngine::scriptScopes() QCOMPARE(use.toInt(), 42); } +void tst_QJSEngine::binaryNumbers() +{ + QJSEngine engine; + + QJSValue result = engine.evaluate("0b1001"); + QVERIFY(result.isNumber()); + QVERIFY(result.toNumber() == 9); + + result = engine.evaluate("0B1001"); + QVERIFY(result.isNumber()); + QVERIFY(result.toNumber() == 9); + + result = engine.evaluate("0b2"); + QVERIFY(result.isError()); +} + +void tst_QJSEngine::octalNumbers() +{ + QJSEngine engine; + + QJSValue result = engine.evaluate("0o11"); + QVERIFY(result.isNumber()); + QVERIFY(result.toNumber() == 9); + + result = engine.evaluate("0O11"); + QVERIFY(result.isNumber()); + QVERIFY(result.toNumber() == 9); + + result = engine.evaluate("0o9"); + QVERIFY(result.isError()); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" diff --git a/tests/auto/qml/qmlmin/tst_qmlmin.cpp b/tests/auto/qml/qmlmin/tst_qmlmin.cpp index 5941385c80..e1ba6d12c0 100644 --- a/tests/auto/qml/qmlmin/tst_qmlmin.cpp +++ b/tests/auto/qml/qmlmin/tst_qmlmin.cpp @@ -125,6 +125,8 @@ void tst_qmlmin::initTestCase() invalidFiles << "tests/auto/qml/qqmlecmascript/data/stringParsing_error.6.qml"; invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.1.qml"; invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.2.qml"; + invalidFiles << "tests/auto/qml/parserstress/tests/ecma_3/FunExpr/fe-001.js"; + invalidFiles << "tests/auto/qml/qjsengine/script/com/trolltech/syntaxerror/__init__.js"; } QStringList tst_qmlmin::findFiles(const QDir &d) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index f40a9758f7..619780bcdd 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -7401,7 +7401,7 @@ void tst_qqmlecmascript::onDestructionViaGC() QVERIFY2(!weakReferenceMutator.isNull(), qPrintable(component.errorString())); weakReferenceMutator->init(v4, weakRef.data(), &mutatorResult); - v4->memoryManager->allocObject<QV4::WeakReferenceSentinel>(weakRef.data(), &sentinelResult); + v4->memoryManager->allocate<QV4::WeakReferenceSentinel>(weakRef.data(), &sentinelResult); } gc(engine); diff --git a/tests/auto/qml/qqmllanguage/data/property.4.errors.txt b/tests/auto/qml/qqmllanguage/data/property.4.errors.txt index b447186849..2807384ec4 100644 --- a/tests/auto/qml/qqmllanguage/data/property.4.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/property.4.errors.txt @@ -1 +1 @@ -5:1:Syntax error +5:1:Expected token `:' diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index ba2b836a6d..a36409a35e 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -50,6 +50,9 @@ private slots: void qmlParser(); #endif void invalidEscapeSequence(); + void stringLiteral(); + void noSubstitutionTemplateLiteral(); + void templateLiteral(); private: QStringList excludedDirs; @@ -183,13 +186,12 @@ void tst_qqmlparser::qmlParser() Lexer lexer(&engine); lexer.setCode(code, 1, qmlMode); Parser parser(&engine); - if (qmlMode) - parser.parse(); - else - parser.parseProgram(); + bool ok = qmlMode ? parser.parse() : parser.parseProgram(); - check::Check chk; - chk(parser.rootNode()); + if (ok) { + check::Check chk; + chk(parser.rootNode()); + } } #endif @@ -204,6 +206,67 @@ void tst_qqmlparser::invalidEscapeSequence() parser.parse(); } +void tst_qqmlparser::stringLiteral() +{ + using namespace QQmlJS; + + Engine engine; + Lexer lexer(&engine); + QLatin1String code("'hello string'"); + lexer.setCode(code , 1); + Parser parser(&engine); + QVERIFY(parser.parseExpression()); + AST::ExpressionNode *expression = parser.expression(); + QVERIFY(expression); + auto *literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(expression); + QVERIFY(literal); + QCOMPARE(literal->value, "hello string"); + QCOMPARE(literal->firstSourceLocation().begin(), 0); + QCOMPARE(literal->lastSourceLocation().end(), code.size()); +} + +void tst_qqmlparser::noSubstitutionTemplateLiteral() +{ + using namespace QQmlJS; + + Engine engine; + Lexer lexer(&engine); + QLatin1String code("`hello template`"); + lexer.setCode(code, 1); + Parser parser(&engine); + QVERIFY(parser.parseExpression()); + AST::ExpressionNode *expression = parser.expression(); + QVERIFY(expression); + + auto *literal = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(expression); + QVERIFY(literal); + + QCOMPARE(literal->value, "hello template"); + QCOMPARE(literal->firstSourceLocation().begin(), 0); + QCOMPARE(literal->lastSourceLocation().end(), code.size()); +} + +void tst_qqmlparser::templateLiteral() +{ + using namespace QQmlJS; + + Engine engine; + Lexer lexer(&engine); + QLatin1String code("`one plus one equals ${1+1}!`"); + lexer.setCode(code, 1); + Parser parser(&engine); + QVERIFY(parser.parseExpression()); + AST::ExpressionNode *expression = parser.expression(); + QVERIFY(expression); + + auto *templateLiteral = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(expression); + QVERIFY(templateLiteral); + + QCOMPARE(templateLiteral->firstSourceLocation().begin(), 0); + auto *e = templateLiteral->expression; + QVERIFY(e); +} + QTEST_MAIN(tst_qqmlparser) #include "tst_qqmlparser.moc" diff --git a/tests/auto/qml/qv4mm/tst_qv4mm.cpp b/tests/auto/qml/qv4mm/tst_qv4mm.cpp index d4ba363d00..07f8e9f1d1 100644 --- a/tests/auto/qml/qv4mm/tst_qv4mm.cpp +++ b/tests/auto/qml/qv4mm/tst_qv4mm.cpp @@ -28,6 +28,7 @@ #include <qtest.h> #include <QQmlEngine> +#include <QLoggingCategory> #include <private/qv4mm_p.h> class tst_qv4mm : public QObject @@ -36,23 +37,15 @@ class tst_qv4mm : public QObject private slots: void gcStats(); - void tweaks(); }; void tst_qv4mm::gcStats() { - qputenv(QV4_MM_STATS, "1"); + QLoggingCategory::setFilterRules("qt.qml.gc.*=true"); QQmlEngine engine; engine.collectGarbage(); } -void tst_qv4mm::tweaks() -{ - qputenv(QV4_MM_MAXBLOCK_SHIFT, "5"); - qputenv(QV4_MM_MAX_CHUNK_SIZE, "65536"); - QQmlEngine engine; -} - QTEST_MAIN(tst_qv4mm) #include "tst_qv4mm.moc" diff --git a/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml b/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml new file mode 100644 index 0000000000..551329a457 --- /dev/null +++ b/tests/auto/quick/qquickanimatedsprite/data/infiniteLoops.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +AnimatedSprite { + loops: AnimatedSprite.Infinite + source: "squarefacesprite.png" + frameCount: 6 + frameDuration: 240 + width: 160 + height: 160 +} diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index d24ebd9878..4ca31fd957 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -53,6 +53,7 @@ private slots: void test_largeAnimation(); void test_reparenting(); void test_changeSourceToSmallerImgKeepingBigFrameSize(); + void test_infiniteLoops(); void test_implicitSize(); }; @@ -79,8 +80,13 @@ void tst_qquickanimatedsprite::test_properties() QVERIFY(sprite->interpolate()); QCOMPARE(sprite->loops(), 30); + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + sprite->setRunning(false); QVERIFY(!sprite->running()); + // The finished() signal shouldn't be emitted when running is manually set to false. + QCOMPARE(finishedSpy.count(), 0); sprite->setInterpolate(false); QVERIFY(!sprite->interpolate()); } @@ -100,10 +106,15 @@ void tst_qquickanimatedsprite::test_runningChangedSignal() QVERIFY(!sprite->running()); QSignalSpy runningChangedSpy(sprite, SIGNAL(runningChanged(bool))); + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + sprite->setRunning(true); QTRY_COMPARE(runningChangedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 0); QTRY_VERIFY(!sprite->running()); QTRY_COMPARE(runningChangedSpy.count(), 2); + QCOMPARE(finishedSpy.count(), 1); } template <typename T> @@ -357,6 +368,28 @@ void tst_qquickanimatedsprite::test_implicitSize() QCOMPARE(frameImplicitHeightChangedSpy.count(), 1); } +void tst_qquickanimatedsprite::test_infiniteLoops() +{ + QQuickView window; + window.setSource(testFileUrl("infiniteLoops.qml")); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject()); + + QQuickAnimatedSprite* sprite = qobject_cast<QQuickAnimatedSprite*>(window.rootObject()); + QVERIFY(sprite); + + QTRY_VERIFY(sprite->running()); + + QSignalSpy finishedSpy(sprite, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + + // The finished() signal shouldn't be emitted for infinite animations. + const int previousFrame = sprite->currentFrame(); + QTRY_VERIFY(sprite->currentFrame() != previousFrame); + QCOMPARE(finishedSpy.count(), 0); +} + QTEST_MAIN(tst_qquickanimatedsprite) #include "tst_qquickanimatedsprite.moc" diff --git a/tests/auto/quick/qquickanimations/data/finished.qml b/tests/auto/quick/qquickanimations/data/finished.qml new file mode 100644 index 0000000000..a18b321501 --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/finished.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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$ +** +****************************************************************************/ + +import QtQuick 2.12 + +Item { + id: root + width: 400 + height: 400 + + property bool finishedUsableInQml: false + + property alias simpleTopLevelAnimation: simpleTopLevelAnimation + property real foo: 0 + + property alias transitionRect: transitionRect + property alias transition: transition + property alias animationWithinTransition: animationWithinTransition + + property real bar: 0 + property alias animationWithinBehavior: animationWithinBehavior + property alias behavior: behavior + + NumberAnimation { + id: simpleTopLevelAnimation + target: root + property: "foo" + from: 0 + to: 1 + duration: 10 + + onFinished: finishedUsableInQml = true + } + + Rectangle { + id: transitionRect + color: "green" + width: 50 + height: 50 + anchors.centerIn: parent + + states: State { + name: "go" + } + transitions: Transition { + id: transition + to: "go" + SequentialAnimation { + NumberAnimation { + id: animationWithinTransition + duration: 10 + property: "foo" + from: 1 + to: 2 + } + } + } + } + + Behavior on bar { + id: behavior + NumberAnimation { + id: animationWithinBehavior + duration: 10 + property: "bar" + from: 0 + to: 1 + } + } +} diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index de86bb16db..3cfe03a376 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -105,6 +105,7 @@ private slots: void pathSvgAnimation(); void pathLineUnspecifiedXYBug(); void unsetAnimatorProxyJobWindow(); + void finished(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -1612,6 +1613,79 @@ void tst_qquickanimations::unsetAnimatorProxyJobWindow() QCOMPARE(proxy.job().data(), job); } +void tst_qquickanimations::finished() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("finished.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root); + + // Test that finished() is emitted for a simple top-level animation. + // (Each test is in its own block so that we can reuse the nice signal names :)) + { + QQuickAbstractAnimation *simpleTopLevelAnimation + = root->property("simpleTopLevelAnimation").value<QQuickAbstractAnimation*>(); + QVERIFY(simpleTopLevelAnimation); + + QSignalSpy stoppedSpy(simpleTopLevelAnimation, SIGNAL(stopped())); + QVERIFY(stoppedSpy.isValid()); + + QSignalSpy finishedSpy(simpleTopLevelAnimation, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + + QVERIFY(simpleTopLevelAnimation->setProperty("running", QVariant(true))); + QTRY_COMPARE(stoppedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + + // Test that the signal is properly revisioned and hence accessible from QML. + QCOMPARE(root->property("finishedUsableInQml").toBool(), true); + } + + // Test that finished() is not emitted for animations within a Transition. + { + QObject *transition = root->property("transition").value<QObject*>(); + QVERIFY(transition); + + QSignalSpy runningChangedSpy(transition, SIGNAL(runningChanged())); + QVERIFY(runningChangedSpy.isValid()); + + QQuickAbstractAnimation *animationWithinTransition + = root->property("animationWithinTransition").value<QQuickAbstractAnimation*>(); + QVERIFY(animationWithinTransition); + + QSignalSpy stoppedSpy(animationWithinTransition, SIGNAL(stopped())); + QVERIFY(stoppedSpy.isValid()); + + QSignalSpy finishedSpy(animationWithinTransition, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + + QObject *transitionRect = root->property("transitionRect").value<QObject*>(); + QVERIFY(transitionRect); + QVERIFY(transitionRect->setProperty("state", QVariant(QLatin1String("go")))); + QTRY_COMPARE(runningChangedSpy.count(), 1); + QCOMPARE(stoppedSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 0); + } + + // Test that finished() is not emitted for animations within a Behavior. + { + QQuickAbstractAnimation *animationWithinBehavior + = root->property("animationWithinBehavior").value<QQuickAbstractAnimation*>(); + QVERIFY(animationWithinBehavior); + + QSignalSpy stoppedSpy(animationWithinBehavior, SIGNAL(stopped())); + QVERIFY(stoppedSpy.isValid()); + + QSignalSpy finishedSpy(animationWithinBehavior, SIGNAL(finished())); + QVERIFY(finishedSpy.isValid()); + + QVERIFY(root->setProperty("bar", QVariant(1.0))); + QTRY_COMPARE(root->property("bar").toReal(), 1.0); + QCOMPARE(stoppedSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 0); + } +} + QTEST_MAIN(tst_qquickanimations) #include "tst_qquickanimations.moc" diff --git a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp index 805baebc7a..6aff66d61e 100644 --- a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp +++ b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp @@ -193,7 +193,7 @@ void tst_QQuickFramebufferObject::testThatStuffWorks() view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QImage result = view.grabWindow(); @@ -233,7 +233,7 @@ void tst_QQuickFramebufferObject::testInvalidate() view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QCOMPARE(frameInfo.fboSize, QSize(200, 200)); diff --git a/tests/auto/quick/qquicktableview/data/plaintableview.qml b/tests/auto/quick/qquicktableview/data/plaintableview.qml new file mode 100644 index 0000000000..7748f51aae --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/plaintableview.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import Qt.labs.tableview 1.0 + +Item { + width: 640 + height: 480 + + property alias tableView: tableView + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + cacheBuffer: 0 + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + implicitWidth: 100 + implicitHeight: 50 + color: "lightgray" + Text { + anchors.centerIn: parent + text: modelData + } + } + } + +} diff --git a/tests/auto/quick/qquicktableview/qquicktableview.pro b/tests/auto/quick/qquicktableview/qquicktableview.pro new file mode 100644 index 0000000000..f4d0265dd3 --- /dev/null +++ b/tests/auto/quick/qquicktableview/qquicktableview.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +TARGET = tst_qquicktableview +macos:CONFIG -= app_bundle + +HEADERS += testmodel.h +SOURCES += tst_qquicktableview.cpp + +include (../../shared/util.pri) +include (../shared/util.pri) + +TESTDATA = data/* + +QT += core-private gui-private qml-private quick-private testlib + diff --git a/tests/auto/quick/qquicktableview/testmodel.h b/tests/auto/quick/qquicktableview/testmodel.h new file mode 100644 index 0000000000..8937aff766 --- /dev/null +++ b/tests/auto/quick/qquicktableview/testmodel.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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$ +** +****************************************************************************/ + +#include <QtCore/QtCore> +#include <QtGui/QStandardItemModel> + +class TestModel : public QAbstractTableModel +{ + Q_OBJECT + Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) + Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) + +public: + TestModel(QObject *parent = nullptr) + : QAbstractTableModel(parent) + {} + + TestModel(int rows, int columns, QObject *parent = nullptr) + : QAbstractTableModel(parent) + , m_rows(rows) + , m_columns(columns) + {} + + int rowCount(const QModelIndex & = QModelIndex()) const override { return m_rows; } + void setRowCount(int count) { beginResetModel(); m_rows = count; emit rowCountChanged(); endResetModel(); } + + int columnCount(const QModelIndex & = QModelIndex()) const override { return m_columns; } + void setColumnCount(int count) { beginResetModel(); m_columns = count; emit columnCountChanged(); endResetModel(); } + + QVariant data(const QModelIndex &index, int role) const override + { + if (!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + + int cell = index.row() + (index.column() * m_columns); + if (selectedCells.contains(cell)) + return QStringLiteral("selected"); + return QString("%1,%2").arg(index.column()).arg(index.row()); + } + + QHash<int, QByteArray> roleNames() const override + { + return { {Qt::DisplayRole, "display"} }; + } + + Q_INVOKABLE void selectCell(int row, int column) + { + int cell = row + (column * m_columns); + selectedCells.insert(cell); + auto index = createIndex(row, column, nullptr); + emit dataChanged(index, index); + } + +signals: + void rowCountChanged(); + void columnCountChanged(); + +private: + int m_rows = 0; + int m_columns = 0; + QSet<int> selectedCells; +}; diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp new file mode 100644 index 0000000000..3a615e1c3b --- /dev/null +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtQuick/qquickview.h> +#include <QtQuick/private/qquicktableview_p.h> + +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlexpression.h> +#include <QtQml/qqmlincubator.h> +#include <QtQml/private/qqmlobjectmodel_p.h> +#include <QtQml/private/qqmllistmodel_p.h> +#include <QtQml/private/qqmldelegatemodel_p.h> + +#include "testmodel.h" + +#include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + +#define CREATE_VAR_FROM_PROPERTY(name, T) \ + T *name = view->rootObject()->property(#name).value<T *>(); \ + QVERIFY(name) + +#define LOAD_TABLEVIEW(fileName) \ + QScopedPointer<QQuickView> view(createView()); \ + view->setSource(testFileUrl(fileName)); \ + view->show(); \ + QVERIFY(QTest::qWaitForWindowActive(view.data())); \ + CREATE_VAR_FROM_PROPERTY(tableView, QQuickTableView) + +class tst_QQuickTableView : public QQmlDataTest +{ + Q_OBJECT +public: + tst_QQuickTableView(); + +private slots: + void initTestCase() override; + + void setAndGetQAIM(); +}; + +tst_QQuickTableView::tst_QQuickTableView() +{ +} + +void tst_QQuickTableView::initTestCase() +{ + QQmlDataTest::initTestCase(); + qmlRegisterType<TestModel>("TestModel", 0, 1, "TestModel"); +} + +void tst_QQuickTableView::setAndGetQAIM() +{ + LOAD_TABLEVIEW("plaintableview.qml"); + + TestModel model(2, 2); + tableView->setModel(QVariant::fromValue<QObject *>(&model)); + auto returnModel = tableView->model().value<TestModel *>(); + QCOMPARE(&model, returnModel); +} + +QTEST_MAIN(tst_QQuickTableView) + +#include "tst_qquicktableview.moc" diff --git a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp index 757cb8f513..bcff0c46fb 100644 --- a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp +++ b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp @@ -354,7 +354,7 @@ void tst_qquickxmllistmodel::xml() QSignalSpy spy(model, SIGNAL(statusChanged(QQuickXmlListModel::Status))); QVERIFY(errorString(model).isEmpty()); - QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); + QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); QCOMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), QQuickXmlListModel::Loading); QTRY_COMPARE(spy.count(), 1); spy.clear(); @@ -410,6 +410,13 @@ void tst_qquickxmllistmodel::headers() QTRY_COMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), QQuickXmlListModel::Ready); + // It doesn't do a network request for a local file + QCOMPARE(factory.lastSentHeaders.count(), 0); + + model->setProperty("source", QUrl("http://localhost/filethatdoesnotexist.xml")); + QTRY_COMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), + QQuickXmlListModel::Error); + QVariantMap expectedHeaders; expectedHeaders["Accept"] = "application/xml,*/*"; @@ -433,7 +440,7 @@ void tst_qquickxmllistmodel::source() QSignalSpy spy(model, SIGNAL(statusChanged(QQuickXmlListModel::Status))); QVERIFY(errorString(model).isEmpty()); - QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); + QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); QCOMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), QQuickXmlListModel::Loading); QTRY_COMPARE(spy.count(), 1); spy.clear(); @@ -447,7 +454,7 @@ void tst_qquickxmllistmodel::source() if (model->property("source").toString().isEmpty()) QCOMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), QQuickXmlListModel::Null); - QCOMPARE(model->property("progress").toDouble(), qreal(0.0)); + QCOMPARE(model->property("progress").toDouble(), qreal(source.isLocalFile() ? 1.0 : 0.0)); QTRY_COMPARE(spy.count(), 1); spy.clear(); QCOMPARE(qvariant_cast<QQuickXmlListModel::Status>(model->property("status")), QQuickXmlListModel::Loading); diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index a54a707f4a..a4b6076a34 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -66,6 +66,7 @@ QUICKTESTS += \ qquickitem2 \ qquickitemlayer \ qquicklistview \ + qquicktableview \ qquickloader \ qquickmousearea \ qquickmultipointtoucharea \ @@ -93,7 +94,7 @@ QUICKTESTS += \ SUBDIRS += $$PUBLICTESTS # Following tests are too slow on qemu + software backend -boot2qt: QUICKTESTS -= qquickgridview qquicklistview qquickpositioners +boot2qt: QUICKTESTS -= qquickgridview qquicklistview qquicktableview qquickpositioners !qtConfig(accessibility):QUICKTESTS -= qquickaccessible diff --git a/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro b/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro new file mode 100644 index 0000000000..ade49c33a2 --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tableview_abstracttablemodel +QT += qml quick +SOURCES += main.cpp +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/abstracttablemodel/main.cpp b/tests/manual/tableview/abstracttablemodel/main.cpp new file mode 100644 index 0000000000..22dda5ca4a --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/main.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QAbstractTableModel> + +class TestTableModel : public QAbstractTableModel +{ + Q_OBJECT + Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) + Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) + +public: + TestTableModel(QObject *parent = nullptr) : QAbstractTableModel(parent) { } + + int rowCount(const QModelIndex & = QModelIndex()) const override { return m_rows; } + void setRowCount(int count) { beginResetModel(); m_rows = count; emit rowCountChanged(); endResetModel(); } + + int columnCount(const QModelIndex & = QModelIndex()) const override { return m_cols; } + void setColumnCount(int count) { beginResetModel(); m_cols = count; emit columnCountChanged(); endResetModel(); } + + QVariant headerData(int section, Qt::Orientation orientation, int role) const + { + Q_UNUSED(orientation); + Q_UNUSED(role); + return QStringLiteral("Column header"); + } + + QVariant data(const QModelIndex &index, int role) const override + { + if (!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + return QString("[%1-%2]").arg(index.column()).arg(index.row()); + } + + QHash<int, QByteArray> roleNames() const override + { + return { {Qt::DisplayRole, "display"} }; + } + +signals: + void rowCountChanged(); + void columnCountChanged(); + +private: + int m_rows = 0; + int m_cols = 0; +}; + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + qmlRegisterType<TestTableModel>("TestTableModel", 0, 1, "TestTableModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + +#include "main.moc" diff --git a/tests/manual/tableview/abstracttablemodel/main.qml b/tests/manual/tableview/abstracttablemodel/main.qml new file mode 100644 index 0000000000..bff851a9f2 --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/main.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import QtQml.Models 2.2 +import Qt.labs.tableview 1.0 +import TestTableModel 0.1 + +Window { + id: window + width: 640 + height: 480 + visible: true + + TestTableModel { + id: tableModel + rowCount: 200 + columnCount: 200 + } + + Rectangle { + anchors.fill: parent + anchors.margins: 10 + color: "darkgray" + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + + model: tableModel + delegate: tableViewDelegate + cacheBuffer: 500 + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + width: TableView.column % 3 ? 80 : 50 + height: TableView.row % 3 ? 80 : 50 + + Text { + anchors.centerIn: parent + text: modelData + } + } + } + + } + +} diff --git a/tests/manual/tableview/listmodel/listmodel.pro b/tests/manual/tableview/listmodel/listmodel.pro new file mode 100644 index 0000000000..dbae0db2b1 --- /dev/null +++ b/tests/manual/tableview/listmodel/listmodel.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tableview_listmodel +QT += qml quick +SOURCES += main.cpp +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/listmodel/main.cpp b/tests/manual/tableview/listmodel/main.cpp new file mode 100644 index 0000000000..2a3b90d392 --- /dev/null +++ b/tests/manual/tableview/listmodel/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/tests/manual/tableview/listmodel/main.qml b/tests/manual/tableview/listmodel/main.qml new file mode 100644 index 0000000000..f4def85455 --- /dev/null +++ b/tests/manual/tableview/listmodel/main.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import Qt.labs.tableview 1.0 +import QtQml.Models 2.2 + +Window { + id: window + width: 640 + height: 480 + visible: true + + ListModel { + id: listModel + Component.onCompleted: { + for (var i = 0; i < 30; ++i) + listModel.append({"name" : i}) + } + } + + Rectangle { + anchors.fill: parent + anchors.margins: 10 + color: "darkgray" + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + columnSpacing: 1 + rowSpacing: 1 + model: listModel + delegate: Component { + Rectangle { + id: tableDelegate + width: 100 + height: 50 + + Text { + anchors.centerIn: parent + text: name + "\n[" + tableDelegate.TableView.column + ", " + tableDelegate.TableView.row + "]" + } + } + } + } + } +} diff --git a/tests/manual/tableview/storagemodel/main.cpp b/tests/manual/tableview/storagemodel/main.cpp new file mode 100644 index 0000000000..97ae619ce4 --- /dev/null +++ b/tests/manual/tableview/storagemodel/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include "storagemodel.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + qmlRegisterType<StorageModel>("StorageModel", 0, 1, "StorageModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + diff --git a/tests/manual/tableview/storagemodel/main.qml b/tests/manual/tableview/storagemodel/main.qml new file mode 100644 index 0000000000..fbeb5f6115 --- /dev/null +++ b/tests/manual/tableview/storagemodel/main.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import Qt.labs.tableview 1.0 +import StorageModel 0.1 + +Window { + id: window + width: 640 + height: 480 + visible: true + color: "darkgray" + title: "Storage Volumes" + + TableView { + id: table + anchors.fill: parent + anchors.margins: 10 + clip: true + model: StorageModel { } + columnSpacing: 1 + rowSpacing: 1 + delegate: Rectangle { + id: tableDelegate + width: displayText.implicitWidth + 8 + height: displayText.implicitHeight + 14 + + Text { + id: displayText + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.leftMargin: 4 + text: display + } + } + } +} diff --git a/tests/manual/tableview/storagemodel/storagemodel.cpp b/tests/manual/tableview/storagemodel/storagemodel.cpp new file mode 100644 index 0000000000..345d1cc63f --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Ivan Komissarov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "storagemodel.h" + +#include <QDir> +#include <QLocale> +#include <qmath.h> +#include <algorithm> +#include <cmath> + +StorageModel::StorageModel(QObject *parent) : + QAbstractTableModel(parent) +{ + refresh(); +} + +void StorageModel::refresh() +{ + beginResetModel(); + m_volumes = QStorageInfo::mountedVolumes(); + std::sort(m_volumes.begin(), m_volumes.end(), + [](const QStorageInfo &st1, const QStorageInfo &st2) { + static const QString rootSortString = QStringLiteral(" "); + return (st1.isRoot() ? rootSortString : st1.rootPath()) + < (st2.isRoot() ? rootSortString : st2.rootPath()); + }); + endResetModel(); +} + +int StorageModel::columnCount(const QModelIndex &/*parent*/) const +{ + return ColumnCount; +} + +int StorageModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return m_volumes.count(); +} + +Qt::ItemFlags StorageModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags result = QAbstractTableModel::flags(index); + switch (index.column()) { + case ColumnAvailable: + case ColumnIsReady: + case ColumnIsReadOnly: + case ColumnIsValid: + result |= Qt::ItemIsUserCheckable; + break; + default: + break; + } + return result; +} + +QVariant StorageModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) { + const QStorageInfo &volume = m_volumes.at(index.row()); + switch (index.column()) { + case ColumnRootPath: + return QDir::toNativeSeparators(volume.rootPath()); + case ColumnName: + return volume.name(); + case ColumnDevice: + return volume.device(); + case ColumnFileSystemName: + return volume.fileSystemType(); + case ColumnTotal: + return QLocale().formattedDataSize(volume.bytesTotal()); + case ColumnFree: + return QLocale().formattedDataSize(volume.bytesFree()); + case ColumnAvailable: + return QLocale().formattedDataSize(volume.bytesAvailable()); + case ColumnIsReady: + return volume.isReady(); + case ColumnIsReadOnly: + return volume.isReadOnly(); + case ColumnIsValid: + return volume.isValid(); + default: + break; + } + } else if (role == Qt::CheckStateRole) { + const QStorageInfo &volume = m_volumes.at(index.row()); + switch (index.column()) { + case ColumnIsReady: + return volume.isReady(); + case ColumnIsReadOnly: + return volume.isReadOnly(); + case ColumnIsValid: + return volume.isValid(); + default: + break; + } + } else if (role == Qt::TextAlignmentRole) { + switch (index.column()) { + case ColumnTotal: + case ColumnFree: + case ColumnAvailable: + return Qt::AlignTrailing; + default: + break; + } + return Qt::AlignLeading; + } else if (role == Qt::ToolTipRole) { + QLocale locale; + const QStorageInfo &volume = m_volumes.at(index.row()); + return tr("Root path : %1\n" + "Name: %2\n" + "Display Name: %3\n" + "Device: %4\n" + "FileSystem: %5\n" + "Total size: %6\n" + "Free size: %7\n" + "Available size: %8\n" + "Is Ready: %9\n" + "Is Read-only: %10\n" + "Is Valid: %11\n" + "Is Root: %12" + ). + arg(QDir::toNativeSeparators(volume.rootPath())). + arg(volume.name()). + arg(volume.displayName()). + arg(QString::fromUtf8(volume.device())). + arg(QString::fromUtf8(volume.fileSystemType())). + arg(locale.formattedDataSize(volume.bytesTotal())). + arg(locale.formattedDataSize(volume.bytesFree())). + arg(locale.formattedDataSize(volume.bytesAvailable())). + arg(volume.isReady() ? tr("true") : tr("false")). + arg(volume.isReadOnly() ? tr("true") : tr("false")). + arg(volume.isValid() ? tr("true") : tr("false")). + arg(volume.isRoot() ? tr("true") : tr("false")); + } + return QVariant(); +} + +QVariant StorageModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation != Qt::Horizontal) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) { + case ColumnRootPath: + return tr("Root Path"); + case ColumnName: + return tr("Volume Name"); + case ColumnDevice: + return tr("Device"); + case ColumnFileSystemName: + return tr("File System"); + case ColumnTotal: + return tr("Total"); + case ColumnFree: + return tr("Free"); + case ColumnAvailable: + return tr("Available"); + case ColumnIsReady: + return tr("Ready"); + case ColumnIsReadOnly: + return tr("Read-only"); + case ColumnIsValid: + return tr("Valid"); + default: + break; + } + + return QVariant(); +} diff --git a/tests/manual/tableview/storagemodel/storagemodel.h b/tests/manual/tableview/storagemodel/storagemodel.h new file mode 100644 index 0000000000..787b2f04de --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Ivan Komissarov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STORAGEMODEL_H +#define STORAGEMODEL_H + +#include <QAbstractTableModel> +#include <QStorageInfo> + +class StorageModel : public QAbstractTableModel +{ + Q_OBJECT + Q_DISABLE_COPY(StorageModel) +public: + enum Column { + ColumnRootPath = 0, + ColumnName, + ColumnDevice, + ColumnFileSystemName, + ColumnTotal, + ColumnFree, + ColumnAvailable, + ColumnIsReady, + ColumnIsReadOnly, + ColumnIsValid, + ColumnCount + }; + + explicit StorageModel(QObject *parent = nullptr); + + int columnCount(const QModelIndex &parent) const override; + int rowCount(const QModelIndex &parent) const override; + + QVariant data(const QModelIndex &index, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + +public slots: + void refresh(); + +private: + QList<QStorageInfo> m_volumes; +}; + +#endif // STORAGEMODEL_H diff --git a/tests/manual/tableview/storagemodel/storagemodel.pro b/tests/manual/tableview/storagemodel/storagemodel.pro new file mode 100644 index 0000000000..c6a018239e --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = tableview_storage +QT += qml quick +SOURCES += main.cpp storagemodel.cpp +HEADERS += storagemodel.h +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/tableview.pro b/tests/manual/tableview/tableview.pro new file mode 100644 index 0000000000..5040f0e747 --- /dev/null +++ b/tests/manual/tableview/tableview.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += abstracttablemodel \ + listmodel \ + storagemodel |