summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-04-05 18:39:14 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-04-06 12:23:37 +0000
commit9b699fa839f560a9ea9da69c8975b9aa4654ab8b (patch)
treee4a3b79c059bf391163c574f4875f99d209b14ce /src/widgets/styles
parent9d0dbc32dd3c37c1199115762fab6ac1cedb9ce3 (diff)
Widgets: use QStringRef to optimize memory allocation
Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. Change-Id: Id1c39093199519f2794b11560c2c0ded2d52b928 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qfusionstyle.cpp12
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp6
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp12
3 files changed, 17 insertions, 13 deletions
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index b15b9701d9..5b6e47e2c6 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -1649,7 +1649,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
- QString s = menuitem->text;
+ QStringRef s(&menuitem->text);
if (!s.isEmpty()) { // draw text
p->save();
int t = s.indexOf(QLatin1Char('\t'));
@@ -1660,12 +1660,13 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
if (t >= 0) {
QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
+ const QString textToDraw = s.mid(t + 1).toString();
if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
p->setPen(menuitem->palette.light().color());
- p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
+ p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
p->setPen(discol);
}
- p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
+ p->drawText(vShortcutRect, text_flags, textToDraw);
s = s.left(t);
}
QFont font = menuitem->font;
@@ -1680,12 +1681,13 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
font.setBold(true);
p->setFont(font);
+ const QString textToDraw = s.left(t).toString();
if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) {
p->setPen(menuitem->palette.light().color());
- p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
+ p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
p->setPen(discol);
}
- p->drawText(vTextRect, text_flags, s.left(t));
+ p->drawText(vTextRect, text_flags, textToDraw);
p->restore();
}
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 053820e459..44555c3058 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -3679,7 +3679,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
QRect textRect = subRule.contentsRect(opt->rect);
textRect.setWidth(textRect.width() - mi.tabWidth);
- QString s = mi.text;
+ QStringRef s(&mi.text);
p->setPen(mi.palette.buttonText().color());
if (!s.isEmpty()) {
int text_flags = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
@@ -3689,10 +3689,10 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (t >= 0) {
QRect vShortcutRect = visualRect(opt->direction, mi.rect,
QRect(textRect.topRight(), QPoint(mi.rect.right(), textRect.bottom())));
- p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
+ p->drawText(vShortcutRect, text_flags, s.mid(t + 1).toString());
s = s.left(t);
}
- p->drawText(textRect, text_flags, s.left(t));
+ p->drawText(textRect, text_flags, s.left(t).toString());
}
if (mi.menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index 36aa312ce8..2ef227762b 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -1198,7 +1198,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
- QString s = menuitem->text;
+ QStringRef s(&menuitem->text);
if (!s.isEmpty()) { // draw text
p->save();
int t = s.indexOf(QLatin1Char('\t'));
@@ -1209,24 +1209,26 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
if (t >= 0) {
QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
+ const QString textToDraw = s.mid(t + 1).toString();
if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
p->setPen(menuitem->palette.light().color());
- p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
+ p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
p->setPen(discol);
}
- p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
+ p->drawText(vShortcutRect, text_flags, textToDraw);
s = s.left(t);
}
QFont font = menuitem->font;
if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
font.setBold(true);
p->setFont(font);
+ const QString textToDraw = s.left(t).toString();
if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
p->setPen(menuitem->palette.light().color());
- p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
+ p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
p->setPen(discol);
}
- p->drawText(vTextRect, text_flags, s.left(t));
+ p->drawText(vTextRect, text_flags, textToDraw);
p->restore();
}
if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow