Fix constness of QPaintDevice arguments

QFont, QFontMetrics, QFontMetricsF and QTextLayout constructors
use only const methods of QPaintDevice so there is no reason
for them to require a non-const pointer argument

Fixes: QTBUG-65967
Change-Id: Ibfcdef2a25f0cd4284dad76135fc4c9bf5667d7a
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Luca Beldi 2018-11-13 08:54:37 +00:00
parent 85b4aaaa99
commit c0c4be672b
6 changed files with 103 additions and 13 deletions

View File

@ -562,14 +562,25 @@ QFontEngineData::~QFontEngineData()
\since 5.2
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
\obsolete
Constructs a font from \a font for use on the paint device \a pd.
*/
QFont::QFont(const QFont &font, QPaintDevice *pd)
: QFont(font, static_cast<const QPaintDevice*>(pd))
{}
#endif
/*!
\since 5.13
Constructs a font from \a font for use on the paint device \a pd.
*/
QFont::QFont(const QFont &font, const QPaintDevice *pd)
: resolve_mask(font.resolve_mask)
{
Q_ASSERT(pd != 0);
int dpi = pd->logicalDpiY();
Q_ASSERT(pd);
const int dpi = pd->logicalDpiY();
const int screen = 0;
if (font.d->dpi != dpi || font.d->screen != screen ) {
d = new QFontPrivate(*font.d);

View File

@ -170,8 +170,11 @@ public:
QFont();
QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
QFont(const QFont &, QPaintDevice *pd);
QFont(const QFont &);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QFont(const QFont &font, QPaintDevice *pd);
#endif
QFont(const QFont &font, const QPaintDevice *pd);
QFont(const QFont &font);
~QFont();
void swap(QFont &other)

View File

@ -156,6 +156,8 @@ QFontMetrics::QFontMetrics(const QFont &font)
}
/*!
\since 5.13
\fn QFontMetrics::QFontMetrics(const QFont &font, const QPaintDevice *paintdevice)
Constructs a font metrics object for \a font and \a paintdevice.
The font metrics will be compatible with the paintdevice passed.
@ -168,9 +170,21 @@ QFontMetrics::QFontMetrics(const QFont &font)
passed in the constructor at the time it is created, and is not
updated if the font's attributes are changed later.
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
\fn QFontMetrics::QFontMetrics(const QFont &font, QPaintDevice *paintdevice)
\obsolete
Identical to QFontMetrics::QFontMetrics(const QFont &font, const QPaintDevice *paintdevice)
*/
QFontMetrics::QFontMetrics(const QFont &font, QPaintDevice *paintdevice)
#else
QFontMetrics::QFontMetrics(const QFont &font, const QPaintDevice *paintdevice)
#endif
{
int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();
const int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();
const int screen = 0;
if (font.d->dpi != dpi || font.d->screen != screen ) {
d = new QFontPrivate(*font.d);
@ -1127,6 +1141,8 @@ QFontMetricsF::QFontMetricsF(const QFont &font)
}
/*!
\fn QFontMetricsF::QFontMetricsF(const QFont &font, const QPaintDevice *paintdevice)
\since 5.13
Constructs a font metrics object for \a font and \a paintdevice.
The font metrics will be compatible with the paintdevice passed.
@ -1139,7 +1155,20 @@ QFontMetricsF::QFontMetricsF(const QFont &font)
passed in the constructor at the time it is created, and is not
updated if the font's attributes are changed later.
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
\fn QFontMetricsF::QFontMetricsF(const QFont &font, QPaintDevice *paintdevice)
\obsolete
Identical to QFontMetricsF::QFontMetricsF(const QFont &font, const QPaintDevice *paintdevice)
*/
QFontMetricsF::QFontMetricsF(const QFont &font, QPaintDevice *paintdevice)
#else
QFontMetricsF::QFontMetricsF(const QFont &font, const QPaintDevice *paintdevice)
#endif
{
int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();
const int screen = 0;

View File

@ -59,7 +59,19 @@ class Q_GUI_EXPORT QFontMetrics
{
public:
explicit QFontMetrics(const QFont &);
QFontMetrics(const QFont &, QPaintDevice *pd);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QFontMetrics(const QFont &font, QPaintDevice *pd);
#ifndef Q_QDOC
// the template is necessary to make QFontMetrics(font,nullptr) and QFontMetrics(font,NULL)
// not ambiguous. Implementation detail that should not be documented.
template<char = 0>
#endif
QFontMetrics(const QFont &font, const QPaintDevice *pd)
: QFontMetrics(font, const_cast<QPaintDevice*>(pd))
{}
#else
QFontMetrics(const QFont &font, const QPaintDevice *pd);
#endif
QFontMetrics(const QFontMetrics &);
~QFontMetrics();
@ -137,8 +149,20 @@ Q_DECLARE_SHARED(QFontMetrics)
class Q_GUI_EXPORT QFontMetricsF
{
public:
explicit QFontMetricsF(const QFont &);
QFontMetricsF(const QFont &, QPaintDevice *pd);
explicit QFontMetricsF(const QFont &font);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QFontMetricsF(const QFont &font, QPaintDevice *pd);
#ifndef Q_QDOC
// the template is necessary to make QFontMetrics(font,nullptr) and QFontMetrics(font,NULL)
// not ambiguous. Implementation detail that should not be documented.
template<char = 0>
#endif
QFontMetricsF(const QFont &font, const QPaintDevice *pd)
: QFontMetricsF(font, const_cast<QPaintDevice*>(pd))
{}
#else
QFontMetricsF(const QFont &font, const QPaintDevice *pd);
#endif
QFontMetricsF(const QFontMetrics &);
QFontMetricsF(const QFontMetricsF &);
~QFontMetricsF();

View File

@ -344,6 +344,8 @@ QTextLayout::QTextLayout(const QString& text)
}
/*!
\since 5.13
\fn QTextLayout::QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice)
Constructs a text layout to lay out the given \a text with the specified
\a font.
@ -351,11 +353,20 @@ QTextLayout::QTextLayout(const QString& text)
the paint device, \a paintdevice. If \a paintdevice is 0 the
calculations will be done in screen metrics.
*/
QTextLayout::QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
\fn QTextLayout::QTextLayout(const QString &text, const QFont &font, QPaintDevice *paintdevice)
\obsolete
Identical to QTextLayout::QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice)
*/
QTextLayout::QTextLayout(const QString &text, const QFont &font, QPaintDevice *paintdevice)
#else
QTextLayout::QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice)
#endif
{
QFont f(font);
if (paintdevice)
f = QFont(font, paintdevice);
const QFont f(paintdevice ? QFont(font, paintdevice) : font);
d = new QTextEngine((text.isNull() ? (const QString&)QString::fromLatin1("") : text), f);
}

View File

@ -107,7 +107,19 @@ public:
// does itemization
QTextLayout();
QTextLayout(const QString& text);
QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = nullptr);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QTextLayout(const QString &text, const QFont &font, QPaintDevice *paintdevice = nullptr);
#ifndef Q_QDOC
// the template is necessary to make QTextLayout(font,text,nullptr) and QTextLayout(font,text,NULL)
// not ambiguous. Implementation detail that should not be documented.
template<char = 0>
#endif
QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice)
: QTextLayout(text, font, const_cast<QPaintDevice*>(paintdevice))
{}
#else
QTextLayout(const QString &text, const QFont &font, const QPaintDevice *paintdevice = nullptr);
#endif
QTextLayout(const QTextBlock &b);
~QTextLayout();