From 15a21652d178e4a298bb522d777602620cbd9938 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Thu, 5 Nov 2009 13:13:26 +0100 Subject: API review: Add convenience functions using QMargins We added the class QMargins, so we should use it wherever we deal with margins, as a convenience to the users. Reviewed-by: Andreas Aardal Hanssen --- src/gui/kernel/qlayout.cpp | 32 ++++++++++++++++++++++++++++++++ src/gui/kernel/qlayout.h | 3 +++ src/gui/widgets/qabstractscrollarea.cpp | 17 +++++++++++++++++ src/gui/widgets/qabstractscrollarea.h | 2 ++ src/gui/widgets/qlineedit.cpp | 23 +++++++++++++++++++++++ src/gui/widgets/qlineedit.h | 3 +++ 6 files changed, 80 insertions(+) diff --git a/src/gui/kernel/qlayout.cpp b/src/gui/kernel/qlayout.cpp index 70cd5a5..5d44b3d 100644 --- a/src/gui/kernel/qlayout.cpp +++ b/src/gui/kernel/qlayout.cpp @@ -496,6 +496,21 @@ void QLayout::setContentsMargins(int left, int top, int right, int bottom) } /*! + \since 4.6 + + Sets the \a margins to use around the layout. + + By default, QLayout uses the values provided by the style. On + most platforms, the margin is 11 pixels in all directions. + + \sa contentsMargins() +*/ +void QLayout::setContentsMargins(const QMargins &margins) +{ + setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); +} + +/*! \since 4.3 Extracts the left, top, right, and bottom margins used around the @@ -521,6 +536,23 @@ void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) c } /*! + \since 4.6 + + Returns the margins used around the layout. + + By default, QLayout uses the values provided by the style. On + most platforms, the margin is 11 pixels in all directions. + + \sa setContentsMargins() +*/ +QMargins QLayout::contentsMargins() const +{ + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + return QMargins(left, top, right, bottom); +} + +/*! \since 4.3 Returns the layout's geometry() rectangle, but taking into account the diff --git a/src/gui/kernel/qlayout.h b/src/gui/kernel/qlayout.h index 83cbab6..2f30294 100644 --- a/src/gui/kernel/qlayout.h +++ b/src/gui/kernel/qlayout.h @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -122,7 +123,9 @@ public: void setSpacing(int); void setContentsMargins(int left, int top, int right, int bottom); + void setContentsMargins(const QMargins &margins); void getContentsMargins(int *left, int *top, int *right, int *bottom) const; + QMargins contentsMargins() const; QRect contentsRect() const; bool setAlignment(QWidget *w, Qt::Alignment alignment); diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 7d81d5a..48099ef 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -51,6 +51,7 @@ #include "qdebug.h" #include "qboxlayout.h" #include "qpainter.h" +#include "qmargins.h" #include "qabstractscrollarea_p.h" #include @@ -868,6 +869,22 @@ void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int b } /*! + \since 4.6 + Sets \a margins around the scrolling area. This is useful for + applications such as spreadsheets with "locked" rows and columns. + The marginal space is is left blank; put widgets in the unused + area. + + By default all margins are zero. + +*/ +void QAbstractScrollArea::setViewportMargins(const QMargins &margins) +{ + setViewportMargins(margins.left(), margins.top(), + margins.right(), margins.bottom()); +} + +/*! \fn bool QAbstractScrollArea::event(QEvent *event) \reimp diff --git a/src/gui/widgets/qabstractscrollarea.h b/src/gui/widgets/qabstractscrollarea.h index b3a1861..18d1e96 100644 --- a/src/gui/widgets/qabstractscrollarea.h +++ b/src/gui/widgets/qabstractscrollarea.h @@ -52,6 +52,7 @@ QT_MODULE(Gui) #ifndef QT_NO_SCROLLAREA +class QMargins; class QScrollBar; class QAbstractScrollAreaPrivate; @@ -95,6 +96,7 @@ protected Q_SLOTS: protected: QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = 0); void setViewportMargins(int left, int top, int right, int bottom); + void setViewportMargins(const QMargins &margins); bool event(QEvent *); virtual bool viewportEvent(QEvent *); diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index e4252b5..f5dbe1c 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1102,6 +1102,17 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) } /*! + \since 4.6 + Sets the \a margins around the text inside the frame. + + See also textMargins(). +*/ +void QLineEdit::setTextMargins(const QMargins &margins) +{ + setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); +} + +/*! Returns the widget's text margins for \a left, \a top, \a right, and \a bottom. \since 4.5 @@ -1121,6 +1132,18 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con } /*! + \since 4.6 + Returns the widget's text margins. + + \sa setTextMargins() +*/ +QMargins QLineEdit::textMargins() const +{ + Q_D(const QLineEdit); + return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); +} + +/*! \property QLineEdit::inputMask \brief The validation input mask diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h index 214509a..ac918c7 100644 --- a/src/gui/widgets/qlineedit.h +++ b/src/gui/widgets/qlineedit.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -158,7 +159,9 @@ public: bool hasAcceptableInput() const; void setTextMargins(int left, int top, int right, int bottom); + void setTextMargins(const QMargins &margins); void getTextMargins(int *left, int *top, int *right, int *bottom) const; + QMargins textMargins() const; public Q_SLOTS: void setText(const QString &); -- cgit v0.12 From 863369deceeb254ea71724a247953fd0760ae30b Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Thu, 5 Nov 2009 14:26:32 +0100 Subject: API review: QMatrix::det() -> QMatrix::determinant(), matching math3d After an API review of the new math3d classes, the full name was considered better than the short version. Therefore we obsolete the short function, and introduce the longer version. Reviewed-by: Andreas Aardal Hanssen --- src/gui/painting/qmatrix.cpp | 18 ++++++++++++++---- src/gui/painting/qmatrix.h | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index 88b2b7a..17b7241 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -85,7 +85,7 @@ QT_BEGIN_NAMESPACE which returns true if the matrix is non-singular (i.e. AB = BA = I). The inverted() function returns an inverted copy of \e this matrix if it is invertible (otherwise it returns the identity - matrix). In addition, QMatrix provides the det() function + matrix). In addition, QMatrix provides the determinant() function returning the matrix's determinant. Finally, the QMatrix class supports matrix multiplication, and @@ -959,9 +959,19 @@ QMatrix &QMatrix::rotate(qreal a) */ /*! + \obsolete \fn qreal QMatrix::det() const Returns the matrix's determinant. + + \sa determinant() +*/ + +/*! + \since 4.6 + \fn qreal QMatrix::determinant() const + + Returns the matrix's determinant. */ /*! @@ -985,8 +995,8 @@ QMatrix &QMatrix::rotate(qreal a) QMatrix QMatrix::inverted(bool *invertible) const { - qreal determinant = det(); - if (determinant == 0.0) { + qreal dtr = determinant(); + if (dtr == 0.0) { if (invertible) *invertible = false; // singular matrix return QMatrix(true); @@ -994,7 +1004,7 @@ QMatrix QMatrix::inverted(bool *invertible) const else { // invertible matrix if (invertible) *invertible = true; - qreal dinv = 1.0/determinant; + qreal dinv = 1.0/dtr; return QMatrix((_m22*dinv), (-_m12*dinv), (-_m21*dinv), (_m11*dinv), ((_m21*_dy - _m22*_dx)*dinv), diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h index 8887f0e..152b3c9 100644 --- a/src/gui/painting/qmatrix.h +++ b/src/gui/painting/qmatrix.h @@ -101,7 +101,8 @@ public: QMatrix &rotate(qreal a); bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); } - qreal det() const { return _m11*_m22 - _m12*_m21; } + qreal determinant() const { return _m11*_m22 - _m12*_m21; } + QT_DEPRECATED qreal det() const { return _m11*_m22 - _m12*_m21; } QMatrix inverted(bool *invertible = 0) const; -- cgit v0.12 From 98e0b95581f46b94773a55195e0e67a466c333ed Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Thu, 5 Nov 2009 15:18:35 +0100 Subject: API review: QRegExp::numCaptures() -> QRegExp::captureCount() QRegExp::numCaptures() is marked as obsolete. Replaced all usage in Qt and test-cases. Reviewed-by: Andreas Aardal Hanssen --- examples/tools/regexp/regexpdialog.cpp | 4 ++-- src/corelib/tools/qregexp.cpp | 18 +++++++++++--- src/corelib/tools/qregexp.h | 3 ++- src/corelib/tools/qstring.cpp | 2 +- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 2 +- src/testlib/qbenchmarkvalgrind.cpp | 2 +- src/xmlpatterns/functions/qpatternmatchingfns.cpp | 2 +- src/xmlpatterns/functions/qpatternplatform_p.h | 2 +- tests/auto/qregexp/tst_qregexp.cpp | 28 +++++++++++----------- tests/auto/qscriptengine/tst_qscriptengine.cpp | 2 +- tests/auto/qtextdocument/tst_qtextdocument.cpp | 10 ++++---- .../designer/src/designer/qdesigner_formwindow.cpp | 2 +- tools/makeqpf/mainwindow.cpp | 2 +- 13 files changed, 46 insertions(+), 33 deletions(-) diff --git a/examples/tools/regexp/regexpdialog.cpp b/examples/tools/regexp/regexpdialog.cpp index 08c7a97..3becc2b 100644 --- a/examples/tools/regexp/regexpdialog.cpp +++ b/examples/tools/regexp/regexpdialog.cpp @@ -180,8 +180,8 @@ void RegExpDialog::refresh() indexEdit->setText(QString::number(rx.indexIn(text))); matchedLengthEdit->setText(QString::number(rx.matchedLength())); for (int i = 0; i < MaxCaptures; ++i) { - captureLabels[i]->setEnabled(i <= rx.numCaptures()); - captureEdits[i]->setEnabled(i <= rx.numCaptures()); + captureLabels[i]->setEnabled(i <= rx.captureCount()); + captureEdits[i]->setEnabled(i <= rx.captureCount()); captureEdits[i]->setText(rx.cap(i)); } diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 1f23211..3ca8ab9 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1083,7 +1083,7 @@ public: bool isValid() const { return valid; } const QString &errorString() const { return yyError; } - int numCaptures() const { return officialncap; } + int captureCount() const { return officialncap; } int createState(QChar ch); int createState(const QRegExpCharClass &cc); @@ -1378,7 +1378,7 @@ void QRegExpMatchState::prepareForMatch(QRegExpEngine *eng) #else int newSlideTabSize = 0; #endif - int numCaptures = eng->numCaptures(); + int numCaptures = eng->captureCount(); int newCapturedSize = 2 + 2 * numCaptures; bigArray = q_check_ptr((int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int))); @@ -4168,12 +4168,24 @@ int QRegExp::matchedLength() const #ifndef QT_NO_REGEXP_CAPTURE /*! + \obsolete Returns the number of captures contained in the regular expression. + + \sa captureCount() */ int QRegExp::numCaptures() const { + return captureCount(); +} + +/*! + \since 4.6 + Returns the number of captures contained in the regular expression. + */ +int QRegExp::captureCount() const +{ prepareEngine(priv); - return priv->eng->numCaptures(); + return priv->eng->captureCount(); } /*! diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index 1a7cf53..2bad40e 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -119,7 +119,8 @@ public: #endif int matchedLength() const; #ifndef QT_NO_REGEXP_CAPTURE - int numCaptures() const; + QT_DEPRECATED int numCaptures() const; + int captureCount() const; QStringList capturedTexts() const; QStringList capturedTexts(); QString cap(int nth = 0) const; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 55ad28d..f7321ef 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2681,7 +2681,7 @@ QString& QString::replace(const QRegExp &rx, const QString &after) realloc(); int index = 0; - int numCaptures = rx2.numCaptures(); + int numCaptures = rx2.captureCount(); int al = after.length(); QRegExp::CaretMode caretMode = QRegExp::CaretAtZero; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 449bc0d..7ddd992 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -1066,7 +1066,7 @@ static inline QColor colorFromName(const QString &name) QRegExp rx("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])"); rx.setCaseSensitivity(Qt::CaseInsensitive); if (rx.exactMatch(name)) { - Q_ASSERT(rx.numCaptures() == 4); + Q_ASSERT(rx.captureCount() == 4); int ints[4]; int i; for (i=0; i<4; ++i) { diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp index 3398737..88cb37f 100644 --- a/src/testlib/qbenchmarkvalgrind.cpp +++ b/src/testlib/qbenchmarkvalgrind.cpp @@ -114,7 +114,7 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName) while (!file.atEnd()) { const QString line(QLatin1String(file.readLine())); if (rxValue.indexIn(line) != -1) { - Q_ASSERT(rxValue.numCaptures() == 1); + Q_ASSERT(rxValue.captureCount() == 1); bool ok; val = rxValue.cap(1).toLongLong(&ok); Q_ASSERT(ok); diff --git a/src/xmlpatterns/functions/qpatternmatchingfns.cpp b/src/xmlpatterns/functions/qpatternmatchingfns.cpp index cb421cb..a7275f6 100644 --- a/src/xmlpatterns/functions/qpatternmatchingfns.cpp +++ b/src/xmlpatterns/functions/qpatternmatchingfns.cpp @@ -82,7 +82,7 @@ Item ReplaceFN::evaluateSingleton(const DynamicContext::Ptr &context) const if(arg) input = arg.stringValue(); - const QString replacement(m_replacementString.isNull() ? parseReplacement(regexp.numCaptures(), context) + const QString replacement(m_replacementString.isNull() ? parseReplacement(regexp.captureCount(), context) : m_replacementString); diff --git a/src/xmlpatterns/functions/qpatternplatform_p.h b/src/xmlpatterns/functions/qpatternplatform_p.h index e007381..a85cd0c 100644 --- a/src/xmlpatterns/functions/qpatternplatform_p.h +++ b/src/xmlpatterns/functions/qpatternplatform_p.h @@ -180,7 +180,7 @@ namespace QPatternist inline int PatternPlatform::captureCount() const { if(m_compiledParts.testFlag(PatternPrecompiled)) - return m_pattern.numCaptures(); + return m_pattern.captureCount(); else return -1; } diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp index 86d831e..e305386 100644 --- a/tests/auto/qregexp/tst_qregexp.cpp +++ b/tests/auto/qregexp/tst_qregexp.cpp @@ -628,7 +628,7 @@ void tst_QRegExp::capturedTexts() QRegExp rx7("([A-Za-z_])([A-Za-z_0-9]*)"); rx7.setCaseSensitivity(Qt::CaseSensitive); rx7.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx7.numCaptures(), 2); + QCOMPARE(rx7.captureCount(), 2); int pos = rx7.indexIn("(10 + delta4) * 32"); QCOMPARE(pos, 6); @@ -1177,36 +1177,36 @@ void tst_QRegExp::prepareEngineOptimization() QCOMPARE(rx1.capturedTexts(), QStringList() << "" << "" << "" << ""); QCOMPARE(rx1.matchedLength(), -1); QCOMPARE(rx1.matchedLength(), -1); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.exactMatch("foo"), true); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); QCOMPARE(rx1.exactMatch("foo"), true); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); QRegExp rx2 = rx1; - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 3); QCOMPARE(rx1.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx1.pos(3), 2); - QCOMPARE(rx2.numCaptures(), 3); + QCOMPARE(rx2.captureCount(), 3); QCOMPARE(rx2.matchedLength(), 3); QCOMPARE(rx2.capturedTexts(), QStringList() << "foo" << "f" << "o" << "o"); QCOMPARE(rx2.pos(3), 2); QCOMPARE(rx1.exactMatch("fo"), true); - QCOMPARE(rx1.numCaptures(), 3); + QCOMPARE(rx1.captureCount(), 3); QCOMPARE(rx1.matchedLength(), 2); QCOMPARE(rx1.capturedTexts(), QStringList() << "fo" << "f" << "o" << ""); QCOMPARE(rx1.pos(2), 1); @@ -1245,25 +1245,25 @@ void tst_QRegExp::prepareEngineOptimization() rx11.setPatternSyntax(QRegExp::Wildcard); QVERIFY(!rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPatternSyntax(QRegExp::RegExp); QVERIFY(!rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPattern("(foo)"); QVERIFY(rx11.isValid()); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), -1); QCOMPARE(rx11.indexIn("ofoo"), 1); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), 3); rx11.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), 3); /* @@ -1278,11 +1278,11 @@ void tst_QRegExp::prepareEngineOptimization() QCOMPARE(rx11.matchedLength(), 3); rx11.setPatternSyntax(QRegExp::Wildcard); - QCOMPARE(rx11.numCaptures(), 0); + QCOMPARE(rx11.captureCount(), 0); QCOMPARE(rx11.matchedLength(), -1); rx11.setPatternSyntax(QRegExp::RegExp); - QCOMPARE(rx11.numCaptures(), 1); + QCOMPARE(rx11.captureCount(), 1); QCOMPARE(rx11.matchedLength(), -1); } diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 804534f..8eaad78 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -4485,7 +4485,7 @@ void tst_QScriptEngine::qRegExpInport() QScriptValue result = func.call(QScriptValue(), QScriptValueList() << string << rexp); rx.indexIn(string); - for (int i = 0; i <= rx.numCaptures(); i++) { + for (int i = 0; i <= rx.captureCount(); i++) { QCOMPARE(result.property(i).toString(), rx.cap(i)); } } diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 5237438..1d54409 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -1721,21 +1721,21 @@ void tst_QTextDocument::capitalizationHtmlInExport() const QString smallcaps = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("font-variant:small-caps;")); cf.setFontCapitalization(QFont::AllUppercase); cursor.mergeCharFormat(cf); const QString uppercase = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("text-transform:uppercase;")); cf.setFontCapitalization(QFont::AllLowercase); cursor.mergeCharFormat(cf); const QString lowercase = doc->toHtml(); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("text-transform:lowercase;")); doc->setHtml(smallcaps); @@ -1761,14 +1761,14 @@ void tst_QTextDocument::wordspacingHtmlExport() cursor.mergeCharFormat(cf); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:4px;")); cf.setFontWordSpacing(-8.5); cursor.mergeCharFormat(cf); QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.numCaptures(), 1); + QCOMPARE(re.captureCount(), 1); QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:-8.5px;")); } diff --git a/tools/designer/src/designer/qdesigner_formwindow.cpp b/tools/designer/src/designer/qdesigner_formwindow.cpp index b2af257..05937cd 100644 --- a/tools/designer/src/designer/qdesigner_formwindow.cpp +++ b/tools/designer/src/designer/qdesigner_formwindow.cpp @@ -182,7 +182,7 @@ int QDesignerFormWindow::getNumberOfUntitledWindows() const if (rx.indexIn(title) != -1) { if (maxUntitled == 0) ++maxUntitled; - if (rx.numCaptures() > 1) { + if (rx.captureCount() > 1) { const QString numberCapture = rx.cap(2); if (!numberCapture.isEmpty()) maxUntitled = qMax(numberCapture.toInt(), maxUntitled); diff --git a/tools/makeqpf/mainwindow.cpp b/tools/makeqpf/mainwindow.cpp index 8fa372b..45ea0a3 100644 --- a/tools/makeqpf/mainwindow.cpp +++ b/tools/makeqpf/mainwindow.cpp @@ -269,7 +269,7 @@ void MainWindow::populateCharacterRanges() if (line.isEmpty() || line.startsWith(QLatin1Char('#'))) continue; - if (!rangeExpr.exactMatch(line) || rangeExpr.numCaptures() != 3) + if (!rangeExpr.exactMatch(line) || rangeExpr.captureCount() != 3) continue; QPF::CharacterRange range; -- cgit v0.12 From e53c26b52c890f242491e0dfed4201313d98f720 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 09:33:33 +0100 Subject: API review: Rename functions numColors(), setNumColors() and numBytes() QPaintDevice and QImage used the functions numColors(), setNumColors(), and numBytes(). However, this is not consistent with the rest of the Qt API which uses *Count() and set*Count(). Removed all usage of these functions inside Qt and test-cases. Reviewed-by: Andreas Aardal Hanssen --- demos/composition/composition.cpp | 2 +- .../WebCore/platform/qt/PlatformScreenQt.cpp | 2 +- src/gui/embedded/qwscursor_qws.cpp | 2 +- src/gui/image/qbmphandler.cpp | 22 ++-- src/gui/image/qimage.cpp | 134 +++++++++++++-------- src/gui/image/qimage.h | 9 +- src/gui/image/qpixmap_mac.cpp | 14 +-- src/gui/image/qpixmap_qws.cpp | 2 +- src/gui/image/qpixmap_raster.cpp | 2 +- src/gui/image/qpixmap_s60.cpp | 8 +- src/gui/image/qpixmap_x11.cpp | 22 ++-- src/gui/image/qpixmapdata.cpp | 2 +- src/gui/image/qpixmapdata_p.h | 3 +- src/gui/image/qpnghandler.cpp | 12 +- src/gui/image/qppmhandler.cpp | 6 +- src/gui/image/qxbmhandler.cpp | 2 +- src/gui/image/qxpmhandler.cpp | 2 +- src/gui/itemviews/qitemdelegate.cpp | 2 +- src/gui/kernel/qcursor_win.cpp | 8 +- src/gui/kernel/qwidget_x11.cpp | 2 +- src/gui/painting/qpaintdevice.h | 3 +- src/gui/painting/qpaintengine_mac.cpp | 2 +- src/gui/styles/qs60style.cpp | 2 +- src/gui/text/qfontengine_qpf.cpp | 4 +- src/multimedia/video/qimagevideobuffer.cpp | 2 +- src/opengl/qgl.cpp | 2 +- src/opengl/qpixmapdata_gl.cpp | 2 +- .../gfxdrivers/directfb/qdirectfbpaintdevice.cpp | 2 +- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 6 +- src/plugins/imageformats/gif/qgifhandler.cpp | 4 +- src/plugins/imageformats/ico/qicohandler.cpp | 4 +- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 6 +- src/qt3support/painting/q3paintdevicemetrics.h | 2 +- src/tools/uic3/embed.cpp | 4 +- tests/arthur/common/paintcommands.cpp | 16 +-- tests/arthur/common/paintcommands.h | 2 +- tests/auto/qdatastream/tst_qdatastream.cpp | 2 +- tests/auto/qimage/tst_qimage.cpp | 24 ++-- tests/auto/qimagewriter/tst_qimagewriter.cpp | 2 +- tests/auto/qitemdelegate/tst_qitemdelegate.cpp | 2 +- tests/auto/qpainter/tst_qpainter.cpp | 4 +- tests/auto/qpixmap/tst_qpixmap.cpp | 6 +- tools/makeqpf/qpf2.cpp | 4 +- tools/qvfb/qvfbview.cpp | 6 +- 44 files changed, 207 insertions(+), 164 deletions(-) diff --git a/demos/composition/composition.cpp b/demos/composition/composition.cpp index 24e9187..1025d3c 100644 --- a/demos/composition/composition.cpp +++ b/demos/composition/composition.cpp @@ -457,7 +457,7 @@ void CompositionRenderer::paint(QPainter *painter) #ifdef Q_WS_QWS m_buffer = m_base_buffer; #else - memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.numBytes()); + memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.byteCount()); #endif { diff --git a/src/3rdparty/webkit/WebCore/platform/qt/PlatformScreenQt.cpp b/src/3rdparty/webkit/WebCore/platform/qt/PlatformScreenQt.cpp index 8221760..442ffa3 100644 --- a/src/3rdparty/webkit/WebCore/platform/qt/PlatformScreenQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/qt/PlatformScreenQt.cpp @@ -72,7 +72,7 @@ int screenDepthPerComponent(Widget* w) bool screenIsMonochrome(Widget* w) { - return QApplication::desktop()->screen(screenNumber(w))->numColors() < 2; + return QApplication::desktop()->screen(screenNumber(w))->colorCount() < 2; } FloatRect screenRect(Widget* w) diff --git a/src/gui/embedded/qwscursor_qws.cpp b/src/gui/embedded/qwscursor_qws.cpp index 07271e1..7d5a3d1 100644 --- a/src/gui/embedded/qwscursor_qws.cpp +++ b/src/gui/embedded/qwscursor_qws.cpp @@ -534,7 +534,7 @@ void QWSCursor::set(const uchar *data, const uchar *mask, if (!width || !height || !data || !mask || cursor.isNull()) return; - cursor.setNumColors(3); + cursor.setColorCount(3); cursor.setColor(0, 0xff000000); cursor.setColor(1, 0xffffffff); cursor.setColor(2, 0x00000000); diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp index 4b6fcba..f3eb7c3 100644 --- a/src/gui/image/qbmphandler.cpp +++ b/src/gui/image/qbmphandler.cpp @@ -52,9 +52,9 @@ QT_BEGIN_NAMESPACE static void swapPixel01(QImage *image) // 1-bpp: swap 0 and 1 pixels { int i; - if (image->depth() == 1 && image->numColors() == 2) { + if (image->depth() == 1 && image->colorCount() == 2) { register uint *p = (uint *)image->bits(); - int nbytes = image->numBytes(); + int nbytes = image->byteCount(); for (i=0; iisWritable()) return false; - if (image.depth() == 8 && image.numColors() <= 16) { + if (image.depth() == 8 && image.colorCount() <= 16) { bpl_bmp = (((bpl+1)/2+3)/4)*4; nbits = 4; } else if (image.depth() == 32) { @@ -554,23 +554,23 @@ bool qt_write_dib(QDataStream &s, QImage image) bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX() : 2834; // 72 dpi default bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834; - bi.biClrUsed = image.numColors(); - bi.biClrImportant = image.numColors(); + bi.biClrUsed = image.colorCount(); + bi.biClrImportant = image.colorCount(); s << bi; // write info header if (s.status() != QDataStream::Ok) return false; if (image.depth() != 32) { // write color table - uchar *color_table = new uchar[4*image.numColors()]; + uchar *color_table = new uchar[4*image.colorCount()]; uchar *rgb = color_table; QVector c = image.colorTable(); - for (int i=0; iwrite((char *)color_table, 4*image.numColors()) == -1) { + if (d->write((char *)color_table, 4*image.colorCount()) == -1) { delete [] color_table; return false; } @@ -754,7 +754,7 @@ bool QBmpHandler::write(const QImage &img) int bpl = image.bytesPerLine(); // Code partially repeated in qt_write_dib - if (image.depth() == 8 && image.numColors() <= 16) { + if (image.depth() == 8 && image.colorCount() <= 16) { bpl_bmp = (((bpl+1)/2+3)/4)*4; } else if (image.depth() == 32) { bpl_bmp = ((image.width()*24+31)/32)*4; @@ -771,7 +771,7 @@ bool QBmpHandler::write(const QImage &img) // write file header bf.bfReserved1 = 0; bf.bfReserved2 = 0; - bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.numColors() * 4; + bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.colorCount() * 4; bf.bfSize = bf.bfOffBits + bpl_bmp*image.height(); s << bf; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 21ca1e3..6d96d7a 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -449,7 +449,7 @@ bool QImageData::checkForAlphaPixels() const to the pixel() function. The pixel() function returns the color as a QRgb value indepedent of the image's format. - In case of monochrome and 8-bit images, the numColors() and + In case of monochrome and 8-bit images, the colorCount() and colorTable() functions provide information about the color components used to store the image data: The colorTable() function returns the image's entire color table. To obtain a single entry, @@ -484,7 +484,7 @@ bool QImageData::checkForAlphaPixels() const depths are 1 (monochrome), 8 and 32 (for more information see the \l {QImage#Image Formats}{Image Formats} section). - The format(), bytesPerLine(), and numBytes() functions provide + The format(), bytesPerLine(), and byteCount() functions provide low-level information about the data stored in the image. The cacheKey() function returns a number that uniquely @@ -623,7 +623,7 @@ bool QImageData::checkForAlphaPixels() const \o Sets the color table used to translate color indexes. Only monochrome and 8-bit formats. \row - \o setNumColors() + \o setColorCount() \o Resizes the color table. Only monochrome and 8-bit formats. \endtable @@ -906,7 +906,7 @@ QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QIm If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. */ QImage::QImage(uchar* data, int width, int height, Format format) : QPaintDevice() @@ -928,7 +928,7 @@ QImage::QImage(uchar* data, int width, int height, Format format) If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, @@ -954,7 +954,7 @@ QImage::QImage(const uchar* data, int width, int height, Format format) If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. */ QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format) :QPaintDevice() @@ -974,7 +974,7 @@ QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format form If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, @@ -1126,7 +1126,7 @@ QImage::QImage(const QImage &image) Use the constructor that accepts a width, a height and a format (i.e. specifying the depth and bit order), in combination with the - setNumColors() function, instead. + setColorCount() function, instead. \oldcode QImage image(width, height, depth, numColors); @@ -1135,15 +1135,15 @@ QImage::QImage(const QImage &image) // For 8 bit images the default number of colors is 256. If // another number of colors is required it can be specified - // using the setNumColors() function. - image.setNumColors(numColors); + // using the setColorCount() function. + image.setColorCount(numColors); \endcode */ -QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder) +QImage::QImage(int w, int h, int depth, int colorCount, Endian bitOrder) : QPaintDevice() { - d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors); + d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), colorCount); } /*! @@ -1152,7 +1152,7 @@ QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder) Use the constructor that accepts a size and a format (i.e. specifying the depth and bit order), in combination with the - setNumColors() function, instead. + setColorCount() function, instead. \oldcode QSize mySize(width, height); @@ -1163,8 +1163,8 @@ QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder) // For 8 bit images the default number of colors is 256. If // another number of colors is required it can be specified - // using the setNumColors() function. - image.setNumColors(numColors); + // using the setColorCount() function. + image.setColorCount(numColors); \endcode */ QImage::QImage(const QSize& size, int depth, int numColors, Endian bitOrder) @@ -1232,7 +1232,7 @@ QImage::QImage(uchar* data, int w, int h, int depth, const QRgb* colortable, int for (int i = 0; i < numColors; ++i) d->colortable[i] = colortable[i]; } else if (numColors) { - setNumColors(numColors); + setColorCount(numColors); } } @@ -1283,7 +1283,7 @@ QImage::QImage(uchar* data, int w, int h, int depth, int bpl, const QRgb* colort for (int i = 0; i < numColors; ++i) d->colortable[i] = colortable[i]; } else if (numColors) { - setNumColors(numColors); + setColorCount(numColors); } } #endif // Q_WS_QWS @@ -1592,17 +1592,31 @@ int QImage::depth() const } /*! + \obsolete \fn int QImage::numColors() const Returns the size of the color table for the image. - Notice that numColors() returns 0 for 32-bpp images because these + \sa setColorCount() +*/ +int QImage::numColors() const +{ + return d ? d->colortable.size() : 0; +} + +/*! + \since 4.6 + \fn int QImage::colorCount() const + + Returns the size of the color table for the image. + + Notice that colorCount() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as ARGB quadruplets. - \sa setNumColors(), {QImage#Image Information}{Image Information} + \sa setColorCount(), {QImage#Image Information}{Image Information} */ -int QImage::numColors() const +int QImage::colorCount() const { return d ? d->colortable.size() : 0; } @@ -1711,7 +1725,7 @@ void QImage::setColorTable(const QVector colors) Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table - \sa setColorTable(), numColors(), color() + \sa setColorTable(), colorCount(), color() */ QVector QImage::colorTable() const { @@ -1720,12 +1734,24 @@ QVector QImage::colorTable() const /*! + \obsolete + Returns the number of bytes occupied by the image data. + + \sa byteCount() +*/ +int QImage::numBytes() const +{ + return d ? d->nbytes : 0; +} + +/*! + \since 4.6 Returns the number of bytes occupied by the image data. \sa bytesPerLine(), bits(), {QImage#Image Information}{Image Information} */ -int QImage::numBytes() const +int QImage::byteCount() const { return d ? d->nbytes : 0; } @@ -1733,7 +1759,7 @@ int QImage::numBytes() const /*! Returns the number of bytes per image scanline. - This is equivalent to numBytes()/ height(). + This is equivalent to byteCount() / height(). \sa scanLine() */ @@ -1756,7 +1782,7 @@ int QImage::bytesPerLine() const */ QRgb QImage::color(int i) const { - Q_ASSERT(i < numColors()); + Q_ASSERT(i < colorCount()); return d ? d->colortable.at(i) : QRgb(uint(-1)); } @@ -1767,9 +1793,9 @@ QRgb QImage::color(int i) const given to \a colorValue. The color value is an ARGB quadruplet. If \a index is outside the current size of the color table, it is - expanded with setNumColors(). + expanded with setColorCount(). - \sa color(), numColors(), setColorTable(), {QImage#Pixel Manipulation}{Pixel + \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel Manipulation} */ void QImage::setColor(int i, QRgb c) @@ -1787,7 +1813,7 @@ void QImage::setColor(int i, QRgb c) return; if (i >= d->colortable.size()) - setNumColors(i+1); + setColorCount(i+1); d->colortable[i] = c; d->has_alpha_clut |= (qAlpha(c) != 255); } @@ -1844,7 +1870,7 @@ const uchar *QImage::scanLine(int i) const data, thus ensuring that this QImage is the only one using the current return value. - \sa scanLine(), numBytes() + \sa scanLine(), byteCount() */ uchar *QImage::bits() { @@ -2025,8 +2051,21 @@ void QImage::invertPixels(InvertMode mode) #endif /*! + \obsolete Resizes the color table to contain \a numColors entries. + \sa setColorCount() +*/ + +void QImage::setNumColors(int numColors) +{ + setColorCount(numColors); +} + +/*! + \since 4.6 + Resizes the color table to contain \a colorCount entries. + If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)). @@ -2034,14 +2073,14 @@ void QImage::invertPixels(InvertMode mode) have entries for all the pixel/index values present in the image, otherwise the results are undefined. - \sa numColors(), colorTable(), setColor(), {QImage#Image + \sa colorsCount(), colorTable(), setColor(), {QImage#Image Transformations}{Image Transformations} */ -void QImage::setNumColors(int numColors) +void QImage::setColorCount(int colorCount) { if (!d) { - qWarning("QImage::setNumColors: null image"); + qWarning("QImage::setColorCount: null image"); return; } @@ -2051,17 +2090,16 @@ void QImage::setNumColors(int numColors) if (!d) return; - if (numColors == d->colortable.size()) + if (colorCount == d->colortable.size()) return; - if (numColors <= 0) { // use no color table + if (colorCount <= 0) { // use no color table d->colortable = QVector(); return; } int nc = d->colortable.size(); - d->colortable.resize(numColors); - for (int i = nc; i < numColors; ++i) + d->colortable.resize(colorCount); + for (int i = nc; i < colorCount; ++i) d->colortable[i] = 0; - } /*! @@ -3674,7 +3712,7 @@ QRgb QImage::pixel(int x, int y) const otherwise the parameter must be a QRgb value. If \a position is not a valid coordinate pair in the image, or if - \a index_or_rgb >= numColors() in the case of monochrome and + \a index_or_rgb >= colorCount() in the case of monochrome and 8-bit images, the result is undefined. \warning This function is expensive due to the call of the internal @@ -3835,7 +3873,7 @@ bool QImage::allGray() const } else { if (d->colortable.isEmpty()) return true; - for (int i = 0; i < numColors(); i++) + for (int i = 0; i < colorCount(); i++) if (!qIsGray(d->colortable.at(i))) return false; } @@ -3862,7 +3900,7 @@ bool QImage::isGrayscale() const case 16: return allGray(); case 8: { - for (int i = 0; i < numColors(); i++) + for (int i = 0; i < colorCount(); i++) if (d->colortable.at(i) != qRgb(i,i,i)) return false; return true; @@ -4128,7 +4166,7 @@ QImage QImage::createHeuristicMask(bool clipTight) const int w = width(); int h = height(); QImage m(w, h, Format_MonoLSB); - m.setNumColors(2); + m.setColorCount(2); m.setColor(0, QColor(Qt::color0).rgba()); m.setColor(1, QColor(Qt::color1).rgba()); m.fill(0xff); @@ -5703,7 +5741,7 @@ QImage QImage::alphaChannel() const int h = d->height; QImage image(w, h, Format_Indexed8); - image.setNumColors(256); + image.setColorCount(256); // set up gray scale table. for (int i=0; i<256; ++i) @@ -5833,7 +5871,7 @@ static QImage smoothScaled(const QImage &source, int w, int h) { static QImage rotated90(const QImage &image) { QImage out(image.height(), image.width(), image.format()); - if (image.numColors() > 0) + if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); int h = image.height(); @@ -5872,7 +5910,7 @@ static QImage rotated90(const QImage &image) { break; default: for (int y=0; y 0) + if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); int h = image.height(); @@ -5931,7 +5969,7 @@ static QImage rotated270(const QImage &image) { break; default: for (int y=0; ycolortable.size() < 256) { // colors are left in the color table, so pick that one as transparent dImage.d->colortable.append(0x0); - memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.numBytes()); + memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount()); } else { - memset(dImage.bits(), 0, dImage.numBytes()); + memset(dImage.bits(), 0, dImage.byteCount()); } break; case 1: case 16: case 24: case 32: - memset(dImage.bits(), 0x00, dImage.numBytes()); + memset(dImage.bits(), 0x00, dImage.byteCount()); break; } diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 1ac56a7..d8809ef 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -165,18 +165,21 @@ public: QRect rect() const; int depth() const; - int numColors() const; + QT_DEPRECATED int numColors() const; + int colorCount() const; QRgb color(int i) const; void setColor(int i, QRgb c); - void setNumColors(int); + QT_DEPRECATED void setNumColors(int); + void setColorCount(int); bool allGray() const; bool isGrayscale() const; uchar *bits(); const uchar *bits() const; - int numBytes() const; + QT_DEPRECATED int numBytes() const; + int byteCount() const; uchar *scanLine(int); const uchar *scanLine(int) const; diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp index 9209d45..6175931 100644 --- a/src/gui/image/qpixmap_mac.cpp +++ b/src/gui/image/qpixmap_mac.cpp @@ -248,7 +248,7 @@ void QMacPixmapData::fromImage(const QImage &img, } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) { conv8 = d == 1; // native depth wanted } else if (d == 1) { - if (image.numColors() == 2) { + if (image.colorCount() == 2) { QRgb c0 = image.color(0); // Auto: convert to best QRgb c1 = image.color(1); conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255); @@ -339,7 +339,7 @@ void QMacPixmapData::fromImage(const QImage &img, bool alphamap = image.depth() == 32; if (sfmt == QImage::Format_Indexed8) { const QVector rgb = image.colorTable(); - for (int i = 0, count = image.numColors(); i < count; ++i) { + for (int i = 0, count = image.colorCount(); i < count; ++i) { const int alpha = qAlpha(rgb[i]); if (alpha != 0xff) { alphamap = true; @@ -355,13 +355,13 @@ void QMacPixmapData::fromImage(const QImage &img, int get_index(QImage * qi,QRgb mycol) { int loopc; - for(loopc=0;loopcnumColors();loopc++) { + for(loopc=0;loopccolorCount();loopc++) { if(qi->color(loopc)==mycol) return loopc; } - qi->setNumColors(qi->numColors()+1); - qi->setColor(qi->numColors(),mycol); - return qi->numColors(); + qi->setColorCount(qi->colorCount()+1); + qi->setColor(qi->colorCount(),mycol); + return qi->colorCount(); } QImage QMacPixmapData::toImage() const @@ -376,7 +376,7 @@ QImage QMacPixmapData::toImage() const const uint sbpr = bytesPerRow; if (format == QImage::Format_MonoLSB) { image.fill(0); - image.setNumColors(2); + image.setColorCount(2); image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); for (int y = 0; y < h; ++y) { diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp index a8516a5..9a52f3f 100644 --- a/src/gui/image/qpixmap_qws.cpp +++ b/src/gui/image/qpixmap_qws.cpp @@ -126,7 +126,7 @@ int QPixmap::numCols() const { if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast(data.data()); - return d->image.numColors(); + return d->image.colorCount(); } return 0; diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index fc76dc3..1b01e6f 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -119,7 +119,7 @@ void QRasterPixmapData::resize(int width, int height) is_null = (w <= 0 || h <= 0); if (pixelType() == BitmapType && !image.isNull()) { - image.setNumColors(2); + image.setColorCount(2); image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); } diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp index cd8a4d4..f7a880c 100644 --- a/src/gui/image/qpixmap_s60.cpp +++ b/src/gui/image/qpixmap_s60.cpp @@ -443,7 +443,7 @@ void QS60PixmapData::fromSymbianBitmap(CFbsBitmap* bitmap) // Create default palette if needed if (cfbsBitmap->DisplayMode() == EGray2) { - image.setNumColors(2); + image.setColorCount(2); image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); @@ -526,13 +526,13 @@ void QS60PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags const uchar *sptr = const_cast(sourceImage).bits(); symbianBitmapDataAccess->beginDataAccess(cfbsBitmap); uchar *dptr = (uchar*)cfbsBitmap->DataAddress(); - Mem::Copy(dptr, sptr, sourceImage.numBytes()); + Mem::Copy(dptr, sptr, sourceImage.byteCount()); symbianBitmapDataAccess->endDataAccess(cfbsBitmap); UPDATE_BUFFER(); if (destFormat == QImage::Format_MonoLSB) { - image.setNumColors(2); + image.setColorCount(2); image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); } else { @@ -835,7 +835,7 @@ void* QS60PixmapData::toNativeType(NativeType type) symbianBitmapDataAccess->beginDataAccess(newBitmap); uchar *dptr = (uchar*)newBitmap->DataAddress(); - Mem::Copy(dptr, sptr, source.numBytes()); + Mem::Copy(dptr, sptr, source.byteCount()); symbianBitmapDataAccess->endDataAccess(newBitmap); diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index c735031..3f297df 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -464,7 +464,7 @@ void QX11PixmapData::fromImage(const QImage &img, } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) { conv8 = (d == 1); // native depth wanted } else if (d == 1) { - if (image.numColors() == 2) { + if (image.colorCount() == 2) { QRgb c0 = image.color(0); // Auto: convert to best QRgb c1 = image.color(1); conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255); @@ -489,7 +489,7 @@ void QX11PixmapData::fromImage(const QImage &img, Visual *visual = (Visual *)xinfo.visual(); XImage *xi = 0; bool trucol = (visual->c_class >= TrueColor); - int nbytes = image.numBytes(); + int nbytes = image.byteCount(); uchar *newbits= 0; #ifndef QT_NO_XRENDER @@ -631,7 +631,7 @@ void QX11PixmapData::fromImage(const QImage &img, if (d8) { // setup pixel translation QVector ctable = cimage.colorTable(); - for (int i=0; i < cimage.numColors(); i++) { + for (int i=0; i < cimage.colorCount(); i++) { int r = qRed (ctable[i]); int g = qGreen(ctable[i]); int b = qBlue (ctable[i]); @@ -957,8 +957,8 @@ void QX11PixmapData::fromImage(const QImage &img, if (d == 8 && !trucol) { // 8 bit pixmap int pop[256]; // pixel popularity - if (image.numColors() == 0) - image.setNumColors(1); + if (image.colorCount() == 0) + image.setColorCount(1); const QImage &cimage = image; memset(pop, 0, sizeof(int)*256); // reset popularity array @@ -988,11 +988,11 @@ void QX11PixmapData::fromImage(const QImage &img, int mindist; }; int ncols = 0; - for (int i=0; i< cimage.numColors(); i++) { // compute number of colors + for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors if (pop[i] > 0) ncols++; } - for (int i = cimage.numColors(); i < 256; i++) // ignore out-of-range pixels + for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels pop[i] = 0; // works since we make sure above to have at least @@ -1651,7 +1651,7 @@ QImage QX11PixmapData::toImage() const } if (d == 1) { // bitmap - image.setNumColors(2); + image.setColorCount(2); image.setColor(0, qRgb(255,255,255)); image.setColor(1, qRgb(0,0,0)); } else if (!trucol) { // pixmap with colormap @@ -1707,10 +1707,10 @@ QImage QX11PixmapData::toImage() const int trans; if (ncols < 256) { trans = ncols++; - image.setNumColors(ncols); // create color table + image.setColorCount(ncols); // create color table image.setColor(trans, 0x00000000); } else { - image.setNumColors(ncols); // create color table + image.setColorCount(ncols); // create color table // oh dear... no spare "transparent" pixel. // use first pixel in image (as good as any). trans = image.scanLine(0)[0]; @@ -1733,7 +1733,7 @@ QImage QX11PixmapData::toImage() const } } } else { - image.setNumColors(ncols); // create color table + image.setColorCount(ncols); // create color table } QVector colors = QColormap::instance(xinfo.screen()).colormap(); int j = 0; diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp index 10194e4..38f6b5d 100644 --- a/src/gui/image/qpixmapdata.cpp +++ b/src/gui/image/qpixmapdata.cpp @@ -201,7 +201,7 @@ QBitmap QPixmapData::mask() const if (mask.isNull()) // allocation failed return QBitmap(); - mask.setNumColors(2); + mask.setColorCount(2); mask.setColor(0, QColor(Qt::color0).rgba()); mask.setColor(1, QColor(Qt::color1).rgba()); diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index d1bb92a..41e2923 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -113,7 +113,8 @@ public: inline int width() const { return w; } inline int height() const { return h; } - inline int numColors() const { return metric(QPaintDevice::PdmNumColors); } + QT_DEPRECATED inline int numColors() const { return metric(QPaintDevice::PdmNumColors); } + inline int colorCount() const { return metric(QPaintDevice::PdmNumColors); } inline int depth() const { return d; } inline bool isNull() const { return is_null; } diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 44d689d..14c863b 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -171,7 +171,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, float scre if (image.isNull()) return; } - image.setNumColors(2); + image.setColorCount(2); image.setColor(1, qRgb(0,0,0)); image.setColor(0, qRgb(255,255,255)); } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { @@ -199,7 +199,7 @@ void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, float scre if (image.isNull()) return; } - image.setNumColors(ncols); + image.setColorCount(ncols); for (int i=0; inum_palette); + image.setColorCount(info_ptr->num_palette); int i = 0; if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { while (i < info_ptr->num_trans) { @@ -508,7 +508,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) // sanity check palette entries if (color_type == PNG_COLOR_TYPE_PALETTE && outImage->format() == QImage::Format_Indexed8) { - int color_table_size = outImage->numColors(); + int color_table_size = outImage->colorCount(); for (int y=0; y<(int)height; ++y) { uchar *p = outImage->scanLine(y); uchar *end = p + width; @@ -762,9 +762,9 @@ bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image_in, png_colorp palette = 0; png_bytep copy_trans = 0; - if (image.numColors()) { + if (image.colorCount()) { // Paletted - int num_palette = image.numColors(); + int num_palette = image.colorCount(); palette = new png_color[num_palette]; png_set_PLTE(png_ptr, info_ptr, palette, num_palette); int* trans = new int[num_palette]; diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp index 28e4a2a..8ec9efb 100644 --- a/src/gui/image/qppmhandler.cpp +++ b/src/gui/image/qppmhandler.cpp @@ -242,11 +242,11 @@ static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, Q } if (nbits == 1) { // bitmap - outImage->setNumColors(2); + outImage->setColorCount(2); outImage->setColor(0, qRgb(255,255,255)); // white outImage->setColor(1, qRgb(0,0,0)); // black } else if (nbits == 8) { // graymap - outImage->setNumColors(maxc+1); + outImage->setColorCount(maxc+1); for (int i=0; i<=maxc; i++) outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc)); } @@ -287,7 +287,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy } } - if (image.depth() == 1 && image.numColors() == 2) { + if (image.depth() == 1 && image.colorCount() == 2) { if (qGray(image.color(0)) < qGray(image.color(1))) { // 0=dark/black, 1=light/white - invert image.detach(); diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 1c74351..0d76ea0 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -135,7 +135,7 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage) return false; } - outImage->setNumColors(2); + outImage->setColorCount(2); outImage->setColor(0, qRgb(255,255,255)); // white outImage->setColor(1, qRgb(0,0,0)); // black diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 4bdd16e..ac4711a 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -895,7 +895,7 @@ static bool read_xpm_body( if (image.isNull()) return false; } - image.setNumColors(ncols); + image.setColorCount(ncols); } QMap colorMap; diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index 3b3036d..3e00dba 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -1059,7 +1059,7 @@ QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, painter.end(); QPixmap selected = QPixmap(QPixmap::fromImage(img)); - int n = (img.numBytes() >> 10) + 1; + int n = (img.byteCount() >> 10) + 1; if (QPixmapCache::cacheLimit() < n) QPixmapCache::setCacheLimit(n); diff --git a/src/gui/kernel/qcursor_win.cpp b/src/gui/kernel/qcursor_win.cpp index 26cde1a..a4e7b1f 100644 --- a/src/gui/kernel/qcursor_win.cpp +++ b/src/gui/kernel/qcursor_win.cpp @@ -153,8 +153,8 @@ static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy) bool invb, invm; bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono); mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono); - invb = bbits.numColors() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); - invm = mbits.numColors() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); + invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); + invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); int sysW = GetSystemMetrics(SM_CXCURSOR); int sysH = GetSystemMetrics(SM_CYCURSOR); @@ -396,8 +396,8 @@ void QCursorData::update() } else { bbits = bm->toImage().convertToFormat(QImage::Format_Mono); mbits = bmm->toImage().convertToFormat(QImage::Format_Mono); - invb = bbits.numColors() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); - invm = mbits.numColors() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); + invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); + invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); } int n = qMax(1, bbits.width() / 8); int h = bbits.height(); diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 28676da..7461637 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -1445,7 +1445,7 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset) icon_data[pos++] = image.width(); icon_data[pos++] = image.height(); if (sizeof(long) == sizeof(quint32)) { - memcpy(icon_data.data() + pos, image.scanLine(0), image.numBytes()); + memcpy(icon_data.data() + pos, image.scanLine(0), image.byteCount()); } else { for (int y = 0; y < image.height(); ++y) { uint *scanLine = reinterpret_cast(image.scanLine(y)); diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h index c8e86b8..9148e4b 100644 --- a/src/gui/painting/qpaintdevice.h +++ b/src/gui/painting/qpaintdevice.h @@ -96,7 +96,8 @@ public: int logicalDpiY() const { return metric(PdmDpiY); } int physicalDpiX() const { return metric(PdmPhysicalDpiX); } int physicalDpiY() const { return metric(PdmPhysicalDpiY); } - int numColors() const { return metric(PdmNumColors); } + QT_DEPRECATED int numColors() const { return metric(PdmNumColors); } + int colorCount() const { return metric(PdmNumColors); } int depth() const { return metric(PdmDepth); } protected: diff --git a/src/gui/painting/qpaintengine_mac.cpp b/src/gui/painting/qpaintengine_mac.cpp index e686373..c1b887c 100644 --- a/src/gui/painting/qpaintengine_mac.cpp +++ b/src/gui/painting/qpaintengine_mac.cpp @@ -1023,7 +1023,7 @@ CGImageRef qt_mac_createCGImageFromQImage(const QImage &img, const QImage **imag #endif QCFType dataProvider = CGDataProviderCreateWithData(image, static_cast(image)->bits(), - image->numBytes(), + image->byteCount(), drawImageReleaseData); if (imagePtr) *imagePtr = image; diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 350a8e6..7457654 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -433,7 +433,7 @@ QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const return Qt::black; const QRgb *pixelRgb = (const QRgb*)frameImage.bits(); - const int pixels = frameImage.numBytes()/sizeof(QRgb); + const int pixels = frameImage.byteCount()/sizeof(QRgb); int estimatedRed = 0; int estimatedGreen = 0; diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp index 94974fc..f978bd8 100644 --- a/src/gui/text/qfontengine_qpf.cpp +++ b/src/gui/text/qfontengine_qpf.cpp @@ -938,7 +938,7 @@ void QFontEngineQPF::loadGlyph(glyph_t glyph) g.advance = qRound(metrics.xoff); QT_WRITE(fd, &g, sizeof(g)); - QT_WRITE(fd, img.bits(), img.numBytes()); + QT_WRITE(fd, img.bits(), img.byteCount()); glyphPos = oldSize - glyphDataOffset; #if 0 && defined(DEBUG_FONTENGINE) @@ -948,7 +948,7 @@ void QFontEngineQPF::loadGlyph(glyph_t glyph) quint32 *gmap = (quint32 *)(fontData + glyphMapOffset); gmap[glyph] = qToBigEndian(glyphPos); - glyphDataSize = glyphPos + sizeof(g) + img.numBytes(); + glyphDataSize = glyphPos + sizeof(g) + img.byteCount(); quint32 *blockSizePtr = (quint32 *)(fontData + glyphDataOffset - 4); *blockSizePtr = qToBigEndian(glyphDataSize); } diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp index bfeb2a0..e57adb6 100644 --- a/src/multimedia/video/qimagevideobuffer.cpp +++ b/src/multimedia/video/qimagevideobuffer.cpp @@ -85,7 +85,7 @@ uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) d->mapMode = mode; if (numBytes) - *numBytes = d->image.numBytes(); + *numBytes = d->image.byteCount(); if (bytesPerLine) *bytesPerLine = d->image.bytesPerLine(); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index ad177dc..8063fc8 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4078,7 +4078,7 @@ QImage QGLWidget::grabFrameBuffer(bool withAlpha) glReadPixels(0, 0, w, h, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, res.bits()); const QVector pal = QColormap::instance().colormap(); if (pal.size()) { - res.setNumColors(pal.size()); + res.setColorCount(pal.size()); for (int i = 0; i < pal.size(); i++) res.setColor(i, pal.at(i).rgb()); } diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index 5ca37ef..fb55097 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -452,7 +452,7 @@ QImage QGLPixmapData::fillImage(const QColor &color) const if (pixelType() == BitmapType) { img = QImage(w, h, QImage::Format_MonoLSB); - img.setNumColors(2); + img.setColorCount(2); img.setColor(0, QColor(Qt::color0).rgba()); img.setColor(1, QColor(Qt::color1).rgba()); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp index cb4fb88..daefa21 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintdevice.cpp @@ -176,7 +176,7 @@ int QDirectFBPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const return QDirectFBScreen::depth(imageFormat); case QPaintDevice::PdmNumColors: { if (!lockedImage.isNull()) - return lockedImage.numColors(); + return lockedImage.colorCount(); DFBResult result; IDirectFBPalette *palette = 0; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 7ddd992..b6faf8b 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -214,7 +214,7 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QImage &image, QImage: const int height = image.height(); const int bplQt = image.bytesPerLine(); if (bplQt == bplDFB && bplQt == (image.width() * image.depth() / 8)) { - memcpy(mem, image.bits(), image.numBytes()); + memcpy(mem, image.bits(), image.byteCount()); } else { for (int i=0; i= 0 ? QImage::Format_ARGB32 : QImage::Format_RGB32; if (image->isNull()) { (*image) = QImage(swidth, sheight, format); - memset(image->bits(), 0, image->numBytes()); + memset(image->bits(), 0, image->byteCount()); // ### size of the upcoming frame, should rather // be known before decoding it. @@ -393,7 +393,7 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, backingstore = QImage(qMax(backingstore.width(), w), qMax(backingstore.height(), h), QImage::Format_RGB32); - memset(image->bits(), 0, image->numBytes()); + memset(image->bits(), 0, image->byteCount()); } for (int ln=0; lnread((char*)rgb, 4) != 4) { @@ -574,7 +574,7 @@ QImage ICOReader::iconAt(int index) if (!image.isNull()) { QImage mask(image.width(), image.height(), QImage::Format_Mono); if (!mask.isNull()) { - mask.setNumColors(2); + mask.setColorCount(2); mask.setColor(0, qRgba(255,255,255,0xff)); mask.setColor(1, qRgba(0 ,0 ,0 ,0xff)); read1BitBMP(mask); diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 3b23e56..6b2f885 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -741,7 +741,7 @@ static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info, *dest = QImage(size, format); if (format == QImage::Format_Indexed8) { - dest->setNumColors(256); + dest->setColorCount(256); for (int i = 0; i < 256; i++) dest->setColor(i, qRgb(i,i,i)); } @@ -851,7 +851,7 @@ static bool read_jpeg_image(QIODevice *device, QImage *outImage, } else if (cinfo.output_components == 1) { if (outImage->size() != QSize(sWidth, sHeight) || outImage->format() != QImage::Format_Indexed8) *outImage = QImage(sWidth, sHeight, QImage::Format_Indexed8); - outImage->setNumColors(256); + outImage->setColorCount(256); for (int i = 0; i < 256; ++i) outImage->setColor(i, qRgb(i,i,i)); } else { @@ -1054,7 +1054,7 @@ static bool write_jpeg_image(const QImage &sourceImage, QIODevice *device, int s case QImage::Format_MonoLSB: case QImage::Format_Indexed8: gray = true; - for (int i = image.numColors(); gray && i--;) { + for (int i = image.colorCount(); gray && i--;) { gray = gray & (qRed(cmap[i]) == qGreen(cmap[i]) && qRed(cmap[i]) == qBlue(cmap[i])); } diff --git a/src/qt3support/painting/q3paintdevicemetrics.h b/src/qt3support/painting/q3paintdevicemetrics.h index 830dd90..4f1603b 100644 --- a/src/qt3support/painting/q3paintdevicemetrics.h +++ b/src/qt3support/painting/q3paintdevicemetrics.h @@ -63,7 +63,7 @@ public: int logicalDpiY() const { return pdev->logicalDpiY(); } int physicalDpiX() const { return pdev->physicalDpiX(); } int physicalDpiY() const { return pdev->physicalDpiY(); } - int numColors() const { return pdev->numColors(); } + int numColors() const { return pdev->colorCount(); } int depth() const { return pdev->depth(); } private: diff --git a/src/tools/uic3/embed.cpp b/src/tools/uic3/embed.cpp index d699623..2eb4dd5 100644 --- a/src/tools/uic3/embed.cpp +++ b/src/tools/uic3/embed.cpp @@ -177,7 +177,7 @@ void Ui3Reader::embed(const char *project, const QStringList &images) e->width = img.width(); e->height = img.height(); e->depth = img.depth(); - e->numColors = img.numColors(); + e->numColors = img.colorCount(); e->colorTable = new QRgb[e->numColors]; e->alpha = img.hasAlphaBuffer(); QVector ct = img.colorTable(); @@ -195,7 +195,7 @@ void Ui3Reader::embed(const char *project, const QStringList &images) #ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION e->compressed = #endif - embedData( out, img.bits(), img.numBytes() ); + embedData( out, img.bits(), img.byteCount() ); out << "\n};\n\n"; if ( e->numColors ) { out << s.sprintf( "static const QRgb %s_ctable[] = {", diff --git a/tests/arthur/common/paintcommands.cpp b/tests/arthur/common/paintcommands.cpp index 44deb0e..feabaed 100644 --- a/tests/arthur/common/paintcommands.cpp +++ b/tests/arthur/common/paintcommands.cpp @@ -587,10 +587,10 @@ void PaintCommands::staticInit() "^image_setColor\\s+([\\w.:\\/]*)\\s+([0-9]*)\\s+#([0-9]*)$", "image_setColor ", "image_setColor myImage 0 black"); - DECL_PAINTCOMMAND("image_setNumColors", command_image_setNumColors, - "^image_setNumColors\\s+([\\w.:\\/]*)\\s+([0-9]*)$", - "image_setNumColors ", - "image_setNumColors myImage 128"); + DECL_PAINTCOMMAND("image_setColorCount", command_image_setColorCount, + "^image_setColorCount\\s+([\\w.:\\/]*)\\s+([0-9]*)$", + "image_setColorCount ", + "image_setColorCount myImage 128"); DECL_PAINTCOMMANDSECTION("transformations"); DECL_PAINTCOMMAND("resetMatrix", command_resetMatrix, @@ -2245,7 +2245,7 @@ void PaintCommands::command_image_load(QRegExp re) } /***************************************************************************************************/ -void PaintCommands::command_image_setNumColors(QRegExp re) +void PaintCommands::command_image_setColorCount(QRegExp re) { QStringList caps = re.capturedTexts(); @@ -2253,10 +2253,10 @@ void PaintCommands::command_image_setNumColors(QRegExp re) int count = convertToInt(caps.at(2)); if (m_verboseMode) - printf(" -(lance) image_setNumColors(%s), %d -> %d\n", - qPrintable(name), m_imageMap[name].numColors(), count); + printf(" -(lance) image_setColorCount(%s), %d -> %d\n", + qPrintable(name), m_imageMap[name].colorCount(), count); - m_imageMap[name].setNumColors(count); + m_imageMap[name].setColorCount(count); } /***************************************************************************************************/ diff --git a/tests/arthur/common/paintcommands.h b/tests/arthur/common/paintcommands.h index ba91a92..e2c4d67 100644 --- a/tests/arthur/common/paintcommands.h +++ b/tests/arthur/common/paintcommands.h @@ -239,7 +239,7 @@ private: void command_image_convertToFormat(QRegExp re); void command_image_load(QRegExp re); void command_image_setColor(QRegExp re); - void command_image_setNumColors(QRegExp re); + void command_image_setColorCount(QRegExp re); // commands: transformation void command_resetMatrix(QRegExp re); diff --git a/tests/auto/qdatastream/tst_qdatastream.cpp b/tests/auto/qdatastream/tst_qdatastream.cpp index 56fc53a..7535645 100644 --- a/tests/auto/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/qdatastream/tst_qdatastream.cpp @@ -1461,7 +1461,7 @@ void tst_QDataStream::readQImage(QDataStream *s) QVERIFY(d12.width() == ref.width()); QVERIFY(d12.height() == ref.height()); QVERIFY(d12.depth() == ref.depth()); - QVERIFY(d12.numColors() == ref.numColors()); + QVERIFY(d12.colorCount() == ref.colorCount()); #ifdef QT3_SUPPORT QVERIFY(d12.hasAlphaBuffer() == ref.hasAlphaBuffer()); #else diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index e15ae8a..da4e85d 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -104,7 +104,7 @@ private slots: void setPixel_data(); void setPixel(); - void setNumColors(); + void setColorCount(); void setColor(); void rasterClipping(); @@ -155,7 +155,7 @@ void tst_QImage::create() #endif //QImage image(7000000, 7000000, 8, 256, QImage::IgnoreEndian); QImage image(7000000, 7000000, QImage::Format_Indexed8); - image.setNumColors(256); + image.setColorCount(256); cr = !image.isNull(); #if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) } catch (...) { @@ -242,7 +242,7 @@ void tst_QImage::convertBitOrder() QSKIP("Qt compiled without Qt3Support", SkipAll); #else QImage i(9,5,1,2,QImage::LittleEndian); - qMemSet(i.bits(), 0, i.numBytes()); + qMemSet(i.bits(), 0, i.byteCount()); i.setDotsPerMeterX(9); i.setDotsPerMeterY(5); @@ -258,7 +258,7 @@ void tst_QImage::convertBitOrder() QVERIFY(i.dotsPerMeterY() == ni.dotsPerMeterY()); QVERIFY(i.depth() == ni.depth()); QVERIFY(i.size() == ni.size()); - QVERIFY(i.numColors() == ni.numColors()); + QVERIFY(i.colorCount() == ni.colorCount()); #endif } @@ -365,7 +365,7 @@ void tst_QImage::setAlphaChannel() QImage alphaChannel; if (gray) { alphaChannel = QImage(width, height, QImage::Format_Indexed8); - alphaChannel.setNumColors(256); + alphaChannel.setColorCount(256); for (int i=0; i<256; ++i) alphaChannel.setColor(i, qRgb(i, i, i)); alphaChannel.fill(alpha); @@ -927,7 +927,7 @@ void tst_QImage::rotate() original.fill(qRgb(255,255,255)); if (format == QImage::Format_Indexed8) { - original.setNumColors(256); + original.setColorCount(256); for (int i = 0; i < 255; ++i) original.setColor(i, qRgb(0, i, i)); } @@ -1196,23 +1196,23 @@ void tst_QImage::convertToFormatPreserveText() } #endif // QT_NO_IMAGE_TEXT -void tst_QImage::setNumColors() +void tst_QImage::setColorCount() { QImage img(0, 0, QImage::Format_Indexed8); - QTest::ignoreMessage(QtWarningMsg, "QImage::setNumColors: null image"); - img.setNumColors(256); - QCOMPARE(img.numColors(), 0); + QTest::ignoreMessage(QtWarningMsg, "QImage::setColorCount: null image"); + img.setColorCount(256); + QCOMPARE(img.colorCount(), 0); } void tst_QImage::setColor() { QImage img(0, 0, QImage::Format_Indexed8); img.setColor(0, qRgba(18, 219, 108, 128)); - QCOMPARE(img.numColors(), 0); + QCOMPARE(img.colorCount(), 0); QImage img2(1, 1, QImage::Format_Indexed8); img2.setColor(0, qRgba(18, 219, 108, 128)); - QCOMPARE(img2.numColors(), 1); + QCOMPARE(img2.colorCount(), 1); } /* Just some sanity checking that we don't draw outside the buffer of diff --git a/tests/auto/qimagewriter/tst_qimagewriter.cpp b/tests/auto/qimagewriter/tst_qimagewriter.cpp index 584a060..ab5572d 100644 --- a/tests/auto/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/qimagewriter/tst_qimagewriter.cpp @@ -546,7 +546,7 @@ void tst_QImageWriter::saveWithNoFormat() QFETCH(QImageWriter::ImageWriterError, error); QImage niceImage(64, 64, QImage::Format_ARGB32); - qMemSet(niceImage.bits(), 0, niceImage.numBytes()); + qMemSet(niceImage.bits(), 0, niceImage.byteCount()); QImageWriter writer(fileName /* , 0 - no format! */); if (error != 0) { diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index 426887d..a2770d4 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -877,7 +877,7 @@ void tst_QItemDelegate::decoration() } case QVariant::Image: { QImage img(size, QImage::Format_Mono); - qMemSet(img.bits(), 0, img.numBytes()); + qMemSet(img.bits(), 0, img.byteCount()); value = img; break; } diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 4d2c626..003a494 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -2918,7 +2918,7 @@ void tst_QPainter::monoImages() QImage img(2, 2, format); - if (img.numColors() > 0) { + if (img.colorCount() > 0) { img.setColor(0, QColor(colorPairs[j][0]).rgba()); img.setColor(1, QColor(colorPairs[j][1]).rgba()); } @@ -2940,7 +2940,7 @@ void tst_QPainter::monoImages() // should not change the image QCOMPARE(original, img); - if (img.numColors() == 0) + if (img.colorCount() == 0) continue; for (int k = 0; k < 2; ++k) { diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 8e02c74..d7f042e 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -293,7 +293,7 @@ void tst_QPixmap::setAlphaChannel() QRgb expected = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { - if (result.numColors() > 0) { + if (result.colorCount() > 0) { ok &= result.pixelIndex(x, y) == expected; } else { ok &= result.pixel(x, y) == expected; @@ -330,7 +330,7 @@ void tst_QPixmap::fromImage() QImage image(37, 16, format); - if (image.numColors() == 2) { + if (image.colorCount() == 2) { image.setColor(0, QColor(Qt::color0).rgba()); image.setColor(1, QColor(Qt::color1).rgba()); } @@ -731,7 +731,7 @@ void tst_QPixmap::testMetrics() void tst_QPixmap::createMaskFromColor() { QImage image(3, 3, QImage::Format_Indexed8); - image.setNumColors(10); + image.setColorCount(10); image.setColor(0, 0xffffffff); image.setColor(1, 0xff000000); image.setColor(2, 0xffff0000); diff --git a/tools/makeqpf/qpf2.cpp b/tools/makeqpf/qpf2.cpp index 23006f0..a0af1a0 100644 --- a/tools/makeqpf/qpf2.cpp +++ b/tools/makeqpf/qpf2.cpp @@ -519,7 +519,7 @@ void QPF::addGlyphs(QFontEngine *fe, const QList &ranges) glyph_metrics_t metrics = fe->boundingBox(glyphIndex); const quint32 oldSize = glyphs.size(); - glyphs.resize(glyphs.size() + sizeof(QFontEngineQPF::Glyph) + img.numBytes()); + glyphs.resize(glyphs.size() + sizeof(QFontEngineQPF::Glyph) + img.byteCount()); uchar *data = reinterpret_cast(glyphs.data() + oldSize); uchar *gmapPtr = reinterpret_cast(gmap.data() + glyphIndex * sizeof(quint32)); @@ -543,7 +543,7 @@ void QPF::addGlyphs(QFontEngine *fe, const QList &ranges) ; } - qMemCopy(data, img.bits(), img.numBytes()); + qMemCopy(data, img.bits(), img.byteCount()); } } } diff --git a/tools/qvfb/qvfbview.cpp b/tools/qvfb/qvfbview.cpp index 8cab641..69817bd 100644 --- a/tools/qvfb/qvfbview.cpp +++ b/tools/qvfb/qvfbview.cpp @@ -596,7 +596,7 @@ QImage QVFbView::getBuffer(const QRect &r, int &leading) const r.width(), r.height(), mView->linestep(), QImage::Format_Indexed8); img.setColorTable(mView->clut()); - if (img.numColors() <= 0) + if (img.colorCount() <= 0) img = QImage(); break; } @@ -613,10 +613,10 @@ QImage QVFbView::getBuffer(const QRect &r, int &leading) const if ( img.format() != QImage::Format_ARGB32_Premultiplied ) img = img.convertToFormat(QImage::Format_RGB32); - // NOTE: calling bits() may change numBytes(), so do not + // NOTE: calling bits() may change byteCount(), so do not // pass them as parameters (which are evaluated right-to-left). QRgb *b = (QRgb*)img.bits(); - int n = img.numBytes()/4; + int n = img.byteCount()/4; dim(b,n,brightness); } } -- cgit v0.12 From 8d4f3c94411d21f0b7d851b56f951ad54d64340f Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 10:36:38 +0100 Subject: API review: Rename numCols() -> colorCount() The name numCols is ambiguous, as sometimes it's refering to the number of columns, and sometimes the number of colors. It also does not match the typical Qt naming convention *Count(). Reviewed-by: Tom Cooksey Reviewed-by: Andreas Aardal Hanssen --- src/gui/embedded/qscreen_qws.cpp | 14 +++++++++++--- src/gui/embedded/qscreen_qws.h | 3 ++- src/gui/image/qpixmap.cpp | 7 +++++++ src/gui/image/qpixmap.h | 3 ++- src/gui/image/qpixmap_qws.cpp | 5 +++++ src/gui/painting/qcolormap_qws.cpp | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp index 911a77e..0dbfd05 100644 --- a/src/gui/embedded/qscreen_qws.cpp +++ b/src/gui/embedded/qscreen_qws.cpp @@ -1385,7 +1385,7 @@ QImage::Format QScreenPrivate::preferredImageFormat() const QScreen provides several functions to retrieve information about the color palette: The clut() function returns a pointer to the - color lookup table (i.e. its color palette). Use the numCols() + color lookup table (i.e. its color palette). Use the colorCount() function to determine the number of entries in this table, and the alloc() function to retrieve the palette index of the color that is the closest match to a given RGB value. @@ -1998,12 +1998,20 @@ QImage::Format QScreenPrivate::preferredImageFormat() const i.e. in modes where only the palette indexes (and not the actual color values) are stored in memory. - \sa alloc(), depth(), numCols() + \sa alloc(), depth(), colorCount() */ /*! + \obsolete \fn int QScreen::numCols() + \sa colorCount() +*/ + +/*! + \since 4.6 + \fn int QScreen::colorCount() + Returns the number of entries in the screen's color lookup table (i.e. its color palette). A pointer to the color table can be retrieved using the clut() function. @@ -2103,7 +2111,7 @@ void QScreen::setPixelFormat(QImage::Format format) i.e. in modes where only the palette indexes (and not the actual color values) are stored in memory. - \sa clut(), numCols() + \sa clut(), colorCount() */ int QScreen::alloc(unsigned int r,unsigned int g,unsigned int b) diff --git a/src/gui/embedded/qscreen_qws.h b/src/gui/embedded/qscreen_qws.h index d20d709..b3246f9 100644 --- a/src/gui/embedded/qscreen_qws.h +++ b/src/gui/embedded/qscreen_qws.h @@ -243,7 +243,8 @@ public: int totalSize() const { return mapsize; } QRgb * clut() { return screenclut; } - int numCols() { return screencols; } + QT_DEPRECATED int numCols() { return screencols; } + int colorCount() { return screencols; } virtual QSize mapToDevice(const QSize &) const; virtual QSize mapFromDevice(const QSize &) const; diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index dfeea76..985a20b 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -2150,6 +2150,13 @@ QPixmapData* QPixmap::pixmapData() const */ /*! \fn int QPixmap::numCols() const + \obsolete + \internal + \sa colorCount() +*/ + +/*! \fn int QPixmap::colorCount() const + \since 4.6 \internal */ diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index d11bd03..d95b4ee 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -185,7 +185,8 @@ public: const uchar *qwsBits() const; int qwsBytesPerLine() const; QRgb *clut() const; - int numCols() const; + QT_DEPRECATED int numCols() const; + int colorCount() const; #elif defined(Q_WS_MAC) Qt::HANDLE macQDHandle() const; Qt::HANDLE macQDAlphaHandle() const; diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp index 9a52f3f..69626ed 100644 --- a/src/gui/image/qpixmap_qws.cpp +++ b/src/gui/image/qpixmap_qws.cpp @@ -124,6 +124,11 @@ QRgb* QPixmap::clut() const int QPixmap::numCols() const { + return colorCount(); +} + +int QPixmap::colorCount() const +{ if (data && data->classId() == QPixmapData::RasterClass) { const QRasterPixmapData *d = static_cast(data.data()); return d->image.colorCount(); diff --git a/src/gui/painting/qcolormap_qws.cpp b/src/gui/painting/qcolormap_qws.cpp index ce4cd09..bc97b08 100644 --- a/src/gui/painting/qcolormap_qws.cpp +++ b/src/gui/painting/qcolormap_qws.cpp @@ -170,7 +170,7 @@ const QColor QColormap::colorAt(uint pixel) const (pixel & green_mask) >> green_shift, (pixel & blue_mask)); } - Q_ASSERT_X(int(pixel) < qt_screen->numCols(), "QColormap::colorAt", "pixel out of bounds of palette"); + Q_ASSERT_X(int(pixel) < qt_screen->colorCount(), "QColormap::colorAt", "pixel out of bounds of palette"); return QColor(qt_screen->clut()[pixel]); } -- cgit v0.12 From 9e0c2d6f00cb1195bf7bc1eae34a6f8f9b43191f Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 11:37:33 +0100 Subject: API review: Rename numDigits() and setNumDigits() QLCDNumber doesn't follow the API convention of *Count and set*Count(). Introduce properly named functions, and obsolete the old ones. Reviewed-by: Andreas Aardal Hanssen --- src/gui/widgets/qlcdnumber.cpp | 41 +++++++++++++++++------- src/gui/widgets/qlcdnumber.h | 7 ++-- src/plugins/accessible/widgets/simplewidgets.cpp | 2 +- tests/auto/qlcdnumber/tst_qlcdnumber.cpp | 16 ++++----- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/gui/widgets/qlcdnumber.cpp b/src/gui/widgets/qlcdnumber.cpp index 9f9e353..f33a98f 100644 --- a/src/gui/widgets/qlcdnumber.cpp +++ b/src/gui/widgets/qlcdnumber.cpp @@ -85,7 +85,7 @@ public: decimal point with setSmallDecimalPoint(). QLCDNumber emits the overflow() signal when it is asked to display - something beyond its range. The range is set by setNumDigits(), + something beyond its range. The range is set by setDigitCount(), but setSmallDecimalPoint() also influences it. If the display is set to hexadecimal, octal or binary, the integer equivalent of the value is displayed. @@ -160,7 +160,7 @@ public: This signal is emitted whenever the QLCDNumber is asked to display a too-large number or a too-long string. - It is never emitted by setNumDigits(). + It is never emitted by setDigitCount(). */ @@ -345,7 +345,7 @@ static const char *getSegments(char ch) // gets list of segments f The \a parent and \a name arguments are passed to the QFrame constructor. - \sa setNumDigits(), setSmallDecimalPoint() + \sa setDigitCount(), setSmallDecimalPoint() */ QLCDNumber::QLCDNumber(QWidget *parent, const char *name) @@ -367,7 +367,7 @@ QLCDNumber::QLCDNumber(QWidget *parent, const char *name) The \a parent and \a name arguments are passed to the QFrame constructor. - \sa setNumDigits(), setSmallDecimalPoint() + \sa setDigitCount(), setSmallDecimalPoint() */ QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name) @@ -387,7 +387,7 @@ QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name) The \a parent argument is passed to the QFrame constructor. - \sa setNumDigits(), setSmallDecimalPoint() + \sa setDigitCount(), setSmallDecimalPoint() */ QLCDNumber::QLCDNumber(QWidget *parent) @@ -407,7 +407,7 @@ QLCDNumber::QLCDNumber(QWidget *parent) The \a parent argument is passed to the QFrame constructor. - \sa setNumDigits(), setSmallDecimalPoint() + \sa setDigitCount(), setSmallDecimalPoint() */ QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent) @@ -426,7 +426,7 @@ void QLCDNumberPrivate::init() val = 0; base = QLCDNumber::Dec; smallPoint = false; - q->setNumDigits(ndigits); + q->setDigitCount(ndigits); q->setSegmentStyle(QLCDNumber::Filled); q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); } @@ -441,8 +441,21 @@ QLCDNumber::~QLCDNumber() /*! + \obsolete \property QLCDNumber::numDigits \brief the current number of digits displayed + \sa setDigitCount +*/ + +void QLCDNumber::setNumDigits(int numDigits) +{ + setDigitCount(numDigits); +} + +/*! + \since 4.6 + \property QLCDNumber::digitCount + \brief the current number of digits displayed Corresponds to the current number of digits. If \l QLCDNumber::smallDecimalPoint is false, the decimal point occupies @@ -453,7 +466,7 @@ QLCDNumber::~QLCDNumber() \sa smallDecimalPoint */ -void QLCDNumber::setNumDigits(int numDigits) +void QLCDNumber::setDigitCount(int numDigits) { Q_D(QLCDNumber); if (numDigits > 99) { @@ -508,13 +521,19 @@ int QLCDNumber::numDigits() const return d->ndigits; } +int QLCDNumber::digitCount() const +{ + Q_D(const QLCDNumber); + return d->ndigits; +} + /*! \overload Returns true if \a num is too big to be displayed in its entirety; otherwise returns false. - \sa display(), numDigits(), smallDecimalPoint() + \sa display(), digitCount(), smallDecimalPoint() */ bool QLCDNumber::checkOverflow(int num) const @@ -530,7 +549,7 @@ bool QLCDNumber::checkOverflow(int num) const Returns true if \a num is too big to be displayed in its entirety; otherwise returns false. - \sa display(), numDigits(), smallDecimalPoint() + \sa display(), digitCount(), smallDecimalPoint() */ bool QLCDNumber::checkOverflow(double num) const @@ -1256,7 +1275,7 @@ QLCDNumber::SegmentStyle QLCDNumber::segmentStyle() const */ QSize QLCDNumber::sizeHint() const { - return QSize(10 + 9 * (numDigits() + (smallDecimalPoint() ? 0 : 1)), 23); + return QSize(10 + 9 * (digitCount() + (smallDecimalPoint() ? 0 : 1)), 23); } /*! \reimp */ diff --git a/src/gui/widgets/qlcdnumber.h b/src/gui/widgets/qlcdnumber.h index 9753f31..e65637d 100644 --- a/src/gui/widgets/qlcdnumber.h +++ b/src/gui/widgets/qlcdnumber.h @@ -60,6 +60,7 @@ class Q_GUI_EXPORT QLCDNumber : public QFrame // LCD number widget Q_ENUMS(Mode SegmentStyle) Q_PROPERTY(bool smallDecimalPoint READ smallDecimalPoint WRITE setSmallDecimalPoint) Q_PROPERTY(int numDigits READ numDigits WRITE setNumDigits) + Q_PROPERTY(int digitCount READ digitCount WRITE setDigitCount) Q_PROPERTY(Mode mode READ mode WRITE setMode) Q_PROPERTY(SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle) Q_PROPERTY(double value READ value WRITE display) @@ -82,8 +83,10 @@ public: bool smallDecimalPoint() const; - int numDigits() const; - void setNumDigits(int nDigits); + QT_DEPRECATED int numDigits() const; + QT_DEPRECATED void setNumDigits(int nDigits); + int digitCount() const; + void setDigitCount(int nDigits); bool checkOverflow(double num) const; bool checkOverflow(int num) const; diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 1d801e4..014d487 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -528,7 +528,7 @@ QString QAccessibleDisplay::text(Text t, int child) const #ifndef QT_NO_LCDNUMBER } else if (qobject_cast(object())) { QLCDNumber *l = qobject_cast(object()); - if (l->numDigits()) + if (l->digitCount()) str = QString::number(l->value()); else str = QString::number(l->intValue()); diff --git a/tests/auto/qlcdnumber/tst_qlcdnumber.cpp b/tests/auto/qlcdnumber/tst_qlcdnumber.cpp index c18ce24..3f52c70 100644 --- a/tests/auto/qlcdnumber/tst_qlcdnumber.cpp +++ b/tests/auto/qlcdnumber/tst_qlcdnumber.cpp @@ -74,14 +74,14 @@ tst_QLCDNumber::~tst_QLCDNumber() void tst_QLCDNumber::getSetCheck() { QLCDNumber obj1; - // int QLCDNumber::numDigits() - // void QLCDNumber::setNumDigits(int) - obj1.setNumDigits(0); - QCOMPARE(0, obj1.numDigits()); - obj1.setNumDigits(INT_MIN); - QCOMPARE(0, obj1.numDigits()); // Range<0, 99> - obj1.setNumDigits(INT_MAX); - QCOMPARE(99, obj1.numDigits()); // Range<0, 99> + // int QLCDNumber::digitCount() + // void QLCDNumber::setDigitCount(int) + obj1.setDigitCount(0); + QCOMPARE(0, obj1.digitCount()); + obj1.setDigitCount(INT_MIN); + QCOMPARE(0, obj1.digitCount()); // Range<0, 99> + obj1.setDigitCount(INT_MAX); + QCOMPARE(99, obj1.digitCount()); // Range<0, 99> } QTEST_MAIN(tst_QLCDNumber) -- cgit v0.12 From 195f4b98fbf31a92e27be4533fc2ccae99372b82 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 11:43:08 +0100 Subject: API review: Rename numPages() -> pageCount() QPrintPreviewWidget wasn't following the Qt API naming convention of *Count()/set*Count(). Introduce proper function, and obsolete the old. Removed all usage of the old function in Qt. Reviewed-by: Andreas Aardal Hanssen --- src/gui/dialogs/qprintpreviewdialog.cpp | 6 +++--- src/gui/widgets/qprintpreviewwidget.cpp | 12 ++++++++++++ src/gui/widgets/qprintpreviewwidget.h | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qprintpreviewdialog.cpp b/src/gui/dialogs/qprintpreviewdialog.cpp index 4cb0c93..1f0b51d 100644 --- a/src/gui/dialogs/qprintpreviewdialog.cpp +++ b/src/gui/dialogs/qprintpreviewdialog.cpp @@ -446,7 +446,7 @@ void QPrintPreviewDialogPrivate::setFitting(bool on) void QPrintPreviewDialogPrivate::updateNavActions() { int curPage = preview->currentPage(); - int numPages = preview->numPages(); + int numPages = preview->pageCount(); nextPageAction->setEnabled(curPage < numPages); prevPageAction->setEnabled(curPage > 1); firstPageAction->setEnabled(curPage > 1); @@ -458,7 +458,7 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel() { Q_Q(QPrintPreviewDialog); - int numPages = preview->numPages(); + int numPages = preview->pageCount(); int maxChars = QString::number(numPages).length(); pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages)); int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars)); @@ -515,7 +515,7 @@ void QPrintPreviewDialogPrivate::_q_navigate(QAction* action) else if (action == firstPageAction) preview->setCurrentPage(1); else if (action == lastPageAction) - preview->setCurrentPage(preview->numPages()); + preview->setCurrentPage(preview->pageCount()); updateNavActions(); } diff --git a/src/gui/widgets/qprintpreviewwidget.cpp b/src/gui/widgets/qprintpreviewwidget.cpp index d92b1ea..0074c91 100644 --- a/src/gui/widgets/qprintpreviewwidget.cpp +++ b/src/gui/widgets/qprintpreviewwidget.cpp @@ -663,7 +663,9 @@ void QPrintPreviewWidget::setZoomFactor(qreal factor) } /*! + \obsolete Returns the number of pages in the preview. + \sa pageCount() */ int QPrintPreviewWidget::numPages() const { @@ -672,6 +674,16 @@ int QPrintPreviewWidget::numPages() const } /*! + \since 4.6 + Returns the number of pages in the preview. +*/ +int QPrintPreviewWidget::pageCount() const +{ + Q_D(const QPrintPreviewWidget); + return d->pages.size(); +} + +/*! Returns the currently viewed page in the preview. */ int QPrintPreviewWidget::currentPage() const diff --git a/src/gui/widgets/qprintpreviewwidget.h b/src/gui/widgets/qprintpreviewwidget.h index 2823873..08e596d 100644 --- a/src/gui/widgets/qprintpreviewwidget.h +++ b/src/gui/widgets/qprintpreviewwidget.h @@ -82,7 +82,8 @@ public: ViewMode viewMode() const; ZoomMode zoomMode() const; int currentPage() const; - int numPages() const; + QT_DEPRECATED int numPages() const; + int pageCount() const; void setVisible(bool visible); public Q_SLOTS: -- cgit v0.12 From 4ad31892d735e6f1a7afffbf0bf8028663855adb Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 12:04:15 +0100 Subject: API review: Rename numRects() -> rectCount() QRegion::numRects() is marked obsolete. Removed all usage of the old function inside Qt and test-cases. Reviewed-by: Andreas Aardal Hanssen --- src/3rdparty/phonon/mmf/videooutput.cpp | 2 +- src/gui/embedded/qscreen_qws.cpp | 4 ++-- src/gui/graphicsview/qgraphicsscene.cpp | 2 +- src/gui/graphicsview/qgraphicsview.cpp | 2 +- src/gui/painting/qpaintengine_raster.cpp | 4 ++-- src/gui/painting/qpaintengineex.cpp | 2 +- src/gui/painting/qregion.cpp | 20 +++++++++++++++++--- src/gui/painting/qregion.h | 3 ++- src/gui/painting/qtransform.cpp | 2 +- src/gui/painting/qwindowsurface_raster.cpp | 6 +++--- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 2 +- src/openvg/qpaintengine_vg.cpp | 16 ++++++++-------- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 6 +++--- .../gfxdrivers/directfb/qdirectfbwindowsurface.cpp | 2 +- .../powervr/pvreglscreen/pvreglwindowsurface.cpp | 2 +- tests/auto/qregion/tst_qregion.cpp | 20 ++++++++++---------- 16 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/3rdparty/phonon/mmf/videooutput.cpp b/src/3rdparty/phonon/mmf/videooutput.cpp index f0393a7..18b2c34 100644 --- a/src/3rdparty/phonon/mmf/videooutput.cpp +++ b/src/3rdparty/phonon/mmf/videooutput.cpp @@ -120,7 +120,7 @@ void MMF::VideoOutput::paintEvent(QPaintEvent* event) TRACE("rect %d %d - %d %d", event->rect().left(), event->rect().top(), event->rect().right(), event->rect().bottom()); - TRACE("regions %d", event->region().numRects()); + TRACE("regions %d", event->region().rectCount()); TRACE("type %d", event->type()); // Do nothing diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp index 0dbfd05..ae5570f 100644 --- a/src/gui/embedded/qscreen_qws.cpp +++ b/src/gui/embedded/qscreen_qws.cpp @@ -600,7 +600,7 @@ static void blit_template(QScreen *screen, const QImage &image, const int screenStride = screen->linestep(); const int imageStride = image.bytesPerLine(); - if (region.numRects() == 1) { + if (region.rectCount() == 1) { const QRect r = region.boundingRect(); const SRC *src = reinterpret_cast(image.scanLine(r.y())) + r.x(); @@ -2463,7 +2463,7 @@ void QScreen::exposeRegion(QRegion r, int windowIndex) delete blendBuffer; } - if (r.numRects() == 1) { + if (r.rectCount() == 1) { setDirty(r.boundingRect()); } else { const QVector rects = r.rects(); diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index dc036f8..e28ab61 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4149,7 +4149,7 @@ static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion & QRect br = pixmapExposed.boundingRect(); // Don't use subpixmap if we get a full update. - if (pixmapExposed.isEmpty() || (pixmapExposed.numRects() == 1 && br.contains(pix->rect()))) { + if (pixmapExposed.isEmpty() || (pixmapExposed.rectCount() == 1 && br.contains(pix->rect()))) { pix->fill(Qt::transparent); pixmapPainter.begin(pix); } else { diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index c88f678..a880402 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -978,7 +978,7 @@ QList QGraphicsViewPrivate::findItems(const QRegion &exposedReg // Step 2) If the expose region is a simple rect and the view is only // translated or scaled, search for items using // QGraphicsScene::items(QRectF). - bool simpleRectLookup = exposedRegion.numRects() == 1 && matrix.type() <= QTransform::TxScale; + bool simpleRectLookup = exposedRegion.rectCount() == 1 && matrix.type() <= QTransform::TxScale; if (simpleRectLookup) { return scene->items(exposedRegionSceneBounds, Qt::IntersectsItemBoundingRect, diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 8d0b961..3f33319 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1362,7 +1362,7 @@ void QRasterPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) Q_D(QRasterPaintEngine); - if (region.numRects() == 1) { + if (region.rectCount() == 1) { clip(region.boundingRect(), op); return; } @@ -4536,7 +4536,7 @@ void QClipData::setClipRect(const QRect &rect) */ void QClipData::setClipRegion(const QRegion ®ion) { - if (region.numRects() == 1) { + if (region.rectCount() == 1) { setClipRect(region.rects().at(0)); return; } diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index 1fb8aab..7d1c109 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -602,7 +602,7 @@ void QPaintEngineEx::clip(const QRect &r, Qt::ClipOperation op) void QPaintEngineEx::clip(const QRegion ®ion, Qt::ClipOperation op) { - if (region.numRects() == 1) + if (region.rectCount() == 1) clip(region.boundingRect(), op); QVector rects = region.rects(); diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index b48b024..9d1d965 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -690,7 +690,7 @@ bool QRegion::intersects(const QRegion ®ion) const if (!rect_intersects(boundingRect(), region.boundingRect())) return false; - if (numRects() == 1 && region.numRects() == 1) + if (rectCount() == 1 && region.rectCount() == 1) return true; const QVector myRects = rects(); @@ -717,7 +717,7 @@ bool QRegion::intersects(const QRect &rect) const const QRect r = rect.normalized(); if (!rect_intersects(boundingRect(), r)) return false; - if (numRects() == 1) + if (rectCount() == 1) return true; const QVector myRects = rects(); @@ -739,6 +739,7 @@ QRegion QRegion::intersect(const QRect &r) const #endif /*! + \obsolete \fn int QRegion::numRects() const \since 4.4 @@ -746,6 +747,13 @@ QRegion QRegion::intersect(const QRect &r) const */ /*! + \fn int QRegion::rectCount() const + \since 4.6 + + Returns the number of rectangles that will be returned in rects(). +*/ + +/*! \fn bool QRegion::isEmpty() const Returns true if the region is empty; otherwise returns false. An @@ -1027,7 +1035,7 @@ void addSegmentsToPath(Segment *segment, QPainterPath &path) Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion ®ion) { QPainterPath result; - if (region.numRects() == 1) { + if (region.rectCount() == 1) { result.addRect(region.boundingRect()); return result; } @@ -4317,6 +4325,12 @@ int QRegion::numRects() const return (d->qt_rgn ? d->qt_rgn->numRects : 0); } +int QRegion::rectCount() const +{ + return (d->qt_rgn ? d->qt_rgn->numRects : 0); +} + + bool QRegion::operator==(const QRegion &r) const { if (!d->qt_rgn) diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h index 7e459ed..2a1be86 100644 --- a/src/gui/painting/qregion.h +++ b/src/gui/painting/qregion.h @@ -116,7 +116,8 @@ public: QRect boundingRect() const; QVector rects() const; void setRects(const QRect *rect, int num); - int numRects() const; + QT_DEPRECATED int numRects() const; + int rectCount() const; const QRegion operator|(const QRegion &r) const; const QRegion operator+(const QRegion &r) const; diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 1bd5842..45db80a 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -1421,7 +1421,7 @@ QRegion QTransform::map(const QRegion &r) const return copy; } - if (t == TxScale && r.numRects() == 1) + if (t == TxScale && r.rectCount() == 1) return QRegion(mapRect(r.boundingRect())); QPainterPath p = map(qt_regionToPath(r)); diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index d412040..5060f95 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -140,7 +140,7 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi // Not ready for painting yet, bail out. This can happen in // QWidget::create_sys() - if (!d->image || rgn.numRects() == 0) + if (!d->image || rgn.rectCount() == 0) return; #ifdef Q_WS_WIN @@ -203,7 +203,7 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi wrgn.translate(-wOffset); QRect wbr = wrgn.boundingRect(); - if (wrgn.numRects() != 1) { + if (wrgn.rectCount() != 1) { int num; XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded); @@ -242,7 +242,7 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi } } - if (wrgn.numRects() != 1) + if (wrgn.rectCount() != 1) XSetClipMask(X11->display, d_ptr->gc, XNone); #endif // FALCON diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 8228c7e..8c5bf0e 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -2107,7 +2107,7 @@ void QGL2PaintEngineExPrivate::systemStateChanged() q->state()->rectangleClip = use_system_clip ? systemClip.boundingRect() : QRect(0, 0, width, height); updateClipScissorTest(); - if (systemClip.numRects() == 1) { + if (systemClip.rectCount() == 1) { if (systemClip.boundingRect() == QRect(0, 0, width, height)) use_system_clip = false; #ifndef QT_GL_NO_SCISSOR_TEST diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 047d9d8..75b7fa5 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -1753,13 +1753,13 @@ void QVGPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) // QRegion copy on the heap for the test if we can. QRegion clip = d->systemClip; // Reference-counted, no alloc. QRect clipRect; - if (clip.numRects() == 1) { + if (clip.rectCount() == 1) { clipRect = clip.boundingRect().intersected(r); } else if (clip.isEmpty()) { clipRect = r; } else { clip = clip.intersect(r); - if (clip.numRects() != 1) { + if (clip.rectCount() != 1) { d->maskValid = false; d->maskIsSet = false; d->maskRect = QRect(); @@ -1810,7 +1810,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) Q_D(QVGPaintEngine); // Use the QRect case if the region consists of a single rectangle. - if (region.numRects() == 1) { + if (region.rectCount() == 1) { clip(region.boundingRect(), op); return; } @@ -1853,7 +1853,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) clip = r; else clip = clip.intersect(r); - if (clip.numRects() == 1) { + if (clip.rectCount() == 1) { d->maskValid = false; d->maskIsSet = false; d->maskRect = clip.boundingRect(); @@ -1871,7 +1871,7 @@ void QVGPaintEngine::clip(const QRegion ®ion, Qt::ClipOperation op) case Qt::IntersectClip: { - if (region.numRects() != 1) { + if (region.rectCount() != 1) { // If there is more than one rectangle, then intersecting // the rectangles one by one in modifyMask() will not give // the desired result. So fall back to path-based clipping. @@ -2148,7 +2148,7 @@ QRegion QVGPaintEngine::defaultClipRegion() bool QVGPaintEngine::isDefaultClipRegion(const QRegion& region) { - if (region.numRects() != 1) + if (region.rectCount() != 1) return false; QPaintDevice *pdev = paintDevice(); @@ -3544,7 +3544,7 @@ void QVGCompositionHelper::fillBackground d->clearColor = color; d->clearOpacity = 1.0f; } - if (region.numRects() == 1) { + if (region.rectCount() == 1) { QRect r = region.boundingRect(); vgClear(r.x(), screenSize.height() - r.y() - r.height(), r.width(), r.height()); @@ -3569,7 +3569,7 @@ void QVGCompositionHelper::fillBackground d->ensureBrush(brush); d->setFillRule(VG_EVEN_ODD); - if (region.numRects() == 1) { + if (region.rectCount() == 1) { fillBackgroundRect(region.boundingRect(), d); } else { const QVector rects = region.rects(); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index b6faf8b..eb771ba 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -1564,7 +1564,7 @@ void QDirectFBScreen::exposeRegion(QRegion r, int) primary->SetColor(primary, 0xff, 0xff, 0xff, cmd.windowOpacity); } const QRegion ®ion = cmd.source; - const int rectCount = region.numRects(); + const int rectCount = region.rectCount(); DFBRectangle source; if (rectCount == 1) { ::initParameters(source, region.boundingRect(), cmd.windowPosition); @@ -1619,7 +1619,7 @@ void QDirectFBScreen::solidFill(const QColor &color, const QRegion ®ion) d_ptr->primarySurface->SetColor(d_ptr->primarySurface, color.red(), color.green(), color.blue(), color.alpha()); - const int n = region.numRects(); + const int n = region.rectCount(); if (n == 1) { const QRect r = region.boundingRect(); d_ptr->primarySurface->FillRectangle(d_ptr->primarySurface, r.x(), r.y(), r.width(), r.height()); @@ -1680,7 +1680,7 @@ void QDirectFBScreen::flipSurface(IDirectFBSurface *surface, DFBSurfaceFlipFlags if (!(flipFlags & DSFLIP_BLIT)) { surface->Flip(surface, 0, flipFlags); } else { - if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.numRects() > 1) { + if (!(d_ptr->directFBFlags & BoundingRectFlip) && region.rectCount() > 1) { const QVector rects = region.rects(); const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT; for (int i=0; iSetBlittingFlags(dfbSurface, DSBLIT_NOFX); - if (region.numRects() == 1) { + if (region.rectCount() == 1) { scrollSurface(dfbSurface, region.boundingRect(), dx, dy); } else { const QVector rects = region.rects(); diff --git a/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglwindowsurface.cpp b/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglwindowsurface.cpp index 4a3787f..51a6c4e 100644 --- a/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglwindowsurface.cpp +++ b/src/plugins/gfxdrivers/powervr/pvreglscreen/pvreglwindowsurface.cpp @@ -199,7 +199,7 @@ void PvrEglWindowSurface::setDirectRegion(const QRegion &r, int id) if (region.isEmpty()) { pvrQwsClearVisibleRegion(drawable); - } else if (region.numRects() == 1) { + } else if (region.rectCount() == 1) { QRect rect = region.boundingRect(); PvrQwsRect pvrRect; pvrRect.x = rect.x(); diff --git a/tests/auto/qregion/tst_qregion.cpp b/tests/auto/qregion/tst_qregion.cpp index e5a3151..582b5e8 100644 --- a/tests/auto/qregion/tst_qregion.cpp +++ b/tests/auto/qregion/tst_qregion.cpp @@ -88,8 +88,8 @@ private slots: void operator_xor_data(); void operator_xor(); - void numRects_data(); - void numRects(); + void rectCount_data(); + void rectCount(); void isEmpty_data(); void isEmpty(); @@ -554,7 +554,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(r1 + r2, expected); - if (r2.numRects() == 1) { + if (r2.rectCount() == 1) { if (r1 + r2.boundingRect() != expected) { qDebug() << "r1 + QRect(r2)" << (r1 + r2.boundingRect()); qDebug() << "expected" << expected; @@ -567,7 +567,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(r2 + r1, expected); - if (r1.numRects() == 1) { + if (r1.rectCount() == 1) { if (r1 + r2.boundingRect() != expected) { qDebug() << "r2 + QRect(r1)" << (r2 + r1.boundingRect()); qDebug() << "expected" << expected; @@ -582,7 +582,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(result1, expected); - if (r2.numRects() == 1) { + if (r2.rectCount() == 1) { result1 = r1; result1 += r2.boundingRect(); if (result1 != expected) { @@ -599,7 +599,7 @@ void tst_QRegion::operator_plus() qDebug() << "expected" << expected; } QCOMPARE(result2, expected); - if (r1.numRects() == 1) { + if (r1.rectCount() == 1) { result2 = r2; result2 += r1.boundingRect(); if (result2 != expected) { @@ -802,7 +802,7 @@ void tst_QRegion::operator_xor() QCOMPARE(dest, expected); } -void tst_QRegion::numRects_data() +void tst_QRegion::rectCount_data() { QTest::addColumn("region"); QTest::addColumn("expected"); @@ -818,12 +818,12 @@ void tst_QRegion::numRects_data() QTest::newRow("2 rects") << dest << rects.size(); } -void tst_QRegion::numRects() +void tst_QRegion::rectCount() { QFETCH(QRegion, region); QFETCH(int, expected); - QCOMPARE(region.numRects(), expected); + QCOMPARE(region.rectCount(), expected); } void tst_QRegion::isEmpty_data() @@ -850,7 +850,7 @@ void tst_QRegion::isEmpty() QVERIFY(region.isEmpty()); QCOMPARE(region, QRegion()); - QCOMPARE(region.numRects(), 0); + QCOMPARE(region.rectCount(), 0); QCOMPARE(region.boundingRect(), QRect()); QVERIFY(region.rects().isEmpty()); } -- cgit v0.12 From a2a3adf7de2ffc9784fea177a43f3124862a992a Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Fri, 6 Nov 2009 12:58:19 +0100 Subject: API review: *Count() are not plural Obsolete the plural version, and replace its usage in Qt. Reviewed-by: Andreas Aardal Hanssen --- tools/assistant/lib/qhelpsearchengine.cpp | 18 ++++++++++++++---- tools/assistant/lib/qhelpsearchengine.h | 3 ++- tools/assistant/lib/qhelpsearchindexreader.cpp | 2 +- tools/assistant/lib/qhelpsearchindexreader_p.h | 2 +- tools/assistant/lib/qhelpsearchresultwidget.cpp | 10 +++++----- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp index cb18142..893495d 100644 --- a/tools/assistant/lib/qhelpsearchengine.cpp +++ b/tools/assistant/lib/qhelpsearchengine.cpp @@ -95,12 +95,11 @@ private: delete indexWriter; } - - int hitsCount() const + int hitCount() const { int count = 0; if (indexReader) - count = indexReader->hitsCount(); + count = indexReader->hitCount(); return count; } @@ -366,11 +365,22 @@ QHelpSearchResultWidget* QHelpSearchEngine::resultWidget() } /*! + \obsolete Returns the amount of hits the search engine found. + \sa hitCount() */ int QHelpSearchEngine::hitsCount() const { - return d->hitsCount(); + return d->hitCount(); +} + +/*! + \since 4.6 + Returns the amount of hits the search engine found. +*/ +int QHelpSearchEngine::hitCount() const +{ + return d->hitCount(); } /*! diff --git a/tools/assistant/lib/qhelpsearchengine.h b/tools/assistant/lib/qhelpsearchengine.h index 1d53411..21f04c5 100644 --- a/tools/assistant/lib/qhelpsearchengine.h +++ b/tools/assistant/lib/qhelpsearchengine.h @@ -86,7 +86,8 @@ public: QHelpSearchQueryWidget* queryWidget(); QHelpSearchResultWidget* resultWidget(); - int hitsCount() const; + QT_DEPRECATED int hitsCount() const; + int hitCount() const; typedef QPair SearchHit; QList hits(int start, int end) const; diff --git a/tools/assistant/lib/qhelpsearchindexreader.cpp b/tools/assistant/lib/qhelpsearchindexreader.cpp index 20d181b..b134605 100644 --- a/tools/assistant/lib/qhelpsearchindexreader.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader.cpp @@ -83,7 +83,7 @@ void QHelpSearchIndexReader::search(const QString &collectionFile, const QString start(QThread::NormalPriority); } -int QHelpSearchIndexReader::hitsCount() const +int QHelpSearchIndexReader::hitCount() const { QMutexLocker lock(&mutex); return hitList.count(); diff --git a/tools/assistant/lib/qhelpsearchindexreader_p.h b/tools/assistant/lib/qhelpsearchindexreader_p.h index 31c392f..adbcdc2 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_p.h @@ -81,7 +81,7 @@ public: void search(const QString &collectionFile, const QString &indexFilesFolder, const QList &queryList); - int hitsCount() const; + int hitCount() const; QList hits(int start, int end) const; signals: diff --git a/tools/assistant/lib/qhelpsearchresultwidget.cpp b/tools/assistant/lib/qhelpsearchresultwidget.cpp index a2f0021..c0d17dd 100644 --- a/tools/assistant/lib/qhelpsearchresultwidget.cpp +++ b/tools/assistant/lib/qhelpsearchresultwidget.cpp @@ -169,13 +169,13 @@ private slots: void showNextResultPage() { if (!searchEngine.isNull() - && resultLastToShow < searchEngine->hitsCount()) { + && resultLastToShow < searchEngine->hitCount()) { resultLastToShow += 20; resultFirstToShow += 20; resultTextBrowser->showResultPage(searchEngine->hits(resultFirstToShow, resultLastToShow), isIndexing); - if (resultLastToShow >= searchEngine->hitsCount()) + if (resultLastToShow >= searchEngine->hitCount()) updateNextButtonState(false); } updateHitRange(); @@ -184,7 +184,7 @@ private slots: void showLastResultPage() { if (!searchEngine.isNull()) { - resultLastToShow = searchEngine->hitsCount(); + resultLastToShow = searchEngine->hitCount(); resultFirstToShow = resultLastToShow - (resultLastToShow % 20); if (resultFirstToShow == resultLastToShow) @@ -214,7 +214,7 @@ private slots: { if (!searchEngine.isNull()) { int count = resultLastToShow % 20; - if (count == 0 || resultLastToShow != searchEngine->hitsCount()) + if (count == 0 || resultLastToShow != searchEngine->hitCount()) count = 20; resultLastToShow -= count; @@ -298,7 +298,7 @@ private: int count = 0; if (!searchEngine.isNull()) { - count = searchEngine->hitsCount(); + count = searchEngine->hitCount(); if (count > 0) { first = resultFirstToShow +1; last = resultLastToShow > count ? count : resultLastToShow; -- cgit v0.12