comparison base/RecentFiles.cpp @ 928:6a94bb528e9d warnfix_no_size_t

Remove size_t's, fix compiler warnings
author Chris Cannam
date Tue, 17 Jun 2014 13:52:07 +0100
parents 3b8008d09541
children 452b48b29c2d
comparison
equal deleted inserted replaced
917:49618f39ff09 928:6a94bb528e9d
19 19
20 #include <QFileInfo> 20 #include <QFileInfo>
21 #include <QSettings> 21 #include <QSettings>
22 #include <QRegExp> 22 #include <QRegExp>
23 23
24 RecentFiles::RecentFiles(QString settingsGroup, size_t maxCount) : 24 RecentFiles::RecentFiles(QString settingsGroup, int maxCount) :
25 m_settingsGroup(settingsGroup), 25 m_settingsGroup(settingsGroup),
26 m_maxCount(maxCount) 26 m_maxCount(maxCount)
27 { 27 {
28 read(); 28 read();
29 } 29 }
38 { 38 {
39 m_names.clear(); 39 m_names.clear();
40 QSettings settings; 40 QSettings settings;
41 settings.beginGroup(m_settingsGroup); 41 settings.beginGroup(m_settingsGroup);
42 42
43 for (size_t i = 0; i < 100; ++i) { 43 for (int i = 0; i < 100; ++i) {
44 QString key = QString("recent-%1").arg(i); 44 QString key = QString("recent-%1").arg(i);
45 QString name = settings.value(key, "").toString(); 45 QString name = settings.value(key, "").toString();
46 if (name == "") break; 46 if (name == "") break;
47 if (i < m_maxCount) m_names.push_back(name); 47 if (i < m_maxCount) m_names.push_back(name);
48 else settings.setValue(key, ""); 48 else settings.setValue(key, "");
55 RecentFiles::write() 55 RecentFiles::write()
56 { 56 {
57 QSettings settings; 57 QSettings settings;
58 settings.beginGroup(m_settingsGroup); 58 settings.beginGroup(m_settingsGroup);
59 59
60 for (size_t i = 0; i < m_maxCount; ++i) { 60 for (int i = 0; i < m_maxCount; ++i) {
61 QString key = QString("recent-%1").arg(i); 61 QString key = QString("recent-%1").arg(i);
62 QString name = ""; 62 QString name = "";
63 if (i < m_names.size()) name = m_names[i]; 63 if (i < (int)m_names.size()) name = m_names[i];
64 settings.setValue(key, name); 64 settings.setValue(key, name);
65 } 65 }
66 66
67 settings.endGroup(); 67 settings.endGroup();
68 } 68 }
69 69
70 void 70 void
71 RecentFiles::truncateAndWrite() 71 RecentFiles::truncateAndWrite()
72 { 72 {
73 while (m_names.size() > m_maxCount) { 73 while (int(m_names.size()) > m_maxCount) {
74 m_names.pop_back(); 74 m_names.pop_back();
75 } 75 }
76 write(); 76 write();
77 } 77 }
78 78
79 std::vector<QString> 79 std::vector<QString>
80 RecentFiles::getRecent() const 80 RecentFiles::getRecent() const
81 { 81 {
82 std::vector<QString> names; 82 std::vector<QString> names;
83 for (size_t i = 0; i < m_maxCount; ++i) { 83 for (int i = 0; i < m_maxCount; ++i) {
84 if (i < m_names.size()) { 84 if (i < (int)m_names.size()) {
85 names.push_back(m_names[i]); 85 names.push_back(m_names[i]);
86 } 86 }
87 } 87 }
88 return names; 88 return names;
89 } 89 }
90 90
91 void 91 void
92 RecentFiles::add(QString name) 92 RecentFiles::add(QString name)
93 { 93 {
94 bool have = false; 94 bool have = false;
95 for (size_t i = 0; i < m_names.size(); ++i) { 95 for (int i = 0; i < int(m_names.size()); ++i) {
96 if (m_names[i] == name) { 96 if (m_names[i] == name) {
97 have = true; 97 have = true;
98 break; 98 break;
99 } 99 }
100 } 100 }
102 if (!have) { 102 if (!have) {
103 m_names.push_front(name); 103 m_names.push_front(name);
104 } else { 104 } else {
105 std::deque<QString> newnames; 105 std::deque<QString> newnames;
106 newnames.push_back(name); 106 newnames.push_back(name);
107 for (size_t i = 0; i < m_names.size(); ++i) { 107 for (int i = 0; i < int(m_names.size()); ++i) {
108 if (m_names[i] == name) continue; 108 if (m_names[i] == name) continue;
109 newnames.push_back(m_names[i]); 109 newnames.push_back(m_names[i]);
110 } 110 }
111 m_names = newnames; 111 m_names = newnames;
112 } 112 }