| 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. No notification is sent if |new_items| |
| 39 // is empty. |
| 40 void AddAll(ScopedVector<ItemType> new_items) { |
| 41 if (new_items.empty()) |
| 42 return; |
| 43 |
| 44 const size_t count = item_count(); |
| 45 items_.insert(items_.end(), new_items.begin(), new_items.end()); |
| 46 new_items.weak_clear(); |
| 47 NotifyItemsAdded(count, items_.size() - count); |
| 48 } |
| 49 |
| 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 |