Skip to content

Commit

Permalink
refactor: use range-based for loop to enhance readability (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech authored Nov 6, 2024
1 parent cdd0efe commit 8dffee6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions qt5/platforminputcontext/fcitxcandidatewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ void FcitxCandidateWindow::updateClientSideUI(
doLayout(lowerLayout_);
labelLayouts_.clear();
candidateLayouts_.clear();
for (int i = 0; i < candidates.size(); i++) {
labelLayouts_.emplace_back(std::make_unique<MultilineText>(
theme_->font(), candidates[i].key()));
candidateLayouts_.emplace_back(std::make_unique<MultilineText>(
theme_->font(), candidates[i].value()));
for (const auto &candidate : candidates) {
labelLayouts_.emplace_back(
std::make_unique<MultilineText>(theme_->font(), candidate.key()));
candidateLayouts_.emplace_back(
std::make_unique<MultilineText>(theme_->font(), candidate.value()));
}
highlight_ = candidateIndex;
hasPrev_ = hasPrev;
Expand Down
10 changes: 5 additions & 5 deletions qt6/quickphrase-editor/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ QFutureWatcher<bool> *QuickPhraseModel::save(const QString &file) {
}

void QuickPhraseModel::saveDataToStream(QTextStream &dev) {
for (int i = 0; i < list_.size(); i++) {
dev << list_[i].first << "\t" << escapeValue(list_[i].second) << "\n";
for (const auto &item : list_) {
dev << item.first << "\t" << escapeValue(item.second) << "\n";
}
}

Expand Down Expand Up @@ -263,10 +263,10 @@ bool QuickPhraseModel::saveData(const QString &file,
if (!tempFile.open(fd, QIODevice::WriteOnly)) {
return false;
}
for (int i = 0; i < list.size(); i++) {
tempFile.write(list[i].first.toUtf8());
for (const auto &item : list) {
tempFile.write(item.first.toUtf8());
tempFile.write("\t");
tempFile.write(escapeValue(list[i].second).toUtf8());
tempFile.write(escapeValue(item.second).toUtf8());
tempFile.write("\n");
}
tempFile.close();
Expand Down

0 comments on commit 8dffee6

Please sign in to comment.