From bba5b21873969587edabc6b8c18c16a834754d4b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 22 Sep 2021 11:17:41 +0200 Subject: [PATCH] [libcalamares] Remove cBoolSetter This class was used only once, and is confusing because the assignment happens always, but to the opposite value as what was visible. It can be replaced with other scoped assignment, instead. Removes the tests for it, too. --- src/libcalamares/utils/RAII.h | 14 -------------- src/libcalamares/utils/Tests.cpp | 28 ++-------------------------- src/modules/locale/LocalePage.cpp | 3 ++- 3 files changed, 4 insertions(+), 41 deletions(-) diff --git a/src/libcalamares/utils/RAII.h b/src/libcalamares/utils/RAII.h index 00e276ec6..186775676 100644 --- a/src/libcalamares/utils/RAII.h +++ b/src/libcalamares/utils/RAII.h @@ -42,20 +42,6 @@ struct cqDeleter } }; -/// @brief Sets a bool to @p value and resets to !value on destruction -template < bool value > -struct cBoolSetter -{ - bool& m_b; - - cBoolSetter( bool& b ) - : m_b( b ) - { - m_b = value; - } - ~cBoolSetter() { m_b = !value; } -}; - /// @brief Blocks signals on a QObject until destruction using cSignalBlocker = QSignalBlocker; diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index a689505e9..bb1bf9520 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -55,7 +55,6 @@ private Q_SLOTS: void testOddSizedPrintable(); /** @section Tests the RAII bits. */ - void testBoolSetter(); void testPointerSetter(); /** @section Tests the Traits bits. */ @@ -340,28 +339,6 @@ LibCalamaresTests::testOddSizedPrintable() } } -void -LibCalamaresTests::testBoolSetter() -{ - bool b = false; - - QVERIFY( !b ); - { - QVERIFY( !b ); - cBoolSetter< true > x( b ); - QVERIFY( b ); - } - QVERIFY( !b ); - - QVERIFY( !b ); - { - QVERIFY( !b ); - cBoolSetter< false > x( b ); - QVERIFY( !b ); // Still! - } - QVERIFY( b ); -} - void LibCalamaresTests::testPointerSetter() { @@ -384,7 +361,7 @@ LibCalamaresTests::testPointerSetter() } QCOMPARE( special, 3 ); { - cPointerSetter p( nullptr ); + cPointerSetter< int > p( nullptr ); } QCOMPARE( special, 3 ); { @@ -490,8 +467,7 @@ LibCalamaresTests::testVariantStringListCode() QStringList { "astring" } ); // A single string **can** be considered a stringlist! m.insert( key, QString( "more strings" ) ); QCOMPARE( getStringList( m, key ).count(), 1 ); - QCOMPARE( getStringList( m, key ), - QStringList { "more strings" } ); + QCOMPARE( getStringList( m, key ), QStringList { "more strings" } ); m.insert( key, QString() ); QCOMPARE( getStringList( m, key ).count(), 1 ); QCOMPARE( getStringList( m, key ), QStringList { QString() } ); diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index f63aed10d..027d50a38 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -174,7 +174,8 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TimeZoneData* locatio { return; } - cBoolSetter< true > b( m_blockTzWidgetSet ); + m_blockTzWidgetSet = true; // Blocked until we go out of scope + cPointerSetter b( &m_blockTzWidgetSet, false ); // Set region index int index = m_regionCombo->findData( location->region() );