ManaPlus
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
SetupItem Class Referenceabstract

#include <setupitem.h>

Inheritance diagram for SetupItem:
ActionListener Widget2 SetupActionDropDown SetupButtonItem SetupItemCheckBox SetupItemDropDown SetupItemDropDownStr SetupItemIntTextField SetupItemLabel SetupItemSlider SetupItemSlider2 SetupItemSliderList SetupItemTextField SetupQuickItem

Public Types

enum  { VBOOL = 0 , VSTR , VINT , VNONE }
 

Public Member Functions

 ~SetupItem ()
 
void load ()
 
virtual void save ()
 
virtual void fromWidget ()=0
 
virtual void toWidget ()=0
 
void setWidget (Widget *widget)
 
WidgetgetWidget () const
 
ConfigurationgetConfig () const
 
virtual std::string getActionEventId () const
 
void action (const ActionEvent &event)
 
virtual void doAction ()
 
virtual void apply (const std::string &eventName)
 
virtual void cancel (const std::string &eventName)
 
virtual void externalUpdated (const std::string &eventName)
 
virtual void externalUnloaded (const std::string &eventName)
 
MainConfig isMainConfig () const
 
void fixFirstItemSize (Widget *const widget)
 
virtual void rereadValue ()
 
void setValue (const std::string &str)
 
std::string getValue () const
 
std::string getEventName () const
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 

Protected Member Functions

 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
 
 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const std::string &def, const MainConfig mainConfig)
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 

Protected Attributes

std::string mText
 
std::string mDescription
 
std::string mKeyName
 
SetupTabScrollmParent
 
std::string mEventName
 
std::string mValue
 
std::string mDefault
 
WidgetmWidget
 
std::list< Widget * > mTempWidgets
 
int mValueType
 
MainConfig mMainConfig
 
bool mUseDefault
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Detailed Description

Definition at line 51 of file setupitem.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
VBOOL 
VSTR 
VINT 
VNONE 

Definition at line 55 of file setupitem.h.

56  {
57  VBOOL = 0,
58  VSTR,
59  VINT,
60  VNONE
61  };

Constructor & Destructor Documentation

◆ ~SetupItem()

SetupItem::~SetupItem ( )

Definition at line 102 of file setupitem.cpp.

103 {
104 }

◆ SetupItem() [1/2]

SetupItem::SetupItem ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const MainConfig  mainConfig 
)
protected

Definition at line 55 of file setupitem.cpp.

60  :
62  Widget2(parent),
63  mText(text),
64  mDescription(description),
65  mKeyName(keyName),
66  mParent(parent),
67  mEventName(eventName),
68  mValue(),
69  mDefault(),
70  mWidget(nullptr),
71  mTempWidgets(),
73  mMainConfig(mainConfig),
74  mUseDefault(false)
75 {
76 }
bool mUseDefault
Definition: setupitem.h:151
Widget * mWidget
Definition: setupitem.h:143
SetupTabScroll * mParent
Definition: setupitem.h:135
std::string mDescription
Definition: setupitem.h:131
std::string mValue
Definition: setupitem.h:139
std::string mDefault
Definition: setupitem.h:141
std::string mText
Definition: setupitem.h:129
int mValueType
Definition: setupitem.h:147
std::string mKeyName
Definition: setupitem.h:133
std::string mEventName
Definition: setupitem.h:137
MainConfig mMainConfig
Definition: setupitem.h:149
std::list< Widget * > mTempWidgets
Definition: setupitem.h:145
Widget2(const Widget2 *const widget)
Definition: widget2.h:103

◆ SetupItem() [2/2]

SetupItem::SetupItem ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const std::string &  def,
const MainConfig  mainConfig 
)
protected

Definition at line 78 of file setupitem.cpp.

84  :
86  Widget2(parent),
87  mText(text),
88  mDescription(description),
89  mKeyName(keyName),
90  mParent(parent),
91  mEventName(eventName),
92  mValue(),
93  mDefault(def),
94  mWidget(nullptr),
95  mTempWidgets(),
97  mMainConfig(mainConfig),
98  mUseDefault(true)
99 {
100 }

Member Function Documentation

◆ action()

