summaryrefslogtreecommitdiffstats
path: root/filestreewidget.cpp
blob: 8d9a4351f737eaced5adefe776094d0ef5732272 (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
/*
  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 <QHBoxLayout>

#include <QDebug>

#include "filestreewidget.h"
#include "smmodelsingleton.h"
#include "filestreemodel.h"

FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent){
	//the view
	mView = new FilesTreeView;
	mModel = static_cast<FilesTreeModel*>(SmModelSingleton::instance()->model("FilesModel"));
	mProxy = new FilesTreeSortModel(this);
	mProxy->setSourceModel(mModel);
	mView->setModel(mProxy);
	mView->setSortingEnabled(true);

	//layout
	QHBoxLayout *mainLayout = new QHBoxLayout;
	mainLayout->addWidget(mView);
	setLayout(mainLayout);
}

FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent){}

FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {}

bool FilesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{
	if(left.parent() == QModelIndex()){
		return false;
	}
	if(left.column() == FilesTreeModel::SizeDisplay){
		return left.data(FilesTreeModel::SizeRole).toLongLong() < right.data(FilesTreeModel::SizeRole).toLongLong();
	}
	if(left.column() == FilesTreeModel::DvdNoRole){
		return left.data(FilesTreeModel::DvdNoRole).toInt() < right.data(FilesTreeModel::DvdNoRole).toInt();
	}
	return QSortFilterProxyModel::lessThan(left, right);
}