OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_MODELS_LIST_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_LIST_MODEL_H_ |
6 #define UI_BASE_MODELS_LIST_MODEL_H_ | 6 #define UI_BASE_MODELS_LIST_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 DCHECK_LE(index, item_count()); | 27 DCHECK_LE(index, item_count()); |
28 items_.insert(items_.begin() + index, item); | 28 items_.insert(items_.begin() + index, item); |
29 NotifyItemsAdded(index, 1); | 29 NotifyItemsAdded(index, 1); |
30 } | 30 } |
31 | 31 |
32 // Convenience function to append an item to the model. | 32 // Convenience function to append an item to the model. |
33 void Add(ItemType* item) { | 33 void Add(ItemType* item) { |
34 AddAt(item_count(), item); | 34 AddAt(item_count(), item); |
35 } | 35 } |
36 | 36 |
37 // Add a vector of items to the end of the model. This triggers one | |
38 // notification after adding all items. | |
39 void AddAll(ScopedVector<ItemType> new_items) { | |
40 size_t count = item_count(); | |
tapted
2013/08/05 03:01:39
I think this needs either a DCHECK(!new_items.empt
| |
41 std::vector<ItemType*> new_items_released; | |
42 new_items.release(&new_items_released); | |
43 items_.insert(items_.end(), | |
44 new_items_released.begin(), | |
45 new_items_released.end()); | |
46 NotifyItemsAdded(count, items_.size()); | |
tapted
2013/08/05 03:01:39
items_.size() isn't right -- it should be new_item
| |
47 } | |
48 | |
37 // Removes an item at given |index| from the model. Note the removed item | 49 // Removes an item at given |index| from the model. Note the removed item |
38 // is NOT deleted and it's up to the caller to delete it. | 50 // is NOT deleted and it's up to the caller to delete it. |
39 ItemType* RemoveAt(size_t index) { | 51 ItemType* RemoveAt(size_t index) { |
40 DCHECK_LT(index, item_count()); | 52 DCHECK_LT(index, item_count()); |
41 ItemType* item = items_[index]; | 53 ItemType* item = items_[index]; |
42 items_.weak_erase(items_.begin() + index); | 54 items_.weak_erase(items_.begin() + index); |
43 NotifyItemsRemoved(index, 1); | 55 NotifyItemsRemoved(index, 1); |
44 return item; | 56 return item; |
45 } | 57 } |
46 | 58 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 private: | 135 private: |
124 ScopedVector<ItemType> items_; | 136 ScopedVector<ItemType> items_; |
125 ObserverList<ListModelObserver> observers_; | 137 ObserverList<ListModelObserver> observers_; |
126 | 138 |
127 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); | 139 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); |
128 }; | 140 }; |
129 | 141 |
130 } // namespace ui | 142 } // namespace ui |
131 | 143 |
132 #endif // UI_BASE_MODELS_LIST_MODEL_H_ | 144 #endif // UI_BASE_MODELS_LIST_MODEL_H_ |
OLD | NEW |