Fix width calculations in flamegraph and timeline

Relying on the index of a detail entry in the children array is
dangerous as the repeater may create the children in any order. Rather,
use the isLabel property to find out if an item is a label.

Also, recognize that the drag handle sits in the outer margin.
Therefore, as the minimumWidth includes margins, we have to subtract one
margin in order to get the x value of the handle.

Task-number: QTCREATORBUG-20012
Change-Id: I828b116c2c52d5aa7f8e3e726f59e3fa9f9095ec
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2018-03-09 12:28:22 +01:00
parent 21d3d0a55d
commit af99c3fe7d
3 changed files with 31 additions and 17 deletions

View File

@@ -155,14 +155,20 @@ Item {
property int minimumWidth: { property int minimumWidth: {
// max(width of longest label * 2, minimumInnerWidth) // max(width of longest label * 2, minimumInnerWidth)
var result = minimumInnerWidth; var result = minimumInnerWidth;
for (var i = 0; i < children.length; i += 2) for (var i = 0; i < children.length; ++i) {
result = Math.max(children[i].implicitWidth * 2 + innerMargin, result); if (children[i].isLabel)
result = Math.max(children[i].implicitWidth * 2 + innerMargin, result);
}
return result + 2 * outerMargin; return result + 2 * outerMargin;
} }
property int labelWidth: (minimumWidth - innerMargin) / 2 - outerMargin
property int valueWidth: dragHandle.x - labelWidth - innerMargin - outerMargin
onMinimumWidthChanged: { onMinimumWidthChanged: {
if (dragHandle.x < minimumWidth) if (dragHandle.x < minimumWidth - outerMargin)
dragHandle.x = minimumWidth; dragHandle.x = minimumWidth - outerMargin;
} }
Repeater { Repeater {
@@ -171,8 +177,7 @@ Item {
property bool isLabel: index % 2 === 0 property bool isLabel: index % 2 === 0
font.bold: isLabel font.bold: isLabel
elide: Text.ElideRight elide: Text.ElideRight
width: (text === "" || isLabel) width: isLabel ? col.labelWidth : col.valueWidth
? implicitWidth : (dragHandle.x - col.minimumWidth / 2 - innerMargin)
text: isLabel ? (modelData + ":") : modelData text: isLabel ? (modelData + ":") : modelData
color: contentTextColor color: contentTextColor
} }
@@ -213,7 +218,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
drag.target: parent drag.target: parent
drag.minimumX: col.minimumWidth drag.minimumX: col.minimumWidth - outerMargin
drag.axis: Drag.XAxis drag.axis: Drag.XAxis
cursorShape: Qt.SizeHorCursor cursorShape: Qt.SizeHorCursor
} }

View File

@@ -28,7 +28,8 @@ import QtQuick 2.1
TimelineText { TimelineText {
property bool isLabel: false property bool isLabel: false
property int valueWidth: 170 property int valueWidth: 170
property int labelWidth: implicitWidth
font.bold: isLabel font.bold: isLabel
elide: Text.ElideRight elide: Text.ElideRight
width: text === "" ? 0 : (isLabel ? implicitWidth : valueWidth) width: text === "" ? 0 : (isLabel ? labelWidth : valueWidth)
} }

View File

@@ -173,27 +173,35 @@ Item {
//details //details
Grid { Grid {
property int outerMargin: 10
property int minimumWidth: 150
property int labelWidth: (minimumWidth - spacing) / 2 - outerMargin
property int valueWidth: dragHandle.x - labelWidth - spacing - outerMargin
id: col id: col
x: 10 x: outerMargin
y: 5 y: 5
spacing: 5 spacing: 5
columns: 2 columns: 2
property int minimumWidth: 150
onChildrenChanged: { onChildrenChanged: {
// max(width of longest label * 2, 150) // max(width of longest label * 2, 150)
var result = 150; var result = 150;
for (var i = 0; i < children.length; i += 2) for (var i = 0; i < children.length; ++i) {
result = Math.max(children[i].implicitWidth * 2 + spacing, result); if (children[i].isLabel)
minimumWidth = result + 20; result = Math.max(children[i].implicitWidth * 2 + spacing, result);
if (dragHandle.x < minimumWidth) }
dragHandle.x = minimumWidth;
minimumWidth = result + 2 * outerMargin;
if (dragHandle.x < minimumWidth - outerMargin)
dragHandle.x = minimumWidth - outerMargin;
} }
Repeater { Repeater {
model: eventInfo.ready ? eventInfo : 0 model: eventInfo.ready ? eventInfo : 0
Detail { Detail {
valueWidth: (dragHandle.x - col.minimumWidth / 2 - col.spacing) labelWidth: col.labelWidth
valueWidth: col.valueWidth
isLabel: index % 2 === 0 isLabel: index % 2 === 0
text: (content === undefined) ? "" : (isLabel ? (content + ":") : content) text: (content === undefined) ? "" : (isLabel ? (content + ":") : content)
} }
@@ -285,7 +293,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
drag.target: parent drag.target: parent
drag.minimumX: col.minimumWidth drag.minimumX: col.minimumWidth - col.outerMargin
drag.axis: Drag.XAxis drag.axis: Drag.XAxis
cursorShape: Qt.SizeHorCursor cursorShape: Qt.SizeHorCursor
} }