Skip to content

Commit

Permalink
UI|Client: Store game session filter and sort order persistently
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 20, 2014
1 parent 3e61726 commit 19d1ecc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion doomsday/client/include/ui/widgets/gamefilterwidget.h
Expand Up @@ -20,14 +20,17 @@
#define DENG_CLIENT_GAMEFILTERWIDGET_H

#include <de/GuiWidget>
#include <de/IPersistent>

/**
* Filtering and sorting parameters for a game selection widget. Allows picking the type
* of games to show (singleplayer or multiplayer) and how the games are sorted.
*
* The widget defines its own height, but width must be set manually.
*
* The filter and sort setting is saved persistently.
*/
class GameFilterWidget : public de::GuiWidget
class GameFilterWidget : public de::GuiWidget, public de::IPersistent
{
Q_OBJECT

Expand Down Expand Up @@ -55,6 +58,10 @@ class GameFilterWidget : public de::GuiWidget

SortOrder sortOrder() const;

// Implements IPersistent.
void operator >> (de::PersistentState &toState) const;
void operator << (de::PersistentState const &fromState);

signals:
void filterChanged();
void sortOrderChanged();
Expand Down
23 changes: 22 additions & 1 deletion doomsday/client/src/ui/widgets/gamefilterwidget.cpp
Expand Up @@ -23,6 +23,7 @@
#include <de/SequentialLayout>
#include <de/DialogContentStylist>
#include <de/TabWidget>
#include <de/PersistentState>

using namespace de;

Expand Down Expand Up @@ -62,13 +63,18 @@ DENG2_PIMPL(GameFilterWidget)
.setInput(Rule::Left, self.rule().left())
.setInput(Rule::Top, self.rule().top());
}

String persistId(String const &name) const
{
return self.name() + "." + name;
}
};

GameFilterWidget::GameFilterWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{
connect(d->tabs, SIGNAL(currentTabChanged()), this, SIGNAL(filterChanged()));
connect(d->sortBy, SIGNAL(selectionChangedByUser(uint)), this, SIGNAL(sortOrderChanged()));
connect(d->sortBy, SIGNAL(selectionChanged(uint)), this, SIGNAL(sortOrderChanged()));

rule().setInput(Rule::Height, d->tabs->rule().height());
}
Expand All @@ -88,3 +94,18 @@ GameFilterWidget::SortOrder GameFilterWidget::sortOrder() const
return SortOrder(d->sortBy->selectedItem().data().toInt());
}

void GameFilterWidget::operator >> (PersistentState &toState) const
{
Record &st = toState.names();

st.set(d->persistId("filter"), dint(filter()));
st.set(d->persistId("order"), dint(sortOrder()));
}

void GameFilterWidget::operator << (PersistentState const &fromState)
{
Record const &st = fromState.names();

d->tabs->setCurrent (d->tabs->items() .findData(int(st[d->persistId("filter")])));
d->sortBy->setSelected(d->sortBy->items().findData(int(st[d->persistId("order" )])));
}

0 comments on commit 19d1ecc

Please sign in to comment.