~ubuntu-branches/ubuntu/saucy/kate/saucy

« back to all changes in this revision

Viewing changes to kate/plugins/filetree/katefiletreeproxymodel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Rohan Garg, Jonathan Riddell
  • Date: 2013-06-21 00:48:29 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20130621004829-y2ui02eg0j47h94y
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release
  - Update and sort install files
  - Drop kubuntu_pate_find_python.diff, kubuntu_kate_initial_preference.patch,
    kubuntu_find_python.diff from debian/patches , not required

[ Jonathan Riddell ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2010 Thomas Fjellstrom <thomas@fjellstrom.ca>
3
 
 
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.
7
 
 
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.
12
 
 
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.
17
 
*/
18
 
 
19
 
#include "katefiletreeproxymodel.h"
20
 
#include "katefiletreemodel.h"
21
 
#include "katefiletreedebug.h"
22
 
 
23
 
#include <kstringhandler.h>
24
 
#include <ktexteditor/document.h>
25
 
 
26
 
KateFileTreeProxyModel::KateFileTreeProxyModel(QObject *parent)
27
 
  : QSortFilterProxyModel(parent)
28
 
{
29
 
  kDebug(debugArea()) << "BEGIN!";
30
 
}
31
 
 
32
 
bool KateFileTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
33
 
{
34
 
  //kDebug(debugArea()) << ": BEGIN!";
35
 
  KateFileTreeModel *model = static_cast<KateFileTreeModel*>(sourceModel());
36
 
  
37
 
  bool left_isdir = model->isDir(left);
38
 
  bool right_isdir = model->isDir(right);
39
 
 
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;
43
 
  }
44
 
  
45
 
  switch(sortRole()) {
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;
50
 
    }
51
 
 
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;
56
 
    }
57
 
 
58
 
    case KateFileTreeModel::OpeningOrderRole:
59
 
      return (left.row() - right.row()) < 0;
60
 
  }
61
 
 
62
 
  kDebug(debugArea()) << "this shouldn't happen!";
63
 
  return false;
64
 
}
65
 
 
66
 
QModelIndex KateFileTreeProxyModel::docIndex(KTextEditor::Document *doc)
67
 
{
68
 
  kDebug(debugArea()) << "!";
69
 
  return mapFromSource(static_cast<KateFileTreeModel*>(sourceModel())->docIndex(doc));
70
 
}
71
 
 
72
 
bool KateFileTreeProxyModel::isDir(const QModelIndex &index)
73
 
{
74
 
  return static_cast<KateFileTreeModel*>(sourceModel())->isDir(mapToSource(index));
75
 
}
76
 
 
77
 
// kate: space-indent on; indent-width 2; replace-tabs on;