[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames
From:       Stefan Majewsky <majewsky () gmx ! net>
Date:       2011-07-29 18:30:34
Message-ID: 20110729183034.190BBAC86C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1243946 by majewsky:

Replace reinterpret_cast by safer casts.

It's mostly qobject_cast now, except when that cannot be used, e.g.
while handling a QObject::destroyed signal. But then, I make it clear
now why it cannot be used.

 M  +3 -1      kdiamond/src/board.cpp  
 M  +1 -1      palapeli/src/creator/propertywidget.cpp  
 M  +3 -1      palapeli/src/engine/interactors.cpp  
 M  +1 -1      palapeli/src/engine/piece.cpp  
 M  +2 -1      palapeli/src/engine/texturehelper.cpp  


--- trunk/KDE/kdegames/kdiamond/src/board.cpp #1243945:1243946
@@ -115,7 +115,9 @@
 {
 	if (m_runningAnimations.isEmpty())
 		return;
-	m_runningAnimations.removeAll(reinterpret_cast<QAbstractAnimation*>(sender()));
+	//static_cast is enough, no need for a qobject_cast
+	//because result pointer is never dereferenced here
+	m_runningAnimations.removeAll(static_cast<QAbstractAnimation*>(sender()));
 	if (m_runningAnimations.isEmpty())
 		emit animationsFinished();
 }
--- trunk/KDE/kdegames/palapeli/src/creator/propertywidget.cpp #1243945:1243946
@@ -78,7 +78,7 @@
 
 void Palapeli::IntegerPropertyWidget::initialize(const Pala::SlicerProperty* property)
 {
-	const Pala::IntegerProperty* intProperty = reinterpret_cast<const Pala::IntegerProperty*>(property);
+	const Pala::IntegerProperty* intProperty = static_cast<const Pala::IntegerProperty*>(property);
 	const QPair<int,int> range = intProperty->range();
 	const QVariantList choices = property->choices();
 	QWidget* usedWidget;
--- trunk/KDE/kdegames/palapeli/src/engine/interactors.cpp #1243945:1243946
@@ -108,7 +108,9 @@
 {
 	//This slot is triggered when a MergeGroup replaces one of the m_currentPieces by a new piece.
 	//remove old piece from data structures
-	int index = m_currentPieces.indexOf(reinterpret_cast<Palapeli::Piece*>(sender()));
+	int index = m_currentPieces.indexOf(qobject_cast<Palapeli::Piece*>(sender()));
+	if (index == -1) //do nothing if sender is not a current piece
+		return;
 	m_currentPieces.removeAt(index);
 	m_basePositions.removeAt(index);
 	//add new piece (might not always be necessary, if the new piece replaces more than one of the selected pieces)
--- trunk/KDE/kdegames/palapeli/src/engine/piece.cpp #1243945:1243946
@@ -200,7 +200,7 @@
 void Palapeli::Piece::announceReplaced(Palapeli::Piece* replacement)
 {
 	emit replacedBy(replacement);
-	delete this;
+	deleteLater();
 }
 
 void Palapeli::Piece::addAtomicSize(const QSize& size)
--- trunk/KDE/kdegames/palapeli/src/engine/texturehelper.cpp #1243945:1243946
@@ -121,7 +121,8 @@
 
 void Palapeli::TextureHelper::removeScene(QObject* scene)
 {
-	m_scenes.removeAll(reinterpret_cast<QGraphicsScene*>(scene));
+	//called by scene->QObject::destroyed signal, so qobject_cast won't work anymore
+	m_scenes.removeAll(static_cast<QGraphicsScene*>(scene));
 }
 
 #include "texturehelper.moc"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic