1
/* This file is part of the KDE project
2
Copyright (C) 2010 Thomas Fjellstrom <thomas@fjellstrom.ca>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "katefiletreeproxymodel.h"
20
#include "katefiletreemodel.h"
21
#include "katefiletreedebug.h"
23
#include <kstringhandler.h>
24
#include <ktexteditor/document.h>
26
KateFileTreeProxyModel::KateFileTreeProxyModel(QObject *parent)
27
: QSortFilterProxyModel(parent)
29
kDebug(debugArea()) << "BEGIN!";
32
bool KateFileTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
34
//kDebug(debugArea()) << ": BEGIN!";
35
KateFileTreeModel *model = static_cast<KateFileTreeModel*>(sourceModel());
37
bool left_isdir = model->isDir(left);
38
bool right_isdir = model->isDir(right);
40
// in tree mode, there will be parent nodes, we want to put those first
41
if(left_isdir != right_isdir) {
42
return ((left_isdir - right_isdir)) > 0;
46
case Qt::DisplayRole: {
47
QString left_name = model->data(left).toString();
48
QString right_name = model->data(right).toString();
49
return KStringHandler::naturalCompare(left_name, right_name, Qt::CaseInsensitive) < 0;
52
case KateFileTreeModel::PathRole: {
53
QString left_name = model->data(left, KateFileTreeModel::PathRole).toString();
54
QString right_name = model->data(right, KateFileTreeModel::PathRole).toString();
55
return KStringHandler::naturalCompare(left_name, right_name, Qt::CaseInsensitive) < 0;
58
case KateFileTreeModel::OpeningOrderRole:
59
return (left.row() - right.row()) < 0;
62
kDebug(debugArea()) << "this shouldn't happen!";
66
QModelIndex KateFileTreeProxyModel::docIndex(KTextEditor::Document *doc)
68
kDebug(debugArea()) << "!";
69
return mapFromSource(static_cast<KateFileTreeModel*>(sourceModel())->docIndex(doc));
72
bool KateFileTreeProxyModel::isDir(const QModelIndex &index)
74
return static_cast<KateFileTreeModel*>(sourceModel())->isDir(mapToSource(index));
77
// kate: space-indent on; indent-width 2; replace-tabs on;