QStyleSheetStyle: misc cleanup
Avoid some calls to detach() and use std::array instead raw c arrays. Change-Id: I95cbfb130b6fe2509e5d87184c6612718b90dd63 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 51e682d5af955a2c1380f7f1c7014b091a577241) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b0c031b51b
commit
27f73a90a1
@ -625,7 +625,7 @@ public:
|
|||||||
Q_DECLARE_TYPEINFO(QRenderRule, Q_RELOCATABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QRenderRule, Q_RELOCATABLE_TYPE);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
static const char knownStyleHints[][45] = {
|
static constexpr std::array<const char*, 90> knownStyleHints = {
|
||||||
"activate-on-singleclick",
|
"activate-on-singleclick",
|
||||||
"alignment",
|
"alignment",
|
||||||
"arrow-keys-navigate-into-children",
|
"arrow-keys-navigate-into-children",
|
||||||
@ -718,13 +718,10 @@ static const char knownStyleHints[][45] = {
|
|||||||
"widget-animation-duration"
|
"widget-animation-duration"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int numKnownStyleHints = sizeof(knownStyleHints)/sizeof(knownStyleHints[0]);
|
static QList<QVariant> subControlLayout(QByteArrayView layout)
|
||||||
|
|
||||||
static QList<QVariant> subControlLayout(const QString& layout)
|
|
||||||
{
|
{
|
||||||
QList<QVariant> buttons;
|
QList<QVariant> buttons;
|
||||||
for (int i = 0; i < layout.size(); i++) {
|
for (int button : layout) {
|
||||||
int button = layout[i].toLatin1();
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case 'm':
|
case 'm':
|
||||||
buttons.append(PseudoElement_MdiMinButton);
|
buttons.append(PseudoElement_MdiMinButton);
|
||||||
@ -786,10 +783,9 @@ QHash<QStyle::SubControl, QRect> QStyleSheetStyle::titleBarLayout(const QWidget
|
|||||||
int offsets[3] = { 0, 0, 0 };
|
int offsets[3] = { 0, 0, 0 };
|
||||||
enum Where { Left, Right, Center, NoWhere } where = Left;
|
enum Where { Left, Right, Center, NoWhere } where = Left;
|
||||||
QList<ButtonInfo> infos;
|
QList<ButtonInfo> infos;
|
||||||
const int numLayouts = layout.size();
|
infos.reserve(layout.size());
|
||||||
infos.reserve(numLayouts);
|
for (const QVariant &val : std::as_const(layout)) {
|
||||||
for (int i = 0; i < numLayouts; i++) {
|
const int element = val.toInt();
|
||||||
const int element = layout[i].toInt();
|
|
||||||
if (element == '(') {
|
if (element == '(') {
|
||||||
where = Center;
|
where = Center;
|
||||||
} else if (element == ')') {
|
} else if (element == ')') {
|
||||||
@ -848,8 +844,7 @@ QHash<QStyle::SubControl, QRect> QStyleSheetStyle::titleBarLayout(const QWidget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < infos.size(); i++) {
|
for (const ButtonInfo &info : std::as_const(infos)) {
|
||||||
const ButtonInfo &info = infos[i];
|
|
||||||
QRect lr = cr;
|
QRect lr = cr;
|
||||||
switch (info.where) {
|
switch (info.where) {
|
||||||
case Center: {
|
case Center: {
|
||||||
@ -1030,8 +1025,8 @@ QRenderRule::QRenderRule(const QList<Declaration> &declarations, const QObject *
|
|||||||
// intentionally left blank...
|
// intentionally left blank...
|
||||||
} else if (decl.d->propertyId == UnknownProperty) {
|
} else if (decl.d->propertyId == UnknownProperty) {
|
||||||
bool knownStyleHint = false;
|
bool knownStyleHint = false;
|
||||||
for (int i = 0; i < numKnownStyleHints; i++) {
|
for (const auto sh : knownStyleHints) {
|
||||||
QLatin1StringView styleHint(knownStyleHints[i]);
|
QLatin1StringView styleHint(sh);
|
||||||
if (decl.d->property.compare(styleHint) == 0) {
|
if (decl.d->property.compare(styleHint) == 0) {
|
||||||
QString hintName = QString(styleHint);
|
QString hintName = QString(styleHint);
|
||||||
QVariant hintValue;
|
QVariant hintValue;
|
||||||
@ -1073,7 +1068,7 @@ QRenderRule::QRenderRule(const QList<Declaration> &declarations, const QObject *
|
|||||||
hintValue = decl.iconValue();
|
hintValue = decl.iconValue();
|
||||||
} else if (hintName == "button-layout"_L1 && decl.d->values.size() != 0
|
} else if (hintName == "button-layout"_L1 && decl.d->values.size() != 0
|
||||||
&& decl.d->values.at(0).type == QCss::Value::String) {
|
&& decl.d->values.at(0).type == QCss::Value::String) {
|
||||||
hintValue = subControlLayout(decl.d->values.at(0).variant.toString());
|
hintValue = subControlLayout(decl.d->values.at(0).variant.toString().toLatin1());
|
||||||
} else {
|
} else {
|
||||||
int integer;
|
int integer;
|
||||||
decl.intValue(&integer);
|
decl.intValue(&integer);
|
||||||
@ -3508,12 +3503,12 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
|
|||||||
|| hasStyleRule(w, PseudoElement_MdiMinButton)) {
|
|| hasStyleRule(w, PseudoElement_MdiMinButton)) {
|
||||||
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
||||||
if (layout.isEmpty())
|
if (layout.isEmpty())
|
||||||
layout = subControlLayout("mNX"_L1);
|
layout = subControlLayout("mNX");
|
||||||
|
|
||||||
QStyleOptionComplex optCopy(*opt);
|
QStyleOptionComplex optCopy(*opt);
|
||||||
optCopy.subControls = { };
|
optCopy.subControls = { };
|
||||||
for (int i = 0; i < layout.size(); i++) {
|
for (const QVariant &val : std::as_const(layout)) {
|
||||||
int layoutButton = layout[i].toInt();
|
int layoutButton = val.toInt();
|
||||||
if (layoutButton < PseudoElement_MdiCloseButton
|
if (layoutButton < PseudoElement_MdiCloseButton
|
||||||
|| layoutButton > PseudoElement_MdiNormalButton)
|
|| layoutButton > PseudoElement_MdiNormalButton)
|
||||||
continue;
|
continue;
|
||||||
@ -3583,7 +3578,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
|
|||||||
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
|
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pes[] = {
|
constexpr std::array<int, 6> pes = {
|
||||||
PseudoElement_TitleBarMaxButton,
|
PseudoElement_TitleBarMaxButton,
|
||||||
PseudoElement_TitleBarMinButton,
|
PseudoElement_TitleBarMinButton,
|
||||||
PseudoElement_TitleBarNormalButton,
|
PseudoElement_TitleBarNormalButton,
|
||||||
@ -3592,8 +3587,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
|
|||||||
PseudoElement_TitleBarContextHelpButton
|
PseudoElement_TitleBarContextHelpButton
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(pes)/sizeof(int); i++) {
|
for (int pe : pes) {
|
||||||
int pe = pes[i];
|
|
||||||
QStyle::SubControl sc = knownPseudoElements[pe].subControl;
|
QStyle::SubControl sc = knownPseudoElements[pe].subControl;
|
||||||
ir = layout[sc];
|
ir = layout[sc];
|
||||||
if (!ir.isValid())
|
if (!ir.isValid())
|
||||||
@ -5499,11 +5493,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
|
|||||||
|
|
||||||
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
||||||
if (layout.isEmpty())
|
if (layout.isEmpty())
|
||||||
layout = subControlLayout("mNX"_L1);
|
layout = subControlLayout("mNX");
|
||||||
|
|
||||||
int width = 0, height = 0;
|
int width = 0, height = 0;
|
||||||
for (int i = 0; i < layout.size(); i++) {
|
for (const QVariant &val : std::as_const(layout)) {
|
||||||
int layoutButton = layout[i].toInt();
|
int layoutButton = val.toInt();
|
||||||
if (layoutButton < PseudoElement_MdiCloseButton
|
if (layoutButton < PseudoElement_MdiCloseButton
|
||||||
|| layoutButton > PseudoElement_MdiNormalButton)
|
|| layoutButton > PseudoElement_MdiNormalButton)
|
||||||
continue;
|
continue;
|
||||||
@ -6065,12 +6059,12 @@ QRect QStyleSheetStyle::subControlRect(ComplexControl cc, const QStyleOptionComp
|
|||||||
|| hasStyleRule(w, PseudoElement_MdiMinButton)) {
|
|| hasStyleRule(w, PseudoElement_MdiMinButton)) {
|
||||||
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
QList<QVariant> layout = rule.styleHint("button-layout"_L1).toList();
|
||||||
if (layout.isEmpty())
|
if (layout.isEmpty())
|
||||||
layout = subControlLayout("mNX"_L1);
|
layout = subControlLayout("mNX");
|
||||||
|
|
||||||
int x = 0, width = 0;
|
int x = 0, width = 0;
|
||||||
QRenderRule subRule;
|
QRenderRule subRule;
|
||||||
for (int i = 0; i < layout.size(); i++) {
|
for (const QVariant &val : std::as_const(layout)) {
|
||||||
int layoutButton = layout[i].toInt();
|
int layoutButton = val.toInt();
|
||||||
if (layoutButton < PseudoElement_MdiCloseButton
|
if (layoutButton < PseudoElement_MdiCloseButton
|
||||||
|| layoutButton > PseudoElement_MdiNormalButton)
|
|| layoutButton > PseudoElement_MdiNormalButton)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user