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 50 of file setupitem.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
VBOOL 
VSTR 
VINT 
VNONE 

Definition at line 54 of file setupitem.h.

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

Constructor & Destructor Documentation

◆ ~SetupItem()

SetupItem::~SetupItem ( )

Definition at line 101 of file setupitem.cpp.

102 {
103 }

◆ 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 54 of file setupitem.cpp.

Referenced by getEventName().

59  :
61  Widget2(parent),
62  mText(text),
63  mDescription(description),
64  mKeyName(keyName),
65  mParent(parent),
66  mEventName(eventName),
67  mValue(),
68  mDefault(),
69  mWidget(nullptr),
70  mTempWidgets(),
72  mMainConfig(mainConfig),
73  mUseDefault(false)
74 {
75 }
bool mUseDefault
Definition: setupitem.h:150
std::string mEventName
Definition: setupitem.h:136
std::list< Widget * > mTempWidgets
Definition: setupitem.h:144
std::string mValue
Definition: setupitem.h:138
std::string mKeyName
Definition: setupitem.h:132
std::string mDescription
Definition: setupitem.h:130
MainConfig mMainConfig
Definition: setupitem.h:148
int mValueType
Definition: setupitem.h:146
Widget * mWidget
Definition: setupitem.h:142
SetupTabScroll * mParent
Definition: setupitem.h:134
std::string mDefault
Definition: setupitem.h:140
Widget2(const Widget2 *const widget)
Definition: widget2.h:102
std::string mText
Definition: setupitem.h:128

◆ 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 77 of file setupitem.cpp.

83  :
85  Widget2(parent),
86  mText(text),
87  mDescription(description),
88  mKeyName(keyName),
89  mParent(parent),
90  mEventName(eventName),
91  mValue(),
92  mDefault(def),
93  mWidget(nullptr),
94  mTempWidgets(),
96  mMainConfig(mainConfig),
97  mUseDefault(true)
98 {
99 }
bool mUseDefault
Definition: setupitem.h:150
std::string mEventName
Definition: setupitem.h:136
std::list< Widget * > mTempWidgets
Definition: setupitem.h:144
std::string mValue
Definition: setupitem.h:138
std::string mKeyName
Definition: setupitem.h:132
std::string mDescription
Definition: setupitem.h:130
MainConfig mMainConfig
Definition: setupitem.h:148
int mValueType
Definition: setupitem.h:146
Widget * mWidget
Definition: setupitem.h:142
SetupTabScroll * mParent
Definition: setupitem.h:134
std::string mDefault
Definition: setupitem.h:140
Widget2(const Widget2 *const widget)
Definition: widget2.h:102
std::string mText
Definition: setupitem.h:128

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 SetupItemSound, SetupItemSliderList, SetupItemSlider2, SetupItemSlider, SetupItemLabel, SetupItemIntTextField, SetupItemTextField, and SetupQuickItem.

Definition at line 162 of file setupitem.cpp.

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

Referenced by getWidget().

163 {
164  if (mWidget == nullptr)
165  return;
166 
167  if (event.getId() == mWidget->getActionEventId())
168  doAction();
169 }
const std::string & getActionEventId() const
Definition: widget.h:604
virtual void doAction()
Definition: setupitem.cpp:171
Widget * mWidget
Definition: setupitem.h:142

◆ apply()

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

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

Definition at line 176 of file setupitem.cpp.

References save().

Referenced by getWidget().

177 {
178  save();
179 }
virtual void save()
Definition: setupitem.cpp:145

◆ cancel()

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

Reimplemented in SetupItemTextField, SetupQuickItem, and SetupButtonItem.

Definition at line 181 of file setupitem.cpp.

References load(), and toWidget().

Referenced by getWidget().

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

◆ doAction()

void SetupItem::doAction ( )
virtual

Definition at line 171 of file setupitem.cpp.

References fromWidget().

Referenced by action(), and getWidget().

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

◆ externalUnloaded()

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

Definition at line 193 of file setupitem.cpp.

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

194 {
195 }

◆ externalUpdated()

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

Reimplemented in SetupItemTextField, SetupQuickItem, and SetupButtonItem.

Definition at line 187 of file setupitem.cpp.

References load(), and toWidget().

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

188 {
189  load();
190  toWidget();
191 }
void load()
Definition: setupitem.cpp:112
virtual void toWidget()=0

◆ fixFirstItemSize()

void SetupItem::fixFirstItemSize ( Widget *const  widget)

◆ fromWidget()

virtual void SetupItem::fromWidget ( )
pure virtual

