forked from qt-creator/qt-creator
Timeline: Make label parsing declarative
Like this the labels are also updated initially and when the model changes. Also, use the more generic label "[unknown]" instead of "<bytecode>" to replace empty descriptions. Even in the QML case it's not always bytecode. Change-Id: Iea0dc36eb9061c928f2cb9706adaaa3b4bab7811 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
@@ -40,9 +40,8 @@ Item {
|
|||||||
property bool mockup
|
property bool mockup
|
||||||
property string text: model ? model.displayName : ""
|
property string text: model ? model.displayName : ""
|
||||||
property bool expanded: model && model.expanded
|
property bool expanded: model && model.expanded
|
||||||
property var descriptions: []
|
property var labels: model ? model.labels : []
|
||||||
property var extdescriptions: []
|
|
||||||
property var selectionIds: []
|
|
||||||
property bool dragging
|
property bool dragging
|
||||||
property int visualIndex
|
property int visualIndex
|
||||||
property int dragOffset
|
property int dragOffset
|
||||||
@@ -65,27 +64,6 @@ Item {
|
|||||||
height: model ? Math.max(txt.height, model.height) : 0
|
height: model ? Math.max(txt.height, model.height) : 0
|
||||||
width: 150
|
width: 150
|
||||||
|
|
||||||
function updateDescriptions() {
|
|
||||||
var desc=[];
|
|
||||||
var ids=[];
|
|
||||||
var extdesc=[];
|
|
||||||
var labelList = model.labels;
|
|
||||||
for (var i = 0; i < labelList.length; i++ ) {
|
|
||||||
extdesc[i] = desc[i] = (labelList[i].description || qsTr("<bytecode>"));
|
|
||||||
ids[i] = labelList[i].id;
|
|
||||||
if (labelList[i].displayName !== undefined)
|
|
||||||
extdesc[i] += " (" + labelList[i].displayName + ")";
|
|
||||||
}
|
|
||||||
descriptions = desc;
|
|
||||||
selectionIds = ids;
|
|
||||||
extdescriptions = extdesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: model
|
|
||||||
onLabelsChanged: updateDescriptions()
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: dragArea
|
id: dragArea
|
||||||
anchors.fill: txt
|
anchors.fill: txt
|
||||||
@@ -131,19 +109,23 @@ Item {
|
|||||||
anchors.top: txt.bottom
|
anchors.top: txt.bottom
|
||||||
visible: expanded
|
visible: expanded
|
||||||
Repeater {
|
Repeater {
|
||||||
model: descriptions.length
|
model: labels.length
|
||||||
Button {
|
Button {
|
||||||
|
id: button
|
||||||
|
property string labelText: labels[index].description ? labels[index].description :
|
||||||
|
qsTr("[unknown]")
|
||||||
width: labelContainer.width
|
width: labelContainer.width
|
||||||
height: column.parentModel ? column.parentModel.rowHeight(index + 1) : 0
|
height: column.parentModel ? column.parentModel.rowHeight(index + 1) : 0
|
||||||
action: Action {
|
action: Action {
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (reverseSelect)
|
if (reverseSelect)
|
||||||
labelContainer.selectPrevBySelectionId(selectionIds[index]);
|
labelContainer.selectPrevBySelectionId(labels[index].id);
|
||||||
else
|
else
|
||||||
labelContainer.selectNextBySelectionId(selectionIds[index]);
|
labelContainer.selectNextBySelectionId(labels[index].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip: extdescriptions[index]
|
tooltip: button.labelText + (labels[index].displayName ?
|
||||||
|
(" (" + labels[index].displayName + ")") : "")
|
||||||
}
|
}
|
||||||
|
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
@@ -153,7 +135,7 @@ Item {
|
|||||||
color: "#eaeaea"
|
color: "#eaeaea"
|
||||||
}
|
}
|
||||||
label: Text {
|
label: Text {
|
||||||
text: descriptions[index]
|
text: button.labelText
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
horizontalAlignment: Text.AlignLeft
|
horizontalAlignment: Text.AlignLeft
|
||||||
|
Reference in New Issue
Block a user