on xenial help sign in
Do not calculate implicitHeight for Cards in a CardGrid

We set their height with item.height = Qt.binding(function() { return cardTool.cardHeight; }); anyway so it's lost CPU time The qmlprofiler said it took around 1.5% of the time of scrolling up/down a very long scope

commita1bb75e1c5c0e028203da9b6f6c74fb7acc11ef5 authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 25 Jul 2016, 12:12 (10 years ago) parent77a5424
3 files changed+35−31
plugins/Dash/CardCreator.js+30−26 plugins/Dash/CardCreatorCache.qml+3−3 qml/Dash/CardTool.qml+2−2
plugins/Dash/CardCreator.js+30−26
@@ -437,7 +437,7 @@ function sanitizeColor(colorString) {
437437 return colorString;
438438}
439439
440−function cardString(template, components, isCardTool, artShapeStyle) {
440+function cardString(template, components, isCardTool, artShapeStyle, categoryLayout) {
441441 var code;
442442
443443 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
@@ -943,29 +943,33 @@ function cardString(template, components, isCardTool, artShapeStyle) {
943943 code += kTouchdownCode.arg(touchdownAnchors);
944944 }
945945
946− var implicitHeight = 'implicitHeight: ';
947− if (hasSocialActions) {
948− implicitHeight += 'socialActionsRow.y + socialActionsRow.height + units.gu(1);\n';
949− } else if (hasSummary) {
950− implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
951− } else if (isAudio) {
952− implicitHeight += 'audioButton.height;\n';
953− } else if (headerAsOverlay) {
954− implicitHeight += 'artShapeHolder.height;\n';
955− } else if (hasHeaderRow) {
956− implicitHeight += 'row.y + row.height + units.gu(1);\n';
957− } else if (hasMascot) {
958− implicitHeight += 'mascotImage.y + mascotImage.height;\n';
959− } else if (hasTitleContainer) {
960− implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
961− } else if (hasAttributes) {
962− implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
963− } else if (hasSubtitle) {
964− implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
965− } else if (hasTitle) {
966− implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
967− } else if (hasArt) {
968− implicitHeight += 'artShapeHolder.height;\n';
946+ if (isCardTool || categoryLayout !== "grid") {
947+ var implicitHeight = 'implicitHeight: ';
948+ if (hasSocialActions) {
949+ implicitHeight += 'socialActionsRow.y + socialActionsRow.height + units.gu(1);\n';
950+ } else if (hasSummary) {
951+ implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
952+ } else if (isAudio) {
953+ implicitHeight += 'audioButton.height;\n';
954+ } else if (headerAsOverlay) {
955+ implicitHeight += 'artShapeHolder.height;\n';
956+ } else if (hasHeaderRow) {
957+ implicitHeight += 'row.y + row.height + units.gu(1);\n';
958+ } else if (hasMascot) {
959+ implicitHeight += 'mascotImage.y + mascotImage.height;\n';
960+ } else if (hasTitleContainer) {
961+ implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
962+ } else if (hasAttributes) {
963+ implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
964+ } else if (hasSubtitle) {
965+ implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
966+ } else if (hasTitle) {
967+ implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
968+ } else if (hasArt) {
969+ implicitHeight += 'artShapeHolder.height;\n';
970+ } else {
971+ implicitHeight = '';
972+ }
969973 } else {
970974 implicitHeight = '';
971975 }
@@ -976,13 +980,13 @@ function cardString(template, components, isCardTool, artShapeStyle) {
976980 return code;
977981}
978982
979−function createCardComponent(parent, template, components, isCardTool, artShapeStyle, identifier) {
983+function createCardComponent(parent, template, components, isCardTool, artShapeStyle, categoryLayout, identifier) {
980984 var imports = 'import QtQuick 2.4; \n\
981985 import Ubuntu.Components 1.3; \n\
982986 import Ubuntu.Settings.Components 0.1; \n\
983987 import Dash 0.1;\n\
984988 import Utils 0.1;\n';
985− var card = cardString(template, components, isCardTool, artShapeStyle);
989+ var card = cardString(template, components, isCardTool, artShapeStyle, categoryLayout);
986990 var code = imports + 'Component {\n' + card + '}\n';
987991
988992 try {
plugins/Dash/CardCreatorCache.qml+3−3
@@ -23,16 +23,16 @@ QtObject {
2323
2424 property var cache: new Object();
2525
26− function getCardComponent(template, components, isCardTool, artShapeStyle) {
26+ function getCardComponent(template, components, isCardTool, artShapeStyle, categoryLayout) {
2727 if (template === undefined || components === undefined)
2828 return undefined;
2929
3030 var tString = JSON.stringify(template);
3131 var cString = JSON.stringify(components);
32− var allString = tString + cString + isCardTool + artShapeStyle;
32+ var allString = tString + cString + isCardTool + artShapeStyle + categoryLayout;
3333 var component = cache[allString];
3434 if (component === undefined) {
35− component = CardCreator.createCardComponent(root, template, components, isCardTool, artShapeStyle, allString);
35+ component = CardCreator.createCardComponent(root, template, components, isCardTool, artShapeStyle, categoryLayout, allString);
3636 cache[allString] = component;
3737 }
3838 return component;
qml/Dash/CardTool.qml+2−2
@@ -71,7 +71,7 @@ Item {
7171 // Not readonly because gets overwritten from GenericScopeView in some cases
7272 property string artShapeStyle: categoryLayout === "carousel" ? "shadow" : "inset"
7373
74− property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false, cardTool.artShapeStyle);
74+ property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false, cardTool.artShapeStyle, cardTool.categoryLayout);
7575
7676 // FIXME: Saviq
7777 // Only way for the card below to actually be laid out completely.
@@ -213,7 +213,7 @@ Item {
213213 "attributes": attributesModel.model,
214214 "socialActions": socialActionsModel.model
215215 }
216− sourceComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, true, cardTool.artShapeStyle);
216+ sourceComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, true, cardTool.artShapeStyle, cardTool.categoryLayout);
217217 onLoaded: {
218218 item.objectName = "cardToolCard";
219219 item.width = Qt.binding(function() { return cardTool.cardWidth !== -1 ? cardTool.cardWidth : item.implicitWidth; });