on xenial help sign in
Do not create Label/Icon if we don't need it

The cards at the store are using a sneaky construct in which half of the attributes are empty to create the attribute layout they want With this the average creation time for the card attributes on the store scope goes from 8ms to 4ms

commita651c56882b277217cd501dc2427fc972c7e2ad0 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 20 May 2016, 12:03 (10 years ago) parentee04e2a
1 file changed+26−18
plugins/Dash/CardAttributes.qml+26−18
plugins/Dash/CardAttributes.qml+26−18
@@ -43,28 +43,36 @@ GridLayout {
4343 Layout.column: index % grid.columns
4444 Layout.row: index / grid.columns
4545 Layout.columnSpan: index == repeater.count - 1 && grid.columns == 3 && column == 1 ? 2 : 1
46− Layout.maximumWidth: Math.max(icon.width, label.x + label.implicitWidth)
46+ Layout.maximumWidth: Math.max(iconLoader.width, labelLoader.x + labelLoader.implicitWidth)
4747 Layout.fillWidth: true
4848 height: units.gu(2)
49− Icon {
50− id: icon
51− height: units.gu(2)
52− // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
53− width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
54− source: "icon" in modelData && modelData["icon"] || ""
55− color: grid.color
49+ Loader {
50+ id: iconLoader
51+ readonly property string source: "icon" in modelData && modelData["icon"] || ""
52+ active: source !== ""
53+ sourceComponent: Icon {
54+ height: units.gu(2)
55+ // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
56+ width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
57+ source: parent.source
58+ color: grid.color
59+ }
5660 }
57− Label {
58− id: label
61+ Loader {
62+ id: labelLoader
5963 width: parent.width - x
60− anchors.verticalCenter: parent.verticalCenter
61− text: "value" in modelData && modelData["value"] || "";
62− elide: Text.ElideRight
63− maximumLineCount: 1
64− font.weight: "style" in modelData && modelData["style"] === "highlighted" ? Font.Bold : Font.Light
65− fontSize: "small"
66− font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
67− color: grid.color
64+ readonly property string value: "value" in modelData && modelData["value"] || ""
65+ active: value !== ""
66+ sourceComponent: Label {
67+ anchors.verticalCenter: parent.verticalCenter
68+ text: parent.value
69+ elide: Text.ElideRight
70+ maximumLineCount: 1
71+ font.weight: "style" in modelData && modelData["style"] === "highlighted" ? Font.Bold : Font.Light
72+ fontSize: "small"
73+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
74+ color: grid.color
75+ }
6876 }
6977 }
7078 }