# # # patch "src/model/Inventory.cpp" # from [053e2fd159965c9f1980d0f9e1cc320f355d9f3c] # to [5d271674ad247b34f192e59f414400c42112d508] # # patch "src/model/Inventory.h" # from [dd3d583eaa911aa15533ded0974a4f16f57481c9] # to [b8192411cbd0363596148c33be1a2c13aa44165a] # # patch "src/view/InventoryView.cpp" # from [2eb9f86bd01b1f5cc192e77bce8e70ea87dfe2b3] # to [e198631d80885cb76929c51545711969e9240513] # # patch "src/view/InventoryView.h" # from [148aa72111fb093f7387aaab496d55c8f8bc82df] # to [2c0326d792dfe74d5bc029db8218b301459b3757] # # patch "src/view/WorkspaceWindow.cpp" # from [dfa4d23546d733bc6c73503d9aee32dabcd70a86] # to [8200dc2b4d67318b8c406d2bc141cfd8f6b41e9c] # # patch "src/view/WorkspaceWindow.h" # from [558c0425e0e25438eb09744828fd0fa3069e67c9] # to [ccc33495e5dbe966045065fb35311d07f5f7e96e] # ============================================================ --- src/model/Inventory.cpp 053e2fd159965c9f1980d0f9e1cc320f355d9f3c +++ src/model/Inventory.cpp 5d271674ad247b34f192e59f414400c42112d508 @@ -53,13 +53,36 @@ void Inventory::refresh() readInventory(QString()); } -void Inventory::fetchMore(const QModelIndex & index) +bool Inventory::canFetchMore(const QModelIndex & parent) const { - if (!index.isValid()) + // special handling for the root item + if (!parent.isValid()) + return true; + + ModelItem * item = static_cast + (parent.internalPointer()); + I(item); + + InventoryItem * invitem = dynamic_cast + (item); + + // not an inventory item + if (!invitem) + return false; + + if (invitem->isExpanded()) + return false; + + return true; +} + +void Inventory::fetchMore(const QModelIndex & parent) +{ + if (!parent.isValid()) return; ModelItem * item = static_cast - (index.internalPointer()); + (parent.internalPointer()); I(item); InventoryItem * invitem = dynamic_cast @@ -77,9 +100,6 @@ void Inventory::fetchMore(const QModelIn // restricting to single files makes no sense for us here either if (invitem->getFSType() != InventoryItem::Directory) return; - // do not query again here if we already expanded this directory - if (invitem->isExpanded()) return; - readInventory(invitem->getPath()); } @@ -171,13 +191,37 @@ void Inventory::processTaskResult(const endInsertRows(); } - // if the inventory's workspace root was read (i.e. inventory was called - // without a path), we've practically resetted the complete view, so we - // make sure modelReset() is signalled by calling reset() - if (task.getArguments().size() == 1) + // + // This is a bit of a hack: Since we replace the original item each + // time we query new data, the view looses the viewport and indexes + // for it. So what we need to do here is to notify the view that it + // should set the viewport to the correct item again _after_ we've + // read it (now) and we need to do this through an already existing + // signal since this model is not directly connected to the view, but + // through a proxy model, so we need to ensure that the proxy model + // transports a known signal to the view. + // The dataChanged signal is normally used for in-place editable + // actions, so I really hope it has + // a) no side effects + // b) I never need it for its original purpose + // + QString path; + if (task.getArguments().size() > 1) { + path = task.getArguments().at(1); + } + else + { + // we need to call reset() before we emit dataChanged, + // otherwise the view doesn't know anything of the new + // index we're going to present her afterwards reset(); + path = ""; } + I(itemMap.contains(path)); + QModelIndex index = indexFromItem(itemMap.value(path), 0); + I(index.isValid()); + emit dataChanged(index, index); } QModelIndex Inventory::indexFromItem(const ModelItem * item, int col) const ============================================================ --- src/model/Inventory.h dd3d583eaa911aa15533ded0974a4f16f57481c9 +++ src/model/Inventory.h b8192411cbd0363596148c33be1a2c13aa44165a @@ -42,12 +42,16 @@ public: QModelIndex parent(const QModelIndex &) const; int rowCount(const QModelIndex &) const; int columnCount(const QModelIndex &) const; + bool canFetchMore( const QModelIndex &) const; + void fetchMore(const QModelIndex &); public slots: void setWorkspacePath(const WorkspacePath &); void refresh(); - void fetchMore(const QModelIndex &); +signals: + void nodeLoaded(const QModelIndex &); + private: void processTaskResult(const MonotoneTask &); QModelIndex indexFromItem(const ModelItem *, int) const; ============================================================ --- src/view/InventoryView.cpp 2eb9f86bd01b1f5cc192e77bce8e70ea87dfe2b3 +++ src/view/InventoryView.cpp e198631d80885cb76929c51545711969e9240513 @@ -192,22 +192,23 @@ void InventoryView::setModel(QSortFilter if (oldModel) { disconnect( - oldModel, SIGNAL(modelReset()), - this, SLOT(resetViewAfterModelReset()) + newModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(newNodeLoaded(const QModelIndex &, const QModelIndex &)) ); } TreeView::setModel(newModel); connect( - newModel, SIGNAL(modelReset()), - this, SLOT(resetViewAfterModelReset()) + newModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(newNodeLoaded(const QModelIndex &, const QModelIndex &)) ); } -void InventoryView::resetViewAfterModelReset() +void InventoryView::newNodeLoaded(const QModelIndex & index, const QModelIndex & dummy) { - QModelIndex index = model()->index(0, 0, QModelIndex()); + Q_UNUSED(dummy); + if (!index.isValid()) { C("Index invalid, aborting..."); ============================================================ --- src/view/InventoryView.h 148aa72111fb093f7387aaab496d55c8f8bc82df +++ src/view/InventoryView.h 2c0326d792dfe74d5bc029db8218b301459b3757 @@ -80,8 +80,7 @@ private slots: InventoryViewDelegate invViewDelegate; private slots: - void resetViewAfterModelReset(); - + void newNodeLoaded(const QModelIndex &, const QModelIndex &); void changeDirectory(const QModelIndex &); void itemClicked(const QModelIndex & index); void slotContextMenuRequested(const QModelIndexList &, const QPoint &); ============================================================ --- src/view/WorkspaceWindow.cpp dfa4d23546d733bc6c73503d9aee32dabcd70a86 +++ src/view/WorkspaceWindow.cpp 8200dc2b4d67318b8c406d2bc141cfd8f6b41e9c @@ -166,21 +166,6 @@ void WorkspaceWindow::setup() treeView, SLOT(expandAllNodes(bool)) ); - connect( - treeView, SIGNAL(expanded(const QModelIndex &)), - this, SLOT(readInventory(const QModelIndex &)) - ); - - connect( - treeView, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(readInventory(const QModelIndex &)) - ); - - connect( - listView, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(readInventory(const QModelIndex &)) - ); - listSplitter->addWidget(listView); listSplitter->addWidget(attrView); @@ -354,10 +339,3 @@ void WorkspaceWindow::invalidWorkspaceFo close(); } -void WorkspaceWindow::readInventory(const QModelIndex & index) -{ - QModelIndex sourceIndex = static_cast - (index.model())->mapToSource(index); - invModel->fetchMore(sourceIndex); -} - ============================================================ --- src/view/WorkspaceWindow.h 558c0425e0e25438eb09744828fd0fa3069e67c9 +++ src/view/WorkspaceWindow.h ccc33495e5dbe966045065fb35311d07f5f7e96e @@ -67,7 +67,6 @@ private slots: void invalidWorkspaceFormat(const QString &); void openFile(const QString &); void checkForUnaccountedRenames(); - void readInventory(const QModelIndex &); }; #endif