/* 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 #include #include "filestreewidget.h" #include "smmodelsingleton.h" #include "filestreemodel.h" FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent){ //the view mView = new FilesTreeView; mModel = static_cast(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); }