Skip to content

Commit

Permalink
Refactor|Client: Renamed ui::Context to ui::Data
Browse files Browse the repository at this point in the history
Data is a more descriptive name for this purpose, and "Context" is
already in use in the script subsystem.
  • Loading branch information
skyjake committed Aug 28, 2013
1 parent c119e72 commit 86cea87
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 141 deletions.
8 changes: 4 additions & 4 deletions doomsday/client/client.pro
Expand Up @@ -353,8 +353,8 @@ DENG_HEADERS += \
include/ui/widgets/choicewidget.h \
include/ui/widgets/consolecommandwidget.h \
include/ui/widgets/consolewidget.h \
include/ui/widgets/context.h \
include/ui/widgets/contextwidgetorganizer.h \
include/ui/widgets/data.h \
include/ui/widgets/documentwidget.h \
include/ui/widgets/gameselectionwidget.h \
include/ui/widgets/dialogwidget.h \
Expand All @@ -368,7 +368,7 @@ DENG_HEADERS += \
include/ui/widgets/labelwidget.h \
include/ui/widgets/legacywidget.h \
include/ui/widgets/lineeditwidget.h \
include/ui/widgets/listcontext.h \
include/ui/widgets/listdata.h \
include/ui/widgets/logwidget.h \
include/ui/widgets/margins.h \
include/ui/widgets/menuwidget.h \
Expand Down Expand Up @@ -671,8 +671,8 @@ SOURCES += \
src/ui/widgets/choicewidget.cpp \
src/ui/widgets/consolecommandwidget.cpp \
src/ui/widgets/consolewidget.cpp \
src/ui/widgets/context.cpp \
src/ui/widgets/contextwidgetorganizer.cpp \
src/ui/widgets/data.cpp \
src/ui/widgets/documentwidget.cpp \
src/ui/widgets/gameselectionwidget.cpp \
src/ui/widgets/dialogwidget.cpp \
Expand All @@ -685,7 +685,7 @@ SOURCES += \
src/ui/widgets/labelwidget.cpp \
src/ui/widgets/legacywidget.cpp \
src/ui/widgets/lineeditwidget.cpp \
src/ui/widgets/listcontext.cpp \
src/ui/widgets/listdata.cpp \
src/ui/widgets/logwidget.cpp \
src/ui/widgets/margins.cpp \
src/ui/widgets/menuwidget.cpp \
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/include/ui/widgets/choicewidget.h
Expand Up @@ -58,13 +58,13 @@ class ChoiceWidget : public ButtonWidget

void setOpeningDirection(ui::Direction dir);

ui::Context &items();
ui::Data &items();

PopupMenuWidget &popup();

void setSelected(ui::Context::Pos pos);
void setSelected(ui::Data::Pos pos);

ui::Context::Pos selected() const;
ui::Data::Pos selected() const;
ui::Item const &selectedItem() const;

public slots:
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/include/ui/widgets/contextwidgetorganizer.h
Expand Up @@ -19,7 +19,7 @@
#ifndef DENG_CLIENT_CONTEXTWIDGETORGANIZER_H
#define DENG_CLIENT_CONTEXTWIDGETORGANIZER_H

#include "context.h"
#include "data.h"
#include "guiwidget.h"

/**
Expand Down Expand Up @@ -108,13 +108,13 @@ class ContextWidgetOrganizer
*
* @param context Context with items.
*/
void setContext(ui::Context const &context);
void setContext(ui::Data const &context);

void unsetContext();

ui::Context const &context() const;
ui::Data const &context() const;

GuiWidget *itemWidget(ui::Context::Pos pos) const;
GuiWidget *itemWidget(ui::Data::Pos pos) const;
GuiWidget *itemWidget(ui::Item const &item) const;
GuiWidget *itemWidget(de::String const &label) const;

