annotate libgui/src/find-files-model.cc @ 16997:90d50e56a06a

Add sortable table headers to find_files_dialog results * libgui/src/find-files-dialog.cc (find_files_dialog::find_files_dialog): enable sorting of rows in _file_list. * libgui/src/find-files-model.cc, libgui/src/find-files-model.h (global): New local class find_file_less_than. (find_files_model::find_files_model): Add/initialize _sortorder var. (find_files_model::addFile): Find pos to add data to sorted entries. (find_files_model::sort): New function.
author John Donoghue <john.donoghue@ieee.org>
date Wed, 17 Jul 2013 21:42:11 -0400
parents 3e8fd0c479b4
children 15e2ad6372f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
1 /*
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
2
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
3 Copyright (C) 2013 John Donoghue
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
4
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
5 This file is part of Octave.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
6
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
10 option) any later version.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
11
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
15 for more details.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
16
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
20
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
21 */
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
22
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
23 #include "find-files-model.h"
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
24 #include <QFileIconProvider>
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
25 #include <QtAlgorithms>
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
26
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
27 class find_file_less_than
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
28 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
29 public:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
30 find_file_less_than (int ord)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
31 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
32 _sortorder = ord;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
33 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
34 QVariant getValue (const QFileInfo &f) const
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
35 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
36 QVariant val;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
37 int col = (_sortorder > 0) ? _sortorder : -_sortorder;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
38
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
39 switch (col-1)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
40 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
41 case 0:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
42 val = QVariant (f.fileName());
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
43 break;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
44
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
45 case 1:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
46 val = QVariant (f.absolutePath());
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
47 break;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
48
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
49 default:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
50 break;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
51 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
52 return val;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
53 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
54 bool lessThan (const QVariant &left, const QVariant &right) const
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
55 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
56 return left.toString ().compare (right.toString (), Qt::CaseInsensitive) < 0;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
57 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
58 bool operator () (const QFileInfo &left, const QFileInfo &right) const
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
59 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
60 QVariant leftval = getValue(left);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
61 QVariant rightval = getValue(right);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
62
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
63 if (_sortorder > 0)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
64 return lessThan(leftval, rightval);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
65 else
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
66 return ! lessThan(leftval, rightval);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
67 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
68 private:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
69 int _sortorder;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
70 };
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
71
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
72
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
73 find_files_model::find_files_model (QObject *p)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
74 : QAbstractListModel(p)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
75 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
76 _columnNames.append (tr ("Filename"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
77 _columnNames.append (tr ("Directory"));
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
78 _sortorder = 0;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
79 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
80
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
81 find_files_model::~find_files_model ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
82 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
83 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
84
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
85 void
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
86 find_files_model::clear ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
87 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
88 beginResetModel();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
89
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
90 _files.clear();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
91
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
92 endResetModel ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
93 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
94
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
95 void
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
96 find_files_model::addFile (const QFileInfo &info)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
97 {
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
98 beginInsertRows (QModelIndex (), _files.size (), _files.size () );
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
99
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
100 QList<QFileInfo>::Iterator it;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
101 find_file_less_than less_than(_sortorder);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
102
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
103 for (it=_files.begin ();it!=_files.end ();it++)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
104 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
105 if (less_than (info, *it)) break;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
106 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
107
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
108 _files.insert (it, info);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
109
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
110 endInsertRows ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
111 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
112
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
113 int
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
114 find_files_model::rowCount (const QModelIndex & p) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
115 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
116 return _files.size();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
117 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
118
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
119 int
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
120 find_files_model::columnCount (const QModelIndex & p) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
121 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
122 return _columnNames.size ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
123 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
124
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
125 QVariant
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
126 find_files_model::data (const QModelIndex& idx, int role) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
127 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
128 QVariant retval;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
129
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
130 if (idx.isValid ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
131 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
132 if(role == Qt::DisplayRole)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
133 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
134 switch (idx.column ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
135 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
136 case 0:
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
137 retval = QVariant (_files[idx.row()].fileName());
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
138 break;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
139
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
140 case 1:
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
141 retval = QVariant (_files[idx.row()].absolutePath());
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
142 break;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
143
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
144 default:
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
145 break;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
146 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
147 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
148 else if(role == Qt:: DecorationRole)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
149 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
150 switch (idx.column())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
151 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
152 case 0:
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
153 retval = fileIcon(idx);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
154 default:
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
155 break;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
156 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
157 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
158 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
159
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
160 return retval;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
161 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
162
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
163 QVariant
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
164 find_files_model::headerData (int section, Qt::Orientation orientation, int role) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
165 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
166 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
167 return _columnNames[section];
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
168 else
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
169 return QVariant ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
170 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
171
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
172 void
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
173 find_files_model::sort (int column, Qt::SortOrder order)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
174 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
175 if(column >= 0)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
176 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
177 if (order == Qt::DescendingOrder)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
178 _sortorder = -(column+1);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
179 else
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
180 _sortorder = column+1;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
181 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
182 else
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
183 _sortorder = 0;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
184
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
185 if (_sortorder != 0)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
186 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
187 beginResetModel ();
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
188 qSort (_files.begin (), _files.end (), find_file_less_than (_sortorder));
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
189 endResetModel ();
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
190 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
191 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
192
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
193 QFileInfo
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
194 find_files_model::fileInfo (const QModelIndex & p) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
195 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
196 if(p.isValid ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
197 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
198 return _files[p.row()];
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
199 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
200 return QFileInfo ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
201 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
202
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
203 QIcon
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
204 find_files_model::fileIcon (const QModelIndex &p) const
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
205 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
206 QFileIconProvider icon_provider;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
207 if(p.isValid ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
208 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
209 return icon_provider.icon (_files[p.row()]);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
210 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
211 return QIcon ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
212 }