Skip to content

Commit 588dc46

Browse files
committed
Refactoring: reduce code duplication in expert.cpp
1 parent 5ceb67e commit 588dc46

1 file changed

Lines changed: 14 additions & 22 deletions

File tree

addon/doxywizard/expert.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ static QString convertToComment(const QString &s)
6565
}
6666
}
6767

68+
static QString displayDocs(const QString &id,const QString &docs)
69+
{
70+
QString display = SMALL_FONT_START + SA("<b>") + id + SA("</b>");
71+
if (!docs.isEmpty())
72+
{
73+
display += SA(" &mdash; ") + docs;
74+
}
75+
display += SMALL_FONT_END;
76+
return display;
77+
}
78+
6879
void Expert::setHeader(const char *header)
6980
{
7081
m_header = SA(header);
@@ -515,14 +526,7 @@ void Expert::createOptionCard(GroupEntry &group, const QDomElement &child)
515526
docsLabel->setWordWrap(true);
516527
docsLabel->setOpenExternalLinks(true);
517528
docsLabel->setContentsMargins(0, 2, 0, 4);
518-
// Use a smaller, muted style for the description text
519-
QString display = SMALL_FONT_START + SA("<b>") + id + SA("</b>");
520-
if (!docs.isEmpty())
521-
{
522-
display += SA(" &mdash; ") + docs;
523-
}
524-
display += SMALL_FONT_END;
525-
docsLabel->setText(display);
529+
docsLabel->setText(displayDocs(id,docs));
526530
// Dim the label using PlaceholderText, which is calibrated for readable
527531
// secondary text in both light and dark modes (available since Qt 5.12).
528532
QColor textColor = docsLabel->palette().color(QPalette::Text);
@@ -1143,13 +1147,7 @@ void Expert::filterChanged(const QString &text)
11431147
}
11441148
if (opt.docsLabel && opt.labelHighlighted)
11451149
{
1146-
QString display = SMALL_FONT_START + SA("<b>") + opt.id + SA("</b>");
1147-
if (!opt.docs.isEmpty())
1148-
{
1149-
display += SA(" &mdash; ") + opt.docs;
1150-
}
1151-
display += SMALL_FONT_END;
1152-
opt.docsLabel->setText(display);
1150+
opt.docsLabel->setText(displayDocs(opt.id, opt.docs));
11531151
opt.input->setText(opt.id);
11541152
opt.labelHighlighted = false;
11551153
}
@@ -1190,13 +1188,7 @@ void Expert::filterChanged(const QString &text)
11901188
QString hiDocs = matchesDocs ? highlightInHtml(opt.docs, filter) : opt.docs;
11911189
QString hiId = matchesId ? highlightInHtml(opt.id, filter) : opt.id;
11921190
opt.input->setText(hiId);
1193-
QString display = SMALL_FONT_START + SA("<b>") + hiId + SA("</b>");
1194-
if (!opt.docs.isEmpty())
1195-
{
1196-
display += SA(" &mdash; ") + hiDocs;
1197-
}
1198-
display += SMALL_FONT_END;
1199-
opt.docsLabel->setText(display);
1191+
opt.docsLabel->setText(displayDocs(hiId,hiDocs));
12001192
opt.labelHighlighted = true;
12011193
}
12021194

0 commit comments

Comments
 (0)