Optimizes includes and forward declarations.
Fixes a bug where SectionWidget removes itself from _sections list during a qDeleteAll call on _sections.. that was stupid..
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSplitter>
|
||||
#include <QLayout>
|
||||
|
||||
#include "ads/ContainerWidget.h"
|
||||
#include "ads/SectionWidget.h"
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "ads/ContainerWidget.h"
|
||||
#include "ads/Internal.h"
|
||||
#include "ads/SectionTitleWidget.h"
|
||||
#include "ads/SectionContentWidget.h"
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
@@ -10,6 +7,13 @@
|
||||
#include <QSplitter>
|
||||
#include <QDataStream>
|
||||
#include <QtGlobal>
|
||||
#include <QGridLayout>
|
||||
#include <QPoint>
|
||||
|
||||
#include "ads/Internal.h"
|
||||
#include "ads/SectionWidget.h"
|
||||
#include "ads/SectionTitleWidget.h"
|
||||
#include "ads/SectionContentWidget.h"
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
@@ -37,6 +41,27 @@ ContainerWidget::ContainerWidget(QWidget *parent) :
|
||||
setLayout(_mainLayout);
|
||||
}
|
||||
|
||||
ContainerWidget::~ContainerWidget()
|
||||
{
|
||||
// Note: It's required to delete in 2 steps
|
||||
// Remove from list, and then delete.
|
||||
// Because the destrcutor of objects wants to modfiy the current
|
||||
// iterating list as well... :-/
|
||||
while (!_sections.isEmpty())
|
||||
{
|
||||
SectionWidget* sw = _sections.takeLast();
|
||||
delete sw;
|
||||
}
|
||||
while (!_floatings.isEmpty())
|
||||
{
|
||||
FloatingWidget* fw = _floatings.takeLast();
|
||||
delete fw;
|
||||
}
|
||||
_scLookupMapById.clear();
|
||||
_scLookupMapByName.clear();
|
||||
_swLookupMapById.clear();
|
||||
}
|
||||
|
||||
Qt::Orientation ContainerWidget::orientation() const
|
||||
{
|
||||
return _orientation;
|
||||
@@ -70,7 +95,12 @@ SectionWidget* ContainerWidget::addSectionContent(const SectionContent::RefPtr&
|
||||
data.content = sc;
|
||||
data.titleWidget = new SectionTitleWidget(sc, NULL);
|
||||
data.contentWidget = new SectionContentWidget(sc, NULL);
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
QObject::connect(data.titleWidget, &SectionTitleWidget::activeTabChanged, this, &ContainerWidget::onActiveTabChanged);
|
||||
#else
|
||||
QObject::connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged()));
|
||||
#endif
|
||||
|
||||
return dropContent(data, sw, area, false);
|
||||
}
|
||||
@@ -96,7 +126,7 @@ bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
|
||||
hsi.data.titleWidget->setVisible(true);
|
||||
hsi.data.contentWidget->setVisible(true);
|
||||
SectionWidget* sw = NULL;
|
||||
if (hsi.preferredSectionId > 0 && (sw = SectionWidget::GetLookupMap().value(hsi.preferredSectionId)) != NULL)
|
||||
if (hsi.preferredSectionId > 0 && (sw = SWLookupMapById(this).value(hsi.preferredSectionId)) != NULL)
|
||||
{
|
||||
sw->addContent(hsi.data, true);
|
||||
return true;
|
||||
@@ -343,7 +373,7 @@ QByteArray ContainerWidget::saveState() const
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value().preferredSectionId <= 0 || !SectionWidget::GetLookupMap().contains(iter.value().preferredSectionId))
|
||||
if (iter.value().preferredSectionId <= 0 || !SWLookupMapById(this).contains(iter.value().preferredSectionId))
|
||||
cnt++;
|
||||
}
|
||||
out << cnt;
|
||||
@@ -351,7 +381,7 @@ QByteArray ContainerWidget::saveState() const
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value().preferredSectionId <= 0 || !SectionWidget::GetLookupMap().contains(iter.value().preferredSectionId))
|
||||
if (iter.value().preferredSectionId <= 0 || !SWLookupMapById(this).contains(iter.value().preferredSectionId))
|
||||
out << iter.value().data.content->uniqueName();
|
||||
}
|
||||
}
|
||||
@@ -417,7 +447,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
||||
QString uname;
|
||||
in >> uname;
|
||||
|
||||
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname);
|
||||
const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname);
|
||||
if (!sc)
|
||||
continue;
|
||||
|
||||
@@ -442,7 +472,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
||||
{
|
||||
QString uname;
|
||||
in >> uname;
|
||||
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname);
|
||||
const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname);
|
||||
if (!sc)
|
||||
continue;
|
||||
|
||||
@@ -478,7 +508,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
||||
contents.append(contentsToHide.at(i));
|
||||
|
||||
// Compare restored contents with available contents
|
||||
const QList<SectionContent::WeakPtr> allContents = SectionContent::GetLookupMap().values();
|
||||
const QList<SectionContent::WeakPtr> allContents = SCLookupMapById(this).values();
|
||||
for (int i = 0; i < allContents.count(); ++i)
|
||||
{
|
||||
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
||||
@@ -885,7 +915,7 @@ bool ContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, QList
|
||||
in >> visible;
|
||||
qDebug() << "Restore FloatingWidget" << uname << geom << visible;
|
||||
|
||||
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname).toStrongRef();
|
||||
const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname).toStrongRef();
|
||||
if (!sc)
|
||||
{
|
||||
qWarning() << "Can not find SectionContent:" << uname;
|
||||
@@ -963,7 +993,7 @@ bool ContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QSplit
|
||||
int preferredIndex = -1;
|
||||
in >> preferredIndex;
|
||||
|
||||
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname).toStrongRef();
|
||||
const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname).toStrongRef();
|
||||
if (!sc)
|
||||
{
|
||||
qWarning() << "Can not find SectionContent:" << uname;
|
||||
@@ -1039,7 +1069,7 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
||||
if (!a)
|
||||
return;
|
||||
const int uid = a->property("uid").toInt();
|
||||
const SectionContent::RefPtr sc = SectionContent::GetLookupMap().value(uid).toStrongRef();
|
||||
const SectionContent::RefPtr sc = SCLookupMapById(this).value(uid).toStrongRef();
|
||||
if (sc.isNull())
|
||||
{
|
||||
qCritical() << "Can not find content by ID" << uid;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include "ads/SectionContent.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
|
||||
#include "ads/Internal.h"
|
||||
#include "ads/ContainerWidget.h"
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
SectionContent::SectionContent() :
|
||||
@@ -17,7 +21,7 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
||||
qFatal("Can not create SectionContent with empty uniqueName");
|
||||
return RefPtr();
|
||||
}
|
||||
else if (GetLookupMapByName().contains(uniqueName))
|
||||
else if (SCLookupMapByName(container).contains(uniqueName))
|
||||
{
|
||||
qFatal("Can not create SectionContent with already used uniqueName");
|
||||
return RefPtr();
|
||||
@@ -34,17 +38,18 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
||||
sc->_titleWidget = title;
|
||||
sc->_contentWidget = content;
|
||||
|
||||
GetLookupMap().insert(sc->uid(), sc);
|
||||
if (!sc->uniqueName().isEmpty())
|
||||
GetLookupMapByName().insert(sc->uniqueName(), sc);
|
||||
|
||||
SCLookupMapById(container).insert(sc->uid(), sc);
|
||||
SCLookupMapByName(container).insert(sc->uniqueName(), sc);
|
||||
return sc;
|
||||
}
|
||||
|
||||
SectionContent::~SectionContent()
|
||||
{
|
||||
GetLookupMap().remove(_uid);
|
||||
GetLookupMapByName().remove(_uniqueName);
|
||||
if (_containerWidget)
|
||||
{
|
||||
SCLookupMapById(_containerWidget).remove(_uid);
|
||||
SCLookupMapByName(_containerWidget).remove(_uniqueName);
|
||||
}
|
||||
delete _titleWidget;
|
||||
delete _contentWidget;
|
||||
}
|
||||
@@ -97,16 +102,4 @@ int SectionContent::GetNextUid()
|
||||
return ++NextUid;
|
||||
}
|
||||
|
||||
QHash<int, SectionContent::WeakPtr>& SectionContent::GetLookupMap()
|
||||
{
|
||||
static QHash<int, SectionContent::WeakPtr> LookupMap;
|
||||
return LookupMap;
|
||||
}
|
||||
|
||||
QHash<QString, SectionContent::WeakPtr>& SectionContent::GetLookupMapByName()
|
||||
{
|
||||
static QHash<QString, SectionContent::WeakPtr> LookupMapByName;
|
||||
return LookupMapByName;
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
|
||||
@@ -73,16 +73,17 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
||||
setGraphicsEffect(shadow);
|
||||
#endif
|
||||
|
||||
GetLookupMap().insert(_uid, this);
|
||||
GetLookupMapByContainer()[_container].insert(_uid, this);
|
||||
SWLookupMapById(_container).insert(_uid, this);
|
||||
}
|
||||
|
||||
SectionWidget::~SectionWidget()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
GetLookupMap().remove(_uid);
|
||||
GetLookupMapByContainer()[_container].remove(_uid);
|
||||
_container->_sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||
if (_container)
|
||||
{
|
||||
SWLookupMapById(_container).remove(_uid);
|
||||
_container->_sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||
}
|
||||
|
||||
// Delete empty QSplitter.
|
||||
QSplitter* splitter = findParentSplitter(this);
|
||||
@@ -324,17 +325,17 @@ int SectionWidget::GetNextUid()
|
||||
return ++NextUid;
|
||||
}
|
||||
|
||||
QHash<int, SectionWidget*>& SectionWidget::GetLookupMap()
|
||||
{
|
||||
static QHash<int, SectionWidget*> LookupMap;
|
||||
return LookupMap;
|
||||
//QHash<int, SectionWidget*>& SectionWidget::GetLookupMap()
|
||||
//{
|
||||
// static QHash<int, SectionWidget*> LookupMap;
|
||||
// return LookupMap;
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
QHash<ContainerWidget*, QHash<int, SectionWidget*> >& SectionWidget::GetLookupMapByContainer()
|
||||
{
|
||||
static QHash<ContainerWidget*, QHash<int, SectionWidget*> > LookupMapByContainer;
|
||||
return LookupMapByContainer;
|
||||
}
|
||||
//QHash<ContainerWidget*, QHash<int, SectionWidget*> >& SectionWidget::GetLookupMapByContainer()
|
||||
//{
|
||||
// static QHash<ContainerWidget*, QHash<int, SectionWidget*> > LookupMapByContainer;
|
||||
// return LookupMapByContainer;
|
||||
//}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user