PageRenderTime 29ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 2ms 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
  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
 29// Precompiled header
 30#include "linden_common.h"
 31// associated header
 32#include "llviewmodel.h"
 33// STL headers
 34// std headers
 35// external library headers
 36// other Linden headers
 37
 38///
 39LLViewModel::LLViewModel()
 40 : mDirty(false)
 41{
 42}
 43
 44/// Instantiate an LLViewModel with an existing data value
 45LLViewModel::LLViewModel(const LLSD& value)
 46  : mDirty(false)
 47{
 48    setValue(value);
 49}
 50
 51/// Update the stored value
 52void LLViewModel::setValue(const LLSD& value)
 53{
 54    mValue = value;
 55    mDirty = true;
 56}
 57
 58LLSD LLViewModel::getValue() const
 59{
 60    return mValue;
 61}
 62
 63////////////////////////////////////////////////////////////////////////////
 64
 65///
 66LLTextViewModel::LLTextViewModel()
 67  : LLViewModel(false),
 68	mUpdateFromDisplay(false)
 69{
 70}
 71
 72/// Instantiate an LLViewModel with an existing data value
 73LLTextViewModel::LLTextViewModel(const LLSD& value)
 74  : LLViewModel(value),
 75	mUpdateFromDisplay(false)
 76{
 77}
 78
 79/// Update the stored value
 80void LLTextViewModel::setValue(const LLSD& value)
 81{
 82	LLViewModel::setValue(value);
 83    mDisplay = utf8str_to_wstring(value.asString());
 84    // mDisplay and mValue agree
 85    mUpdateFromDisplay = false;
 86}
 87
 88void LLTextViewModel::setDisplay(const LLWString& value)
 89{
 90    // This is the strange way to alter the value. Normally we'd setValue()
 91    // and do the utf8str_to_wstring() to get the corresponding mDisplay
 92    // value. But a text editor might want to edit the display string
 93    // directly, then convert back to UTF8 on commit.
 94    mDisplay = value;
 95    mDirty = true;
 96    // Don't immediately convert to UTF8 -- do it lazily -- we expect many
 97    // more setDisplay() calls than getValue() calls. Just flag that it needs
 98    // doing.
 99    mUpdateFromDisplay = true;
100}
101
102LLSD LLTextViewModel::getValue() const
103{
104    // Has anyone called setDisplay() since the last setValue()? If so, have
105    // to convert mDisplay back to UTF8.
106    if (mUpdateFromDisplay)
107    {
108        // The fact that we're lazily updating fields in this object should be
109        // transparent to clients, which is why this method is left
110        // conventionally const. Nor do we particularly want to make these
111        // members mutable. Just cast away constness in this one place.
112        LLTextViewModel* nthis = const_cast<LLTextViewModel*>(this);
113        nthis->mUpdateFromDisplay = false;
114        nthis->mValue = wstring_to_utf8str(mDisplay);
115    }
116    return LLViewModel::getValue();
117}
118
119
120////////////////////////////////////////////////////////////////////////////
121
122LLListViewModel::LLListViewModel(const LLSD& values)
123  : LLViewModel()
124{
125}
126
127void LLListViewModel::addColumn(const LLSD& column, EAddPosition pos)
128{
129}
130
131void LLListViewModel::clearColumns()
132{
133}
134
135void LLListViewModel::setColumnLabel(const std::string& column, const std::string& label)
136{
137}
138
139LLScrollListItem* LLListViewModel::addElement(const LLSD& value, EAddPosition pos,
140                                         void* userdata)
141{
142    return NULL;
143}
144
145LLScrollListItem* LLListViewModel::addSimpleElement(const std::string& value, EAddPosition pos,
146                                               const LLSD& id)
147{
148    return NULL;
149}
150
151void LLListViewModel::clearRows()
152{
153}
154
155void LLListViewModel::sortByColumn(const std::string& name, bool ascending)
156{
157}