From: Peter Penz Date: Fri, 21 Sep 2007 18:52:46 +0000 (+0000) Subject: implemented reloading of all columns of the column view (just updating the directory... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/d24597def8cee35fa230ebd9457e4bea89374d02 implemented reloading of all columns of the column view (just updating the directory lister is not enough in this case...) svn path=/trunk/KDE/kdebase/apps/; revision=715294 --- diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 49434d64a..6d4f58425 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -452,13 +452,42 @@ QRect DolphinColumnView::visualRect(const QModelIndex& index) const void DolphinColumnView::setModel(QAbstractItemModel* model) { + if (m_dolphinModel != 0) { + m_dolphinModel->disconnect(this); + } + m_proxyModel = static_cast(model); m_dolphinModel = static_cast(m_proxyModel->sourceModel()); + connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), + this, SLOT(triggerReloadColumns(const QModelIndex&))); activeColumn()->setModel(model); QAbstractItemView::setModel(model); } +void DolphinColumnView::reload() +{ + deleteInactiveChildColumns(); + + // Due to the reloading of the model all columns will be reset to show + // the same content as the first column. As this is not wanted, all columns + // except of the first column are temporary hidden until the root index can + // be updated again. + QList::iterator start = m_columns.begin() + 1; + QList::iterator end = m_columns.end(); + for (QList::iterator it = start; it != end; ++it) { + (*it)->hide(); + (*it)->setRootIndex(QModelIndex()); + } + + // all columns are hidden, now reload the directory lister + KDirLister* dirLister = m_dolphinModel->dirLister(); + connect(dirLister, SIGNAL(completed()), + this, SLOT(expandToActiveUrl())); + const KUrl baseUrl = m_columns[0]->url(); + dirLister->openUrl(baseUrl, false, true); +} + bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const { Q_UNUSED(index); @@ -513,6 +542,7 @@ void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::Sel QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const { + Q_UNUSED(selection); return QRegion(); //activeColumn()->visualRegionForSelection(selection); } @@ -663,6 +693,42 @@ void DolphinColumnView::updateDecorationSize() doItemsLayout(); } +void DolphinColumnView::expandToActiveUrl() +{ + const KUrl& activeUrl = m_controller->url(); + const KUrl baseUrl = m_dolphinModel->dirLister()->url(); + if (baseUrl.isParentOf(activeUrl) && (baseUrl != activeUrl)) { + m_dolphinModel->expandToUrl(activeUrl); + reloadColumns(); + } +} + +void DolphinColumnView::triggerReloadColumns(const QModelIndex& index) +{ + Q_UNUSED(index); + disconnect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), + this, SLOT(triggerReloadColumns(const QModelIndex&))); + // the reloading of the columns may not be done in the context of this slot + QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection); +} + +void DolphinColumnView::reloadColumns() +{ + const int count = m_columns.count() - 1; // ignore the last column + for (int i = 0; i < count; ++i) { + ColumnWidget* nextColumn = m_columns[i + 1]; + const QModelIndex rootIndex = nextColumn->rootIndex(); + if (!rootIndex.isValid()) { + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_columns[i]->childUrl()); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (proxyIndex.isValid()) { + nextColumn->setRootIndex(proxyIndex); + nextColumn->show(); + } + } + } +} + bool DolphinColumnView::isZoomInPossible() const { ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index ba5ed8101..37deffd2c 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -50,6 +50,13 @@ public: virtual QRect visualRect(const QModelIndex& index) const; virtual void setModel(QAbstractItemModel* model); + /** + * Reloads the content of all columns. In opposite to non-hierarchical views + * it is not enough to reload the KDirLister, instead this method must be explicitly + * invoked. + */ + void reload(); + protected: virtual bool isIndexHidden(const QModelIndex& index) const; virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); @@ -86,6 +93,25 @@ private slots: */ void updateDecorationSize(); + /** + * Expands the directory model the the currently active URL. + * Used by DolphinColumnView::reload() after the directory + * lister has been loaded. + */ + void expandToActiveUrl(); + + /** + * Triggers the reloading of columns after the model index + * \a index has been expanded. Used by DolphinModel::expandToActiveUrl(). + */ + void triggerReloadColumns(const QModelIndex& index); + + /** + * Adjusts the root index of all columns to represent the reloaded + * model. Used by DolphinModel::triggerReloadColumns(). + */ + void reloadColumns(); + private: bool isZoomInPossible() const; bool isZoomOutPossible() const; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 2dd8e289b..d7e79f330 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -505,28 +505,20 @@ void DolphinView::startDirLister(const KUrl& url, bool reload) m_dirLister->stop(); - bool openDir = true; bool keepOldDirs = isColumnViewActive() && !m_initializeColumnView; m_initializeColumnView = false; if (keepOldDirs) { + // keeping old directories is only necessary for hierarchical views + // like the column view if (reload) { - keepOldDirs = false; - - const KUrl& dirListerUrl = m_dirLister->url(); - if (dirListerUrl.isValid()) { - const KUrl::List dirs = m_dirLister->directories(); - KUrl url; - foreach(url, dirs) { - m_dirLister->updateDirectory(url); - } - openDir = false; - } + // for the column view it is not enough to reload the directory lister, + // so this task is delegated to the column view directly + m_columnView->reload(); } else if (m_dirLister->directories().contains(url)) { // The dir lister contains the directory already, so - // KDirLister::openUrl() may not been invoked twice. + // KDirLister::openUrl() may not get invoked twice. m_dirLister->updateDirectory(url); - openDir = false; } else { const KUrl& dirListerUrl = m_dirLister->url(); if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) { @@ -535,11 +527,10 @@ void DolphinView::startDirLister(const KUrl& url, bool reload) // and hence the view must be reset. keepOldDirs = false; } + m_dirLister->openUrl(url, keepOldDirs, false); } - } - - if (openDir) { - m_dirLister->openUrl(url, keepOldDirs, reload); + } else { + m_dirLister->openUrl(url, false, reload); } }