+ const int itemCount = m_model->count();
+ int rangesItemCount = 0;
+ foreach (const KItemRange& range, itemRanges) {
+ rangesItemCount += range.count;
+ }
+
+ if (itemCount == rangesItemCount) {
+ // The sizes of all roles need to be determined
+ m_visibleRolesSizes = visibleRolesSizes(itemRanges);
+ } else {
+ // Only a sub range of the roles need to be determined.
+ // The chances are good that the sizes of the sub ranges
+ // already fit into the available sizes and hence no
+ // expensive update might be required.
+ bool updateRequired = false;
+
+ const QHash<QByteArray, QSizeF> updatedSizes = visibleRolesSizes(itemRanges);
+ QHashIterator<QByteArray, QSizeF> it(updatedSizes);
+ while (it.hasNext()) {
+ it.next();
+ const QByteArray& role = it.key();
+ const QSizeF& updatedSize = it.value();
+ const QSizeF currentSize = m_visibleRolesSizes.value(role);
+ if (updatedSize.width() > currentSize.width() || updatedSize.height() > currentSize.height()) {
+ m_visibleRolesSizes.insert(role, updatedSize);
+ updateRequired = true;
+ }
+ }
+
+ if (!updateRequired) {
+ // All the updated sizes are smaller than the current sizes and no change
+ // of the roles-widths is required
+ return;
+ }
+ }
+