mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Uses static lazy loaded QHash objects instead of static linker initialized
class members. This should fix multi initialization when linking static into DLL and EXE at the same time. Hopefully..
This commit is contained in:
parent
8508a0323a
commit
0238828afa
@ -50,9 +50,12 @@ private:
|
|||||||
QPointer<QWidget> _title;
|
QPointer<QWidget> _title;
|
||||||
QPointer<QWidget> _content;
|
QPointer<QWidget> _content;
|
||||||
|
|
||||||
static int NextUid;
|
static int GetNextUid();
|
||||||
static QHash<int, SectionContent::WeakPtr> LookupMap;
|
static QHash<int, SectionContent::WeakPtr>& GetLookupMap();
|
||||||
static QHash<QString, SectionContent::WeakPtr> LookupMapByName;
|
static QHash<QString, SectionContent::WeakPtr>& GetLookupMapByName();
|
||||||
|
|
||||||
|
//static QHash<int, SectionContent::WeakPtr> LookupMap;
|
||||||
|
//static QHash<QString, SectionContent::WeakPtr> LookupMapByName;
|
||||||
};
|
};
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
|
@ -68,9 +68,13 @@ private:
|
|||||||
SectionContent::RefPtr _mousePressContent;
|
SectionContent::RefPtr _mousePressContent;
|
||||||
SectionTitleWidget* _mousePressTitleWidget;
|
SectionTitleWidget* _mousePressTitleWidget;
|
||||||
|
|
||||||
static int NextUid;
|
static int GetNextUid();
|
||||||
static QHash<int, SectionWidget*> LookupMap;
|
static QHash<int, SectionWidget*>& GetLookupMap();
|
||||||
static QHash<ContainerWidget*, QHash<int, SectionWidget*> > LookupMapByContainer;
|
static QHash<ContainerWidget*, QHash<int, SectionWidget*> >& GetLookupMapByContainer();
|
||||||
|
|
||||||
|
// static int NextUid;
|
||||||
|
// static QHash<int, SectionWidget*> LookupMap;
|
||||||
|
// static QHash<ContainerWidget*, QHash<int, SectionWidget*> > LookupMapByContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
|
@ -94,7 +94,7 @@ bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
|
|||||||
hsi.data.titleWidget->setVisible(true);
|
hsi.data.titleWidget->setVisible(true);
|
||||||
hsi.data.contentWidget->setVisible(true);
|
hsi.data.contentWidget->setVisible(true);
|
||||||
SectionWidget* sw = NULL;
|
SectionWidget* sw = NULL;
|
||||||
if (hsi.preferredSectionId > 0 && (sw = SectionWidget::LookupMap.value(hsi.preferredSectionId)) != NULL)
|
if (hsi.preferredSectionId > 0 && (sw = SectionWidget::GetLookupMap().value(hsi.preferredSectionId)) != NULL)
|
||||||
{
|
{
|
||||||
sw->addContent(hsi.data, true);
|
sw->addContent(hsi.data, true);
|
||||||
return true;
|
return true;
|
||||||
@ -302,7 +302,7 @@ QByteArray ContainerWidget::saveState() const
|
|||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
iter.next();
|
iter.next();
|
||||||
if (iter.value().preferredSectionId <= 0 || !SectionWidget::LookupMap.contains(iter.value().preferredSectionId))
|
if (iter.value().preferredSectionId <= 0 || !SectionWidget::GetLookupMap().contains(iter.value().preferredSectionId))
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
out << cnt;
|
out << cnt;
|
||||||
@ -310,7 +310,7 @@ QByteArray ContainerWidget::saveState() const
|
|||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
iter.next();
|
iter.next();
|
||||||
if (iter.value().preferredSectionId <= 0 || !SectionWidget::LookupMap.contains(iter.value().preferredSectionId))
|
if (iter.value().preferredSectionId <= 0 || !SectionWidget::GetLookupMap().contains(iter.value().preferredSectionId))
|
||||||
out << iter.value().data.content->uniqueName();
|
out << iter.value().data.content->uniqueName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
|||||||
QString uname;
|
QString uname;
|
||||||
in >> uname;
|
in >> uname;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = SectionContent::LookupMapByName.value(uname);
|
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
|||||||
{
|
{
|
||||||
QString uname;
|
QString uname;
|
||||||
in >> uname;
|
in >> uname;
|
||||||
const SectionContent::RefPtr sc = SectionContent::LookupMapByName.value(uname);
|
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
|||||||
contents.append(contentsToHide.at(i));
|
contents.append(contentsToHide.at(i));
|
||||||
|
|
||||||
// Compare restored contents with available contents
|
// Compare restored contents with available contents
|
||||||
const QList<SectionContent::WeakPtr> allContents = SectionContent::LookupMap.values();
|
const QList<SectionContent::WeakPtr> allContents = SectionContent::GetLookupMap().values();
|
||||||
for (int i = 0; i < allContents.count(); ++i)
|
for (int i = 0; i < allContents.count(); ++i)
|
||||||
{
|
{
|
||||||
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
||||||
@ -844,7 +844,7 @@ bool ContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, QList
|
|||||||
in >> visible;
|
in >> visible;
|
||||||
qDebug() << "Restore FloatingWidget" << uname << geom << visible;
|
qDebug() << "Restore FloatingWidget" << uname << geom << visible;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = SectionContent::LookupMapByName.value(uname).toStrongRef();
|
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname).toStrongRef();
|
||||||
if (!sc)
|
if (!sc)
|
||||||
{
|
{
|
||||||
qWarning() << "Can not find SectionContent:" << uname;
|
qWarning() << "Can not find SectionContent:" << uname;
|
||||||
@ -922,7 +922,7 @@ bool ContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QSplit
|
|||||||
int preferredIndex = -1;
|
int preferredIndex = -1;
|
||||||
in >> preferredIndex;
|
in >> preferredIndex;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = SectionContent::LookupMapByName.value(uname).toStrongRef();
|
const SectionContent::RefPtr sc = SectionContent::GetLookupMapByName().value(uname).toStrongRef();
|
||||||
if (!sc)
|
if (!sc)
|
||||||
{
|
{
|
||||||
qWarning() << "Can not find SectionContent:" << uname;
|
qWarning() << "Can not find SectionContent:" << uname;
|
||||||
@ -988,7 +988,7 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
|||||||
if (!a)
|
if (!a)
|
||||||
return;
|
return;
|
||||||
const int uid = a->property("uid").toInt();
|
const int uid = a->property("uid").toInt();
|
||||||
const SectionContent::RefPtr sc = SectionContent::LookupMap.value(uid).toStrongRef();
|
const SectionContent::RefPtr sc = SectionContent::GetLookupMap().value(uid).toStrongRef();
|
||||||
if (sc.isNull())
|
if (sc.isNull())
|
||||||
{
|
{
|
||||||
qCritical() << "Can not find content by ID" << uid;
|
qCritical() << "Can not find content by ID" << uid;
|
||||||
|
@ -5,12 +5,8 @@
|
|||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
int SectionContent::NextUid = 1;
|
|
||||||
QHash<int, SectionContent::WeakPtr> SectionContent::LookupMap;
|
|
||||||
QHash<QString, SectionContent::WeakPtr> SectionContent::LookupMapByName;
|
|
||||||
|
|
||||||
SectionContent::SectionContent() :
|
SectionContent::SectionContent() :
|
||||||
_uid(NextUid++)
|
_uid(GetNextUid())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +17,7 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
|||||||
qFatal("Can not create SectionContent with empty uniqueName");
|
qFatal("Can not create SectionContent with empty uniqueName");
|
||||||
return RefPtr();
|
return RefPtr();
|
||||||
}
|
}
|
||||||
else if (LookupMapByName.contains(uniqueName))
|
else if (GetLookupMapByName().contains(uniqueName))
|
||||||
{
|
{
|
||||||
qFatal("Can not create SectionContent with already used uniqueName");
|
qFatal("Can not create SectionContent with already used uniqueName");
|
||||||
return RefPtr();
|
return RefPtr();
|
||||||
@ -38,17 +34,17 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
|||||||
sc->_title = title;
|
sc->_title = title;
|
||||||
sc->_content = content;
|
sc->_content = content;
|
||||||
|
|
||||||
LookupMap.insert(sc->uid(), sc);
|
GetLookupMap().insert(sc->uid(), sc);
|
||||||
if (!sc->uniqueName().isEmpty())
|
if (!sc->uniqueName().isEmpty())
|
||||||
LookupMapByName.insert(sc->uniqueName(), sc);
|
GetLookupMapByName().insert(sc->uniqueName(), sc);
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionContent::~SectionContent()
|
SectionContent::~SectionContent()
|
||||||
{
|
{
|
||||||
LookupMap.remove(_uid);
|
GetLookupMap().remove(_uid);
|
||||||
LookupMapByName.remove(_uniqueName);
|
GetLookupMapByName().remove(_uniqueName);
|
||||||
delete _title;
|
delete _title;
|
||||||
delete _content;
|
delete _content;
|
||||||
}
|
}
|
||||||
@ -78,4 +74,22 @@ QWidget* SectionContent::contentWidget() const
|
|||||||
return _content;
|
return _content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SectionContent::GetNextUid()
|
||||||
|
{
|
||||||
|
static int NextUid = 0;
|
||||||
|
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
|
ADS_NAMESPACE_END
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
int SectionWidget::NextUid = 1;
|
//int SectionWidget::NextUid = 1;
|
||||||
QHash<int, SectionWidget*> SectionWidget::LookupMap;
|
//QHash<int, SectionWidget*> SectionWidget::LookupMap;
|
||||||
QHash<ContainerWidget*, QHash<int, SectionWidget*> > SectionWidget::LookupMapByContainer;
|
//QHash<ContainerWidget*, QHash<int, SectionWidget*> > SectionWidget::LookupMapByContainer;
|
||||||
|
|
||||||
SectionWidget::SectionWidget(ContainerWidget* parent) :
|
SectionWidget::SectionWidget(ContainerWidget* parent) :
|
||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
_uid(NextUid++),
|
_uid(GetNextUid()),
|
||||||
_container(parent),
|
_container(parent),
|
||||||
_tabsLayout(NULL),
|
_tabsLayout(NULL),
|
||||||
_contentsLayout(NULL),
|
_contentsLayout(NULL),
|
||||||
@ -73,15 +73,15 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
|||||||
setGraphicsEffect(shadow);
|
setGraphicsEffect(shadow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LookupMap.insert(_uid, this);
|
GetLookupMap().insert(_uid, this);
|
||||||
LookupMapByContainer[_container].insert(_uid, this);
|
GetLookupMapByContainer()[_container].insert(_uid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionWidget::~SectionWidget()
|
SectionWidget::~SectionWidget()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
LookupMap.remove(_uid);
|
GetLookupMap().remove(_uid);
|
||||||
LookupMapByContainer[_container].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...
|
_container->_sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||||
|
|
||||||
// Delete empty QSplitter.
|
// Delete empty QSplitter.
|
||||||
@ -318,4 +318,23 @@ void SectionWidget::onCloseButtonClicked()
|
|||||||
_container->hideSectionContent(sc);
|
_container->hideSectionContent(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SectionWidget::GetNextUid()
|
||||||
|
{
|
||||||
|
static int NextUid = 0;
|
||||||
|
return ++NextUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
|
Loading…
Reference in New Issue
Block a user