Skip to content

Commit

Permalink
refactor: replace non-empty QString constructors with QStringLiteral() (
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech authored Nov 6, 2024
1 parent 5a0f364 commit 09eb335
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion layout/keyboardlayoutwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static QString FcitxXkbFindXkbRulesFile() {
QString rulesName = FcitxXkbGetRulesName();

if (!rulesName.isEmpty()) {
rulesFile = QString("%1/rules/%2.xml")
rulesFile = QStringLiteral("%1/rules/%2.xml")
.arg(XKEYBOARDCONFIG_XKBBASE)
.arg(rulesName);
}
Expand Down
6 changes: 3 additions & 3 deletions src/kcm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void configOptionToVariant(QVariantList &options,
for (const auto &subOption : subOptions) {
auto map = subOption.value<QVariantMap>();
if (map["isSection"].toBool()) {
map["description"] = QString("%1 > %2").arg(
map["description"] = QStringLiteral("%1 > %2").arg(
option.description(), map["description"].toString());
options.append(map);
} else {
Expand Down Expand Up @@ -418,15 +418,15 @@ void FcitxModule::fixLayout() {
const auto &imEntries = imConfig_->imEntries();
if (imEntries.size() > 0 &&
imEntries[0].key() !=
QString("keyboard-%0").arg(imConfig_->defaultLayout()) &&
QStringLiteral("keyboard-%0").arg(imConfig_->defaultLayout()) &&
imEntries[0].key().startsWith("keyboard-")) {
auto layoutString = imEntries[0].key().mid(9);
imConfig_->setDefaultLayout(layoutString);
}
}

void FcitxModule::fixInputMethod() {
auto imname = QString("keyboard-%0").arg(imConfig_->defaultLayout());
auto imname = QStringLiteral("keyboard-%0").arg(imConfig_->defaultLayout());
FcitxQtStringKeyValue imEntry;
int i = 0;
auto imEntries = imConfig_->imEntries();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/configlib/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ QString fcitx::kcm::fontToString(const QFont &font) {
break;
}
style = styles.join(" ");
return QString("%1%2%3 %4")
return QStringLiteral("%1%2%3 %4")
.arg(font.family(), (!style.isEmpty() ? " " : ""), style,
QString::number(font.pointSize()));
}
2 changes: 1 addition & 1 deletion src/lib/configlib/layoutprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LayoutProvider : public QObject {
if (variant.isEmpty()) {
return layout;
}
return QString("%1-%2").arg(layout, variant);
return QStringLiteral("%1-%2").arg(layout, variant);
}
return QString();
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/configlib/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ QVariant FilteredIMModel::data(const QModelIndex &index, int role) const {
return QString();
}
case FcitxIMActiveRole:
return index.row() > 0 ? QString("active") : QString("inactive");
return index.row() > 0 ? QStringLiteral("active")
: QStringLiteral("inactive");

default:
return QVariant();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/configwidgetslib/addonselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ void AddonDelegate::configureClicked() {
}
auto addonName = index.data(Qt::DisplayRole).toString();
QPointer<QDialog> dialog = ConfigWidget::configDialog(
parent_, parent_->dbus(), QString("fcitx://config/addon/%1").arg(name),
addonName);
parent_, parent_->dbus(),
QStringLiteral("fcitx://config/addon/%1").arg(name), addonName);
if (dialog) {
dialog->exec();
delete dialog;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/configwidgetslib/configwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ QString joinPath(const QString &path, const QString &option) {
if (path.isEmpty()) {
return option;
}
return QString("%1/%2").arg(path, option);
return QStringLiteral("%1/%2").arg(path, option);
}
} // namespace

Expand Down
13 changes: 7 additions & 6 deletions src/lib/configwidgetslib/impage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ void IMPage::selectDefaultLayout() {
config_->setDefaultLayout(result.first);
} else {
config_->setDefaultLayout(
QString("%0-%1").arg(result.first, result.second));
QStringLiteral("%0-%1").arg(result.first, result.second));
}

auto imname = QString("keyboard-%0").arg(config_->defaultLayout());
auto imname = QStringLiteral("keyboard-%0").arg(config_->defaultLayout());
if (config_->imEntries().empty() ||
config_->imEntries().front().key() != imname) {
auto result = QMessageBox::question(
Expand Down Expand Up @@ -344,8 +344,8 @@ void IMPage::selectLayout() {
if (result.second.isEmpty()) {
config_->setLayout(imName, result.first);
} else {
config_->setLayout(imName,
QString("%0-%1").arg(result.first, result.second));
config_->setLayout(
imName, QStringLiteral("%0-%1").arg(result.first, result.second));
}
}

Expand All @@ -363,7 +363,7 @@ void IMPage::checkDefaultLayout() {
const auto &imEntries = config_->imEntries();
if (imEntries.size() > 0 &&
imEntries[0].key() !=
QString("keyboard-%0").arg(config_->defaultLayout()) &&
QStringLiteral("keyboard-%0").arg(config_->defaultLayout()) &&
imEntries[0].key().startsWith("keyboard-")) {
// Remove "keyboard-".
auto layoutString = imEntries[0].key().mid(9);
Expand All @@ -390,7 +390,8 @@ void IMPage::configureIM() {
}
const QString uniqueName = curIndex.data(FcitxIMUniqueNameRole).toString();
QPointer<QDialog> dialog = ConfigWidget::configDialog(
this, dbus_, QString("fcitx://config/inputmethod/%1").arg(uniqueName),
this, dbus_,
QStringLiteral("fcitx://config/inputmethod/%1").arg(uniqueName),
curIndex.data(Qt::DisplayRole).toString());
if (dialog) {
dialog->exec();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/configwidgetslib/listoptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ListOptionWidgetModel : public QAbstractListModel {
int i = 0;
values_.clear();
while (true) {
auto value = readVariant(map, QString("%1%2%3")
auto value = readVariant(map, QStringLiteral("%1%2%3")
.arg(path)
.arg(path.isEmpty() ? "" : "/")
.arg(i));
Expand All @@ -62,7 +62,7 @@ class ListOptionWidgetModel : public QAbstractListModel {
void writeValueTo(QVariantMap &map, const QString &path) {
int i = 0;
for (auto &value : values_) {
writeVariant(map, QString("%1/%2").arg(path).arg(i), value);
writeVariant(map, QStringLiteral("%1/%2").arg(path).arg(i), value);
i++;
}
if (!i) {
Expand Down
29 changes: 15 additions & 14 deletions src/lib/configwidgetslib/optionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ class KeyListOptionWidget : public OptionWidget {
int i = 0;
for (auto &key : keys) {
auto value = QString::fromUtf8(key.toString().data());
writeVariant(map, QString("%1/%2").arg(path()).arg(i), value);
writeVariant(map, QStringLiteral("%1/%2").arg(path()).arg(i),
value);
i++;
}
if (keys.empty()) {
Expand All @@ -241,7 +242,7 @@ class KeyListOptionWidget : public OptionWidget {
int i = 0;
QList<Key> keys;
while (true) {
auto value = readString(map, QString("%1%2%3")
auto value = readString(map, QStringLiteral("%1%2%3")
.arg(path)
.arg(path.isEmpty() ? "" : "/")
.arg(i));
Expand Down Expand Up @@ -320,18 +321,18 @@ class EnumOptionWidget : public OptionWidget {

int i = 0;
while (true) {
auto value =
readString(option.properties(), QString("Enum/%1").arg(i));
auto value = readString(option.properties(),
QStringLiteral("Enum/%1").arg(i));
if (value.isNull()) {
break;
}
auto text =
readString(option.properties(), QString("EnumI18n/%1").arg(i));
auto text = readString(option.properties(),
QStringLiteral("EnumI18n/%1").arg(i));
if (text.isEmpty()) {
text = value;
}
auto subConfigPath = readString(option.properties(),
QString("SubConfigPath/%1").arg(i));
auto subConfigPath = readString(
option.properties(), QStringLiteral("SubConfigPath/%1").arg(i));
comboBox_->addItem(text, value);
comboBox_->setItemData(i, subConfigPath, subConfigPathRole);
i++;
Expand Down Expand Up @@ -578,8 +579,8 @@ bool OptionWidget::execOptionDialog(QWidget *parent,
} else {
QFormLayout *subLayout = new QFormLayout;
dialogLayout->addLayout(subLayout);
optionWidget =
addWidget(subLayout, option, QString("Value"), dialog.data());
optionWidget = addWidget(subLayout, option, QStringLiteral("Value"),
dialog.data());
if (!optionWidget) {
return false;
}
Expand Down Expand Up @@ -630,13 +631,13 @@ QString OptionWidget::prettify(const fcitx::FcitxQtConfigOption &option,
QMap<QString, QString> enumMap;
int i = 0;
while (true) {
auto value =
readString(option.properties(), QString("Enum/%1").arg(i));
auto value = readString(option.properties(),
QStringLiteral("Enum/%1").arg(i));
if (value.isNull()) {
break;
}
auto text =
readString(option.properties(), QString("EnumI18n/%1").arg(i));
auto text = readString(option.properties(),
QStringLiteral("EnumI18n/%1").arg(i));
if (text.isEmpty()) {
text = value;
}
Expand Down

0 comments on commit 09eb335

Please sign in to comment.