Commit 73f1a307 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

Added weakpointers to Sidebar to make sure things aren't double-deleted

Reviewed-by: con
parent 3be86bb8
......@@ -69,7 +69,12 @@ SideBar::SideBar(QList<SideBarItem*> itemList,
SideBar::~SideBar()
{
qDeleteAll(m_itemMap);
QMutableMapIterator<QString, QWeakPointer<SideBarItem> > iter(m_itemMap);
while(iter.hasNext()) {
iter.next();
if (!iter.value().isNull())
delete iter.value().data();
}
}
QStringList SideBar::availableItems() const
......@@ -93,9 +98,9 @@ void SideBar::setCloseWhenEmpty(bool value)
void SideBar::makeItemAvailable(SideBarItem *item)
{
QMap<QString, SideBarItem*>::const_iterator it = m_itemMap.constBegin();
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = m_itemMap.constBegin();
while (it != m_itemMap.constEnd()) {
if (it.value() == item) {
if (it.value().data() == item) {
m_availableItems.append(it.key());
m_unavailableItems.removeAll(it.key());
qSort(m_availableItems);
......@@ -135,7 +140,7 @@ SideBarItem *SideBar::item(const QString &title)
m_unavailableItems.append(title);
emit availableItemsChanged();
return m_itemMap.value(title);
return m_itemMap.value(title).data();
}
return 0;
}
......@@ -241,10 +246,10 @@ void SideBar::readSettings(QSettings *settings, const QString &name)
void SideBar::activateItem(SideBarItem *item)
{
QMap<QString, SideBarItem*>::const_iterator it = m_itemMap.constBegin();
QMap<QString, QWeakPointer<SideBarItem> >::const_iterator it = m_itemMap.constBegin();
QString title;
while (it != m_itemMap.constEnd()) {
if (it.value() == item) {
if (it.value().data() == item) {
title = it.key();
break;
}
......
......@@ -60,8 +60,9 @@ class ComboBox;
*
* The SideBarItem takes ownership over the widget.
*/
class CORE_EXPORT SideBarItem
class CORE_EXPORT SideBarItem : public QObject
{
Q_OBJECT
public:
SideBarItem(QWidget *widget)
: m_widget(widget)
......@@ -93,8 +94,8 @@ public:
/*
* The SideBar takes ownership of the SideBarItems.
*/
SideBar(QList<SideBarItem*> widgetList,
QList<SideBarItem*> defaultVisible);
SideBar(QList< SideBarItem*> widgetList,
QList< SideBarItem*> defaultVisible);
~SideBar();
QStringList availableItems() const;
......@@ -129,7 +130,7 @@ private:
void removeSideBarWidget(Internal::SideBarWidget *widget);
QList<Internal::SideBarWidget*> m_widgets;
QMap<QString, SideBarItem*> m_itemMap;
QMap<QString, QWeakPointer<SideBarItem> > m_itemMap;
QStringList m_availableItems;
QStringList m_unavailableItems;
QStringList m_defaultVisible;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment