From bd6a6a7c42dabe2d0d86e309a6dc6b04de7c0a10 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 6 Jul 2013 08:06:52 +0200 Subject: Basic ArchiveFilesModel and ArchiveController Implement a new file model for the archive. It's quite basic at this stage, but finally something happens when clicking the archive tree. Also, implement the interaction (signal -> slot) between the views and models in an explicit controller to prevent the mess from the old archive. --- archivecontroller.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 archivecontroller.cpp (limited to 'archivecontroller.cpp') diff --git a/archivecontroller.cpp b/archivecontroller.cpp new file mode 100644 index 0000000..0c67ef7 --- /dev/null +++ b/archivecontroller.cpp @@ -0,0 +1,54 @@ +/* + 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; +} -- cgit v1.2.3-70-g09d2