QTableView: replace QLinkedList with std::list
The object is never copied, so there's no point in using a cow'ed list implementation. Apart from the usual API adaptions (isEmpty() -> empty(), append() -> push_back()), alse replaced two foreach-loops with ranged-for. The first one does not call into out-of-line functions, and doesn't modify the container it iterates over, so is safe. The second does call into out-of-line functions, but they are const. The loop does not modify the container it iterates over, either, so is also safe (except for some fishy const_cast somewhere, or const being lost due to shallowness of const). Also replaced explicit-iterator loops with ranged-for where possible. Change-Id: I60b0f2d356846d527bfbaa6a0ecbb8395013b852 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
b703279235
commit
68eea0196e
@ -58,6 +58,8 @@
|
||||
#include <qaccessible.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/** \internal
|
||||
@ -65,7 +67,7 @@ QT_BEGIN_NAMESPACE
|
||||
*/
|
||||
void QSpanCollection::addSpan(QSpanCollection::Span *span)
|
||||
{
|
||||
spans.append(span);
|
||||
spans.push_back(span);
|
||||
Index::iterator it_y = index.lowerBound(-span->top());
|
||||
if (it_y == index.end() || it_y.key() != -span->top()) {
|
||||
//there is no spans that starts with the row in the index, so create a sublist for it.
|
||||
@ -132,7 +134,7 @@ void QSpanCollection::updateSpan(QSpanCollection::Span *span, int old_height)
|
||||
}
|
||||
|
||||
if (span->width() == 0 && span->height() == 0) {
|
||||
spans.removeOne(span);
|
||||
spans.remove(span);
|
||||
delete span;
|
||||
}
|
||||
}
|
||||
@ -212,15 +214,14 @@ void QSpanCollection::updateInsertedRows(int start, int end)
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << start << end << Qt::endl << index;
|
||||
#endif
|
||||
if (spans.isEmpty())
|
||||
if (spans.empty())
|
||||
return;
|
||||
|
||||
int delta = end - start + 1;
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug("Before");
|
||||
#endif
|
||||
for (SpanList::iterator it = spans.begin(); it != spans.end(); ++it) {
|
||||
Span *span = *it;
|
||||
for (Span *span : spans) {
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << span << *span;
|
||||
#endif
|
||||
@ -260,15 +261,14 @@ void QSpanCollection::updateInsertedColumns(int start, int end)
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << start << end << Qt::endl << index;
|
||||
#endif
|
||||
if (spans.isEmpty())
|
||||
if (spans.empty())
|
||||
return;
|
||||
|
||||
int delta = end - start + 1;
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug("Before");
|
||||
#endif
|
||||
for (SpanList::iterator it = spans.begin(); it != spans.end(); ++it) {
|
||||
Span *span = *it;
|
||||
for (Span *span : spans) {
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << span << *span;
|
||||
#endif
|
||||
@ -341,7 +341,7 @@ void QSpanCollection::updateRemovedRows(int start, int end)
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << start << end << Qt::endl << index;
|
||||
#endif
|
||||
if (spans.isEmpty())
|
||||
if (spans.empty())
|
||||
return;
|
||||
|
||||
SpanList spansToBeDeleted;
|
||||
@ -377,7 +377,7 @@ void QSpanCollection::updateRemovedRows(int start, int end)
|
||||
if (span->m_top == span->m_bottom && span->m_left == span->m_right)
|
||||
span->will_be_deleted = true;
|
||||
if (span->will_be_deleted) {
|
||||
spansToBeDeleted.append(span);
|
||||
spansToBeDeleted.push_back(span);
|
||||
it = spans.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
@ -389,7 +389,7 @@ void QSpanCollection::updateRemovedRows(int start, int end)
|
||||
foreach (QSpanCollection::Span *span, spans)
|
||||
qDebug() << span << *span;
|
||||
#endif
|
||||
if (spans.isEmpty()) {
|
||||
if (spans.empty()) {
|
||||
qDeleteAll(spansToBeDeleted);
|
||||
index.clear();
|
||||
return;
|
||||
@ -468,7 +468,7 @@ void QSpanCollection::updateRemovedColumns(int start, int end)
|
||||
#ifdef DEBUG_SPAN_UPDATE
|
||||
qDebug() << start << end << Qt::endl << index;
|
||||
#endif
|
||||
if (spans.isEmpty())
|
||||
if (spans.empty())
|
||||
return;
|
||||
|
||||
SpanList toBeDeleted;
|
||||
@ -504,7 +504,7 @@ void QSpanCollection::updateRemovedColumns(int start, int end)
|
||||
if (span->m_top == span->m_bottom && span->m_left == span->m_right)
|
||||
span->will_be_deleted = true;
|
||||
if (span->will_be_deleted) {
|
||||
toBeDeleted.append(span);
|
||||
toBeDeleted.push_back(span);
|
||||
it = spans.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
@ -516,7 +516,7 @@ void QSpanCollection::updateRemovedColumns(int start, int end)
|
||||
foreach (QSpanCollection::Span *span, spans)
|
||||
qDebug() << span << *span;
|
||||
#endif
|
||||
if (spans.isEmpty()) {
|
||||
if (spans.empty()) {
|
||||
qDeleteAll(toBeDeleted);
|
||||
index.clear();
|
||||
return;
|
||||
@ -552,13 +552,13 @@ bool QSpanCollection::checkConsistency() const
|
||||
for (SubIndex::const_iterator it = subIndex.begin(); it != subIndex.end(); ++it) {
|
||||
int x = -it.key();
|
||||
Span *span = it.value();
|
||||
if (!spans.contains(span) || span->left() != x
|
||||
|| y < span->top() || y > span->bottom())
|
||||
const bool contains = std::find(spans.begin(), spans.end(), span) != spans.end();
|
||||
if (!contains || span->left() != x || y < span->top() || y > span->bottom())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const Span *span, spans) {
|
||||
for (const Span *span : spans) {
|
||||
if (span->width() < 1 || span->height() < 1
|
||||
|| (span->width() == 1 && span->height() == 1))
|
||||
return false;
|
||||
@ -1923,7 +1923,7 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF
|
||||
int right = qMax(d->visualColumn(tl.column()), d->visualColumn(br.column()));
|
||||
do {
|
||||
expanded = false;
|
||||
foreach (QSpanCollection::Span *it, d->spans.spans) {
|
||||
for (QSpanCollection::Span *it : d->spans.spans) {
|
||||
const QSpanCollection::Span &span = *it;
|
||||
int t = d->visualRow(span.top());
|
||||
int l = d->visualColumn(span.left());
|
||||
|
@ -53,12 +53,13 @@
|
||||
|
||||
#include <QtWidgets/private/qtwidgetsglobal_p.h>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QLinkedList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QDebug>
|
||||
#include "private/qabstractitemview_p.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
QT_REQUIRE_CONFIG(tableview);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -115,7 +116,7 @@ public:
|
||||
bool checkConsistency() const;
|
||||
#endif
|
||||
|
||||
typedef QLinkedList<Span *> SpanList;
|
||||
typedef std::list<Span *> SpanList;
|
||||
SpanList spans; //lists of all spans
|
||||
private:
|
||||
//the indexes are negative so the QMap::lowerBound do what i need.
|
||||
@ -210,7 +211,7 @@ public:
|
||||
return span(row, column).width();
|
||||
}
|
||||
inline bool hasSpans() const {
|
||||
return !spans.spans.isEmpty();
|
||||
return !spans.spans.empty();
|
||||
}
|
||||
inline int rowSpanHeight(int row, int span) const {
|
||||
return sectionSpanSize(verticalHeader, row, span);
|
||||
|
Loading…
Reference in New Issue
Block a user