}
}
+ // In case if items of the same group have been inserted before an item that
+ // currently represents the first item of the group, the group header of
+ // this item must be removed.
+ if (m_grouped && index + count < m_model->count()) {
+ updateGroupHeaderForWidget(m_visibleItems.value(index + count));
+ }
+
if (m_model->count() == count && m_activeTransactions == 0) {
// Check whether a scrollbar is required to show the inserted items. In this case
// the size of the layouter will be decreased before calling doLayout(): This prevents
#include "kstandarditem.h"
#include <KDebug>
+#include "kstandarditemmodel.h"
KStandardItem::KStandardItem(KStandardItem* parent) :
m_parent(parent),
void KStandardItem::setText(const QString& text)
{
- m_data.insert("text", text);
+ setDataValue("text", text);
}
QString KStandardItem::text() const
void KStandardItem::setIcon(const QIcon& icon)
{
- m_data.insert("iconName", icon.name());
+ setDataValue("iconName", icon.name());
}
QIcon KStandardItem::icon() const
void KStandardItem::setGroup(const QString& group)
{
- m_data.insert("group", group);
+ setDataValue("group", group);
}
QString KStandardItem::group() const
void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
{
m_data.insert(role, value);
+ if (m_model) {
+ const int index = m_model->index(this);
+ QSet<QByteArray> changedRoles;
+ changedRoles.insert(role);
+ emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
+ }
}
QVariant KStandardItem::dataValue(const QByteArray& role) const
}
painter->setFont(itemListStyleOption.font);
- painter->setPen(textColor());
+ painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
const TextInfo* textInfo = m_textInfo.value("text");
painter->drawStaticText(textInfo->pos, textInfo->staticText);
QSet<QByteArray> dirtyRoles;
if (roles.isEmpty()) {
dirtyRoles = visibleRoles().toSet();
- dirtyRoles.insert("iconPixmap");
- dirtyRoles.insert("iconName");
} else {
dirtyRoles = roles;
}
+ // The icon-state might depend from other roles and hence is
+ // marked as dirty whenever a role has been changed
+ dirtyRoles.insert("iconPixmap");
+ dirtyRoles.insert("iconName");
+
QSetIterator<QByteArray> it(dirtyRoles);
while (it.hasNext()) {
const QByteArray& role = it.next();
void KStandardItemModel::insertItem(int index, KStandardItem* item)
{
- if (item && !m_indexesForItems.contains(item) && !item->m_model) {
+ if (item && !m_indexesForItems.contains(item)) {
item->m_model = this;
m_items.insert(index, item);
m_indexesForItems.insert(item, index);
void KStandardItemModel::replaceItem(int index, KStandardItem* item)
{
- if (item && index >= 0 && index < count() && !item->m_model) {
+ if (item && index >= 0 && index < count()) {
item->m_model = this;
QSet<QByteArray> changedRoles;
private:
QList<KStandardItem*> m_items;
QHash<const KStandardItem*, int> m_indexesForItems;
+
+ friend class KStandardItem;
};
#endif
int PlacesItemModel::hiddenCount() const
{
+ int modelIndex = 0;
int itemCount = 0;
- foreach (const KStandardItem* item, m_hiddenItems) {
- if (item) {
+ foreach (const KStandardItem* hiddenItem, m_hiddenItems) {
+ if (hiddenItem) {
++itemCount;
+ } else {
+ if (item(modelIndex)->dataValue("isHidden").toBool()) {
+ ++itemCount;
+ }
+ ++modelIndex;
}
}
void PlacesItemModel::setHiddenItemsShown(bool show)
{
- if (m_hiddenItemsShown != show) {
- m_hiddenItemsShown = show;
+ if (m_hiddenItemsShown == show) {
+ return;
+ }
+
+ m_hiddenItemsShown = show;
+
+ if (show) {
+ int modelIndex = 0;
+ for (int hiddenIndex = 0; hiddenIndex < m_hiddenItems.count(); ++hiddenIndex) {
+ if (m_hiddenItems[hiddenIndex]) {
+ KStandardItem* visibleItem = new KStandardItem(*m_hiddenItems[hiddenIndex]);
+ delete m_hiddenItems[hiddenIndex];
+ m_hiddenItems.removeAt(hiddenIndex);
+ insertItem(modelIndex, visibleItem);
+ Q_ASSERT(!m_hiddenItems[hiddenIndex]);
+ }
+ ++modelIndex;
+ }
+ } else {
+
}
+#ifdef PLACESITEMMODEL_DEBUG
+ kDebug() << "Changed visibility of hidden items";
+ showModelState();
+#endif
}
bool PlacesItemModel::hiddenItemsShown() const
void PlacesItemModel::onItemInserted(int index)
{
- if (index == count() - 1) {
- m_hiddenItems.append(0);
- } else {
- m_hiddenItems.insert(hiddenIndex(index), 0);
+ int modelIndex = 0;
+ int hiddenIndex = 0;
+ while (hiddenIndex < m_hiddenItems.count()) {
+ if (!m_hiddenItems[hiddenIndex]) {
+ ++modelIndex;
+ if (modelIndex + 1 == index) {
+ ++hiddenIndex;
+ break;
+ }
+ }
+ ++hiddenIndex;
}
+ m_hiddenItems.insert(hiddenIndex, 0);
+
+#ifdef PLACESITEMMODEL_DEBUG
+ kDebug() << "Inserted item" << index;
+ showModelState();
+#endif
}
void PlacesItemModel::onItemRemoved(int index)
KMenu menu(this);
QAction* addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry..."));
+
+ QAction* showAllAction = 0;
+ if (m_model->hiddenCount() > 0) {
+ showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
+ showAllAction->setCheckable(true);
+ showAllAction->setChecked(m_model->hiddenItemsShown());
+ }
+
menu.addSeparator();
foreach (QAction* action, customContextMenuActions()) {
menu.addAction(action);
}
QAction* action = menu.exec(pos.toPoint());
- if (action == addAction) {
- addEntry();
+ if (action) {
+ if (action == addAction) {
+ addEntry();
+ } else if (action == showAllAction) {
+ m_model->setHiddenItemsShown(showAllAction->isChecked());
+ }
}
selectClosestItem();