X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fd5ba3b4b22e923cff11b65654e9b6f931ce9a3c..8f7c3619ec734bbf31ae81315a6548db9cbd19aa:/src/kitemviews/kstandarditemlistwidget.cpp diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 621cd81cc..4b9f33b6f 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -57,13 +57,12 @@ KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant() QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemListView* view) const { - const QHash values = view->model()->data(index); const KItemListStyleOption& option = view->styleOption(); const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0); switch (static_cast(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; @@ -100,6 +99,7 @@ QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemList // to show all roles without horizontal clipping. qreal maximumRequiredWidth = 0.0; + const QHash values = view->model()->data(index); foreach (const QByteArray& role, view->visibleRoles()) { const QString text = roleText(role, values); const qreal requiredWidth = option.fontMetrics.width(text); @@ -159,6 +159,11 @@ qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArra 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& values) const { @@ -204,8 +209,13 @@ KStandardItemListWidget::~KStandardItemListWidget() 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) @@ -649,16 +659,15 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const 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); @@ -791,7 +800,6 @@ void KStandardItemListWidget::updateExpansionArea() { if (m_supportsItemExpanding) { const QHash values = data(); - Q_ASSERT(values.contains("expandedParentsCount")); const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); if (expandedParentsCount >= 0) { const qreal widgetHeight = size().height(); @@ -1027,12 +1035,15 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() 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; } @@ -1303,6 +1314,9 @@ void KStandardItemListWidget::closeRoleEditor() scene()->views()[0]->parentWidget()->setFocus(); } + if (m_oldRoleEditor) { + m_oldRoleEditor->deleteLater(); + } m_oldRoleEditor = m_roleEditor; m_roleEditor->hide(); m_roleEditor = 0;