summaryrefslogtreecommitdiffstats
path: root/archivecontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'archivecontroller.cpp')
-rw-r--r--archivecontroller.cpp54
1 files changed, 54 insertions, 0 deletions
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<int> 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;
+}