# # # patch "src/model/InventoryModel.cpp" # from [130c5c2d483106de0b1181f300f70078ceb3ca7c] # to [449f8bff08ed3c9316cc5d59ccb6eac1fe71d19e] # # patch "src/model/InventoryModel.h" # from [b18ea84b5d13dfc7aca550e26238233a7c764b82] # to [79749c6f114e8202469c52b73014322d28083834] # # patch "src/model/InventoryWatcher.cpp" # from [f3e0038411789e66fa7e5f5b5c0721cef4d91f4c] # to [eb4db8f6cd3d776a5c4ff210ede88dad0058e13b] # # patch "src/model/InventoryWatcher.h" # from [0ddc4c5fcc764c4c6676d938aa7f3e56ff0f6428] # to [08010c5c36ef15d3d2107a749de8f293f2961a8b] # # patch "src/view/InventoryView.cpp" # from [b138e484c4dfdc3e790bef5359f31620591fa151] # to [bbc8682e8ac362ff0b909a7162f4a47589ec34e4] # # patch "src/view/InventoryView.h" # from [aabacd229a25b7188d3e02d2c9f326e54d1e8de7] # to [c3bbc745b0e5b49a883a888ce8efef698640a9aa] # # patch "src/view/WorkspaceWindow.cpp" # from [313818ac62c61486a5a96ea6963a3734619c9307] # to [9ae0a5ea1f3095ecc8824221b1d1523956942144] # ============================================================ --- src/model/InventoryModel.cpp 130c5c2d483106de0b1181f300f70078ceb3ca7c +++ src/model/InventoryModel.cpp 449f8bff08ed3c9316cc5d59ccb6eac1fe71d19e @@ -56,6 +56,7 @@ InventoryModel::~InventoryModel() InventoryModel::~InventoryModel() { + I(nodeInsertions.size() == 0); delete inventory; } @@ -299,15 +300,46 @@ void InventoryModel::triggerBeginInsertR void InventoryModel::triggerBeginInsertRows(ModelItem * parent, int start, int end) { beginInsertRows(indexFromItem(parent, 0), start, end); + nodeInsertions.push(new NodeInsertion(parent, start, end)); } + void InventoryModel::triggerEndInsertRows() { + NodeInsertion * insertion = nodeInsertions.pop(); + + QStringList paths; + for (int i=insertion->start; i<=insertion->end; i++) + { + ModelItem * child = insertion->parent->child(i); + InventoryItem * invItem = qobject_cast(child); + if (!invItem) continue; + // do not monitor non-existing files + if (invItem->getFSType() == InventoryItem::None) continue; + // a little optimization: we don't care about / monitor ignored files + if (invItem->hasStatus(InventoryItem::Ignored)) continue; + paths.push_back(invItem->getPath()); + } + + delete insertion; + emit pathsInserted(paths); + endInsertRows(); } void InventoryModel::triggerBeginRemoveRows(ModelItem * parent, int start, int end) { beginRemoveRows(indexFromItem(parent, 0), start, end); + + QStringList paths; + for (int i=start; i<=end; i++) + { + ModelItem * child = parent->child(i); + InventoryItem * invItem = qobject_cast(child); + if (!invItem) continue; + paths.push_back(invItem->getPath()); + } + + emit pathsRemoved(paths); } void InventoryModel::triggerEndRemoveRows() ============================================================ --- src/model/InventoryModel.h b18ea84b5d13dfc7aca550e26238233a7c764b82 +++ src/model/InventoryModel.h 79749c6f114e8202469c52b73014322d28083834 @@ -22,7 +22,16 @@ #include "Inventory.h" #include +#include +struct NodeInsertion { + NodeInsertion(ModelItem * p, int s, int e) + : parent(p), start(s), end(e) {} + ModelItem * parent; + int start; + int end; +}; + class InventoryModel : public QAbstractItemModel { Q_OBJECT @@ -50,6 +59,7 @@ private: Inventory * inventory; WorkspacePath workspacePath; + QStack nodeInsertions; private slots: void triggerBeginInsertRows(ModelItem *, int, int); @@ -63,6 +73,8 @@ signals: signals: //! forward void invalidWorkspaceFormat(const QString &); + void pathsInserted(const QStringList &); + void pathsRemoved(const QStringList &); }; #endif ============================================================ --- src/model/InventoryWatcher.cpp f3e0038411789e66fa7e5f5b5c0721cef4d91f4c +++ src/model/InventoryWatcher.cpp eb4db8f6cd3d776a5c4ff210ede88dad0058e13b @@ -40,32 +40,30 @@ void InventoryWatcher::setWorkspacePath( workspace = wp; } -void InventoryWatcher::watchItems(const QModelIndexList & indexes) +void InventoryWatcher::watchPaths(const QStringList & paths) { - addPaths(pathsFromIndexes(indexes)); -} + QStringList watchedPaths = files() + directories(); -void InventoryWatcher::unwatchItems(const QModelIndexList & indexes) -{ - //removePaths(pathsFromIndexes(indexes)); + foreach (QString path, paths) + { + QString fullPath(workspace); + if (!path.isEmpty()) fullPath += "/" + path; + if (watchedPaths.indexOf(fullPath) != -1) continue; + addPath(fullPath); + } } -QStringList InventoryWatcher::pathsFromIndexes(const QModelIndexList & indexes) +void InventoryWatcher::unwatchPaths(const QStringList & paths) { - if (workspace.isEmpty()) QStringList(); - QStringList paths; + QStringList watchedPaths = files() + directories(); - foreach (QModelIndex idx, indexes) + foreach (QString path, paths) { - if (!idx.isValid()) continue; - ModelItem * item = static_cast(idx.internalPointer()); - I(item); - InventoryItem * invitem = qobject_cast(item); - if (!invitem) continue; - if (invitem->getFSType() == InventoryItem::None) continue; - paths.append(workspace + "/" + invitem->getPath()); + QString fullPath(workspace); + if (!path.isEmpty()) fullPath += "/" + path; + if (watchedPaths.indexOf(fullPath) == -1) continue; + removePath(fullPath); } - return paths; } void InventoryWatcher::pathChanged(const QString & path) ============================================================ --- src/model/InventoryWatcher.h 0ddc4c5fcc764c4c6676d938aa7f3e56ff0f6428 +++ src/model/InventoryWatcher.h 08010c5c36ef15d3d2107a749de8f293f2961a8b @@ -35,11 +35,10 @@ public slots: public slots: void setWorkspacePath(const WorkspacePath &); - void watchItems(const QModelIndexList &); - void unwatchItems(const QModelIndexList &); + void watchPaths(const QStringList &); + void unwatchPaths(const QStringList &); private: - QStringList pathsFromIndexes(const QModelIndexList &); WorkspacePath workspace; private slots: ============================================================ --- src/view/InventoryView.cpp b138e484c4dfdc3e790bef5359f31620591fa151 +++ src/view/InventoryView.cpp bbc8682e8ac362ff0b909a7162f4a47589ec34e4 @@ -28,7 +28,7 @@ InventoryView::InventoryView(QWidget * p #include InventoryView::InventoryView(QWidget * parent, const QString & objectName) - : TreeView(parent, objectName), invViewDelegate(parent), selectModel(0) + : TreeView(parent, objectName), invViewDelegate(parent) { setItemDelegate(&invViewDelegate); setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -205,8 +205,6 @@ InventoryView::~InventoryView() delete actIgnoreMultiple; delete actUnignoreMultiple; delete actRevertMultiple; - - if (selectModel) delete selectModel; } // ensure that we only accept sortfilterproxymodels @@ -243,7 +241,6 @@ void InventoryView::setModel(QSortFilter } TreeView::setModel(newModel); - selectModel = new QItemSelectionModel(newModel); connect( newModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), @@ -871,58 +868,3 @@ void InventoryView::setBackgroundImage() } } -bool InventoryView::viewportEvent(QEvent * ev) -{ - switch (ev->type()) - { - case QEvent::Paint: - notifyAboutViewportChanges(); - default: - return QAbstractScrollArea::viewportEvent(ev); - } - I(false); -} - -void InventoryView::notifyAboutViewportChanges() -{ - // save the old selection model reference - QItemSelectionModel * oldSelectModel = selectionModel(); - - setSelectionModel(selectModel); - setSelection(viewport()->rect(), - QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); - QModelIndexList newIndexes = selectedIndexes(); - - // restore it again - setSelectionModel(oldSelectModel); - - // convert proxy into real indexes and remove column indexes > 0 - for (int i=0; i 0) - { - newIndexes.removeAt(i); - continue; - } - newIndexes[i] = sourceIndex(newIndexes[i]); - i++; - } - - QSet oldIndexSet = QSet::fromList(itemsVisibleInViewport); - QSet newIndexSet = QSet::fromList(newIndexes); - - QSet removedIndexes = oldIndexSet - newIndexSet; - if (removedIndexes.size() > 0) - { - emit removedFromViewport(removedIndexes.toList()); - } - - QSet addedIndexes = newIndexSet - oldIndexSet; - if (addedIndexes.size() > 0) - { - emit addedToViewport(addedIndexes.toList()); - } - - itemsVisibleInViewport = newIndexes; -} - ============================================================ --- src/view/InventoryView.h aabacd229a25b7188d3e02d2c9f326e54d1e8de7 +++ src/view/InventoryView.h c3bbc745b0e5b49a883a888ce8efef698640a9aa @@ -48,8 +48,6 @@ signals: void diffFile(const QString &); void fileHistory(const QString &); void commitRevision(const QStringList &); - void addedToViewport(const QModelIndexList &); - void removedFromViewport(const QModelIndexList &); void refreshPath(const QString &); private: @@ -60,8 +58,6 @@ private: DefaultAction getDefaultAction(const QModelIndex &) const; void createAndConnectContextActions(); void closeEvent(); - bool viewportEvent(QEvent *); - void notifyAboutViewportChanges(); inline QModelIndex sourceIndex(const QModelIndex &, bool useIndexModel = false) const; inline QModelIndex proxyIndex(const QModelIndex &) const; @@ -92,9 +88,6 @@ private: InventoryViewDelegate invViewDelegate; - QModelIndexList itemsVisibleInViewport; - QItemSelectionModel * selectModel; - private slots: void newNodeLoaded(const QModelIndex &, const QModelIndex &); void changeDirectory(const QModelIndex &); ============================================================ --- src/view/WorkspaceWindow.cpp 313818ac62c61486a5a96ea6963a3734619c9307 +++ src/view/WorkspaceWindow.cpp 9ae0a5ea1f3095ecc8824221b1d1523956942144 @@ -201,6 +201,16 @@ void WorkspaceWindow::setup() proxyModelFileList->setSourceModel(invModel); connect( + invModel, SIGNAL(pathsInserted(const QStringList &)), + invWatcher, SLOT(watchPaths(const QStringList &)) + ); + + connect( + invModel, SIGNAL(pathsRemoved(const QStringList &)), + invWatcher, SLOT(unwatchPaths(const QStringList &)) + ); + + connect( invWatcher, SIGNAL(changedPath(const QString &)), invModel, SLOT(refresh(const QString &)) ); @@ -256,26 +266,6 @@ void WorkspaceWindow::setup() invModel, SLOT(refresh(const QString &)) ); - connect( - treeView, SIGNAL(addedToViewport(const QModelIndexList &)), - invWatcher, SLOT(watchItems(const QModelIndexList &)) - ); - - connect( - treeView, SIGNAL(removedFromViewport(const QModelIndexList &)), - invWatcher, SLOT(unwatchItems(const QModelIndexList &)) - ); - - connect( - listView, SIGNAL(addedToViewport(const QModelIndexList &)), - invWatcher, SLOT(watchItems(const QModelIndexList &)) - ); - - connect( - listView, SIGNAL(removedFromViewport(const QModelIndexList &)), - invWatcher, SLOT(unwatchItems(const QModelIndexList &)) - ); - attrView->setModel(attrModel); iconHelp = new IconHelp(this);