blob: c39805bc3883ab674b7b0fc574930770802b1d4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
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 <QVBoxLayout>
#include <QSortFilterProxyModel>
#include "archivebrowser.h"
#include "archivebrowsermodel.h"
#include "smtreeview.h"
#include "smglobals.h"
#include "delegates.h"
ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent){
//prep
mModel = static_cast<ArchiveBrowserModel*>(SmGlobals::instance()->model("BrowserModel"));
mProxy = new QSortFilterProxyModel;
mProxy->setSourceModel(mModel);
mTree = new SmTreeView;
mTree->setModel(mProxy);
mTree->setColumnHidden(ArchiveBrowserModel::GenericId, true);
mTree->setColumnHidden(ArchiveBrowserModel::NodeType, true);
mTree->setSortingEnabled(true);
mTree->setItemDelegateForColumn(ArchiveBrowserModel::TotalSize, new SizeDelegate(this));
mTree->setItemDelegateForColumn(ArchiveBrowserModel::FileType, new FileTypeDelegate(this));
mTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
//connect
connect(mTree->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(browserSelectionChanged(QItemSelection,QItemSelection)));
//make widget
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mTree);
setLayout(mainLayout);
}
void ArchiveBrowser::browserSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
Q_UNUSED(selected);
Q_UNUSED(deselected);
QModelIndexList sel = mTree->selectionModel()->selectedRows();
qint64 size = 0;
int selItems = 0;
foreach(QModelIndex idx, sel){
size += idx.data(ArchiveBrowserModel::TotalSizeRole).toDouble();
++selItems;
}
emit sizeChanged(size);
emit itemCountChanged(selItems);
}
|