Convert Q_FOREACH loops to C++11 for loops.

Q_FOREACH will de deprecated soon.
This commit is contained in:
Felix Geyer 2016-09-02 19:51:51 +02:00 committed by Jonathan White
parent ad834f0f58
commit fff9e7ac46
31 changed files with 202 additions and 143 deletions

View file

@ -64,7 +64,8 @@ bool CsvExporter::writeGroup(QIODevice* device, const Group* group, QString grou
}
groupPath.append(group->name());
Q_FOREACH (const Entry* entry, group->entries()) {
const QList<Entry*> entryList = group->entries();
for (const Entry* entry : entryList) {
QString line;
addColumn(line, groupPath);
@ -82,7 +83,8 @@ bool CsvExporter::writeGroup(QIODevice* device, const Group* group, QString grou
}
}
Q_FOREACH (const Group* child, group->children()) {
const QList<Group*> children = group->children();
for (const Group* child : children) {
if (!writeGroup(device, child, groupPath)) {
return false;
}

View file

@ -195,7 +195,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
return nullptr;
}
Q_FOREACH (Entry* entry, entries) {
for (Entry* entry : asConst(entries)) {
if (isMetaStream(entry)) {
parseMetaStream(entry);
@ -215,7 +215,8 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
db->rootGroup()->setName(tr("Root"));
Q_FOREACH (Group* group, db->rootGroup()->children()) {
const QList<Group*> children = db->rootGroup()->children();
for (Group* group : children) {
if (group->name() == "Backup") {
group->setSearchingEnabled(Group::Disable);
group->setAutoTypeEnabled(Group::Disable);
@ -225,11 +226,12 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
Q_ASSERT(m_tmpParent->children().isEmpty());
Q_ASSERT(m_tmpParent->entries().isEmpty());
Q_FOREACH (Group* group, groups) {
for (Group* group : asConst(groups)) {
group->setUpdateTimeinfo(true);
}
Q_FOREACH (Entry* entry, m_db->rootGroup()->entriesRecursive()) {
const QList<Entry*> dbEntries = m_db->rootGroup()->entriesRecursive();
for (Entry* entry : dbEntries) {
entry->setUpdateTimeinfo(true);
}
@ -298,15 +300,14 @@ QString KeePass1Reader::errorString()
SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const QByteArray& keyfileData,
qint64 contentPos)
{
QList<PasswordEncoding> encodings;
encodings << Windows1252 << Latin1 << UTF8;
const QList<PasswordEncoding> encodings = { Windows1252, Latin1, UTF8 };
QScopedPointer<SymmetricCipherStream> cipherStream;
QByteArray passwordData;
QTextCodec* codec = QTextCodec::codecForName("Windows-1252");
QByteArray passwordDataCorrect = codec->fromUnicode(password);
Q_FOREACH (PasswordEncoding encoding, encodings) {
for (PasswordEncoding encoding : encodings) {
if (encoding == Windows1252) {
passwordData = passwordDataCorrect;
}
@ -727,7 +728,8 @@ void KeePass1Reader::parseNotes(const QString& rawNotes, Entry* entry)
QStringList notes;
bool lastLineAutoType = false;
Q_FOREACH (QString line, rawNotes.split("\n")) {
const QStringList rawNotesLines = rawNotes.split("\n");
for (QString line : rawNotesLines) {
line.remove("\r");
if (sequenceRegexp.exactMatch(line)) {
@ -769,8 +771,9 @@ void KeePass1Reader::parseNotes(const QString& rawNotes, Entry* entry)
i.next();
QString sequence = sequences.value(i.key());
const QStringList windowList = i.value();
Q_FOREACH (const QString& window, i.value()) {
for (const QString& window : windowList) {
AutoTypeAssociations::Association assoc;
assoc.window = window;
assoc.sequence = sequence;

View file

@ -86,17 +86,17 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra
}
}
QSet<QString> poolKeys = m_binaryPool.keys().toSet();
QSet<QString> entryKeys = m_binaryMap.keys().toSet();
QSet<QString> unmappedKeys = entryKeys - poolKeys;
QSet<QString> unusedKeys = poolKeys - entryKeys;
const QSet<QString> poolKeys = m_binaryPool.keys().toSet();
const QSet<QString> entryKeys = m_binaryMap.keys().toSet();
const QSet<QString> unmappedKeys = entryKeys - poolKeys;
const QSet<QString> unusedKeys = poolKeys - entryKeys;
if (!unmappedKeys.isEmpty()) {
raiseError("Unmapped keys left.");
}
if (!m_xml.error()) {
Q_FOREACH (const QString& key, unusedKeys) {
for (const QString& key : unusedKeys) {
qWarning("KeePass2XmlReader::readDatabase: found unused key \"%s\"", qPrintable(key));
}
}
@ -118,7 +118,8 @@ void KeePass2XmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Ra
for (iEntry = m_entries.constBegin(); iEntry != m_entries.constEnd(); ++iEntry) {
iEntry.value()->setUpdateTimeinfo(true);
Q_FOREACH (Entry* histEntry, iEntry.value()->historyItems()) {
const QList<Entry*> historyItems = iEntry.value()->historyItems();
for (Entry* histEntry : historyItems) {
histEntry->setUpdateTimeinfo(true);
}
}
@ -614,11 +615,11 @@ Group* KeePass2XmlReader::parseGroup()
raiseError("No group uuid found");
}
Q_FOREACH (Group* child, children) {
for (Group* child : asConst(children)) {
child->setParent(group);
}
Q_FOREACH (Entry* entry, entries) {
for (Entry* entry : asConst(entries)) {
entry->setGroup(group);
}
@ -777,7 +778,7 @@ Entry* KeePass2XmlReader::parseEntry(bool history)
raiseError("No entry uuid found");
}
Q_FOREACH (Entry* historyItem, historyItems) {
for (Entry* historyItem : asConst(historyItems)) {
if (historyItem->uuid() != entry->uuid()) {
if (m_strictMode) {
raiseError("History element with different uuid");
@ -788,7 +789,7 @@ Entry* KeePass2XmlReader::parseEntry(bool history)
entry->addHistoryItem(historyItem);
}
Q_FOREACH (const StringPair& ref, binaryRefs) {
for (const StringPair& ref : asConst(binaryRefs)) {
m_binaryMap.insertMulti(ref.first, qMakePair(entry, ref.second));
}

View file

@ -82,11 +82,12 @@ QString KeePass2XmlWriter::errorString()
void KeePass2XmlWriter::generateIdMap()
{
QList<Entry*> allEntries = m_db->rootGroup()->entriesRecursive(true);
const QList<Entry*> allEntries = m_db->rootGroup()->entriesRecursive(true);
int nextId = 0;
Q_FOREACH (Entry* entry, allEntries) {
Q_FOREACH (const QString& key, entry->attachments()->keys()) {
for (Entry* entry : allEntries) {
const QList<QString> attachmentKeys = entry->attachments()->keys();
for (const QString& key : attachmentKeys) {
QByteArray data = entry->attachments()->value(key);
if (!m_idMap.contains(data)) {
m_idMap.insert(data, nextId++);
@ -149,7 +150,8 @@ void KeePass2XmlWriter::writeCustomIcons()
{
m_xml.writeStartElement("CustomIcons");
Q_FOREACH (const Uuid& uuid, m_meta->customIconsOrder()) {
const QList<Uuid> customIconsOrder = m_meta->customIconsOrder();
for (const Uuid& uuid : customIconsOrder) {
writeIcon(uuid, m_meta->customIcon(uuid));
}
@ -220,7 +222,8 @@ void KeePass2XmlWriter::writeCustomData()
m_xml.writeStartElement("CustomData");
QHash<QString, QString> customFields = m_meta->customFields();
Q_FOREACH (const QString& key, customFields.keys()) {
const QList<QString> keyList = customFields.keys();
for (const QString& key : keyList) {
writeCustomDataItem(key, customFields.value(key));
}
@ -273,11 +276,13 @@ void KeePass2XmlWriter::writeGroup(const Group* group)
writeUuid("LastTopVisibleEntry", group->lastTopVisibleEntry());
Q_FOREACH (const Entry* entry, group->entries()) {
const QList<Entry*> entryList = group->entries();
for (const Entry* entry : entryList) {
writeEntry(entry);
}
Q_FOREACH (const Group* child, group->children()) {
const QList<Group*> children = group->children();
for (const Group* child : children) {
writeGroup(child);
}
@ -303,7 +308,8 @@ void KeePass2XmlWriter::writeDeletedObjects()
{
m_xml.writeStartElement("DeletedObjects");
Q_FOREACH (const DeletedObject& delObj, m_db->deletedObjects()) {
const QList<DeletedObject> delObjList = m_db->deletedObjects();
for (const DeletedObject& delObj : delObjList) {
writeDeletedObject(delObj);
}
@ -337,7 +343,8 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
writeString("Tags", entry->tags());
writeTimes(entry->timeInfo());
Q_FOREACH (const QString& key, entry->attributes()->keys()) {
const QList<QString> attributesKeyList = entry->attributes()->keys();
for (const QString& key : attributesKeyList) {
m_xml.writeStartElement("String");
bool protect = ( ((key == "Title") && m_meta->protectTitle()) ||
@ -379,7 +386,8 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
m_xml.writeEndElement();
}
Q_FOREACH (const QString& key, entry->attachments()->keys()) {
const QList<QString> attachmentsKeyList = entry->attachments()->keys();
for (const QString& key : attachmentsKeyList) {
m_xml.writeStartElement("Binary");
writeString("Key", key);
@ -408,7 +416,8 @@ void KeePass2XmlWriter::writeAutoType(const Entry* entry)
writeNumber("DataTransferObfuscation", entry->autoTypeObfuscation());
writeString("DefaultSequence", entry->defaultAutoTypeSequence());
Q_FOREACH (const AutoTypeAssociations::Association& assoc, entry->autoTypeAssociations()->getAll()) {
const QList<AutoTypeAssociations::Association> autoTypeAssociations = entry->autoTypeAssociations()->getAll();
for (const AutoTypeAssociations::Association& assoc : autoTypeAssociations) {
writeAutoTypeAssoc(assoc);
}
@ -430,7 +439,7 @@ void KeePass2XmlWriter::writeEntryHistory(const Entry* entry)
m_xml.writeStartElement("History");
const QList<Entry*>& historyItems = entry->historyItems();
Q_FOREACH (const Entry* item, historyItems) {
for (const Entry* item : historyItems) {
writeEntry(item);
}