diff options
| author | Peter Penz <[email protected]> | 2012-05-01 23:11:06 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-01 23:14:52 +0200 |
| commit | d76b113ad10fe207ef23d5dd44c63ee076c71521 (patch) | |
| tree | 2cda5384e4036f4f048392548ea75243ce6b7fc2 /src/kitemviews/kstandarditemmodel.cpp | |
| parent | 6a7cb5ff7d29cc636b432a96e0db9ef9f9030527 (diff) | |
Places Panel: Allow hiding of items
Related changes:
- Animate changed items for the details-view in case it is not expandable
- Remove the hardcoded "isHidden"-code in KStandardItemListWidget and
allow derived widgets to define themselves what means "hidden" within
their context.
The current code needs a lot of bugfixing, but lets make this in smaller
steps during the next days...
Diffstat (limited to 'src/kitemviews/kstandarditemmodel.cpp')
| -rw-r--r-- | src/kitemviews/kstandarditemmodel.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/kitemviews/kstandarditemmodel.cpp b/src/kitemviews/kstandarditemmodel.cpp index 04749b9b5..d0be1325f 100644 --- a/src/kitemviews/kstandarditemmodel.cpp +++ b/src/kitemviews/kstandarditemmodel.cpp @@ -38,19 +38,22 @@ KStandardItemModel::~KStandardItemModel() void KStandardItemModel::insertItem(int index, KStandardItem* item) { - if (!m_indexesForItems.contains(item) && !item->m_model) { + if (item && !m_indexesForItems.contains(item) && !item->m_model) { + item->m_model = this; m_items.insert(index, item); m_indexesForItems.insert(item, index); - item->m_model = this; // TODO: no hierarchical items are handled yet + onItemInserted(index); emit itemsInserted(KItemRangeList() << KItemRange(index, 1)); } } void KStandardItemModel::replaceItem(int index, KStandardItem* item) { - if (index >= 0 && index < count()) { + if (item && index >= 0 && index < count() && !item->m_model) { + item->m_model = this; + QSet<QByteArray> changedRoles; KStandardItem* oldItem= m_items[index]; @@ -75,6 +78,7 @@ void KStandardItemModel::replaceItem(int index, KStandardItem* item) m_items[index] = item; m_indexesForItems.insert(item, index); + onItemReplaced(index); emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles); } else { kWarning() << "No item available to replace on the given index" << index; @@ -83,11 +87,6 @@ void KStandardItemModel::replaceItem(int index, KStandardItem* item) } } -void KStandardItemModel::appendItem(KStandardItem *item) -{ - insertItem(m_items.count(), item); -} - void KStandardItemModel::removeItem(int index) { if (index >= 0 && index < count()) { @@ -97,6 +96,7 @@ void KStandardItemModel::removeItem(int index) delete item; item = 0; + onItemRemoved(index); emit itemsRemoved(KItemRangeList() << KItemRange(index, 1)); // TODO: no hierarchical items are handled yet } @@ -115,6 +115,11 @@ int KStandardItemModel::index(const KStandardItem* item) const return m_indexesForItems.value(item, -1); } +void KStandardItemModel::appendItem(KStandardItem *item) +{ + insertItem(m_items.count(), item); +} + int KStandardItemModel::count() const { return m_items.count(); @@ -186,4 +191,20 @@ QList<QPair<int, QVariant> > KStandardItemModel::groups() const return groups; } +void KStandardItemModel::onItemInserted(int index) +{ + Q_UNUSED(index); +} + +void KStandardItemModel::onItemReplaced(int index) +{ + Q_UNUSED(index); +} + +void KStandardItemModel::onItemRemoved(int index) +{ + Q_UNUSED(index); +} + + #include "kstandarditemmodel.moc" |
