r21665 by jghali - safer deletion of item delegates in ColorListBox

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 18 19:29:30 UTC 2016


Author: jghali
Date: Sun Dec 18 19:29:29 2016
New Revision: 21665

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21665
Log:
safer deletion of item delegates in ColorListBox

Modified:
    trunk/Scribus/scribus/ui/colorlistbox.cpp

Modified: trunk/Scribus/scribus/ui/colorlistbox.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21665&path=/trunk/Scribus/scribus/ui/colorlistbox.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/colorlistbox.cpp	(original)
+++ trunk/Scribus/scribus/ui/colorlistbox.cpp	Sun Dec 18 19:29:29 2016
@@ -265,36 +265,39 @@
 {
 	if (type == ColorListBox::fancyPixmap)
 	{
-		ColorFancyItemDelegate* colorDelegate = dynamic_cast<ColorFancyItemDelegate*>(itemDelegate());
+		QAbstractItemDelegate* oldDelegate = itemDelegate();
+		ColorFancyItemDelegate* colorDelegate = dynamic_cast<ColorFancyItemDelegate*>(oldDelegate);
 		if (!colorDelegate)
 		{
-			if (itemDelegate())
-				delete itemDelegate();
 			setItemDelegate(new ColorFancyItemDelegate());
-		}
-		m_type = type;
+			if (oldDelegate)
+				delete oldDelegate;
+			m_type = type;
+		}
 	}
 	else if (type == ColorListBox::widePixmap)
 	{
-		ColorWideItemDelegate* colorDelegate = dynamic_cast<ColorWideItemDelegate*>(itemDelegate());
+		QAbstractItemDelegate* oldDelegate = itemDelegate();
+		ColorWideItemDelegate* colorDelegate = dynamic_cast<ColorWideItemDelegate*>(oldDelegate);
 		if (!colorDelegate)
 		{
-			if (itemDelegate())
-				delete itemDelegate();
 			setItemDelegate(new ColorWideItemDelegate());
-		}
-		m_type = type;
+			if (oldDelegate)
+				delete oldDelegate;
+			m_type = type;
+		}
 	}
 	else if (type == ColorListBox::smallPixmap)
 	{
-		ColorSmallItemDelegate* colorDelegate = dynamic_cast<ColorSmallItemDelegate*>(itemDelegate());
+		QAbstractItemDelegate* oldDelegate = itemDelegate();
+		ColorSmallItemDelegate* colorDelegate = dynamic_cast<ColorSmallItemDelegate*>(oldDelegate);
 		if (!colorDelegate)
 		{
-			if (itemDelegate())
-				delete itemDelegate();
 			setItemDelegate(new ColorSmallItemDelegate());
-		}
-		m_type = type;
+			if (oldDelegate)
+				delete oldDelegate;
+			m_type = type;
+		}
 	}
 }
 




More information about the scribus-commit mailing list