PageRenderTime 401ms CodeModel.GetById 385ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llviewmodel.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 214 lines | 58 code | 16 blank | 140 comment | 0 complexity | c1a98536b7c9bf417e9f79c91a137493 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewmodel.h
  3. * @author Nat Goodspeed
  4. * @date 2008-08-08
  5. * @brief Define "View Model" classes intended to store data values for use
  6. * by LLUICtrl subclasses. The phrase is borrowed from Microsoft
  7. * terminology, in which "View Model" means the storage object
  8. * underlying a specific widget object -- as in our case -- rather
  9. * than the business "model" object underlying the overall "view"
  10. * presented by the collection of widgets.
  11. *
  12. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  13. * Second Life Viewer Source Code
  14. * Copyright (C) 2010, Linden Research, Inc.
  15. *
  16. * This library is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU Lesser General Public
  18. * License as published by the Free Software Foundation;
  19. * version 2.1 of the License only.
  20. *
  21. * This library is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. * Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public
  27. * License along with this library; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. *
  30. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  31. * $/LicenseInfo$
  32. */
  33. #if ! defined(LL_LLVIEWMODEL_H)
  34. #define LL_LLVIEWMODEL_H
  35. #include "llpointer.h"
  36. #include "llsd.h"
  37. #include "llrefcount.h"
  38. #include "stdenums.h"
  39. #include "llstring.h"
  40. #include <string>
  41. class LLScrollListItem;
  42. class LLViewModel;
  43. class LLTextViewModel;
  44. class LLListViewModel;
  45. // Because LLViewModel is derived from LLRefCount, always pass, store
  46. // and return LLViewModelPtr rather than plain LLViewModel*.
  47. typedef LLPointer<LLViewModel> LLViewModelPtr;
  48. typedef LLPointer<LLTextViewModel> LLTextViewModelPtr;
  49. typedef LLPointer<LLListViewModel> LLListViewModelPtr;
  50. /**
  51. * LLViewModel stores a scalar LLSD data item, the current display value of a
  52. * scalar LLUICtrl widget. LLViewModel subclasses are used to store data
  53. * collections used for aggregate widgets. LLViewModel is ref-counted because
  54. * -- for multiple skins -- we may have distinct widgets sharing the same
  55. * LLViewModel data. This way, the LLViewModel is quietly deleted when the
  56. * last referencing widget is destroyed.
  57. */
  58. class LLViewModel: public LLRefCount
  59. {
  60. public:
  61. LLViewModel();
  62. /// Instantiate an LLViewModel with an existing data value
  63. LLViewModel(const LLSD& value);
  64. /// Update the stored value
  65. virtual void setValue(const LLSD& value);
  66. /// Get the stored value, in appropriate type.
  67. virtual LLSD getValue() const;
  68. /// Has the value been changed since last time we checked?
  69. bool isDirty() const { return mDirty; }
  70. /// Once the value has been saved to a file, or otherwise consumed by the
  71. /// app, we no longer need to enable the Save button
  72. void resetDirty() { mDirty = false; }
  73. //
  74. void setDirty() { mDirty = true; }
  75. protected:
  76. LLSD mValue;
  77. bool mDirty;
  78. };
  79. /**
  80. * LLTextViewModel stores a value displayed as text.
  81. */
  82. class LLTextViewModel: public LLViewModel
  83. {
  84. public:
  85. LLTextViewModel();
  86. /// Instantiate an LLViewModel with an existing data value
  87. LLTextViewModel(const LLSD& value);
  88. // LLViewModel functions
  89. virtual void setValue(const LLSD& value);
  90. virtual LLSD getValue() const;
  91. // New functions
  92. /// Get the stored value in string form
  93. const LLWString& getDisplay() const { return mDisplay; }
  94. /**
  95. * Set the display string directly (see LLTextEditor). What the user is
  96. * editing is actually the LLWString value rather than the underlying
  97. * UTF-8 value.
  98. */
  99. void setDisplay(const LLWString& value);
  100. private:
  101. /// To avoid converting every widget's stored value from LLSD to LLWString
  102. /// every frame, cache the converted value
  103. LLWString mDisplay;
  104. /// As the user edits individual characters (setDisplay()), defer
  105. /// LLWString-to-UTF8 conversions until s/he's done.
  106. bool mUpdateFromDisplay;
  107. };
  108. /**
  109. * LLListViewModel stores a list of data items. The semantics are borrowed
  110. * from LLScrollListCtrl.
  111. */
  112. class LLListViewModel: public LLViewModel
  113. {
  114. public:
  115. LLListViewModel() {}
  116. LLListViewModel(const LLSD& values);
  117. virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
  118. virtual void clearColumns();
  119. virtual void setColumnLabel(const std::string& column, const std::string& label);
  120. virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM,
  121. void* userdata = NULL);
  122. virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos,
  123. const LLSD& id);
  124. virtual void clearRows();
  125. virtual void sortByColumn(const std::string& name, bool ascending);
  126. };
  127. //namespace LLViewModel
  128. //{
  129. // class Value
  130. // {
  131. // public:
  132. // Value(const LLSD& value = LLSD());
  133. //
  134. // LLSD getValue() const { return mValue; }
  135. // void setValue(const LLSD& value) { mValue = value; }
  136. //
  137. // bool isAvailable() const { return false; }
  138. // bool isReadOnly() const { return false; }
  139. //
  140. // bool undo() { return false; }
  141. // bool redo() { return false; }
  142. //
  143. // /// Has the value been changed since last time we checked?
  144. // bool isDirty() const { return mDirty; }
  145. // /// Once the value has been saved to a file, or otherwise consumed by the
  146. // /// app, we no longer need to enable the Save button
  147. // void resetDirty() { mDirty = false; }
  148. // //
  149. // void setDirty() { mDirty = true; }
  150. //
  151. // protected:
  152. // LLSD mValue;
  153. // bool mDirty;
  154. // };
  155. //
  156. // class Numeric : public Value
  157. // {
  158. // public:
  159. // Numeric(S32 value = 0);
  160. // Numeric(F32 value);
  161. //
  162. // F32 getPrecision();
  163. // F32 getMin();
  164. // F32 getMax();
  165. //
  166. // void increment();
  167. // void decrement();
  168. // };
  169. //
  170. // class MultipleValues : public Value
  171. // {
  172. // class Selector
  173. // {};
  174. //
  175. // MultipleValues();
  176. // virtual S32 numElements();
  177. // };
  178. //
  179. // class Tuple : public MultipleValues
  180. // {
  181. // Tuple(S32 size);
  182. // LLSD getValue(S32 which) const;
  183. // void setValue(S32 which, const LLSD& value);
  184. // };
  185. //
  186. // class List : public MultipleValues
  187. // {
  188. // List();
  189. //
  190. // void add(const ValueModel& value);
  191. // bool remove(const Selector& item);
  192. //
  193. // void setSortElement(const Selector& element);
  194. // void sort();
  195. // };
  196. //
  197. //};
  198. #endif /* ! defined(LL_LLVIEWMODEL_H) */