◆ getActionEventId()

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

Definition at line 154 of file setupitem.cpp.

References Widget::getActionEventId(), and mWidget.

Referenced by SetupTabScroll::addControl(), and getWidget().

155 {
156  if (mWidget == nullptr)
157  return std::string();
158 
159  return mWidget->getActionEventId();
160 }
const std::string & getActionEventId() const
Definition: widget.h:604
Widget * mWidget
Definition: setupitem.h:142

◆ getConfig()

Configuration * SetupItem::getConfig ( ) const

Definition at line 105 of file setupitem.cpp.

References config, MainConfig_true, mMainConfig, and serverConfig.

Referenced by getWidget(), load(), and save().

106 {
108  return &config;
109  return &serverConfig;
110 }
Configuration config
MainConfig mMainConfig
Definition: setupitem.h:148
Configuration serverConfig
const bool MainConfig_true
Definition: mainconfig.h:29

◆ getEventName()

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

Definition at line 109 of file setupitem.h.

References mEventName, restrict, and SetupItem().

Referenced by Setup_Mods::saveMods().

110  { return mEventName; }
std::string mEventName
Definition: setupitem.h:136

◆ getValue()

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

Definition at line 106 of file setupitem.h.

References mValue.

Referenced by Setup_Mods::saveMods().

107  { return mValue; }
std::string mValue
Definition: setupitem.h:138

◆ getWidget()

Widget* SetupItem::getWidget ( ) const
inline

◆ isMainConfig()

MainConfig SetupItem::isMainConfig ( ) const
inline

Definition at line 96 of file setupitem.h.

References fixFirstItemSize(), mMainConfig, and rereadValue().

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

97  { return mMainConfig; }
MainConfig mMainConfig
Definition: setupitem.h:148

◆ load()

void SetupItem::load ( )

Definition at line 112 of file setupitem.cpp.

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(), SetupActionDropDown::createControls(), SetupItemCheckBox::createControls(), SetupItemTextField::createControls(), SetupItemIntTextField::createControls(), SetupItemDropDown::createControls(), SetupItemDropDownStr::createControls(), SetupItemSlider::createControls(), SetupItemSlider2::createControls(), SetupItemSliderList::createControls(), externalUpdated(), SetupItemTextField::externalUpdated(), rereadValue(), and SetupItemTextField::rereadValue().

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

◆ rereadValue()

void SetupItem::rereadValue ( )
virtual

Reimplemented in SetupItemTextField, SetupQuickItem, and SetupButtonItem.

Definition at line 206 of file setupitem.cpp.

References load(), and toWidget().

Referenced by isMainConfig(), and SetupTabScroll::reread().

207 {
208  load();
209  toWidget();
210 }
void load()
Definition: setupitem.cpp:112
virtual void toWidget()=0

◆ save()

void SetupItem::save ( )
virtual

Reimplemented in SetupItemTextField, SetupQuickItem, and SetupButtonItem.

Definition at line 145 of file setupitem.cpp.

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().

146 {
147  if (mKeyName.empty())
148  return;
149 
150  Configuration *const cfg = getConfig();
151  cfg->setValue(mKeyName, mValue);
152 }
std::string mValue
Definition: setupitem.h:138
std::string mKeyName
Definition: setupitem.h:132
Configuration * getConfig() const
Definition: setupitem.cpp:105
void setValue(const std::string &key, const std::string &value)

◆ setValue()

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

Definition at line 103 of file setupitem.h.

References mValue, and ServerCommandType::str.

Referenced by Setup_Mods::loadMods().

104  { mValue = str; }
std::string mValue
Definition: setupitem.h:138

◆ setWidget()

void SetupItem::setWidget ( Widget widget)
inline

Definition at line 74 of file setupitem.h.

References mWidget.

75  { mWidget = widget; }
Widget * mWidget
Definition: setupitem.h:142

◆ toWidget()

virtual void SetupItem::toWidget ( )
pure virtual

Field Documentation

◆ mDefault

std::string SetupItem::mDefault
protected

Definition at line 140 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 132 of file setupitem.h.

Referenced by load(), and save().

◆ mMainConfig

MainConfig SetupItem::mMainConfig
protected

Definition at line 148 of file setupitem.h.

Referenced by getConfig(), and isMainConfig().

◆ mParent

SetupTabScroll* SetupItem::mParent
protected

◆ mTempWidgets

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

Definition at line 144 of file setupitem.h.

◆ mText

std::string SetupItem::mText
protected

◆ mUseDefault

bool SetupItem::mUseDefault
protected

Definition at line 150 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: