TODO: Fix QML injection, port away from Qt.createQmlObject to TextMetrics
In file kde/workspace/kdeplasma-addons/windowswitchers/text/contents/ui/main.qml
the code is doing unacceptable things:
ListView {
id: textListView
function calculateMaxRowWidth() {
var width = 0;
var textElement = Qt.createQmlObject(
'import QtQuick 2.0;'
+ 'Text {\n'
+ ' text: "' + tabBox.model.longestCaption() + '"\n'
+ ' visible: false\n'
+ '}',
textListView, "calculateMaxRowWidth");
width = Math.max(textElement.width, width);
textElement.destroy();
return width + hoverItem.margins.right + hoverItem.margins.left;
}
/**
* Calculates the height of one row based on the text height and icon size.
* @return Row height
**/
function calcRowHeight() {
var textElement = Qt.createQmlObject(
'import QtQuick 2.0;'
+ 'Text {\n'
+ ' text: "Some Text"\n'
+ ' visible: false\n'
+ '}',
textListView, "calcRowHeight");
var height = textElement.height;
textElement.destroy();
// icon size or two text elements and margins and hoverItem margins
return height + hoverItem.margins.top + hoverItem.margins.bottom;
}
// the maximum text width + icon item width (32 + 4 margin) + margins for hover item
property int maxRowWidth: calculateMaxRowWidth()
property int rowHeight: calcRowHeight()
It should be using safe and efficient TextMetrics QML Type instead.