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 Approved by: Andrea Cimitan

commit7a22ba23a809f87dbf7197d6b2c15111f60bed8d authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 11 Aug 2016, 06:23 (10 years ago) parent93dca21ecf80d7
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
@@ -429,7 +429,7 @@ function sanitizeColor(colorString) {
429429 return colorString;
430430}
431431
432−function cardString(template, components, isCardTool, artShapeStyle) {
432+function cardString(template, components, isCardTool, artShapeStyle, categoryLayout) {
433433 var code;
434434
435435 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
@@ -935,29 +935,33 @@ function cardString(template, components, isCardTool, artShapeStyle) {
935935 code += kTouchdownCode.arg(touchdownAnchors);
936936 }
937937
938− var implicitHeight = 'implicitHeight: ';
939− if (hasSocialActions) {
940− implicitHeight += 'socialActionsRow.y + socialActionsRow.height + units.gu(1);\n';
941− } else if (hasSummary) {
942− implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
943− } else if (isAudio) {
944− implicitHeight += 'audioButton.height;\n';
945− } else if (headerAsOverlay) {
946− implicitHeight += 'artShapeLoader.height;\n';
947− } else if (hasHeaderRow) {
948− implicitHeight += 'row.y + row.height + units.gu(1);\n';
949− } else if (hasMascot) {
950− implicitHeight += 'mascotImage.y + mascotImage.height;\n';
951− } else if (hasTitleContainer) {
952− implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
953− } else if (hasAttributes) {
954− implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
955− } else if (hasSubtitle) {
956− implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
957− } else if (hasTitle) {
958− implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
959− } else if (hasArt) {
960− implicitHeight += 'artShapeLoader.height;\n';
938+ if (isCardTool || categoryLayout !== "grid") {
939+ var implicitHeight = 'implicitHeight: ';
940+ if (hasSocialActions) {
941+ implicitHeight += 'socialActionsRow.y + socialActionsRow.height + units.gu(1);\n';
942+ } else if (hasSummary) {
943+ implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
944+ } else if (isAudio) {
945+ implicitHeight += 'audioButton.height;\n';
946+ } else if (headerAsOverlay) {
947+ implicitHeight += 'artShapeLoader.height;\n';
948+ } else if (hasHeaderRow) {
949+ implicitHeight += 'row.y + row.height + units.gu(1);\n';
950+ } else if (hasMascot) {
951+ implicitHeight += 'mascotImage.y + mascotImage.height;\n';
952+ } else if (hasTitleContainer) {
953+ implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
954+ } else if (hasAttributes) {
955+ implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
956+ } else if (hasSubtitle) {
957+ implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
958+ } else if (hasTitle) {
959+ implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
960+ } else if (hasArt) {
961+ implicitHeight += 'artShapeLoader.height;\n';
962+ } else {
963+ implicitHeight = '';
964+ }
961965 } else {
962966 implicitHeight = '';
963967 }
@@ -968,13 +972,13 @@ function cardString(template, components, isCardTool, artShapeStyle) {
968972 return code;
969973}
970974
971−function createCardComponent(parent, template, components, isCardTool, artShapeStyle, identifier) {
975+function createCardComponent(parent, template, components, isCardTool, artShapeStyle, categoryLayout, identifier) {
972976 var imports = 'import QtQuick 2.4; \n\
973977 import Ubuntu.Components 1.3; \n\
974978 import Ubuntu.Settings.Components 0.1; \n\
975979 import Dash 0.1;\n\
976980 import Utils 0.1;\n';
977− var card = cardString(template, components, isCardTool, artShapeStyle);
981+ var card = cardString(template, components, isCardTool, artShapeStyle, categoryLayout);
978982 var code = imports + 'Component {\n' + card + '}\n';
979983
980984 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; });