Expand Down
@@ -1,4 +1,4 @@
/** @file context.h UI data context.
/** @file data.h UI data context.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,8 +16,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_CONTEXT_H
#define DENG_CLIENT_UI_CONTEXT_H
#ifndef DENG_CLIENT_UI_DATA_H
#define DENG_CLIENT_UI_DATA_H

#include <de/Observers>
#include "ui/widgets/guiwidget.h"
Expand All @@ -27,58 +27,59 @@ namespace ui {
class Item;

/**
* UI data context containing an enumerable collection of items. Context and
* ui::Item are pure data -- they know nothing about how the data is presented.
* There may be multiple simultaneous, alternative presentations of the same
* context and items.
* UI data context containing an enumerable collection of items. ui::Data and
* ui::Item are pure content -- they know nothing about how the data is
* presented. There may be multiple simultaneous, alternative presentations of
* the same context and items.
*
* Modifying a Context will automatically cause the changes to be reflected in
* any widget currently presenting the context's items.
* Modifying Data will automatically cause the changes to be reflected in
* any widget currently presenting the data context's items.
*
* Context has ownership of all the items in it.
* Data has ownership of all the items in it.
*
* @see ContextWidgetOrganizer
*/
class Context
class Data
{
public:
typedef de::dsize Pos;

static de::dsize const InvalidPos;

/**
* Notified when a new item is added to the context.
* Notified when a new item is added to the data context.
*/
DENG2_DEFINE_AUDIENCE(Addition, void contextItemAdded(Pos id, Item const &item))

/**
* Notified when an item has been removed from the context. When this is
* called @a item is no longer in the context and can be modified at will.
* Notified when an item has been removed from the data context. When this
* is called @a item is no longer in the context and can be modified at
* will.
*/
DENG2_DEFINE_AUDIENCE(Removal, void contextItemRemoved(Pos oldId, Item &item))

DENG2_DEFINE_AUDIENCE(OrderChange, void contextItemOrderChanged())

public:
virtual ~Context() {}
virtual ~Data() {}

virtual Context &clear() = 0;
virtual Data &clear() = 0;

inline bool isEmpty() const { return !size(); }

inline Context &operator << (Item *item) { return append(item); }
inline Data &operator << (Item *item) { return append(item); }

inline Context &append(Item *item) { return insert(size(), item); }
inline Data &append(Item *item) { return insert(size(), item); }

/**
* Insert an item into the context.
* Insert an item into the data context.
*
* @param pos Position of the item.
* @param item Item to insert. Context gets ownership.
*
* @return Reference to this Context.
* @return Reference to this Data.
*/
virtual Context &insert(Pos pos, Item *item) = 0;
virtual Data &insert(Pos pos, Item *item) = 0;

virtual void remove(Pos pos) = 0;

Expand All @@ -91,7 +92,7 @@ class Context
*
* @param item Item to find.
*
* @return The items' position, or Context::InvalidPos if not found.
* @return The items' position, or Data::InvalidPos if not found.
*/
virtual Pos find(Item const &item) const = 0;

Expand All @@ -100,7 +101,7 @@ class Context
*
* @param data Data to find.
*
* @return The items' position, or Context::InvalidPos if not found.
* @return The items' position, or Data::InvalidPos if not found.
*/
virtual Pos findData(QVariant const &data) const = 0;

Expand All @@ -118,11 +119,11 @@ class Context
virtual void stableSort(LessThanFunc func) = 0;

/**
* Returns the total number of items in the context.
* Returns the total number of items in the data context.
*/
virtual de::dsize size() const = 0;
};

} // namespace ui

#endif // DENG_CLIENT_UI_CONTEXT_H
#endif // DENG_CLIENT_UI_DATA_H
38 changes: 19 additions & 19 deletions doomsday/client/include/ui/widgets/item.h
@@ -1,4 +1,4 @@
/** @file item.h Context item.
/** @file item.h Data context item.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,8 +16,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_CONTEXTITEM_H
#define DENG_CLIENT_UI_CONTEXTITEM_H
#ifndef DENG_CLIENT_UI_DATAITEM_H
#define DENG_CLIENT_UI_DATAITEM_H

#include <de/Observers>
#include <de/String>
Expand All @@ -26,17 +26,17 @@

namespace ui {

class Context;
class Data;

/**
* Data item.
*
* Context items are pure content -- the exact presentation parameters (widget
* type, alignment, scaling, etc.) is determined by the container widget and/or
* Items are pure content -- the exact presentation parameters (widget type,
* alignment, scaling, etc.) is determined by the container widget and/or
* responsible organizer, not by the item. This allows one item to be presented
* in different ways by different widgets/contexts.
*
* @see ui::Context
* @see ui::Data
*/
class Item
{
Expand All @@ -55,11 +55,6 @@ class Item
Separator = 0x200,

DefaultSemantics = ShownAsLabel

//Action, ///< Closes popup menu.
//Submenu,
//Separator,
//Toggle
};
Q_DECLARE_FLAGS(Semantics, SemanticFlag)

