PageRenderTime 30ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llviewmodel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 157 lines | 81 code | 21 blank | 55 comment | 1 complexity | 664bbdcf7a4d53eb3e683fa0dfbc9d5a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewmodel.cpp
  3. * @author Nat Goodspeed
  4. * @date 2008-08-08
  5. * @brief Implementation for llviewmodel.
  6. *
  7. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "linden_common.h"
  30. // associated header
  31. #include "llviewmodel.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. // other Linden headers
  36. ///
  37. LLViewModel::LLViewModel()
  38. : mDirty(false)
  39. {
  40. }
  41. /// Instantiate an LLViewModel with an existing data value
  42. LLViewModel::LLViewModel(const LLSD& value)
  43. : mDirty(false)
  44. {
  45. setValue(value);
  46. }
  47. /// Update the stored value
  48. void LLViewModel::setValue(const LLSD& value)
  49. {
  50. mValue = value;
  51. mDirty = true;
  52. }
  53. LLSD LLViewModel::getValue() const
  54. {
  55. return mValue;
  56. }
  57. ////////////////////////////////////////////////////////////////////////////
  58. ///
  59. LLTextViewModel::LLTextViewModel()
  60. : LLViewModel(false),
  61. mUpdateFromDisplay(false)
  62. {
  63. }
  64. /// Instantiate an LLViewModel with an existing data value
  65. LLTextViewModel::LLTextViewModel(const LLSD& value)
  66. : LLViewModel(value),
  67. mUpdateFromDisplay(false)
  68. {
  69. }
  70. /// Update the stored value
  71. void LLTextViewModel::setValue(const LLSD& value)
  72. {
  73. LLViewModel::setValue(value);
  74. mDisplay = utf8str_to_wstring(value.asString());
  75. // mDisplay and mValue agree
  76. mUpdateFromDisplay = false;
  77. }
  78. void LLTextViewModel::setDisplay(const LLWString& value)
  79. {
  80. // This is the strange way to alter the value. Normally we'd setValue()
  81. // and do the utf8str_to_wstring() to get the corresponding mDisplay
  82. // value. But a text editor might want to edit the display string
  83. // directly, then convert back to UTF8 on commit.
  84. mDisplay = value;
  85. mDirty = true;
  86. // Don't immediately convert to UTF8 -- do it lazily -- we expect many
  87. // more setDisplay() calls than getValue() calls. Just flag that it needs
  88. // doing.
  89. mUpdateFromDisplay = true;
  90. }
  91. LLSD LLTextViewModel::getValue() const
  92. {
  93. // Has anyone called setDisplay() since the last setValue()? If so, have
  94. // to convert mDisplay back to UTF8.
  95. if (mUpdateFromDisplay)
  96. {
  97. // The fact that we're lazily updating fields in this object should be
  98. // transparent to clients, which is why this method is left
  99. // conventionally const. Nor do we particularly want to make these
  100. // members mutable. Just cast away constness in this one place.
  101. LLTextViewModel* nthis = const_cast<LLTextViewModel*>(this);
  102. nthis->mUpdateFromDisplay = false;
  103. nthis->mValue = wstring_to_utf8str(mDisplay);
  104. }
  105. return LLViewModel::getValue();
  106. }
  107. ////////////////////////////////////////////////////////////////////////////
  108. LLListViewModel::LLListViewModel(const LLSD& values)
  109. : LLViewModel()
  110. {
  111. }
  112. void LLListViewModel::addColumn(const LLSD& column, EAddPosition pos)
  113. {
  114. }
  115. void LLListViewModel::clearColumns()
  116. {
  117. }
  118. void LLListViewModel::setColumnLabel(const std::string& column, const std::string& label)
  119. {
  120. }
  121. LLScrollListItem* LLListViewModel::addElement(const LLSD& value, EAddPosition pos,
  122. void* userdata)
  123. {
  124. return NULL;
  125. }
  126. LLScrollListItem* LLListViewModel::addSimpleElement(const std::string& value, EAddPosition pos,
  127. const LLSD& id)
  128. {
  129. return NULL;
  130. }
  131. void LLListViewModel::clearRows()
  132. {
  133. }
  134. void LLListViewModel::sortByColumn(const std::string& name, bool ascending)
  135. {
  136. }