X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=42a40f7fd1d68d74d01aa700a697aa04c40688d3;hb=23eed68958b7585552be04fab4e5871a781b7f38;hp=ffcec13c1db82b26a40f2333181376de94dbbaf5;hpb=25bc72972586c19fb9a8c4a94d5845b2d16af121;p=quassel.git diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index ffcec13c..42a40f7f 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -105,7 +105,6 @@ void AbstractTreeItem::removeAllChilds() { return; emit beginRemoveChilds(0, childCount() - 1); - AbstractTreeItem *child; foreach(int column, _childItems.keys()) { QList::iterator iter = _childItems[column].begin(); @@ -233,10 +232,23 @@ SimpleTreeItem::~SimpleTreeItem() { } QVariant SimpleTreeItem::data(int column, int role) const { - if(role == Qt::DisplayRole && column < _itemData.count()) + if(column >= columnCount() || role != Qt::DisplayRole) + return QVariant(); + else return _itemData[column]; +} + +bool SimpleTreeItem::setData(int column, const QVariant &value, int role) { + if(column > columnCount() || role != Qt::DisplayRole) + return false; + + if(column == columnCount()) + _itemData.append(value); else - return QVariant(); + _itemData[column] = value; + + emit dataChanged(column); + return true; } int SimpleTreeItem::columnCount() const { @@ -263,15 +275,20 @@ PropertyMapItem::~PropertyMapItem() { } QVariant PropertyMapItem::data(int column, int role) const { - if(column >= columnCount()) - return QVariant(); - - if(role != Qt::DisplayRole) + if(column >= columnCount() || role != Qt::DisplayRole) return QVariant(); return property(_propertyOrder[column].toAscii()); } +bool PropertyMapItem::setData(int column, const QVariant &value, int role) { + if(column >= columnCount() || role != Qt::DisplayRole) + return false; + + emit dataChanged(column); + return setProperty(_propertyOrder[column].toAscii(), value); +} + int PropertyMapItem::columnCount() const { return _propertyOrder.count(); } @@ -289,6 +306,19 @@ TreeModel::TreeModel(const QList &data, QObject *parent) : QAbstractItemModel(parent) { rootItem = new SimpleTreeItem(data, 0); + + connect(rootItem, SIGNAL(dataChanged(int)), + this, SLOT(itemDataChanged(int))); + + connect(rootItem, SIGNAL(newChild(AbstractTreeItem *)), + this, SLOT(newChild(AbstractTreeItem *))); + + connect(rootItem, SIGNAL(beginRemoveChilds(int, int)), + this, SLOT(beginRemoveChilds(int, int))); + + connect(rootItem, SIGNAL(endRemoveChilds()), + this, SLOT(endRemoveChilds())); + } TreeModel::~TreeModel() { @@ -390,10 +420,18 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const { if(!index.isValid()) return QVariant(); - AbstractTreeItem *item = static_cast(index.internalPointer()); + AbstractTreeItem *item = static_cast(index.internalPointer()); return item->data(index.column(), role); } +bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int role) { + if(!index.isValid()) + return false; + + AbstractTreeItem *item = static_cast(index.internalPointer()); + return item->setData(index.column(), value, role); +} + Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const { AbstractTreeItem *item; if(!index.isValid()) @@ -507,6 +545,5 @@ bool TreeModel::removeRows(int row, int count, const QModelIndex &parent) { } void TreeModel::clear() { - removeRows(0, rowCount()); - reset(); + rootItem->removeAllChilds(); }