From: Peter Penz Date: Fri, 15 Dec 2006 01:56:57 +0000 (+0000) Subject: Update for using a proxy model: prevent accessing the model by model() and doing... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/3b4dfa2040c1e970ba6689bd7a874fab5f423e2d Update for using a proxy model: prevent accessing the model by model() and doing a cast do KDirModel afterwards. Instead the access to the KDirModel is done by a member variable. Still the proxy model does not seem to work and leads to a crash as soon as the QListView should work with the proxy model -> in the meantime in line 112 from DolphinView.cpp the KDirModel is used instead of the proxy model. svn path=/trunk/playground/utils/dolphin/; revision=613768 --- diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 98d1a05b1..eb3dde47f 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -58,6 +58,10 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) const QModelIndex index = indexAt(event->pos()); if (index.isValid()) { + // TODO: assuming that model() returns an instance of the class + // KDirModel is dangerous, especially in combination with a proxy model. + // As the current test implementation of proxy model does not work, this + // will be cleaned up later. KDirModel* dirModel = static_cast(model()); item = dirModel->itemForIndex(index); } diff --git a/src/dolphinsortfilterproxymodel.h b/src/dolphinsortfilterproxymodel.h index fd1005bfd..b400400f6 100644 --- a/src/dolphinsortfilterproxymodel.h +++ b/src/dolphinsortfilterproxymodel.h @@ -45,8 +45,8 @@ public: Qt::SortOrder sortOrder() const { return m_sortOrder; } protected: - virtual bool lessThan(const QModelIndex& left, - const QModelIndex& right) const; + virtual bool lessThan(const QModelIndex& left, + const QModelIndex& right) const; private: DolphinView::Sorting m_sorting; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index c23cb2baa..1a02ddea0 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -67,6 +67,7 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, m_iconsView(0), m_filterBar(0), m_statusBar(0), + m_dirModel(0), m_dirLister(0), m_proxyModel(0) { @@ -102,20 +103,19 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, m_iconsView = new DolphinIconsView(this); applyModeToView(); - KDirModel* model = new KDirModel(); - model->setDirLister(m_dirLister); + m_dirModel = new KDirModel(); + m_dirModel->setDirLister(m_dirLister); m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(model); - m_proxyModel->setDynamicSortFilter(true); + m_proxyModel->setSourceModel(m_dirModel); - m_iconsView->setModel(model); + m_iconsView->setModel(m_dirModel); // TODO: using m_proxyModel crashed when clicking on an item KFileItemDelegate* delegate = new KFileItemDelegate(this); m_iconsView->setItemDelegate(delegate); m_dirLister->setDelayedMimeTypes(true); - new KMimeTypeResolver(m_iconsView, model); + new KMimeTypeResolver(m_iconsView, m_dirModel); m_iconSize = K3Icon::SizeMedium; @@ -476,12 +476,11 @@ KFileItemList DolphinView::selectedItems() const KFileItemList itemList; if (selModel->hasSelection()) { - KDirModel* dirModel = static_cast(m_iconsView->model()); const QModelIndexList indexList = selModel->selectedIndexes(); QModelIndexList::const_iterator end = indexList.end(); for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) { - KFileItem* item = dirModel->itemForIndex(*it); + KFileItem* item = m_dirModel->itemForIndex(*it); if (item != 0) { itemList.append(item); } @@ -648,8 +647,7 @@ void DolphinView::triggerIconsViewItem(Q3IconViewItem* item) void DolphinView::triggerItem(const QModelIndex& index) { - KDirModel* dirModel = static_cast(m_iconsView->model()); - KFileItem* item = dirModel->itemForIndex(index); + KFileItem* item = m_dirModel->itemForIndex(index); if (item == 0) { return; } diff --git a/src/dolphinview.h b/src/dolphinview.h index 42e54f802..297dd3bd8 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -53,6 +53,7 @@ class DolphinDetailsView; class DolphinSortFilterProxyModel; class ViewProperties; class KProgress; +class KDirModel; class FilterBar; class QModelIndex; @@ -464,6 +465,7 @@ private: FilterBar *m_filterBar; DolphinStatusBar* m_statusBar; + KDirModel* m_dirModel; DolphinDirLister* m_dirLister; DolphinSortFilterProxyModel* m_proxyModel;