Skip to content

Commit

Permalink
libappfw|GuiWidget: Enabling/disabling widget state serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 6, 2014
1 parent ec6ef2c commit e67b786
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doomsday/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -252,6 +252,14 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget

void removeEventHandler(IEventHandler *handler);

/**
* Enables or disables automatic state serialization for widgets derived from
* IPersistent. State serialization occurs when the widget is gl(De)Init'd.
*
* @param enabled @c true to enable, @c false to disable.
*/
void enableStateSerialization(bool enabled = true);

// Events.
void initialize();
void deinitialize();
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libappfw/src/guiwidget.cpp
Expand Up @@ -47,6 +47,7 @@ DENG2_PIMPL(GuiWidget)
bool inited;
bool needGeometry;
bool styleChanged;
bool stateSerializationEnabled;
Background background;
Animation opacity;
Animation opacityWhenDisabled;
Expand Down Expand Up @@ -74,6 +75,7 @@ DENG2_PIMPL(GuiWidget)
, inited(false)
, needGeometry(true)
, styleChanged(false)
, stateSerializationEnabled(true)
, opacity(1.f, Animation::Linear)
, opacityWhenDisabled(1.f, Animation::Linear)
, firstUpdateAfterCreation(true)
Expand Down Expand Up @@ -319,6 +321,7 @@ DENG2_PIMPL(GuiWidget)

void restoreState()
{
if(!stateSerializationEnabled) return;
try
{
if(IPersistent *po = self.maybeAs<IPersistent>())
Expand All @@ -336,6 +339,7 @@ DENG2_PIMPL(GuiWidget)

void saveState()
{
if(!stateSerializationEnabled) return;
try
{
if(IPersistent *po = self.maybeAs<IPersistent>())
Expand Down Expand Up @@ -535,6 +539,11 @@ void GuiWidget::removeEventHandler(IEventHandler *handler)
d->eventHandlers.removeOne(handler);
}

void GuiWidget::enableStateSerialization(bool enabled)
{
d->stateSerializationEnabled = enabled;
}

void GuiWidget::initialize()
{
if(d->inited) return;
Expand Down

0 comments on commit e67b786

Please sign in to comment.