-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized tooltip generation in WBaseWidget #13952
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -139,63 +139,72 @@ void WBaseWidget::setControlParameterRightUp(double v) { | |||||||
} | ||||||||
|
||||||||
void WBaseWidget::updateTooltip() { | ||||||||
// If we are in developer mode, update the tooltip. | ||||||||
// Remove leading and trailing whitespace/line breaks from the tooltip. | ||||||||
QString base = baseTooltip().trimmed(); | ||||||||
|
||||||||
// If we are in developer mode, expand the tooltip. | ||||||||
if (CmdlineArgs::Instance().getDeveloper()) { | ||||||||
QStringList debug; | ||||||||
fillDebugTooltip(&debug); | ||||||||
|
||||||||
QString base = baseTooltip(); | ||||||||
if (!base.isEmpty()) { | ||||||||
debug.append(QString("Tooltip: \"%1\"").arg(base)); | ||||||||
debug.append(QStringLiteral("Tooltip: \"%1\"").arg(base)); | ||||||||
} | ||||||||
m_pWidget->setToolTip(debug.join("\n")); | ||||||||
m_pWidget->setToolTip(debug.join(QStringLiteral("\n"))); | ||||||||
} else { | ||||||||
m_pWidget->setToolTip(base); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
template <> | ||||||||
template<> | ||||||||
QString toDebugString(const QSizePolicy::Policy& policy) { | ||||||||
switch (policy) { | ||||||||
case QSizePolicy::Fixed: | ||||||||
return "Fixed"; | ||||||||
case QSizePolicy::Minimum: | ||||||||
return "Minimum"; | ||||||||
case QSizePolicy::Maximum: | ||||||||
return "Maximum"; | ||||||||
case QSizePolicy::Preferred: | ||||||||
return "Preferred"; | ||||||||
case QSizePolicy::Expanding: | ||||||||
return "Expanding"; | ||||||||
case QSizePolicy::MinimumExpanding: | ||||||||
return "MinimumExpanding"; | ||||||||
case QSizePolicy::Ignored: | ||||||||
return "Ignored"; | ||||||||
default: | ||||||||
break; | ||||||||
} | ||||||||
return QString::number(static_cast<int>(policy)); | ||||||||
case QSizePolicy::Fixed: | ||||||||
return QStringLiteral("Fixed"); | ||||||||
case QSizePolicy::Minimum: | ||||||||
return QStringLiteral("Minimum"); | ||||||||
case QSizePolicy::Maximum: | ||||||||
return QStringLiteral("Maximum"); | ||||||||
case QSizePolicy::Preferred: | ||||||||
return QStringLiteral("Preferred"); | ||||||||
case QSizePolicy::Expanding: | ||||||||
return QStringLiteral("Expanding"); | ||||||||
case QSizePolicy::MinimumExpanding: | ||||||||
return QStringLiteral("MinimumExpanding"); | ||||||||
case QSizePolicy::Ignored: | ||||||||
return QStringLiteral("Ignored"); | ||||||||
default: | ||||||||
return QString::number(static_cast<int>(policy)); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
void WBaseWidget::fillDebugTooltip(QStringList* debug) { | ||||||||
QSizePolicy policy = m_pWidget->sizePolicy(); | ||||||||
*debug << QString("ClassName: %1").arg(m_pWidget->metaObject()->className()) | ||||||||
<< QString("ObjectName: %1").arg(m_pWidget->objectName()) | ||||||||
<< QString("Position: %1").arg(toDebugString(m_pWidget->pos())) | ||||||||
<< QString("SizePolicy: %1,%2").arg(toDebugString(policy.horizontalPolicy()), | ||||||||
toDebugString(policy.verticalPolicy())) | ||||||||
<< QString("Size: %1").arg(toDebugString(m_pWidget->size())) | ||||||||
<< QString("SizeHint: %1").arg(toDebugString(m_pWidget->sizeHint())) | ||||||||
<< QString("MinimumSizeHint: %1").arg(toDebugString(m_pWidget->minimumSizeHint())); | ||||||||
|
||||||||
for (const auto& pControlConnection : std::as_const(m_leftConnections)) { | ||||||||
*debug << QString("LeftConnection: %1").arg(pControlConnection->toDebugString()); | ||||||||
} | ||||||||
for (const auto& pControlConnection : std::as_const(m_rightConnections)) { | ||||||||
*debug << QString("RightConnection: %1").arg(pControlConnection->toDebugString()); | ||||||||
} | ||||||||
for (const auto& pControlConnection : std::as_const(m_connections)) { | ||||||||
*debug << QString("Connection: %1").arg(pControlConnection->toDebugString()); | ||||||||
*debug << QStringLiteral("ClassName: %1") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is supposed to be an optimization, you may want to consider reserving space as appropriate. This adds quite a lot of elements, so it needs to reallocate at least once, avoiding the second allocation by reserving enough upfront may make sense.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The QStringBuilder does it implicit for us, if we replace the %1 placeholder by normal string concat using +. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that makes a meaningful difference for a single argument |
||||||||
.arg(m_pWidget->metaObject()->className()) | ||||||||
<< QStringLiteral("ObjectName: %1").arg(m_pWidget->objectName()) | ||||||||
<< QStringLiteral("Position: %1") | ||||||||
.arg(toDebugString(m_pWidget->pos())) | ||||||||
<< QStringLiteral("SizePolicy: %1,%2") | ||||||||
.arg(toDebugString(policy.horizontalPolicy()), | ||||||||
toDebugString(policy.verticalPolicy())) | ||||||||
<< QStringLiteral("Size: %1").arg(toDebugString(m_pWidget->size())) | ||||||||
<< QStringLiteral("SizeHint: %1") | ||||||||
.arg(toDebugString(m_pWidget->sizeHint())) | ||||||||
<< QStringLiteral("MinimumSizeHint: %1") | ||||||||
.arg(toDebugString(m_pWidget->minimumSizeHint())); | ||||||||
|
||||||||
for (const auto& pControlConnection : m_leftConnections) { | ||||||||
*debug << QStringLiteral("LeftConnection: %1").arg(pControlConnection->toDebugString()); | ||||||||
} | ||||||||
for (const auto& pControlConnection : m_rightConnections) { | ||||||||
*debug << QStringLiteral("RightConnection: %1").arg(pControlConnection->toDebugString()); | ||||||||
} | ||||||||
for (const auto& pControlConnection : m_connections) { | ||||||||
*debug << QStringLiteral("Connection: %1").arg(pControlConnection->toDebugString()); | ||||||||
} | ||||||||
if (m_pDisplayConnection) { | ||||||||
*debug << QString("DisplayConnection: %1").arg(m_pDisplayConnection->toDebugString()); | ||||||||
*debug << QStringLiteral("DisplayConnection: %1") | ||||||||
.arg(m_pDisplayConnection->toDebugString()); | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.