commit 0e4754a0eacd4528a4d2b369704afca9f36e366f Author: Christoph Feck <christoph@maxiom.de> Date: Sat Aug 20 11:00:54 2011 +0200 Fix crash in KCharSelect - use Selected instead of Current table cell item - emit correct signals on layout changes Thanks Albert for confirmation! BUG: 235020 FIXED-IN: 4.7.1 REVIEW: 102263 diff --git a/kdeui/widgets/kcharselect.cpp b/kdeui/widgets/kcharselect.cpp index c511191..5b8a1be 100644 --- a/kdeui/widgets/kcharselect.cpp +++ b/kdeui/widgets/kcharselect.cpp @@ -58,7 +58,7 @@ public: void _k_resizeCells(); void _k_doubleClicked(const QModelIndex & index); - void _k_slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous); + void _k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); }; class KCharSelect::KCharSelectPrivate @@ -196,7 +196,7 @@ void KCharSelectTable::setContents(QList<QChar> chars) setSelectionModel(selectionModel); setSelectionBehavior(QAbstractItemView::SelectItems); setSelectionMode(QAbstractItemView::SingleSelection); - connect(selectionModel, SIGNAL(currentChanged(const QModelIndex & , const QModelIndex &)), this, SLOT(_k_slotCurrentChanged(const QModelIndex &, const QModelIndex &))); + connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(_k_slotSelectionChanged(const QItemSelection &, const QItemSelection &))); connect(d->model, SIGNAL(showCharRequested(QChar)), this, SIGNAL(showCharRequested(QChar))); delete m; // this should hopefully delete aold selection models too, since it is the parent of them (didn't track, if there are setParent calls somewhere. Check that (jowenn) } @@ -211,11 +211,12 @@ void KCharSelectTable::scrollTo(const QModelIndex & index, ScrollHint hint) } } -void KCharSelectTablePrivate::_k_slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous) +void KCharSelectTablePrivate::_k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) { - Q_UNUSED(previous); - if (!model) return; - QVariant temp = model->data(current, KCharSelectItemModel::CharacterRole); + Q_UNUSED(deselected); + if (!model || selected.indexes().isEmpty()) + return; + QVariant temp = model->data(selected.indexes().at(0), KCharSelectItemModel::CharacterRole); if (temp.type() != QVariant::Char) return; QChar c = temp.toChar(); diff --git a/kdeui/widgets/kcharselect_p.h b/kdeui/widgets/kcharselect_p.h index d414d23..6188f9f 100644 --- a/kdeui/widgets/kcharselect_p.h +++ b/kdeui/widgets/kcharselect_p.h @@ -103,7 +103,7 @@ Q_SIGNALS: void showCharRequested(const QChar& c); private: - Q_PRIVATE_SLOT(d, void _k_slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous)) + Q_PRIVATE_SLOT(d, void _k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)) Q_PRIVATE_SLOT(d, void _k_resizeCells()) Q_PRIVATE_SLOT(d, void _k_doubleClicked(const QModelIndex & index)) @@ -199,7 +199,7 @@ public: void updateColumnCount(int maxWidth) { - + emit layoutAboutToBeChanged(); QFontMetrics fm(m_font); int maxChar = fm.maxWidth(); if (maxChar < 2*fm.xHeight()) { @@ -212,7 +212,7 @@ public: if (m_columns <= 0) { m_columns = 1; } - reset(); + emit layoutChanged(); } private: QList<QChar> m_chars;