[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.
This commit is contained in:
Adriaan de Groot 2021-09-22 11:17:41 +02:00
parent b0149c2712
commit bba5b21873
3 changed files with 4 additions and 41 deletions

View File

@ -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 /// @brief Blocks signals on a QObject until destruction
using cSignalBlocker = QSignalBlocker; using cSignalBlocker = QSignalBlocker;

View File

@ -55,7 +55,6 @@ private Q_SLOTS:
void testOddSizedPrintable(); void testOddSizedPrintable();
/** @section Tests the RAII bits. */ /** @section Tests the RAII bits. */
void testBoolSetter();
void testPointerSetter(); void testPointerSetter();
/** @section Tests the Traits bits. */ /** @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 void
LibCalamaresTests::testPointerSetter() LibCalamaresTests::testPointerSetter()
{ {
@ -490,8 +467,7 @@ LibCalamaresTests::testVariantStringListCode()
QStringList { "astring" } ); // A single string **can** be considered a stringlist! QStringList { "astring" } ); // A single string **can** be considered a stringlist!
m.insert( key, QString( "more strings" ) ); m.insert( key, QString( "more strings" ) );
QCOMPARE( getStringList( m, key ).count(), 1 ); QCOMPARE( getStringList( m, key ).count(), 1 );
QCOMPARE( getStringList( m, key ), QCOMPARE( getStringList( m, key ), QStringList { "more strings" } );
QStringList { "more strings" } );
m.insert( key, QString() ); m.insert( key, QString() );
QCOMPARE( getStringList( m, key ).count(), 1 ); QCOMPARE( getStringList( m, key ).count(), 1 );
QCOMPARE( getStringList( m, key ), QStringList { QString() } ); QCOMPARE( getStringList( m, key ), QStringList { QString() } );

View File

@ -174,7 +174,8 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TimeZoneData* locatio
{ {
return; return;
} }
cBoolSetter< true > b( m_blockTzWidgetSet ); m_blockTzWidgetSet = true; // Blocked until we go out of scope
cPointerSetter b( &m_blockTzWidgetSet, false );
// Set region index // Set region index
int index = m_regionCombo->findData( location->region() ); int index = m_regionCombo->findData( location->region() );