Expand All @@ -78,12 +73,12 @@ class Item

de::String label() const;

void setContext(Context &context) { _context = &context; }
void setDataContext(Data &context) { _context = &context; }

bool hasContext() const { return _context != 0; }
bool hasDataContext() const { return _context != 0; }

Context &context() const {
DENG2_ASSERT(_context != 0);
Data &dataContext() const {
DENG2_ASSERT(hasDataContext());
return *_context;
}

Expand All @@ -93,6 +88,11 @@ class Item
*/
virtual de::String sortKey() const;

/**
* Sets the custom user data of the item.
*
* @param d Variant data to be associated with the item.
*/
void setData(QVariant const &d) { _data = d; }

QVariant const &data() const { return _data; }
Expand All @@ -107,15 +107,15 @@ class Item

private:
Semantics _semantics;
Context *_context;
Data *_context;
de::String _label;
QVariant _data;

friend class Context;
friend class Data;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Item::Semantics)

} // namespace ui

#endif // DENG_CLIENT_UI_CONTEXTITEM_H
#endif // DENG_CLIENT_UI_DATAITEM_H
2 changes: 1 addition & 1 deletion doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -25,7 +25,7 @@

#include "guiwidget.h"
#include "../uidefs.h"
#include "context.h"
#include "data.h"
#include "proceduralimage.h"

/**
Expand Down
@@ -1,4 +1,4 @@
/** @file listcontext.h List-based UI data context.
/** @file listdata.h List-based UI data context.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,10 +16,10 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_LISTCONTEXT_H
#define DENG_CLIENT_UI_LISTCONTEXT_H
#ifndef DENG_CLIENT_UI_LISTDATA_H
#define DENG_CLIENT_UI_LISTDATA_H

#include "context.h"
#include "data.h"
#include "item.h"

#include <QList>
Expand All @@ -29,19 +29,19 @@ namespace ui {
/**
* List-based UI data context.
*/
class ListContext : public Context
class ListData : public Data
{
public:
ListContext() {}
~ListContext();
ListData() {}
~ListData();

de::dsize size() const;
Item const &at(Pos pos) const;
Pos find(Item const &item) const;
Pos findData(QVariant const &data) const;

Context &clear();
Context &insert(Pos pos, Item *item);
Data &clear();
Data &insert(Pos pos, Item *item);
void remove(Pos pos);
Item *take(Pos pos);
void sort(LessThanFunc lessThan);
Expand All @@ -54,4 +54,4 @@ class ListContext : public Context

} // namespace ui

#endif // DENG_CLIENT_UI_LISTCONTEXT_H
#endif // DENG_CLIENT_UI_LISTDATA_H
8 changes: 4 additions & 4 deletions doomsday/client/include/ui/widgets/menuwidget.h
Expand Up @@ -21,7 +21,7 @@

#include "scrollareawidget.h"
#include "buttonwidget.h"
#include "context.h"
#include "data.h"
#include "contextwidgetorganizer.h"
#include "actionitem.h"
#include "submenuitem.h"
Expand Down Expand Up @@ -73,17 +73,17 @@ class MenuWidget : public ScrollAreaWidget
void setGridSize(int columns, ui::SizePolicy columnPolicy,
int rows, ui::SizePolicy rowPolicy);

ui::Context &items();
ui::Data &items();

ui::Context const &items() const;
ui::Data const &items() const;

/**
* Sets the data context of the menu to some existing context. The context
* must remain in existence until the MenuWidget is deleted.
*
* @param items Ownership not taken.
*/
void setItems(ui::Context const &items);
void setItems(ui::Data const &items);

ContextWidgetOrganizer const &organizer() const;

Expand Down

0 comments on commit 86cea87

Please sign in to comment.