From 3693dd74febbd928eefa8291a05f6ef5a65ffe63 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 8 Aug 2023 18:45:42 +0200 Subject: [PATCH] tst_QWizard: port from QSharedPointer to std::shared_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QSharedPointer is 'meh', see QTBUG-109570 and 18113e22e92a7b8d759fd0f9c9d696ee7e97a849. This is just a textual replacement of - QSharedPointer<(.+)>::create() → std::make_shared<\1>() - QSharedPointer → std::shared_ptr And it compiles and still passes. No non-standard APIs to fix up. Task-number: QTBUG-109570 Change-Id: I827d4a9be0511780c3900bd53ffcbdcb6aacbc3b Reviewed-by: Richard Moe Gustavsen Reviewed-by: Ahmad Samir --- .../widgets/dialogs/qwizard/tst_qwizard.cpp | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index 3af657744e..583aaaeb0f 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -19,6 +19,8 @@ #include +#include + Q_DECLARE_METATYPE(QWizard::WizardButton); static QImage grabWidget(QWidget *window) @@ -1581,9 +1583,9 @@ class SetPage : public Operation QString describe() const override { return QLatin1String("set page ") + QString::number(page); } int page; public: - static QSharedPointer create(int page) + static std::shared_ptr create(int page) { - QSharedPointer o = QSharedPointer::create(); + std::shared_ptr o = std::make_shared(); o->page = page; return o; } @@ -1595,9 +1597,9 @@ class SetStyle : public Operation QString describe() const override { return QLatin1String("set style ") + QString::number(style); } QWizard::WizardStyle style; public: - static QSharedPointer create(QWizard::WizardStyle style) + static std::shared_ptr create(QWizard::WizardStyle style) { - QSharedPointer o = QSharedPointer::create(); + std::shared_ptr o = std::make_shared(); o->style = style; return o; } @@ -1610,9 +1612,9 @@ class SetOption : public Operation QWizard::WizardOption option; bool on; public: - static QSharedPointer create(QWizard::WizardOption option, bool on) + static std::shared_ptr create(QWizard::WizardOption option, bool on) { - QSharedPointer o = QSharedPointer::create(); + std::shared_ptr o = std::make_shared(); o->option = option; o->on = on; return o; @@ -1641,7 +1643,7 @@ class OptionInfo tags[QWizard::HaveCustomButton3] = "15/CB3"; for (int i = 0; i < 2; ++i) { - QMap > operations_; + QMap > operations_; for (const auto &[option, _] : std::as_const(tags).asKeyValueRange()) operations_[option] = SetOption::create(option, i == 1); operations << operations_; @@ -1650,7 +1652,7 @@ class OptionInfo OptionInfo(OptionInfo const&); OptionInfo& operator=(OptionInfo const&); QMap tags; - QList > > operations; + QList > > operations; public: static OptionInfo &instance() { @@ -1659,7 +1661,7 @@ public: } QString tag(QWizard::WizardOption option) const { return tags.value(option); } - QSharedPointer operation(QWizard::WizardOption option, bool on) const + std::shared_ptr operation(QWizard::WizardOption option, bool on) const { return operations.at(on).value(option); } QList options() const { return tags.keys(); } }; @@ -1670,7 +1672,7 @@ QString SetOption::describe() const + QLatin1Char(on ? '1' : '0'); } -Q_DECLARE_METATYPE(QList>) +Q_DECLARE_METATYPE(QList>) class TestGroup { @@ -1687,7 +1689,7 @@ public: combinations.clear(); } - QList> &add() + QList> &add() { combinations.resize(combinations.size() + 1); return combinations.last(); @@ -1708,7 +1710,7 @@ private: QString name; Type type; int nRows_; - QList>> combinations; + QList>> combinations; }; class IntroPage : public QWizardPage @@ -1792,9 +1794,9 @@ public: } } - void applyOperations(const QList> &operations) + void applyOperations(const QList> &operations) { - for (const QSharedPointer &op : operations) { + for (const std::shared_ptr &op : operations) { if (op) { op->apply(this); opsDescr += QLatin1Char('(') + op->describe() + QLatin1String(") "); @@ -1814,24 +1816,24 @@ public: class CombinationsTestData { TestGroup testGroup; - const QSharedPointer pageOps[3] = { + const std::shared_ptr pageOps[3] = { SetPage::create(0), SetPage::create(1), SetPage::create(2), }; - const QSharedPointer styleOps[3] = { + const std::shared_ptr styleOps[3] = { SetStyle::create(QWizard::ClassicStyle), SetStyle::create(QWizard::ModernStyle), SetStyle::create(QWizard::MacStyle), }; - QMap>> setAllOptions; + QMap>> setAllOptions; public: CombinationsTestData() { QTest::addColumn("ref"); QTest::addColumn("testEquality"); - QTest::addColumn>>("operations"); + QTest::addColumn>>("operations"); #define SETPAGE(page) pageOps[page] #define SETSTYLE(style) styleOps[style] #define OPT(option, on) OptionInfo::instance().operation(option, on) @@ -1895,7 +1897,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList> setOptions = setAllOptions.value(i == 1); + QList> setOptions = setAllOptions.value(i == 1); testGroup.reset("testAll 3.1"); testGroup.add() << setOptions; @@ -1912,14 +1914,14 @@ public: testGroup.createTestRows(); } - for (const QSharedPointer &pageOp : pageOps) { + for (const std::shared_ptr &pageOp : pageOps) { testGroup.reset("testAll 4.1"); testGroup.add() << pageOp; testGroup.add() << pageOp << pageOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList> optionOps = setAllOptions.value(i == 1); + QList> optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 4.2"); testGroup.add() << optionOps << pageOp; testGroup.add() << pageOp << optionOps; @@ -1927,7 +1929,7 @@ public: const auto options = OptionInfo::instance().options(); for (QWizard::WizardOption option : options) { - QSharedPointer optionOp = OPT(option, i == 1); + std::shared_ptr optionOp = OPT(option, i == 1); testGroup.reset("testAll 4.3"); testGroup.add() << optionOp << pageOp; testGroup.add() << pageOp << optionOp; @@ -1936,14 +1938,14 @@ public: } } - for (const QSharedPointer &styleOp : styleOps) { + for (const std::shared_ptr &styleOp : styleOps) { testGroup.reset("testAll 5.1"); testGroup.add() << styleOp; testGroup.add() << styleOp << styleOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList> optionOps = setAllOptions.value(i == 1); + QList> optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 5.2"); testGroup.add() << optionOps << styleOp; testGroup.add() << styleOp << optionOps; @@ -1951,7 +1953,7 @@ public: const auto options = OptionInfo::instance().options(); for (QWizard::WizardOption option : options) { - QSharedPointer optionOp = OPT(option, i == 1); + std::shared_ptr optionOp = OPT(option, i == 1); testGroup.reset("testAll 5.3"); testGroup.add() << optionOp << styleOp; testGroup.add() << styleOp << optionOp; @@ -1960,8 +1962,8 @@ public: } } - for (const QSharedPointer &pageOp : pageOps) { - for (const QSharedPointer &styleOp : styleOps) { + for (const std::shared_ptr &pageOp : pageOps) { + for (const std::shared_ptr &styleOp : styleOps) { testGroup.reset("testAll 6.1"); testGroup.add() << pageOp; @@ -1979,7 +1981,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList> optionOps = setAllOptions.value(i == 1); + QList> optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 6.4"); testGroup.add() << optionOps << pageOp << styleOp; testGroup.add() << pageOp << optionOps << styleOp; @@ -1991,7 +1993,7 @@ public: const auto options = OptionInfo::instance().options(); for (QWizard::WizardOption option : options) { - QSharedPointer optionOp = OPT(option, i == 1); + std::shared_ptr optionOp = OPT(option, i == 1); testGroup.reset("testAll 6.5"); testGroup.add() << optionOp << pageOp << styleOp; testGroup.add() << pageOp << optionOp << styleOp; @@ -2053,7 +2055,7 @@ void tst_QWizard::combinations() { QFETCH(bool, ref); QFETCH(bool, testEquality); - QFETCH(const QList>, operations); + QFETCH(const QList>, operations); TestWizard wizard; #if !defined(QT_NO_STYLE_WINDOWSVISTA)