# # # patch "src/model/InventoryItem.cpp" # from [adff7c83b3515ff7672b1ebe4db8690c5733bacb] # to [5f6c50c2278d777156a4fc510f8d1bffcb716d0a] # # patch "src/model/InventoryItem.h" # from [f9a843860c2aa346bcd442e2d502dfac7a618386] # to [48309b9513a8ed11f47567da52d494e38ee45620] # ============================================================ --- src/model/InventoryItem.cpp adff7c83b3515ff7672b1ebe4db8690c5733bacb +++ src/model/InventoryItem.cpp 5f6c50c2278d777156a4fc510f8d1bffcb716d0a @@ -23,6 +23,122 @@ #include #include +ModelItem::ModelItem(const QString & l) : parentItem(0), label(l) +{} + +ModelItem::ModelItem(const ModelItem * other) +{ + parentItem = other->parent(); + children = other->getChildren(); + label = other->getLabel(); +} + +ModelItem::~ModelItem() +{ + deleteAllChildren(); +} + +void ModelItem::setLabel(const QString & l) +{ + label = l; +} + +QString ModelItem::getLabel() const +{ + return label; +} + +void ModelItem::deleteAllChildren() +{ + qDeleteAll(children); + children.clear(); +} + +void ModelItem::appendChild(ModelItem * child) +{ + child->setParent(this); + children.append(child); +} + +void ModelItem::setChildren(QList items) +{ + deleteAllChildren(); + foreach (ModelItem * item, items) + { + appendChild(item); + } +} + +QList ModelItem::getChildren() const +{ + return children; +} + +void ModelItem::setParent(ModelItem * p) +{ + parentItem = p; +} + +ModelItem * ModelItem::parent() const +{ + return parentItem; +} + +ModelItem * ModelItem::child(int row) const +{ + if (row < children.size()) + { + return children.value(row); + } + return 0; +} + +int ModelItem::childCount() const +{ + return children.count(); +} + +int ModelItem::row() const +{ + if (parentItem) + { + return parentItem->children.indexOf(const_cast(this)); + } + return 0; +} + +QVariant ModelItem::data(int column, int role) const +{ + if (role == Qt::DisplayRole) + { + // return column headers for root item + if (parentItem == this) + { + switch (column) + { + case 0: return QVariant(QString(tr("File"))); + case 1: return QVariant(QString(tr("Status"))); + case 2: return QVariant(QString(tr("Additional info"))); + default: return QVariant(); + } + } + + switch (column) + { + case 0: return QVariant(label); + default: return QVariant(); + } + } + + if (role == Qt::DecorationRole && column == 0) + { + IconProvider * provider = IconProvider::singleton(); + return provider->getIcon(this); + } + + return QVariant(); +} + const int InventoryItem::RenameSource = 1; const int InventoryItem::RenameTarget = 2; const int InventoryItem::Added = 4; @@ -242,7 +358,9 @@ int InventoryItem::getStatusRecursive() for (int i=0,s=children.size(); i(children.at(i)); + InventoryItem * item = qobject_cast(children.at(i)); + // skip everything other than InventoryItems + if (!item) continue; overallStatus |= item->getStatusRecursive(); } ============================================================ --- src/model/InventoryItem.h f9a843860c2aa346bcd442e2d502dfac7a618386 +++ src/model/InventoryItem.h 48309b9513a8ed11f47567da52d494e38ee45620 @@ -30,111 +30,24 @@ public: { Q_OBJECT public: - ModelItem(const QString & l = QString()) : parentItem(0), label(l) {} - ModelItem(const ModelItem * other) - { - parentItem = other->parent(); - children = other->getChildren(); - label = other->getLabel(); - } + ModelItem(const QString & l = QString()); + ModelItem(const ModelItem *); + virtual ~ModelItem(); - virtual ~ModelItem() { deleteAllChildren(); } + virtual void setLabel(const QString &); + virtual QString getLabel() const; + virtual QVariant data(int, int) const; - virtual void setLabel(const QString & l) { label = l; } - virtual QString getLabel() const { return label; } + void deleteAllChildren(); + void appendChild(ModelItem *); + void setChildren(QList); + QList getChildren() const; + void setParent(ModelItem *); + ModelItem * parent() const; + ModelItem * child(int) const; + int childCount() const; + int row() const; - void deleteAllChildren() - { - qDeleteAll(children); - children.clear(); - } - - void appendChild(ModelItem * child) - { - child->setParent(this); - children.append(child); - } - - void setChildren(QList items) - { - foreach (ModelItem * item, items) - { - item->setParent(this); - } - deleteAllChildren(); - children = items; - } - - QList getChildren() const - { - return children; - } - - void setParent(ModelItem * p) - { - parentItem = p; - } - - ModelItem * parent() const - { - return parentItem; - } - - ModelItem * child(int row) const - { - if (row < children.size()) - { - return children.value(row); - } - return 0; - } - - int childCount() const - { - return children.count(); - } - - int row() const - { - if (parentItem) - { - return parentItem->children.indexOf(const_cast(this)); - } - return 0; - } - - virtual QVariant data(int column, int role) const - { - if (role == Qt::DisplayRole) - { - // return column headers for root item - if (parentItem == this) - { - switch (column) - { - case 0: return QVariant(QString(tr("File"))); - case 1: return QVariant(QString(tr("Status"))); - case 2: return QVariant(QString(tr("Additional info"))); - default: return QVariant(); - } - } - - switch (column) - { - case 0: return QVariant(label); - default: return QVariant(); - } - } - - if (role == Qt::DecorationRole && column == 0) - { - IconProvider * provider = IconProvider::singleton(); - return provider->getIcon(this); - } - - return QVariant(); - } - protected: ModelItem * parentItem; QList children; @@ -213,9 +126,6 @@ private: static const int ContentsChanged; private: - InventoryItem * parentItem; - QList children; - QString path; QString old_path; QString new_path;