Equipment: Include Unused Tanks in Merge if Preference is Enabled.

Include unused tanks in merges of multiple logs into a single dive if
the 'Show unused cylinders' preference is enabled.
Also rename the preference (in code) to `include_unused_tanks` to
reflect the fact that it is already used in more places than just the
display (exporting, cloning dives).
Simplified the cylinder model to make forced inclusion of unused tanks
dependent on use of the model in planner.
Leaving the persisted name of the preference as `display_unused_tanks`
to avoid resetting this for all users - is there a good way to migrate
preference names?

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2023-07-09 12:14:27 +12:00
parent cb6f768865
commit 5fae7ce7a0
17 changed files with 50 additions and 47 deletions

View file

@ -24,8 +24,8 @@ void TestQPrefEquipment::test_struct_get()
auto tst = qPrefEquipment::instance();
prefs.default_cylinder = copy_qstring("new base11");
QCOMPARE(tst->default_cylinder(), QString(prefs.default_cylinder));
prefs.display_unused_tanks = true;
QCOMPARE(tst->display_unused_tanks(), prefs.display_unused_tanks);
prefs.include_unused_tanks = true;
QCOMPARE(tst->include_unused_tanks(), prefs.include_unused_tanks);
}
void TestQPrefEquipment::test_set_struct()
@ -35,8 +35,8 @@ void TestQPrefEquipment::test_set_struct()
auto tst = qPrefEquipment::instance();
tst->set_default_cylinder("new base21");
QCOMPARE(QString(prefs.default_cylinder), QString("new base21"));
tst->set_display_unused_tanks(false);
QCOMPARE(prefs.display_unused_tanks, false);
tst->set_include_unused_tanks(false);
QCOMPARE(prefs.include_unused_tanks, false);
}
void TestQPrefEquipment::test_set_load_struct()
@ -47,11 +47,11 @@ void TestQPrefEquipment::test_set_load_struct()
tst->set_default_cylinder("new base31");
prefs.default_cylinder = copy_qstring("error");
tst->set_display_unused_tanks(false);
prefs.display_unused_tanks = true;
tst->set_include_unused_tanks(false);
prefs.include_unused_tanks = true;
tst->load();
QCOMPARE(QString(prefs.default_cylinder), QString("new base31"));
QCOMPARE(prefs.display_unused_tanks, false);
QCOMPARE(prefs.include_unused_tanks, false);
}
void TestQPrefEquipment::test_struct_disk()
@ -60,15 +60,15 @@ void TestQPrefEquipment::test_struct_disk()
auto tst = qPrefEquipment::instance();
prefs.default_cylinder = copy_qstring("base41");
prefs.display_unused_tanks = true;
prefs.include_unused_tanks = true;
tst->sync();
prefs.default_cylinder = copy_qstring("error");
prefs.display_unused_tanks = false;
prefs.include_unused_tanks = false;
tst->load();
QCOMPARE(QString(prefs.default_cylinder), QString("base41"));
QCOMPARE(prefs.display_unused_tanks, true);
QCOMPARE(prefs.include_unused_tanks, true);
}
@ -85,17 +85,17 @@ void TestQPrefEquipment::test_oldPreferences()
TEST(equipment->default_cylinder(), QStringLiteral("cylinder_2"));
equipment->set_default_cylinder("cylinder_1");
TEST(equipment->default_cylinder(), QStringLiteral("cylinder_1"));
equipment->set_display_unused_tanks(true);
TEST(equipment->display_unused_tanks(), true);
equipment->set_display_unused_tanks(false);
TEST(equipment->display_unused_tanks(), false);
equipment->set_include_unused_tanks(true);
TEST(equipment->include_unused_tanks(), true);
equipment->set_include_unused_tanks(false);
TEST(equipment->include_unused_tanks(), false);
}
void TestQPrefEquipment::test_signals()
{
qPrefEquipment::set_default_cylinder("signal test");
QSignalSpy spy1(qPrefEquipment::instance(), &qPrefEquipment::default_cylinderChanged);
QSignalSpy spy2(qPrefEquipment::instance(), &qPrefEquipment::display_unused_tanksChanged);
QSignalSpy spy2(qPrefEquipment::instance(), &qPrefEquipment::include_unused_tanksChanged);
// set default cylinder to same value it already had
qPrefEquipment::set_default_cylinder("signal test");
@ -106,8 +106,8 @@ void TestQPrefEquipment::test_signals()
QCOMPARE(spy1.count(), 1);
QVERIFY(spy1.takeFirst().at(0).toBool() == true);
prefs.display_unused_tanks = true;
qPrefEquipment::set_display_unused_tanks(false);
prefs.include_unused_tanks = true;
qPrefEquipment::set_include_unused_tanks(false);
QCOMPARE(spy2.count(), 1);
QVERIFY(spy2.takeFirst().at(0).toBool() == false);
}