Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit e6dad8b

Browse files
committed
WindowState can weakly reference a QWidget
1 parent b0279f8 commit e6dad8b

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/libHeaven/CentralUI/States/WindowState.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,31 @@ namespace Heaven
226226
return mOptions.contains(name);
227227
}
228228

229+
void WindowState::setWidget(QWidget* widget)
230+
{
231+
mWidget = widget;
232+
233+
if (mWidget) {
234+
applyConfig();
235+
}
236+
}
237+
238+
void WindowState::clearWidgets()
239+
{
240+
if (mWidget) {
241+
updateConfig();
242+
}
243+
244+
mWidget = NULL;
245+
246+
foreach (WindowState::Ptr pChild, mChildren) {
247+
pChild->clearWidgets();
248+
}
249+
}
250+
251+
QWidget* WindowState::widget() const
252+
{
253+
return mWidget;
254+
}
255+
229256
}

src/libHeaven/CentralUI/States/WindowState.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <QSharedData>
2323
#include <QVariant>
24+
#include <QPointer>
2425
#include <QVector>
2526
#include <QSet>
2627

@@ -82,6 +83,11 @@ namespace Heaven
8283
void setCurrentContent( AbstractViewWidget* avw );
8384
AbstractViewWidget* currentContent();
8485

86+
public:
87+
void setWidget(QWidget* widget);
88+
QWidget* widget() const;
89+
void clearWidgets();
90+
8591
protected:
8692
void readOptions(const QDomElement& el);
8793
void readChildren(const QDomElement& elParent, ChildTypes allowed);
@@ -100,10 +106,11 @@ namespace Heaven
100106
QVector< WindowState::Ptr > mChildren;
101107
ViewIdentifier mId;
102108
QVariantHash mOptions;
109+
QPointer< QWidget > mWidget;
103110
};
104111

105112
}
106113

107-
Q_DECLARE_OPERATORS_FOR_FLAGS( Heaven::WindowState::ChildTypes );
114+
Q_DECLARE_OPERATORS_FOR_FLAGS(Heaven::WindowState::ChildTypes)
108115

109116
#endif

0 commit comments

Comments
 (0)