The first columns model and selection model should be the same as the view's model and selection model.

This means
1) We don't leak memory switching to and from column view
2) Selection is preserved when switching views
3) We don't have 2 models running for the root directory

CCMAIL:peter.penz@gmx.at

svn path=/trunk/KDE/kdebase/apps/; revision=744386
This commit is contained in:
John Tapsell 2007-12-03 10:32:27 +00:00
parent 0f4ecd1c61
commit e80f077357
4 changed files with 26 additions and 10 deletions

View file

@ -554,4 +554,19 @@ void DolphinColumnView::removeAllColumns()
assureVisibleActiveColumn(); assureVisibleActiveColumn();
} }
void DolphinColumnView::setModel ( QAbstractItemModel * model )
{
QAbstractItemView::setModel(model);
if(m_columns[0]) {
m_columns[0]->setModel(model);
m_columns[0]->setSelectionModel(selectionModel());
}
}
void DolphinColumnView::setSelectionModel ( QItemSelectionModel * selectionModel )
{
if(m_columns[0])
m_columns[0]->setSelectionModel(selectionModel);
QAbstractItemView::setSelectionModel(selectionModel);
}
#include "dolphincolumnview.moc" #include "dolphincolumnview.moc"

View file

@ -103,6 +103,8 @@ protected:
virtual void mousePressEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event);
virtual void resizeEvent(QResizeEvent* event); virtual void resizeEvent(QResizeEvent* event);
virtual void setSelectionModel ( QItemSelectionModel * selectionModel );
virtual void setModel ( QAbstractItemModel * model );
private slots: private slots:
void zoomIn(); void zoomIn();

View file

@ -115,18 +115,16 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
m_dirLister->setShowingDotFiles(showHiddenFiles); m_dirLister->setShowingDotFiles(showHiddenFiles);
connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
this, SLOT(generatePreviews(const KFileItemList&))); this, SLOT(generatePreviews(const KFileItemList&)));
}
m_dolphinModel = new DolphinModel(this); void DolphinColumnWidget::setModel ( QAbstractItemModel * model )
m_dolphinModel->setDirLister(m_dirLister); {
m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); m_proxyModel = dynamic_cast<DolphinSortFilterProxyModel *>(model);
if(m_proxyModel)
m_proxyModel = new DolphinSortFilterProxyModel(this); m_dolphinModel = dynamic_cast<DolphinModel *>(m_proxyModel->sourceModel());
m_proxyModel->setSourceModel(m_dolphinModel);
setModel(m_proxyModel);
new KMimeTypeResolver(this, m_dolphinModel); new KMimeTypeResolver(this, m_dolphinModel);
m_dirLister->openUrl(m_url, KDirLister::NoFlags);
m_dirLister->openUrl(url, KDirLister::NoFlags); QListView::setModel(m_proxyModel);
} }
DolphinColumnWidget::~DolphinColumnWidget() DolphinColumnWidget::~DolphinColumnWidget()

View file

@ -89,6 +89,7 @@ public:
* which contain the given filter string will be shown. * which contain the given filter string will be shown.
*/ */
void setNameFilter(const QString& nameFilter); void setNameFilter(const QString& nameFilter);
virtual void setModel ( QAbstractItemModel * model );
protected: protected:
virtual QStyleOptionViewItem viewOptions() const; virtual QStyleOptionViewItem viewOptions() const;