void SetupItem::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Reimplemented in SetupQuickItem, SetupItemSound, SetupItemSliderList, SetupItemSlider2, SetupItemSlider, SetupItemLabel, SetupItemIntTextField, and SetupItemTextField.

Definition at line 163 of file setupitem.cpp.

164 {
165  if (mWidget == nullptr)
166  return;
167 
168  if (event.getId() == mWidget->getActionEventId())
169  doAction();
170 }
virtual void doAction()
Definition: setupitem.cpp:172
const std::string & getActionEventId() const
Definition: widget.h:605

References doAction(), Widget::getActionEventId(), ActionEvent::getId(), and mWidget.

◆ apply()

void SetupItem::apply ( const std::string &  eventName)
virtual

Reimplemented in SetupQuickItem, SetupItemSliderList, SetupItemSlider2, SetupItemSlider, SetupItemLabel, SetupItemIntTextField, SetupItemTextField, and SetupButtonItem.

Definition at line 177 of file setupitem.cpp.

178 {
179  save();
180 }
virtual void save()
Definition: setupitem.cpp:146

References save().

◆ cancel()

void SetupItem::cancel ( const std::string &  eventName)
virtual

Reimplemented in SetupQuickItem, SetupItemTextField, and SetupButtonItem.

Definition at line 182 of file setupitem.cpp.

183 {
184  load();
185  toWidget();
186 }
void load()
Definition: setupitem.cpp:113
virtual void toWidget()=0

References load(), and toWidget().

◆ doAction()

void SetupItem::doAction ( )
virtual

Definition at line 172 of file setupitem.cpp.

173 {
174  fromWidget();
175 }
virtual void fromWidget()=0

References fromWidget().

Referenced by action().

◆ externalUnloaded()

void SetupItem::externalUnloaded ( const std::string &  eventName)
virtual

Definition at line 194 of file setupitem.cpp.

195 {
196 }

Referenced by SetupTabScroll::externalUnloaded().

◆ externalUpdated()

void SetupItem::externalUpdated ( const std::string &  eventName)
virtual

Reimplemented in SetupQuickItem, SetupItemTextField, and SetupButtonItem.

Definition at line 188 of file setupitem.cpp.

189 {
190  load();
191  toWidget();
192 }

References load(), and toWidget().

Referenced by SetupTabScroll::externalUpdated().

◆ fixFirstItemSize()

void SetupItem::fixFirstItemSize ( Widget *const  widget)

◆ fromWidget()

virtual void SetupItem::fromWidget ( )
pure virtual

◆ getActionEventId()

std::string SetupItem::getActionEventId ( ) const
virtual

Definition at line 155 of file setupitem.cpp.

156 {
157  if (mWidget == nullptr)
158  return std::string();
159 
160  return mWidget->getActionEventId();
161 }

References Widget::getActionEventId(), and mWidget.

Referenced by SetupTabScroll::addControl().

◆ getConfig()

Configuration * SetupItem::getConfig ( ) const

Definition at line 106 of file setupitem.cpp.

107 {
109  return &config;
110  return &serverConfig;
111 }
Configuration config
Configuration serverConfig
const bool MainConfig_true
Definition: mainconfig.h:30

References config, MainConfig_true, mMainConfig, and serverConfig.

Referenced by load(), and save().

◆ getEventName()

std::string SetupItem::getEventName ( ) const
inline

Definition at line 110 of file setupitem.h.

111  { return mEventName; }

References mEventName.

Referenced by Setup_Mods::saveMods().

◆ getValue()

std::string SetupItem::getValue ( ) const
inline

Definition at line 107 of file setupitem.h.

108  { return mValue; }

References mValue.

Referenced by Setup_Mods::saveMods().

◆ getWidget()

Widget* SetupItem::getWidget ( ) const
inline

Definition at line 78 of file setupitem.h.

79  { return mWidget; }

References mWidget.

◆ isMainConfig()

MainConfig SetupItem::isMainConfig ( ) const
inline

Definition at line 97 of file setupitem.h.

98  { return mMainConfig; }

References mMainConfig.

Referenced by SetupTabScroll::externalUnloaded(), and SetupTabScroll::externalUpdated().

◆ load()

void SetupItem::load ( )

Definition at line 113 of file setupitem.cpp.

