QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemListView* view) const
{
- const QHash<QByteArray, QVariant> values = view->model()->data(index);
const KItemListStyleOption& option = view->styleOption();
const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
case KStandardItemListWidget::IconsLayout: {
- const QString text = KStringHandler::preProcessWrap(values["text"].toString());
+ const QString text = KStringHandler::preProcessWrap(itemText(index, view));
const qreal itemWidth = view->itemSize().width();
const qreal maxWidth = itemWidth - 2 * option.padding;
// to show all roles without horizontal clipping.
qreal maximumRequiredWidth = 0.0;
+ const QHash<QByteArray, QVariant> values = view->model()->data(index);
foreach (const QByteArray& role, view->visibleRoles()) {
const QString text = roleText(role, values);
const qreal requiredWidth = option.fontMetrics.width(text);
return width;
}
+QString KStandardItemListWidgetInformant::itemText(int index, const KItemListView* view) const
+{
+ return view->model()->data(index).value("text").toString();
+}
+
QString KStandardItemListWidgetInformant::roleText(const QByteArray& role,
const QHash<QByteArray, QVariant>& values) const
{
qDeleteAll(m_textInfo);
m_textInfo.clear();
- delete m_roleEditor;
- delete m_oldRoleEditor;
+ if (m_roleEditor) {
+ m_roleEditor->deleteLater();
+ }
+
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
}
void KStandardItemListWidget::setLayout(Layout layout)
this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
+
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
m_oldRoleEditor = m_roleEditor;
m_roleEditor->hide();
m_roleEditor = 0;
}
return;
- } else if (m_oldRoleEditor) {
- // Delete the old editor before constructing the new one to
- // prevent a memory leak.
- m_oldRoleEditor->deleteLater();
- m_oldRoleEditor = 0;
}
Q_ASSERT(!m_roleEditor);
{
if (m_supportsItemExpanding) {
const QHash<QByteArray, QVariant> values = data();
- Q_ASSERT(values.contains("expandedParentsCount"));
const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt();
if (expandedParentsCount >= 0) {
const qreal widgetHeight = size().height();
const int textLength = line.textStart() + line.textLength();
if (textLength < nameText.length()) {
// Elide the last line of the text
- QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
+ QString lastTextLine = nameText.mid(line.textStart());
lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
Qt::ElideRight,
- line.naturalTextWidth() - 1);
+ maxWidth);
const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
nameTextInfo->staticText.setText(elidedText);
+
+ const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+ nameWidth = qMax(nameWidth, lastLineWidth);
}
break;
}
scene()->views()[0]->parentWidget()->setFocus();
}
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
m_oldRoleEditor = m_roleEditor;
m_roleEditor->hide();
m_roleEditor = 0;