From f109f5b8a9c7e6939dfd6c6f72a3b67548f5483c Mon Sep 17 00:00:00 2001 From: Eckhart Koppen Date: Wed, 16 Nov 2011 09:47:45 +0200 Subject: Fix Q_ASSERT usage in case -force-asserts is enabled Certain Q_ASSERT usages are not compiling with -force-asserts since they are checking for instance variables or other items which are not available in release mode. This fix guards the asserts to only be enabled in debug mode. Change-Id: I2ed74e3d5118608361e8c924e93d8ff0efdc8eab Reviewed-by: Lars Knoll --- src/gui/text/qtextdocument_p.cpp | 8 ++++++++ src/widgets/itemviews/qheaderview.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index f4cb742d34..e70c5e63b5 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -322,7 +322,9 @@ void QTextDocumentPrivate::setLayout(QAbstractTextDocumentLayout *layout) void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op) { // ##### optimize when only appending to the fragment! +#ifndef QT_NO_DEBUG Q_ASSERT(noBlockInString(text.mid(strPos, length))); +#endif split(pos); uint x = fragments.insert_single(pos, length); @@ -478,7 +480,9 @@ void QTextDocumentPrivate::insert(int pos, const QString &str, int format) if (str.size() == 0) return; +#ifndef QT_NO_DEBUG Q_ASSERT(noBlockInString(str)); +#endif int strPos = text.length(); text.append(str); @@ -496,7 +500,9 @@ int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand:: Q_ASSERT(blocks.size(b) > length); Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length); +#ifndef QT_NO_DEBUG Q_ASSERT(noBlockInString(text.mid(fragments.fragment(x)->stringPosition, length))); +#endif blocks.setSize(b, blocks.size(b)-length); @@ -630,7 +636,9 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O if (key+1 != blocks.position(b)) { // qDebug("remove_string from %d length %d", key, X->size_array[0]); +#ifndef QT_NO_DEBUG Q_ASSERT(noBlockInString(text.mid(X->stringPosition, X->size_array[0]))); +#endif w = remove_string(key, X->size_array[0], op); if (needsInsert) { diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index aee39a5ea1..2ad75b7263 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3115,12 +3115,16 @@ void QHeaderViewPrivate::createSectionSpan(int start, int end, int size, QHeader sectionSpans[i].resizeMode = mode; // ### check if we can merge the section with any of its neighbours removeSpans(spansToRemove); +#ifndef QT_NO_DEBUG Q_ASSERT(initial_section_count == headerSectionCount()); +#endif return; } else if (start > start_section && end < end_section) { if (sectionSpans.at(i).sectionSize() == span.sectionSize() && sectionSpans.at(i).resizeMode == span.resizeMode) { +#ifndef QT_NO_DEBUG Q_ASSERT(initial_section_count == headerSectionCount()); +#endif return; } // the new span is in the middle of the old span, so we have to split it @@ -3149,9 +3153,13 @@ void QHeaderViewPrivate::createSectionSpan(int start, int end, int size, QHeader int last_span_size = section_size * last_span_count; sectionSpans.insert(i + 2, SectionSpan(last_span_size, last_span_count, span_mode)); length += last_span_size; +#ifndef QT_NO_DEBUG Q_ASSERT(span_count == first_span_count + mid_span_count + last_span_count); +#endif removeSpans(spansToRemove); +#ifndef QT_NO_DEBUG Q_ASSERT(initial_section_count == headerSectionCount()); +#endif return; } else if (start > start_section && start <= end_section && end >= end_section) { // the new span covers the last part of the existing span @@ -3167,7 +3175,9 @@ void QHeaderViewPrivate::createSectionSpan(int start, int end, int size, QHeader sectionSpans.insert(i + 1, span); // insert after length += span.size; removeSpans(spansToRemove); +#ifndef QT_NO_DEBUG Q_ASSERT(initial_section_count == headerSectionCount()); +#endif return; } } else if (end < end_section && end >= start_section && start <= start_section) { @@ -3183,7 +3193,9 @@ void QHeaderViewPrivate::createSectionSpan(int start, int end, int size, QHeader sectionSpans.insert(i, span); // insert before length += span.size; removeSpans(spansToRemove); +#ifndef QT_NO_DEBUG Q_ASSERT(initial_section_count == headerSectionCount()); +#endif return; } start_section += section_count; -- cgit v1.2.3