Skip to content

Commit fa94955

Browse files
authored
Fix legacy position population (#1069)
* Reworked legacy position population - Changed data structure to a static list of pairs to avoid unnecessary deep copies - Fixed oversight which caused iteration over the value and not the key of the previous QMap * clang-format pass :rolling_eyes: * disambiguate pair order further
1 parent 764b2f8 commit fa94955

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

src/courtroom.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,26 +1394,18 @@ void Courtroom::set_background(QString p_background, bool display)
13941394
ui_vp_testimony->stopPlayback();
13951395
current_background = p_background;
13961396

1397-
// welcome to hardcode central may I take your order of regularly scheduled
1398-
// CBT
1399-
QMap<QString, QString> default_pos;
1400-
default_pos["defenseempty"] = "def";
1401-
default_pos["helperstand"] = "hld";
1402-
default_pos["prosecutorempty"] = "pro";
1403-
default_pos["prohelperstand"] = "hlp";
1404-
default_pos["witnessempty"] = "wit";
1405-
default_pos["judgestand"] = "jud";
1406-
default_pos["jurystand"] = "jur";
1407-
default_pos["seancestand"] = "sea";
1397+
// Modern positions paired to their legacy counterparts for use in dropdown population
1398+
// {"new", "old"}
1399+
static QList<QPair<QString, QString>> legacy_positions = {{"def", "defenseempty"}, {"hld", "helperstand"}, {"pro", "prosecutorempty"}, {"hlp", "prohelperstand"}, {"wit", "witnessempty"}, {"jud", "judgestand"}, {"jur", "jurystand"}, {"sea", "seancestand"}};
14081400

14091401
// Populate the dropdown list with all pos that exist on this bg
14101402
QStringList pos_list = {};
1411-
for (const QString &key : std::as_const(default_pos))
1403+
for (const QPair<QString, QString> &pos_pair : std::as_const(legacy_positions))
14121404
{
1413-
if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path(default_pos[key]))) || // if we have 2.8-style positions, e.g. def.png, wit.webp, hld.apng
1414-
file_exists(ao_app->get_image_suffix(ao_app->get_background_path(key))))
1415-
{ // if we have pre-2.8-style positions, e.g. defenseempty.png
1416-
pos_list.append(default_pos[key]);
1405+
if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path(pos_pair.first))) || // if we have 2.8-style positions, e.g. def.png, wit.webp, hld.apng
1406+
file_exists(ao_app->get_image_suffix(ao_app->get_background_path(pos_pair.second)))) // if we have pre-2.8-style positions, e.g. defenseempty.png
1407+
{
1408+
pos_list.append(pos_pair.first); // the dropdown always uses the new style
14171409
}
14181410
}
14191411
if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path("court"))))

0 commit comments

Comments
 (0)