# # # patch "guitone/src/model/Inventory.cpp" # from [772074d5e31ac0818d33e77f06c6c09f681a2179] # to [547fc8cf017c30da0f7a2772013d83f42c63a28f] # # patch "guitone/src/model/InventoryItem.cpp" # from [355359d12820d5b033152183174b9d738ce601e1] # to [940ee31302a885f24f2658630ba64e259b6fda42] # # patch "guitone/src/model/InventoryItem.h" # from [70cef46c046d56928dbe9adc86b0d9da8a3f282c] # to [74e2924b72a68f29d5f0eb7b4f791e1c8c6a05d5] # # patch "guitone/src/view/InventoryView.cpp" # from [7ecee38b487625d1da171e490841d6f466243c6a] # to [75865a2ee33160e4529cda5d8a587899e031c431] # ============================================================ --- guitone/src/model/Inventory.cpp 772074d5e31ac0818d33e77f06c6c09f681a2179 +++ guitone/src/model/Inventory.cpp 547fc8cf017c30da0f7a2772013d83f42c63a28f @@ -77,8 +77,10 @@ void Inventory::parseOutput() } // this item is given a parent explicitely later on - item = new InventoryItem(NULL, path, status, isDirectory); - + item = new InventoryItem(isDirectory); + item->setPath(path); + item->setStatus(status); + if (from_id > 0) { renameMap[-from_id] = item; @@ -104,11 +106,15 @@ void Inventory::parseOutput() // FIXME: we shouldn't really add a workspace root item here, but // mtn automate inventory currently doesn't print the root workspace dir - InventoryItem * branch = new InventoryItem(rootItem, ".", 0, true, true); + InventoryItem * branch = new InventoryItem(true, true); + branch->setParent(rootItem); + branch->setPath("."); + branch->setStatus(0); branch->setLabel(MonotoneDelegate::getBranchName(this)); + branch->setChildren(buildTreeRecursive(tempItems, NULL)); + rootItem->appendChild(branch); - branch->setChildren(buildTreeRecursive(tempItems, NULL)); - + // reset the model to repaint the view completly // (all QModelIndexes are discarded through that, e.g. selections!) reset(); @@ -133,15 +139,14 @@ QList Inventory::buildTr } // add pseudo item "cd up" for each directory - InventoryItem *cdUp = new InventoryItem( - parentItem, - parentPath + QString("/.."), - parentStatus, - true - ); + InventoryItem * cdUp = new InventoryItem(true); + cdUp->setParent(parentItem); + cdUp->setPath(parentPath + QString("/..")); + cdUp->setStatus(parentStatus); + items.prepend(cdUp); - InventoryItem *currentItem; + InventoryItem * currentItem; while (items.size() > 0) { currentItem = items.front(); @@ -182,7 +187,7 @@ const QModelIndex Inventory::index(int row, int column, const QModelIndex &parent) const { - InventoryItem *parentItem; + InventoryItem * parentItem; if (!parent.isValid()) { @@ -193,7 +198,7 @@ const parentItem = static_cast(parent.internalPointer()); } - InventoryItem *childItem = parentItem->child(row); + InventoryItem * childItem = parentItem->child(row); if (childItem) { @@ -220,7 +225,7 @@ QVariant Inventory::data(const QModelInd return QVariant(); } - InventoryItem *item = static_cast(index.internalPointer()); + InventoryItem * item = static_cast(index.internalPointer()); if((role == Qt::DecorationRole) && (index.column() == 0)) { @@ -249,13 +254,22 @@ Qt::ItemFlags Inventory::flags(const QMo Qt::ItemFlags Inventory::flags(const QModelIndex &index) const { - if (index.isValid()) + if (!index.isValid()) return 0; + + QFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; + + InventoryItem * item = static_cast(index.internalPointer()); + + if (item->isCdUp() || item->isRootDirectory()) return flags; + + flags |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled; + + if (item->isDirectory()) { - return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | - Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; - } + flags |= Qt::ItemIsDropEnabled; + } - return Qt::ItemIsDropEnabled; + return flags; } // the root item needs to store the header for each field @@ -289,7 +303,7 @@ int Inventory::rowCount(const QModelInde int Inventory::rowCount(const QModelIndex& parent) const { - InventoryItem *parentItem = rootItem; + InventoryItem * parentItem = rootItem; if (parent.isValid()) { ============================================================ --- guitone/src/model/InventoryItem.cpp 355359d12820d5b033152183174b9d738ce601e1 +++ guitone/src/model/InventoryItem.cpp 940ee31302a885f24f2658630ba64e259b6fda42 @@ -33,25 +33,27 @@ const int InventoryItem::Ignored = 256; const int InventoryItem::Unknown = 128; const int InventoryItem::Ignored = 256; -InventoryItem::InventoryItem() +InventoryItem::InventoryItem(bool isDir /* =false */, bool isRoot /* =false */) { parentItem = this; path = ""; label = ""; status = 0; - dirFlag = false; - childDirFlag = false; - rootFlag = false; + dirFlag = isDir; + rootFlag = isRoot; } -InventoryItem::InventoryItem(InventoryItem* parent, QString p, int st, bool isDir, bool isRoot) +InventoryItem::InventoryItem(const InventoryItem * other) { - parentItem = parent; - path = p; - status = st; - dirFlag = isDir; - childDirFlag = false; - rootFlag = isRoot; + dirFlag = other->isDirectory(); + rootFlag = other->isRootDirectory(); + renamed_from = other->getRenamedFrom(); + renamed_to = other->getRenamedTo(); + parentItem = other->parent(); + children = other->getChildren(); + status = other->getStatus(); + path = other->getPath(); + label = other->getLabel(); } InventoryItem::~InventoryItem() @@ -83,7 +85,6 @@ void InventoryItem::deleteAllChildren(vo path = ""; status = 0; dirFlag = false; - childDirFlag = false; rootFlag = false; qDeleteAll(children); children.clear(); @@ -105,10 +106,6 @@ void InventoryItem::setChildren(QListsetParent(this); - if (item->isDirectory()) - { - childDirFlag = true; - } } children.clear(); @@ -134,6 +131,7 @@ QVariant InventoryItem::data(int 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(); } } @@ -142,6 +140,7 @@ QVariant InventoryItem::data(int column, { case 0: return QVariant(getLabel()); case 1: return QVariant(getStatusString()); + case 2: return QVariant(getRenameInfo()); default: return QVariant(); } } @@ -266,6 +265,21 @@ QString InventoryItem::getStatusString() return list.join(", "); } +QString InventoryItem::getRenameInfo() const +{ + QStringList strings; + if (hasStatus(RenamedFrom)) + { + strings << tr("new name: %1").arg(getRenamedTo()->getPath()); + } + + if (hasStatus(RenamedTo)) + { + strings << tr("old name: %1").arg(getRenamedFrom()->getPath()); + } + return strings.join(", "); +} + bool InventoryItem::rename(const QString & n) { QString newName(n.trimmed()); @@ -295,9 +309,7 @@ bool InventoryItem::rename(const QString } // apparently its not, lets create a new rename entry - InventoryItem * renamedItem = new InventoryItem(); - parentItem->appendChild(renamedItem); - qDebug("child count: %d", parentItem->childCount()); + InventoryItem * renamedItem = new InventoryItem(this); renamedItem->setStatus(status | InventoryItem::RenamedTo); setStatus(status | InventoryItem::RenamedFrom); ============================================================ --- guitone/src/model/InventoryItem.h 70cef46c046d56928dbe9adc86b0d9da8a3f282c +++ guitone/src/model/InventoryItem.h 74e2924b72a68f29d5f0eb7b4f791e1c8c6a05d5 @@ -28,8 +28,8 @@ public: Q_OBJECT public: - InventoryItem(void); - InventoryItem(InventoryItem*, QString, int, bool, bool isRoot = false); + InventoryItem(bool isDir = false, bool isRoot = false); + InventoryItem(const InventoryItem *); ~InventoryItem(void); inline void setRenamedFrom(InventoryItem * from) { renamed_from = from; } @@ -48,13 +48,12 @@ public: inline bool isTracked() const { return hasNotStatus(Ignored | Unknown); } inline bool isDirectory(void) const { return dirFlag; } inline bool isRootDirectory(void) const { return rootFlag; } - inline bool hasChildDirs(void) const { return childDirFlag; } - inline int getStatus(void) { return status; } + inline int getStatus(void) const { return status; } inline void setStatus(int st) { status = st; } inline InventoryItem * child(int row) const { return children.value(row); } inline int childCount(void) const { return children.count(); }; - inline int columnCount(void) const { return 2; } + inline int columnCount(void) const { return 3; } void setChildren(QList); void deleteAllChildren(void); @@ -70,7 +69,6 @@ public: bool hasNotStatus(int) const; int getStatusRecursive() const; bool hasChangedRecursive() const; - QString getStatusString(void) const; /* needed for Qt model class */ int row(void) const; @@ -88,14 +86,16 @@ public: static const int Unknown; static const int Ignored; -private: +private: + QString getStatusString(void) const; + QString getRenameInfo(void) const; + InventoryItem * renamed_from; InventoryItem * renamed_to; InventoryItem * parentItem; QList children; int status; bool dirFlag; - bool childDirFlag; bool rootFlag; QString path; QString label; ============================================================ --- guitone/src/view/InventoryView.cpp 7ecee38b487625d1da171e490841d6f466243c6a +++ guitone/src/view/InventoryView.cpp 75865a2ee33160e4529cda5d8a587899e031c431 @@ -192,7 +192,8 @@ void InventoryView::slotContextMenuReque } if (item->hasNotStatus(InventoryItem::Ignored) && - item->hasNotStatus(InventoryItem::Unknown)) + item->hasNotStatus(InventoryItem::Unknown) && + !item->isRootDirectory() && !item->isCdUp()) { menu.addAction(actRemove); menu.addAction(actRename); @@ -352,10 +353,7 @@ void InventoryView::changeDirectory(cons static_cast(model())->mapFromSource(source); // expand the selection if needed - if (item->hasChildDirs()) - { - expand(proxyFolderIndex); - } + expand(proxyFolderIndex); // select the item selectionModel()->setCurrentIndex(