Skip to content

Commit

Permalink
UI: replace QString() with QStringLiteral() for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Nov 2, 2024
1 parent 52a0486 commit fc46b2a
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 76 deletions.
4 changes: 2 additions & 2 deletions UI/auth-youtube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner, const std::string &serv
}
const auto auth = std::make_shared<YoutubeApiWrappers>(*it);

QString redirect_uri = QString("http://127.0.0.1:%1").arg(server.GetPort());
QString redirect_uri = QStringLiteral("http://127.0.0.1:%1").arg(server.GetPort());

QMessageBox dlg(owner);
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowCloseButtonHint);
Expand All @@ -254,7 +254,7 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner, const std::string &serv
QString url = url_template.arg(YOUTUBE_AUTH_URL, clientid.c_str(), redirect_uri, state);

QString text = QTStr("YouTube.Auth.WaitingAuth.Text");
text = text.arg(QString("<a href='%1'>Google OAuth Service</a>").arg(url));
text = text.arg(QStringLiteral("<a href='%1'>Google OAuth Service</a>").arg(url));

dlg.setText(text);
dlg.setTextFormat(Qt::RichText);
Expand Down
2 changes: 1 addition & 1 deletion UI/context-bar-controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void ColorSourceToolbar::UpdateColor()
ui->color->setFrameStyle(QFrame::Sunken | QFrame::Panel);
ui->color->setText(color.name(QColor::HexRgb));
ui->color->setPalette(palette);
ui->color->setStyleSheet(QString("background-color :%1; color: %2;")
ui->color->setStyleSheet(QStringLiteral("background-color :%1; color: %2;")
.arg(palette.color(QPalette::Window).name(QColor::HexRgb))
.arg(palette.color(QPalette::WindowText).name(QColor::HexRgb)));
ui->color->setAutoFillBackground(true);
Expand Down
6 changes: 3 additions & 3 deletions UI/log-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ void OBSLogViewer::AddLine(int type, const QString &str)

switch (type) {
case LOG_WARNING:
msg = QString("<font color=\"#c08000\">%1</font>").arg(msg);
msg = QStringLiteral("<font color=\"#c08000\">%1</font>").arg(msg);
break;
case LOG_ERROR:
msg = QString("<font color=\"#c00000\">%1</font>").arg(msg);
msg = QStringLiteral("<font color=\"#c00000\">%1</font>").arg(msg);
break;
default:
msg = QString("<font>%1</font>").arg(msg);
msg = QStringLiteral("<font>%1</font>").arg(msg);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion UI/media-controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,5 @@ void MediaControls::UpdateLabels(int val)
if (!countDownTimer)
ui->durationLabel->setText(FormatSeconds((int)(duration / 1000.0f)));
else
ui->durationLabel->setText(QString("-") + FormatSeconds((int)((duration - time) / 1000.0f)));
ui->durationLabel->setText(QStringLiteral("-") + FormatSeconds((int)((duration - time) / 1000.0f)));
}
6 changes: 3 additions & 3 deletions UI/multitrack-video-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,15 @@ bool MultitrackVideoOutput::HandleIncompatibleSettings(QWidget *parent, config_t
if (!setting)
return;

incompatible_settings += QString(" %1. %2\n").arg(num).arg(QTStr(name));
incompatible_settings += QStringLiteral(" %1. %2\n").arg(num).arg(QTStr(name));

where_to_disable += QString(" %1. [%2 → %3 → %4]\n")
where_to_disable += QStringLiteral(" %1. [%2 → %3 → %4]\n")
.arg(num)
.arg(QTStr("Settings"))
.arg(QTStr("Basic.Settings.Advanced"))
.arg(QTStr(section));

incompatible_settings_list += QString("%1, ").arg(name);
incompatible_settings_list += QStringLiteral("%1, ").arg(name);

num += 1;
};
Expand Down
2 changes: 1 addition & 1 deletion UI/obs-app-theming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static bool ParseCalc(CFParser &cfp, QStringList &calc, vector<OBSThemeVariable>
OBSThemeVariable var;
QStringList subcalc;

var.name = QString("__unnamed_%1").arg(QRandomGenerator::global()->generate64());
var.name = QStringLiteral("__unnamed_%1").arg(QRandomGenerator::global()->generate64());

if (!ParseCalc(cfp, subcalc, vars))
return false;
Expand Down
16 changes: 8 additions & 8 deletions UI/source-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,14 @@ SourceTree::SourceTree(QWidget *parent_) : QListView(parent_)
{
SourceTreeModel *stm_ = new SourceTreeModel(this);
setModel(stm_);
setStyleSheet(QString("*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}"
"*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}"
"*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}"
"*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}"
"*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}"
"*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}"
"*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}"
"*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));
setStyleSheet(QStringLiteral("*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}"
"*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}"
"*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}"
"*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}"
"*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}"
"*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}"
"*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}"
"*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));

UpdateNoSourcesMessage();
connect(App(), &OBSApp::StyleChanged, this, &SourceTree::UpdateNoSourcesMessage);
Expand Down
2 changes: 1 addition & 1 deletion UI/visibility-item-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void VisibilityItemWidget::SetColor(const QColor &color, bool active_, bool sele
pal.setColor(QPalette::WindowText, color);
vis->setPalette(pal);

label->setStyleSheet(QString("color: %1;").arg(color.name()));
label->setStyleSheet(QStringLiteral("color: %1;").arg(color.name()));

active = active_;
selected = selected_;
Expand Down
8 changes: 4 additions & 4 deletions UI/window-basic-auto-config-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,10 @@ void AutoConfigTestPage::FinalizeResults()
}
}

QString baseRes =
QString("%1x%2").arg(QString::number(wiz->baseResolutionCX), QString::number(wiz->baseResolutionCY));
QString scaleRes =
QString("%1x%2").arg(QString::number(wiz->idealResolutionCX), QString::number(wiz->idealResolutionCY));
QString baseRes = QStringLiteral("%1x%2").arg(QString::number(wiz->baseResolutionCX),
QString::number(wiz->baseResolutionCY));
QString scaleRes = QStringLiteral("%1x%2").arg(QString::number(wiz->idealResolutionCX),
QString::number(wiz->idealResolutionCY));

if (wiz->recordingEncoder != AutoConfig::Encoder::Stream ||
wiz->recordingQuality != AutoConfig::Quality::Stream)
Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-auto-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ AutoConfigVideoPage::AutoConfigVideoPage(QWidget *parent) : QWizardPage(parent),

auto addRes = [&](int cx, int cy) {
encRes = (cx << 16) | cy;
QString str = QString("%1x%2").arg(QString::number(cx), QString::number(cy));
QString str = QStringLiteral("%1x%2").arg(QString::number(cx), QString::number(cy));
ui->canvasRes->addItem(str, encRes);
};

Expand Down
4 changes: 2 additions & 2 deletions UI/window-basic-filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void OBSBasicFilters::AddNewFilter(const char *id)
QString text{placeholder};
int i = 2;
while ((existing_filter = obs_source_get_filter_by_name(source, QT_TO_UTF8(text)))) {
text = QString("%1 %2").arg(placeholder).arg(i++);
text = QStringLiteral("%1 %2").arg(placeholder).arg(i++);
}

bool success = NameDialog::AskForName(this, QTStr("Basic.Filters.AddFilter.Title"),
Expand Down Expand Up @@ -894,7 +894,7 @@ void OBSBasicFilters::DuplicateItem(QListWidgetItem *item)
QString text{placeholder};
int i = 2;
while ((existing_filter = obs_source_get_filter_by_name(source, QT_TO_UTF8(text)))) {
text = QString("%1 %2").arg(placeholder).arg(i++);
text = QStringLiteral("%1 %2").arg(placeholder).arg(i++);
}

bool success = NameDialog::AskForName(this, QTStr("Basic.Filters.AddFilter.Title"),
Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-main-transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static inline QString MakeQuickTransitionText(QuickTransition *qt)
name = QTStr("FadeToBlack");

if (!obs_transition_fixed(qt->source))
name += QString(" (%1ms)").arg(QString::number(qt->duration));
name += QStringLiteral(" (%1ms)").arg(QString::number(qt->duration));
return name;
}

Expand Down
22 changes: 11 additions & 11 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5128,9 +5128,9 @@ QList<QString> OBSBasic::GetProjectorMenuMonitorsFormatted()
name = name.simplified();

if (name.length() == 0) {
name = QString("%1 %2").arg(QTStr("Display")).arg(QString::number(i + 1));
name = QStringLiteral("%1 %2").arg(QTStr("Display")).arg(QString::number(i + 1));
}
QString str = QString("%1: %2x%3 @ %4,%5")
QString str = QStringLiteral("%1: %2x%3 @ %4,%5")
.arg(name, QString::number(screenGeometry.width() * ratio),
QString::number(screenGeometry.height() * ratio),
QString::number(screenGeometry.x()), QString::number(screenGeometry.y()));
Expand Down Expand Up @@ -5509,14 +5509,14 @@ QMenu *OBSBasic::AddBackgroundColorMenu(QMenu *menu, QWidgetAction *widgetAction
{
QAction *action;

menu->setStyleSheet(QString("*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}"
"*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}"
"*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}"
"*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}"
"*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}"
"*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}"
"*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}"
"*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));
menu->setStyleSheet(QStringLiteral("*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}"
"*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}"
"*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}"
"*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}"
"*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}"
"*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}"
"*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}"
"*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));

obs_data_t *privData = obs_sceneitem_get_private_settings(item);
obs_data_release(privData);
Expand Down Expand Up @@ -7604,7 +7604,7 @@ void OBSBasic::on_actionShowWhatsNew_triggered()
void OBSBasic::on_actionReleaseNotes_triggered()
{
QString addr("https://github.com/obsproject/obs-studio/releases");
QUrl url(QString("%1/%2").arg(addr, obs_get_version_string()), QUrl::TolerantMode);
QUrl url(QStringLiteral("%1/%2").arg(addr, obs_get_version_string()), QUrl::TolerantMode);
QDesktopServices::openUrl(url);
}

Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-settings-a11y.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void SetStyle(QLabel *label, uint32_t colorVal)
label->setFrameStyle(QFrame::Sunken | QFrame::Panel);
label->setText(color.name(QColor::HexRgb));
label->setPalette(palette);
label->setStyleSheet(QString("background-color: %1; color: %2;")
label->setStyleSheet(QStringLiteral("background-color: %1; color: %2;")
.arg(palette.color(QPalette::Window).name(QColor::HexRgb))
.arg(palette.color(QPalette::WindowText).name(QColor::HexRgb)));
label->setAutoFillBackground(true);
Expand Down
17 changes: 9 additions & 8 deletions UI/window-basic-settings-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,18 +650,18 @@ QString OBSBasicSettings::FindProtocol()
{
if (IsCustomService()) {
if (ui->customServer->text().isEmpty())
return QString("RTMP");
return QStringLiteral("RTMP");

QString server = ui->customServer->text();

if (obs_is_output_protocol_registered("RTMPS") && server.startsWith("rtmps://"))
return QString("RTMPS");
return QStringLiteral("RTMPS");

if (server.startsWith("srt://"))
return QString("SRT");
return QStringLiteral("SRT");

if (server.startsWith("rist://"))
return QString("RIST");
return QStringLiteral("RIST");

} else {
obs_properties_t *props = obs_get_service_properties("rtmp_common");
Expand All @@ -679,7 +679,7 @@ QString OBSBasicSettings::FindProtocol()
return QT_UTF8(protocol);
}

return QString("RTMP");
return QStringLiteral("RTMP");
}

void OBSBasicSettings::UpdateServerList()
Expand Down Expand Up @@ -1045,7 +1045,8 @@ void OBSBasicSettings::UpdateServiceRecommendations()
}
}

QString res_str = QString("%1x%2").arg(QString::number(best_res.cx), QString::number(best_res.cy));
QString res_str =
QStringLiteral("%1x%2").arg(QString::number(best_res.cx), QString::number(best_res.cy));
text += ENFORCE_TEXT("MaxResolution").arg(res_str);
}
if (fps) {
Expand Down Expand Up @@ -1221,7 +1222,7 @@ bool OBSBasicSettings::UpdateResFPSLimits()
}
}

QString res_str = QString("%1x%2").arg(QString::number(cx), QString::number(cy));
QString res_str = QStringLiteral("%1x%2").arg(QString::number(cx), QString::number(cy));

/* ------------------------------------ */
/* Display message box if res/FPS bad */
Expand Down Expand Up @@ -1281,7 +1282,7 @@ bool OBSBasicSettings::UpdateResFPSLimits()

for (size_t i = 0; i < res_count; i++) {
obs_service_resolution val = res_list[i];
QString str = QString("%1x%2").arg(QString::number(val.cx), QString::number(val.cy));
QString str = QStringLiteral("%1x%2").arg(QString::number(val.cx), QString::number(val.cy));
ui->outputResolution->addItem(str);

if (val.cx == cx && val.cy == cy)
Expand Down
14 changes: 7 additions & 7 deletions UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ void OBSBasicSettings::LoadFormats()
if (audio || video) {
QString itemText(format.name);
if (audio ^ video)
itemText += QString(" (%1)").arg(audio ? AUDIO_STR : VIDEO_STR);
itemText += QStringLiteral(" (%1)").arg(audio ? AUDIO_STR : VIDEO_STR);

ui->advOutFFFormat->addItem(itemText, QVariant::fromValue(format));
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ static void AddCodec(QComboBox *combo, const FFmpegCodec &codec)
{
QString itemText;
if (codec.long_name)
itemText = QString("%1 - %2").arg(codec.name, codec.long_name);
itemText = QStringLiteral("%1 - %2").arg(codec.name, codec.long_name);
else
itemText = codec.name;

Expand All @@ -1116,9 +1116,9 @@ static void AddDefaultCodec(QComboBox *combo, const FFmpegFormat &format, FFmpeg

QString itemText;
if (codec.long_name) {
itemText = QString("%1 - %2 (%3)").arg(codec.name, codec.long_name, AV_ENCODER_DEFAULT_STR);
itemText = QStringLiteral("%1 - %2 (%3)").arg(codec.name, codec.long_name, AV_ENCODER_DEFAULT_STR);
} else {
itemText = QString("%1 (%2)").arg(codec.name, AV_ENCODER_DEFAULT_STR);
itemText = QStringLiteral("%1 (%2)").arg(codec.name, AV_ENCODER_DEFAULT_STR);
}

combo->addItem(itemText, QVariant::fromValue(codec));
Expand Down Expand Up @@ -3323,7 +3323,7 @@ void OBSBasicSettings::SaveEncoder(QComboBox *combo, const char *section, const
if (!v.isNull())
cd = v.value<FFmpegCodec>();

config_set_int(main->Config(), section, QT_TO_UTF8(QString("%1Id").arg(value)), cd.id);
config_set_int(main->Config(), section, QT_TO_UTF8(QStringLiteral("%1Id").arg(value)), cd.id);
if (cd.id != 0)
config_set_string(main->Config(), section, value, cd.name);
else
Expand Down Expand Up @@ -5382,8 +5382,8 @@ void OBSBasicSettings::SimpleRecordingQualityLosslessWarning(int idx)
if (qual == "Lossless") {
QMessageBox::StandardButton button;

QString warningString =
SIMPLE_OUTPUT_WARNING("Lossless") + QString("\n\n") + SIMPLE_OUTPUT_WARNING("Lossless.Msg");
QString warningString = SIMPLE_OUTPUT_WARNING("Lossless") + QStringLiteral("\n\n") +
SIMPLE_OUTPUT_WARNING("Lossless.Msg");

button = OBSMessageBox::question(this, SIMPLE_OUTPUT_WARNING("Lossless.Title"), warningString);

Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-source-select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, const char *id_, un
int i = 2;
OBSSourceAutoRelease source = nullptr;
while ((source = obs_get_source_by_name(QT_TO_UTF8(text)))) {
text = QString("%1 %2").arg(placeHolderText).arg(i++);
text = QStringLiteral("%1 %2").arg(placeHolderText).arg(i++);
}

ui->sourceName->setText(text);
Expand Down
10 changes: 5 additions & 5 deletions UI/window-basic-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static QString MakeTimeLeftText(int hours, int minutes)

static QString MakeMissedFramesText(uint32_t total_lagged, uint32_t total_rendered, long double num)
{
return QString("%1 / %2 (%3%)")
return QStringLiteral("%1 / %2 (%3%)")
.arg(QString::number(total_lagged), QString::number(total_rendered), QString::number(num, 'f', 1));
}

Expand Down Expand Up @@ -372,7 +372,7 @@ void OBSBasicStats::Update()
num = total_encoded ? (long double)total_skipped / (long double)total_encoded : 0.0l;
num *= 100.0l;

str = QString("%1 / %2 (%3%)")
str = QStringLiteral("%1 / %2 (%3%)")
.arg(QString::number(total_skipped), QString::number(total_encoded),
QString::number(num, 'f', 1));
skippedFrames->setText(str);
Expand Down Expand Up @@ -526,15 +526,15 @@ void OBSBasicStats::OutputLabels::Update(obs_output_t *output, bool rec)
num /= 1024;
unit = "GiB";
}
megabytesSent->setText(QString("%1 %2").arg(num, 0, 'f', 1).arg(unit));
megabytesSent->setText(QStringLiteral("%1 %2").arg(num, 0, 'f', 1).arg(unit));

num = kbps;
unit = "kb/s";
if (num >= 10'000) {
num /= 1000;
unit = "Mb/s";
}
bitrate->setText(QString("%1 %2").arg(num, 0, 'f', 0).arg(unit));
bitrate->setText(QStringLiteral("%1 %2").arg(num, 0, 'f', 0).arg(unit));

if (!rec) {
int total = output ? obs_output_get_total_frames(output) : 0;
Expand All @@ -550,7 +550,7 @@ void OBSBasicStats::OutputLabels::Update(obs_output_t *output, bool rec)

num = total ? (long double)dropped / (long double)total * 100.0l : 0.0l;

str = QString("%1 / %2 (%3%)")
str = QStringLiteral("%1 / %2 (%3%)")
.arg(QString::number(dropped), QString::number(total), QString::number(num, 'f', 1));
droppedFrames->setText(str);

Expand Down
Loading

0 comments on commit fc46b2a

Please sign in to comment.