QtWidgets: Fix const correctness in old style casts

Found with GCC's -Wcast-qual.

Change-Id: Ia0aac2f09e9245339951ffff13c94684f8498f21
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Thiago Macieira 2015-03-05 22:25:45 -08:00
parent 4da46bbb9a
commit 4cdff7a0ea
12 changed files with 26 additions and 26 deletions

View File

@ -329,7 +329,7 @@ static void convolute(
QRectF sbounded = srect.adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2); QRectF sbounded = srect.adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
QPoint srcStartPoint = sbounded.toAlignedRect().topLeft()+(targetRect.topLeft()-rect.topLeft()); QPoint srcStartPoint = sbounded.toAlignedRect().topLeft()+(targetRect.topLeft()-rect.topLeft());
const uint *sourceStart = (uint*)processImage.scanLine(0); const uint *sourceStart = (const uint*)processImage.scanLine(0);
uint *outputStart = (uint*)destImage->scanLine(0); uint *outputStart = (uint*)destImage->scanLine(0);
int yk = srcStartPoint.y(); int yk = srcStartPoint.y();
@ -946,7 +946,7 @@ static void grayscale(const QImage &image, QImage &dest, const QRect& rect = QRe
destRect.moveTo(QPoint(0, 0)); destRect.moveTo(QPoint(0, 0));
} }
unsigned int *data = (unsigned int *)image.bits(); const unsigned int *data = (const unsigned int *)image.bits();
unsigned int *outData = (unsigned int *)dest.bits(); unsigned int *outData = (unsigned int *)dest.bits();
if (dest.size() == image.size() && image.rect() == srcRect) { if (dest.size() == image.size() && image.rect() == srcRect) {
@ -959,7 +959,7 @@ static void grayscale(const QImage &image, QImage &dest, const QRect& rect = QRe
} else { } else {
int yd = destRect.top(); int yd = destRect.top();
for (int y = srcRect.top(); y <= srcRect.bottom() && y < image.height(); y++) { for (int y = srcRect.top(); y <= srcRect.bottom() && y < image.height(); y++) {
data = (unsigned int*)image.scanLine(y); data = (const unsigned int*)image.scanLine(y);
outData = (unsigned int*)dest.scanLine(yd++); outData = (unsigned int*)dest.scanLine(yd++);
int xd = destRect.left(); int xd = destRect.left();
for (int x = srcRect.left(); x <= srcRect.right() && x < image.width(); x++) { for (int x = srcRect.left(); x <= srcRect.right() && x < image.width(); x++) {

View File

@ -1275,7 +1275,7 @@ QSize QGridLayout::maximumSize() const
*/ */
bool QGridLayout::hasHeightForWidth() const bool QGridLayout::hasHeightForWidth() const
{ {
return ((QGridLayout*)this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing()); return const_cast<QGridLayout*>(this)->d_func()->hasHeightForWidth(horizontalSpacing(), verticalSpacing());
} }
/*! /*!

View File

@ -370,7 +370,7 @@ Q_WIDGETS_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSize
Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidgetItem *i) Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidgetItem *i)
{ {
QWidget *w = ((QWidgetItem *)i)->widget(); QWidget *w = const_cast<QWidgetItem *>(i)->widget();
return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(),
w->minimumSize(), w->maximumSize(), w->minimumSize(), w->maximumSize(),
w->sizePolicy()); w->sizePolicy());
@ -408,7 +408,7 @@ Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QSize &sizeHint,
Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidgetItem *i, Qt::Alignment align) Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidgetItem *i, Qt::Alignment align)
{ {
QWidget *w = ((QWidgetItem*)i)->widget(); QWidget *w = const_cast<QWidgetItem*>(i)->widget();
return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(),
w->sizePolicy(), align); w->sizePolicy(), align);

View File

@ -495,7 +495,7 @@ private slots:
QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent) QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent)
{ {
#ifndef QT_NO_IMAGEFORMAT_XPM #ifndef QT_NO_IMAGEFORMAT_XPM
QPixmap p((const char**)button_image); QPixmap p(button_image);
setIcon(p); setIcon(p);
#endif #endif
setCheckable(true); setCheckable(true);

View File

@ -4284,7 +4284,7 @@ QPoint QWidget::mapFromParent(const QPoint &pos) const
QWidget *QWidget::window() const QWidget *QWidget::window() const
{ {
QWidget *w = (QWidget *)this; QWidget *w = const_cast<QWidget *>(this);
QWidget *p = w->parentWidget(); QWidget *p = w->parentWidget();
while (!w->isWindow() && p) { while (!w->isWindow() && p) {
w = p; w = p;

View File

@ -3707,12 +3707,12 @@ QPixmap QFusionStyle::standardPixmap(StandardPixmap standardPixmap, const QStyle
#ifndef QT_NO_IMAGEFORMAT_XPM #ifndef QT_NO_IMAGEFORMAT_XPM
switch (standardPixmap) { switch (standardPixmap) {
case SP_TitleBarNormalButton: case SP_TitleBarNormalButton:
return QPixmap((const char **)dock_widget_restore_xpm); return QPixmap(dock_widget_restore_xpm);
case SP_TitleBarMinButton: case SP_TitleBarMinButton:
return QPixmap((const char **)workspace_minimize); return QPixmap(workspace_minimize);
case SP_TitleBarCloseButton: case SP_TitleBarCloseButton:
case SP_DockWidgetCloseButton: case SP_DockWidgetCloseButton:
return QPixmap((const char **)dock_widget_close_xpm); return QPixmap(dock_widget_close_xpm);
default: default:
break; break;

View File

@ -234,7 +234,7 @@ void QGtk2Painter::paintBoxGap(GtkWidget *gtkWidget, const gchar* part,
shadow, shadow,
NULL, NULL,
gtkWidget, gtkWidget,
(gchar*)part, (const gchar*)part,
0, 0, 0, 0,
rect.width(), rect.width(),
rect.height(), rect.height(),
@ -618,7 +618,7 @@ void QGtk2Painter::paintExtention(GtkWidget *gtkWidget,
if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
DRAW_TO_CACHE(QGtk2PainterPrivate::gtk_paint_extension (style, pixmap, state, shadow, DRAW_TO_CACHE(QGtk2PainterPrivate::gtk_paint_extension (style, pixmap, state, shadow,
NULL, gtkWidget, NULL, gtkWidget,
(gchar*)part, 0, 0, (const gchar*)part, 0, 0,
rect.width(), rect.width(),
rect.height(), rect.height(),
gap_pos)); gap_pos));

View File

@ -4056,7 +4056,7 @@ QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
switch (sp) { switch (sp) {
case SP_TitleBarNormalButton: { case SP_TitleBarNormalButton: {
QImage restoreButton((const char **)dock_widget_restore_xpm); QImage restoreButton(dock_widget_restore_xpm);
QColor alphaCorner = restoreButton.color(2); QColor alphaCorner = restoreButton.color(2);
alphaCorner.setAlpha(80); alphaCorner.setAlpha(80);
restoreButton.setColor(2, alphaCorner.rgba()); restoreButton.setColor(2, alphaCorner.rgba());
@ -4069,7 +4069,7 @@ QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
case SP_TitleBarCloseButton: // Fall through case SP_TitleBarCloseButton: // Fall through
case SP_DockWidgetCloseButton: { case SP_DockWidgetCloseButton: {
QImage closeButton((const char **)dock_widget_close_xpm); QImage closeButton(dock_widget_close_xpm);
QColor alphaCorner = closeButton.color(2); QColor alphaCorner = closeButton.color(2);
alphaCorner.setAlpha(80); alphaCorner.setAlpha(80);
closeButton.setColor(2, alphaCorner.rgba()); closeButton.setColor(2, alphaCorner.rgba());

View File

@ -1478,7 +1478,7 @@ public:
do { do {
const ushort *uc = (const ushort *)nodeName.constData(); const ushort *uc = (const ushort *)nodeName.constData();
const ushort *e = uc + nodeName.length(); const ushort *e = uc + nodeName.length();
const uchar *c = (uchar *)metaObject->className(); const uchar *c = (const uchar *)metaObject->className();
while (*c && uc != e && (*uc == *c || (*c == ':' && *uc == '-'))) { while (*c && uc != e && (*uc == *c || (*c == ':' && *uc == '-'))) {
++uc; ++uc;
++c; ++c;
@ -1579,7 +1579,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QObject *obj) const
styleSelector.styleSheets += objectSs; styleSelector.styleSheets += objectSs;
StyleSelector::NodePtr n; StyleSelector::NodePtr n;
n.ptr = (void *)obj; n.ptr = const_cast<QObject *>(obj);
QVector<QCss::StyleRule> rules = styleSelector.styleRulesForNode(n); QVector<QCss::StyleRule> rules = styleSelector.styleRulesForNode(n);
styleSheetCaches->styleRulesCache.insert(obj, rules); styleSheetCaches->styleRulesCache.insert(obj, rules);
return rules; return rules;

View File

@ -790,7 +790,7 @@ bool QDockWidgetPrivate::isAnimating() const
if (mainWinLayout == 0) if (mainWinLayout == 0)
return false; return false;
return (void*)mainWinLayout->pluggingWidget == (void*)q; return (const void*)mainWinLayout->pluggingWidget == (const void*)q;
} }
bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event) bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event)

View File

@ -826,7 +826,7 @@ QSize QTabWidget::sizeHint() const
if(d->rightCornerWidget) if(d->rightCornerWidget)
rc = d->rightCornerWidget->sizeHint(); rc = d->rightCornerWidget->sizeHint();
if (!d->dirty) { if (!d->dirty) {
QTabWidget *that = (QTabWidget*)this; QTabWidget *that = const_cast<QTabWidget*>(this);
that->setUpLayout(true); that->setUpLayout(true);
} }
QSize s(d->stack->sizeHint()); QSize s(d->stack->sizeHint());
@ -858,7 +858,7 @@ QSize QTabWidget::minimumSizeHint() const
if(d->rightCornerWidget) if(d->rightCornerWidget)
rc = d->rightCornerWidget->minimumSizeHint(); rc = d->rightCornerWidget->minimumSizeHint();
if (!d->dirty) { if (!d->dirty) {
QTabWidget *that = (QTabWidget*)this; QTabWidget *that = const_cast<QTabWidget*>(this);
that->setUpLayout(true); that->setUpLayout(true);
} }
QSize s(d->stack->minimumSizeHint()); QSize s(d->stack->minimumSizeHint());
@ -894,7 +894,7 @@ int QTabWidget::heightForWidth(int width) const
if(d->rightCornerWidget) if(d->rightCornerWidget)
rc = d->rightCornerWidget->sizeHint(); rc = d->rightCornerWidget->sizeHint();
if (!d->dirty) { if (!d->dirty) {
QTabWidget *that = (QTabWidget*)this; QTabWidget *that = const_cast<QTabWidget*>(this);
that->setUpLayout(true); that->setUpLayout(true);
} }
QSize t(d->tabs->sizeHint()); QSize t(d->tabs->sizeHint());

View File

@ -111,7 +111,7 @@ public:
void _q_buttonClicked(); void _q_buttonClicked();
void _q_widgetDestroyed(QObject*); void _q_widgetDestroyed(QObject*);
Page *page(QWidget *widget) const; const Page *page(QWidget *widget) const;
const Page *page(int index) const; const Page *page(int index) const;
Page *page(int index); Page *page(int index);
@ -123,14 +123,14 @@ public:
Page *currentPage; Page *currentPage;
}; };
QToolBoxPrivate::Page *QToolBoxPrivate::page(QWidget *widget) const const QToolBoxPrivate::Page *QToolBoxPrivate::page(QWidget *widget) const
{ {
if (!widget) if (!widget)
return 0; return 0;
for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
if ((*i).widget == widget) if ((*i).widget == widget)
return (Page*) &(*i); return (const Page*) &(*i);
return 0; return 0;
} }
@ -448,7 +448,7 @@ void QToolBoxPrivate::_q_widgetDestroyed(QObject *object)
// no verification - vtbl corrupted already // no verification - vtbl corrupted already
QWidget *p = (QWidget*)object; QWidget *p = (QWidget*)object;
QToolBoxPrivate::Page *c = page(p); const QToolBoxPrivate::Page *c = page(p);
if (!p || !c) if (!p || !c)
return; return;
@ -550,7 +550,7 @@ QWidget *QToolBox::widget(int index) const
int QToolBox::indexOf(QWidget *widget) const int QToolBox::indexOf(QWidget *widget) const
{ {
Q_D(const QToolBox); Q_D(const QToolBox);
QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0); const QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0);
return c ? d->pageList.indexOf(*c) : -1; return c ? d->pageList.indexOf(*c) : -1;
} }