Skip to content

Commit 764b2f8

Browse files
authored
Merge pull request #1067 from AttorneyOnline/cleanup
Very cool and professional cleanup of clazy warnings
2 parents ed8bc45 + a9e2ea1 commit 764b2f8

19 files changed

Lines changed: 73 additions & 62 deletions

src/animationlayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void CharacterAnimationLayer::loadCharacterEmote(QString character, QString file
435435

436436
QVector<VPath> path_list;
437437
QVector<QString> prefixed_emote_list;
438-
for (const QString &prefix : qAsConst(prefixes))
438+
for (const QString &prefix : std::as_const(prefixes))
439439
{
440440
path_list << ao_app->get_character_path(character, prefix + m_emote);
441441
prefixed_emote_list << prefix + m_emote;
@@ -479,13 +479,13 @@ void CharacterAnimationLayer::setFrameEffects(QStringList data)
479479
const EffectType effect_type = EFFECT_TYPE_LIST.at(i);
480480

481481
QStringList emotes = data.at(i).split("^");
482-
for (const QString &emote : qAsConst(emotes))
482+
for (const QString &emote : std::as_const(emotes))
483483
{
484484
QStringList emote_effects = emote.split("|");
485485

486486
const QString emote_name = emote_effects.takeFirst();
487487

488-
for (const QString &raw_effect : qAsConst(emote_effects))
488+
for (const QString &raw_effect : std::as_const(emote_effects))
489489
{
490490
QStringList frame_data = raw_effect.split("=");
491491

@@ -553,7 +553,7 @@ void CharacterAnimationLayer::notifyFrameEffect(int frameNumber)
553553
auto it = m_effects.constFind(frameNumber);
554554
if (it != m_effects.constEnd())
555555
{
556-
for (const FrameEffect &effect : qAsConst(*it))
556+
for (const FrameEffect &effect : std::as_const(*it))
557557
{
558558
if (effect.emote_name == m_resolved_emote)
559559
{

src/animationloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ AnimationFrame AnimationLoader::frame(int frameNumber)
7272
m_task_signal.wait(&m_task_lock);
7373
}
7474

75-
AnimationFrame frame = qAsConst(m_frames)[frameNumber];
75+
AnimationFrame frame = std::as_const(m_frames)[frameNumber];
7676
m_task_lock.unlock();
7777

7878
return frame;

src/aoapplication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class VPath : QString
4343
inline VPath operator+(const VPath &str) const { return VPath(this->toQString() + str.toQString()); }
4444
};
4545

46-
inline size_t qHash(const VPath &key, uint seed = qGlobalQHashSeed())
46+
inline size_t qHash(const VPath &key, uint seed = QHashSeed::globalSeed())
4747
{
4848
return qHash(key.toQString(), seed);
4949
}

src/aopacket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QString AOPacket::toString(bool ensureEncoded)
3737
QString message = m_header;
3838
if (!m_content.isEmpty())
3939
{
40-
for (QString item : qAsConst(m_content))
40+
for (QString item : std::as_const(m_content))
4141
{
4242
if (ensureEncoded)
4343
{

src/aotextboxwidgets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void AOChatboxLabel::paintEvent(QPaintEvent *event)
9090

9191
if (alignment() & Qt::AlignLeft)
9292
{
93-
x = rect.left() + l_indent - std::min(metrics.leftBearing(text()[0]), 0);
93+
x = rect.left() + l_indent - std::min(metrics.leftBearing(text().at(0)), 0);
9494
}
9595
else if (alignment() & Qt::AlignRight)
9696
{

src/aoutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void AOUtils::migrateEffects(QSettings &p_effects_ini)
4646
// realization_scaling - This would not be appended to the key_list as it matches scaling property.
4747
// realization_alt - This would be appened as it contains an underscore, but not a property.
4848
// hearts - This would be appended as it does not contain a property
49-
const QRegularExpression l_regex(QStringLiteral("(\\w+)_(%1)$").arg(l_property_list.join("|")));
49+
static QRegularExpression l_regex(QStringLiteral("(\\w+)_(%1)$").arg(l_property_list.join("|")));
5050
for (auto i = l_effect_map.begin(); i != l_effect_map.end(); i++)
5151
{
5252
if (l_regex.match(i.key()).hasMatch())
@@ -57,7 +57,7 @@ void AOUtils::migrateEffects(QSettings &p_effects_ini)
5757
}
5858

5959
int i = 0;
60-
for (const QString &i_effect_key : qAsConst(l_key_list))
60+
for (const QString &i_effect_key : std::as_const(l_key_list))
6161
{
6262
p_effects_ini.beginGroup(QString::number(i++));
6363
p_effects_ini.setValue("name", i_effect_key);

src/charselect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void Courtroom::set_char_select_page()
116116
ui_char_select_left->hide();
117117
ui_char_select_right->hide();
118118

119-
for (AOCharButton *i_button : qAsConst(ui_char_button_list))
119+
for (AOCharButton *i_button : std::as_const(ui_char_button_list))
120120
{
121121
i_button->hide();
122122
i_button->move(0, 0);
@@ -352,7 +352,7 @@ void Courtroom::filter_character_list()
352352
for (int i = 0; i < char_list.size(); i++)
353353
{
354354
AOCharButton *current_char = ui_char_button_list.at(i);
355-
QTreeWidgetItem *current_char_list_item = ui_char_list->findItems(QString::number(i), Qt::MatchExactly | Qt::MatchRecursive, 1)[0];
355+
QTreeWidgetItem *current_char_list_item = ui_char_list->findItems(QString::number(i), Qt::MatchExactly | Qt::MatchRecursive, 1).at(0);
356356

357357
// It seems passwording characters is unimplemented yet?
358358
// Until then, this will stay here, I suppose.

src/courtroom.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void Courtroom::set_mute_list()
705705

706706
QStringList sorted_mute_list;
707707

708-
for (const CharacterSlot &i_char : qAsConst(char_list))
708+
for (const CharacterSlot &i_char : std::as_const(char_list))
709709
{
710710
sorted_mute_list.append(i_char.name);
711711
}
@@ -723,7 +723,7 @@ void Courtroom::set_pair_list()
723723
{
724724
QStringList sorted_pair_list;
725725

726-
for (const CharacterSlot &i_char : qAsConst(char_list))
726+
for (const CharacterSlot &i_char : std::as_const(char_list))
727727
{
728728
sorted_pair_list.append(i_char.name);
729729
}
@@ -1408,7 +1408,7 @@ void Courtroom::set_background(QString p_background, bool display)
14081408

14091409
// Populate the dropdown list with all pos that exist on this bg
14101410
QStringList pos_list = {};
1411-
for (const QString &key : default_pos.keys())
1411+
for (const QString &key : std::as_const(default_pos))
14121412
{
14131413
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
14141414
file_exists(ao_app->get_image_suffix(ao_app->get_background_path(key))))
@@ -3120,7 +3120,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP
31203120

31213121
void Courtroom::post_transition_cleanup()
31223122
{
3123-
for (kal::CharacterAnimationLayer *layer : qAsConst(ui_vp_char_list))
3123+
for (kal::CharacterAnimationLayer *layer : std::as_const(ui_vp_char_list))
31243124
{
31253125
bool is_visible = layer->isVisible();
31263126
layer->stopPlayback();
@@ -3404,7 +3404,7 @@ void Courtroom::handle_callwords()
34043404
// No more file IO on every message.
34053405
QStringList call_words = Options::getInstance().callwords();
34063406
// Loop through each word in the call words list
3407-
for (const QString &word : qAsConst(call_words))
3407+
for (const QString &word : std::as_const(call_words))
34083408
{
34093409
// If our message contains that specific call word
34103410
if (f_message.contains(word, Qt::CaseInsensitive))
@@ -3765,7 +3765,8 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int
37653765
// white-space: pre; stylesheet tag, but for whataver reason it doesn't work
37663766
// no matter where I try it. If somoene else can get that piece of HTML
37673767
// memery to work, please do.
3768-
p_text_escaped.replace(QRegularExpression("^\\s|(?<=\\s)\\s"), "&nbsp;");
3768+
static QRegularExpression whitespace("^\\s|(?<=\\s)\\s");
3769+
p_text_escaped.replace(whitespace, "&nbsp;");
37693770
if (!align.isEmpty())
37703771
{
37713772
p_text_escaped.append("</div>");
@@ -5115,9 +5116,10 @@ void Courtroom::on_ooc_return_pressed()
51155116
casefile.setValue("doc", "");
51165117
casefile.setValue("status", command[2]);
51175118
casefile.sync();
5119+
static QRegularExpression owner_regexp("<owner = ...>...");
51185120
for (int i = 0; i < local_evidence_list.size(); i++)
51195121
{
5120-
QString clean_evidence_dsc = local_evidence_list[i].description.replace(QRegularExpression("<owner = ...>..."), "");
5122+
QString clean_evidence_dsc = local_evidence_list[i].description.replace(owner_regexp, "");
51215123
clean_evidence_dsc = clean_evidence_dsc.replace(clean_evidence_dsc.lastIndexOf(">"), 1, "");
51225124
casefile.beginGroup(QString::number(i));
51235125
casefile.sync();
@@ -5428,7 +5430,7 @@ void Courtroom::set_sfx_dropdown()
54285430
sound_list += ao_app->get_list_file(VPath("soundlist.ini"));
54295431

54305432
QStringList display_sounds;
5431-
for (const QString &sound : qAsConst(sound_list))
5433+
for (const QString &sound : std::as_const(sound_list))
54325434
{
54335435
QStringList unpacked = sound.split("=");
54345436
QString display = unpacked[0].trimmed();
@@ -5730,7 +5732,7 @@ void Courtroom::on_pair_list_clicked(QModelIndex p_index)
57305732
// Redo the character list.
57315733
QStringList sorted_pair_list;
57325734

5733-
for (const CharacterSlot &i_char : qAsConst(char_list))
5735+
for (const CharacterSlot &i_char : std::as_const(char_list))
57345736
{
57355737
sorted_pair_list.append(i_char.name);
57365738
}
@@ -5798,19 +5800,19 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
57985800
}
57995801

58005802
menu->addAction(new QAction(tr("Fade Out Previous"), this));
5801-
menu->actions().back()->setCheckable(true);
5802-
menu->actions().back()->setChecked(music_flags & FADE_OUT);
5803-
connect(menu->actions().back(), &QAction::toggled, this, &Courtroom::music_fade_out);
5803+
menu->actions().constLast()->setCheckable(true);
5804+
menu->actions().constLast()->setChecked(music_flags & FADE_OUT);
5805+
connect(menu->actions().constLast(), &QAction::toggled, this, &Courtroom::music_fade_out);
58045806

58055807
menu->addAction(new QAction(tr("Fade In"), this));
5806-
menu->actions().back()->setCheckable(true);
5807-
menu->actions().back()->setChecked(music_flags & FADE_IN);
5808-
connect(menu->actions().back(), &QAction::toggled, this, &Courtroom::music_fade_in);
5808+
menu->actions().constLast()->setCheckable(true);
5809+
menu->actions().constLast()->setChecked(music_flags & FADE_IN);
5810+
connect(menu->actions().constLast(), &QAction::toggled, this, &Courtroom::music_fade_in);
58095811

58105812
menu->addAction(new QAction(tr("Synchronize"), this));
5811-
menu->actions().back()->setCheckable(true);
5812-
menu->actions().back()->setChecked(music_flags & SYNC_POS);
5813-
connect(menu->actions().back(), &QAction::toggled, this, &Courtroom::music_synchronize);
5813+
menu->actions().constLast()->setCheckable(true);
5814+
menu->actions().constLast()->setChecked(music_flags & SYNC_POS);
5815+
connect(menu->actions().constLast(), &QAction::toggled, this, &Courtroom::music_synchronize);
58145816

58155817
menu->addSeparator();
58165818
menu->addAction(QString("Open base music folder"), this, [=] {
@@ -5930,7 +5932,7 @@ void Courtroom::music_stop(bool no_effects)
59305932
if (!music_list.contains(fake_song))
59315933
{
59325934
// Loop through our music list
5933-
for (const QString &song : qAsConst(music_list))
5935+
for (const QString &song : std::as_const(music_list))
59345936
{
59355937
// Pick first song that does not contain a file extension
59365938
if (!song.contains('.'))

src/demoserver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void DemoServer::load_demo(QString filename)
361361
out.setCodec("UTF-8");
362362
#endif
363363
out << p_demo_data.dequeue();
364-
for (const QString &line : qAsConst(p_demo_data))
364+
for (const QString &line : std::as_const(p_demo_data))
365365
{
366366
out << "\n" << line;
367367
}
@@ -442,6 +442,7 @@ void DemoServer::playback()
442442
}
443443
// Take the first arg as the command
444444
QString command = f_contents.takeFirst();
445+
Q_UNUSED(command); // this seems load-bearing. TODO: this should not be load-bearing
445446
int duration = 0;
446447
if (!f_contents.isEmpty())
447448
{

src/emotes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void Courtroom::set_emote_page()
110110
ui_emote_left->hide();
111111
ui_emote_right->hide();
112112

113-
for (AOEmoteButton *i_button : qAsConst(ui_emote_list))
113+
for (AOEmoteButton *i_button : std::as_const(ui_emote_list))
114114
{
115115
i_button->hide();
116116
}
@@ -265,7 +265,6 @@ void Courtroom::show_emote_menu(const QPoint &pos)
265265
emote_preview->updateViewportGeometry();
266266
update_emote_preview();
267267
}));
268-
QString prefix;
269268
QString f_pre = ao_app->get_pre_emote(current_char, emote_num);
270269
if (!f_pre.isEmpty() && f_pre != "-")
271270
{

0 commit comments

Comments
 (0)