Chromium Code Reviews| 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(); | |
|
xiyuan
2013/08/06 03:42:07
nit: const size_t
calamity
2013/08/07 07:19:40
Done.
| |
| 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()); | |
|
xiyuan
2013/08/06 03:42:07
How about getting rid of |new_items_released| and
calamity
2013/08/07 07:19:40
Done.
| |
| 46 NotifyItemsAdded(count, new_items_released.size()); | |
| 47 } | |
| 48 | |
| 49 | |
|
xiyuan
2013/08/06 03:42:07
nit: nuke one empty line
calamity
2013/08/07 07:19:40
Done.
| |
| 37 // Removes an item at given |index| from the model. Note the removed item | 50 // 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. | 51 // is NOT deleted and it's up to the caller to delete it. |
| 39 ItemType* RemoveAt(size_t index) { | 52 ItemType* RemoveAt(size_t index) { |
| 40 DCHECK_LT(index, item_count()); | 53 DCHECK_LT(index, item_count()); |
| 41 ItemType* item = items_[index]; | 54 ItemType* item = items_[index]; |
| 42 items_.weak_erase(items_.begin() + index); | 55 items_.weak_erase(items_.begin() + index); |
| 43 NotifyItemsRemoved(index, 1); | 56 NotifyItemsRemoved(index, 1); |
| 44 return item; | 57 return item; |
| 45 } | 58 } |
| 46 | 59 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 private: | 136 private: |
| 124 ScopedVector<ItemType> items_; | 137 ScopedVector<ItemType> items_; |
| 125 ObserverList<ListModelObserver> observers_; | 138 ObserverList<ListModelObserver> observers_; |
| 126 | 139 |
| 127 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); | 140 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); |
| 128 }; | 141 }; |
| 129 | 142 |
| 130 } // namespace ui | 143 } // namespace ui |
| 131 | 144 |
| 132 #endif // UI_BASE_MODELS_LIST_MODEL_H_ | 145 #endif // UI_BASE_MODELS_LIST_MODEL_H_ |
| OLD | NEW |