114 {
115  if (mKeyName.empty())
116  return;
117 
118  const Configuration *const cfg = getConfig();
119  if (mUseDefault)
120  {
121  mValue = cfg->getValue(mKeyName, mDefault);
122  }
123  else
124  {
125  switch (mValueType)
126  {
127  case VBOOL:
128  if (cfg->getBoolValue(mKeyName))
129  mValue = "1";
130  else
131  mValue = "0";
132  break;
133  case VSTR:
134  default:
136  break;
137  case VINT:
139  break;
140  case VNONE:
141  break;
142  }
143  }
144 }
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
int getIntValue(const std::string &key) const
Configuration * getConfig() const
Definition: setupitem.cpp:106
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References Configuration::getBoolValue(), getConfig(), Configuration::getIntValue(), Configuration::getStringValue(), ConfigurationObject::getValue(), mDefault, mKeyName, mUseDefault, mValue, mValueType, Catch::toString(), VBOOL, VINT, VNONE, and VSTR.

Referenced by cancel(), SetupItemTextField::cancel(), SetupItemCheckBox::createControls(), SetupItemTextField::createControls(), SetupItemIntTextField::createControls(), SetupItemDropDown::createControls(), SetupItemDropDownStr::createControls(), SetupItemSlider::createControls(), SetupItemSlider2::createControls(), SetupItemSliderList::createControls(), SetupActionDropDown::createControls(), externalUpdated(), SetupItemTextField::externalUpdated(), rereadValue(), and SetupItemTextField::rereadValue().

◆ rereadValue()

void SetupItem::rereadValue ( )
virtual

Reimplemented in SetupQuickItem, SetupItemTextField, and SetupButtonItem.

Definition at line 207 of file setupitem.cpp.

208 {
209  load();
210  toWidget();
211 }

References load(), and toWidget().

Referenced by SetupTabScroll::reread().

◆ save()

void SetupItem::save ( )
virtual

Reimplemented in SetupQuickItem, SetupItemTextField, and SetupButtonItem.

Definition at line 146 of file setupitem.cpp.

147 {
148  if (mKeyName.empty())
149  return;
150 
151  Configuration *const cfg = getConfig();
152  cfg->setValue(mKeyName, mValue);
153 }
void setValue(const std::string &key, const std::string &value)

References getConfig(), mKeyName, mValue, and Configuration::setValue().

Referenced by SetupItemSlider::action(), SetupItemSlider2::action(), SetupItemSliderList::action(), apply(), SetupItemIntTextField::apply(), SetupItemSlider::apply(), SetupItemSlider2::apply(), SetupItemSliderList::apply(), and SetupItemTextField::save().

◆ setValue()

void SetupItem::setValue ( const std::string &  str)
inline

Definition at line 104 of file setupitem.h.

105  { mValue = str; }

References mValue.

Referenced by Setup_Mods::loadMods().

◆ setWidget()

void SetupItem::setWidget ( Widget widget)
inline

Definition at line 75 of file setupitem.h.

76  { mWidget = widget; }

References mWidget.

◆ toWidget()

virtual void SetupItem::toWidget ( )
pure virtual

Field Documentation

◆ mDefault

std::string SetupItem::mDefault
protected

Definition at line 141 of file setupitem.h.

Referenced by load().

◆ mDescription

std::string SetupItem::mDescription
protected

◆ mEventName

std::string SetupItem::mEventName
protected

◆ mKeyName

std::string SetupItem::mKeyName
protected

Definition at line 133 of file setupitem.h.

Referenced by load(), and save().

◆ mMainConfig

MainConfig SetupItem::mMainConfig
protected

Definition at line 149 of file setupitem.h.

Referenced by getConfig(), and isMainConfig().

◆ mParent

SetupTabScroll* SetupItem::mParent
protected

◆ mTempWidgets

std::list<Widget*> SetupItem::mTempWidgets
protected

Definition at line 145 of file setupitem.h.

◆ mText

std::string SetupItem::mText
protected

◆ mUseDefault

bool SetupItem::mUseDefault
protected

Definition at line 151 of file setupitem.h.

Referenced by load().

◆ mValue

std::string SetupItem::mValue
protected

◆ mValueType

int SetupItem::mValueType
protected

◆ mWidget

Widget* SetupItem::mWidget
protected

The documentation for this class was generated from the following files: