[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
using cSignalBlocker = QSignalBlocker;

View file

@ -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<int> 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() } );

View file

@ -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() );