/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #include "archivecontroller.h" #include "archivemodel.h" #include "archiveview.h" ArchiveController::ArchiveController(QObject *parent) : QObject(parent) {} void ArchiveController::setArchiveView(ArchiveTree *atree, ArchiveProxy *aproxy){ mArchiveTree = atree; mArchiveProxy = aproxy; mArchiveSelection = mArchiveTree->selectionModel(); } void ArchiveController::setArchiveFiles(ArchiveFiles *afiles, ArchiveFilesProxy *afilesproxy){ mArchiveFiles = afiles; mArchiveFilesProxy = afilesproxy; } void ArchiveController::setModels(ArchiveModel *amodel, ArchiveFilesModel *afilesmodel){ mArchiveModel = amodel; mArchiveFilesModel = afilesmodel; } void ArchiveController::init(){ connect(mArchiveSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeSelectionChanged(QItemSelection,QItemSelection))); } void ArchiveController::treeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){ Q_UNUSED(selected); Q_UNUSED(deselected); QModelIndexList sel = mapToSource(mArchiveProxy, mArchiveSelection->selectedRows()); if(sel.isEmpty()){ return; } QSet ids; foreach(QModelIndex idx, sel){ ids.unite(mArchiveModel->seriesPartIds(idx)); } mArchiveFilesModel->populate(ids); } QModelIndexList ArchiveController::mapToSource(const QSortFilterProxyModel *proxy, const QModelIndexList idxs) const{ QModelIndexList retval; foreach(QModelIndex idx, idxs){ retval << proxy->mapToSource(idx); } return retval; }