annotate libgui/src/find-files-model.cc @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents 4197fc428c7d
children
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18712
diff changeset
3 Copyright (C) 2013-2015 John Donoghue
16519
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
17921
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
23 #ifdef HAVE_CONFIG_H
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
24 #include <config.h>
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
25 #endif
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
26
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
27 #include <QFileIconProvider>
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
28 #include <QtAlgorithms>
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
29
17921
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
30 #include "find-files-model.h"
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
31
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
32 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
33 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
34 public:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
35 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
36 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
37 _sortorder = ord;
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 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
40 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
41 QVariant val;
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
42 int col = (_sortorder > 0) ? _sortorder : -_sortorder;
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
43
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
44 switch (col-1)
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
45 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
46 case 0:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
47 val = QVariant (f.fileName ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
48 break;
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
49
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
50 case 1:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
51 val = QVariant (f.absolutePath ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
52 break;
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
53
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
54 default:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
55 break;
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
56 }
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
57 return val;
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
58 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
59 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
60 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
61 return
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
62 left.toString ().compare (right.toString (), Qt::CaseInsensitive) < 0;
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
63 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
64 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
65 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
66 QVariant leftval = getValue (left);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
67 QVariant rightval = getValue (right);
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
68
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
69 if (_sortorder > 0)
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
70 return lessThan (leftval, rightval);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
71 else
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
72 return ! lessThan (leftval, rightval);
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
73 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
74 private:
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
75 int _sortorder;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
76 };
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
77
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
78
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
79 find_files_model::find_files_model (QObject *p)
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
80 : QAbstractListModel (p)
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
81 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
82 _columnNames.append (tr ("Filename"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
83 _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
84 _sortorder = 0;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
85 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
86
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
87 find_files_model::~find_files_model ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
88 {
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
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
91 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
92 find_files_model::clear ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
93 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
94 beginResetModel ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
95
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
96 _files.clear ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
97
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
98 endResetModel ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
99 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
100
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
101 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
102 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
103 {
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17921
diff changeset
104 beginInsertRows (QModelIndex (), _files.size (), _files.size ());
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
105
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
106 QList<QFileInfo>::Iterator it;
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
107 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
108
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
109 for (it=_files.begin (); it!=_files.end (); it++)
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
110 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
111 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
112 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
113
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
114 _files.insert (it, info);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
115
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
116 endInsertRows ();
16519
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
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
119 int
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 16997
diff changeset
120 find_files_model::rowCount (const QModelIndex &) const
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
121 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
122 return _files.size ();
16519
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
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
125 int
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 16997
diff changeset
126 find_files_model::columnCount (const QModelIndex &) const
16519
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 return _columnNames.size ();
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
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
131 QVariant
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
132 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
133 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
134 QVariant retval;
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 if (idx.isValid ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
137 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
138 if (role == Qt::DisplayRole)
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
139 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
140 switch (idx.column ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
141 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
142 case 0:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
143 retval = QVariant (_files[idx.row ()].fileName ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
144 break;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
145
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
146 case 1:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
147 retval = QVariant (_files[idx.row ()].absolutePath ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
148 break;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
149
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
150 default:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
151 break;
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
152 }
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
153 }
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
154 else if (role == Qt:: DecorationRole)
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
155 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
156 switch (idx.column ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
157 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
158 case 0:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
159 retval = fileIcon (idx);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
160 default:
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
161 break;
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
162 }
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
163 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
164 }
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 return retval;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
167 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
168
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
169 QVariant
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
170 find_files_model::headerData (int section, Qt::Orientation orientation,
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
171 int role) const
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
172 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
173 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
174 return _columnNames[section];
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
175 else
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
176 return QVariant ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
177 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
178
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
179 void
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
180 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
181 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
182 if (column >= 0)
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
183 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
184 if (order == Qt::DescendingOrder)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
185 _sortorder = -(column+1);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
186 else
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
187 _sortorder = column+1;
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
188 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
189 else
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
190 _sortorder = 0;
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 if (_sortorder != 0)
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
193 {
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
194 beginResetModel ();
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
195 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
196 endResetModel ();
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
197 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
198 }
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
199
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
200 QFileInfo
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
201 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
202 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
203 if (p.isValid ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
204 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
205 return _files[p.row ()];
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
206 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
207 return QFileInfo ();
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
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
210 QIcon
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
211 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
212 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
213 QFileIconProvider icon_provider;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
214 if (p.isValid ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
215 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
216 return icon_provider.icon (_files[p.row ()]);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17377
diff changeset
217 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
218 return QIcon ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
219 }