diff options
author | Yuriy Astrov <yuriastrov@gmail.com> | 2016-10-15 19:47:36 +0300 |
---|---|---|
committer | Yuriy Astrov <yuriastrov@gmail.com> | 2016-10-15 19:47:36 +0300 |
commit | 11f10765c240a30996c50a9cf94194cd088fa671 (patch) | |
tree | 9fb447bc5166ea84d6224f4a98d6f05283c96b76 /source | |
parent | 52df387dc45a69966ecd23fa1aa6e736e7a62c67 (diff) |
Qt foreach have been replaced by C++11 for loop. Preincrement and Predecrement have been used.
Diffstat (limited to 'source')
-rw-r--r-- | source/fb2app.cpp | 2 | ||||
-rw-r--r-- | source/fb2code.cpp | 10 | ||||
-rw-r--r-- | source/fb2dock.cpp | 2 | ||||
-rw-r--r-- | source/fb2head.cpp | 13 | ||||
-rw-r--r-- | source/fb2html.cpp | 14 | ||||
-rw-r--r-- | source/fb2imgs.cpp | 2 | ||||
-rw-r--r-- | source/fb2logs.cpp | 2 | ||||
-rw-r--r-- | source/fb2main.cpp | 2 | ||||
-rw-r--r-- | source/fb2mode.cpp | 4 | ||||
-rw-r--r-- | source/fb2read.cpp | 2 | ||||
-rw-r--r-- | source/fb2read.hpp | 2 | ||||
-rw-r--r-- | source/fb2save.cpp | 19 | ||||
-rw-r--r-- | source/fb2text.cpp | 6 | ||||
-rw-r--r-- | source/fb2tree.cpp | 30 | ||||
-rw-r--r-- | source/fb2xml.cpp | 2 | ||||
-rw-r--r-- | source/js/export.js | 2 |
16 files changed, 58 insertions, 56 deletions
diff --git a/source/fb2app.cpp b/source/fb2app.cpp index 0756f6d..df8c65b 100644 --- a/source/fb2app.cpp +++ b/source/fb2app.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) app.installTranslator(&translator); int count = app.arguments().count(); - for (int i = 1; i < count; i++) { + for (int i = 1; i < count; ++i) { QString arg = app.arguments().at(i); (new FbMainWindow(arg))->show(); } diff --git a/source/fb2code.cpp b/source/fb2code.cpp index 16ca16a..8d564df 100644 --- a/source/fb2code.cpp +++ b/source/fb2code.cpp @@ -235,13 +235,13 @@ void FbHighlighter::highlightBlock(const QString& text) return; } } - - for (; i < text.length(); i++) + const int len = text.length(); + for (; i < len; ++i) { switch (text.at(i).toAscii()) { case '<': - brackets++; + ++brackets; if (brackets == 1) { setFormat(i, 1, fmtSyntaxChar); @@ -255,7 +255,7 @@ void FbHighlighter::highlightBlock(const QString& text) break; case '>': - brackets--; + --brackets; if (brackets == 0) { setFormat(i, 1, fmtSyntaxChar); @@ -345,7 +345,7 @@ void FbHighlighter::highlightBlock(const QString& text) setFormat(iLength - 3, 3, fmtSyntaxChar); i += iLength - 2; // skip comment state = NoState; - brackets--; + --brackets; } else { diff --git a/source/fb2dock.cpp b/source/fb2dock.cpp index 47f96d7..44ffb9b 100644 --- a/source/fb2dock.cpp +++ b/source/fb2dock.cpp @@ -218,7 +218,7 @@ void FbMainDock::addMenu(QMenu *menu) void FbMainDock::enableMenu(bool value)
{
- foreach (QMenu *menu, m_menus) {
+ for (QMenu *menu: m_menus) {
menu->setEnabled(value);
}
}
diff --git a/source/fb2head.cpp b/source/fb2head.cpp index fc6223b..825738c 100644 --- a/source/fb2head.cpp +++ b/source/fb2head.cpp @@ -122,8 +122,9 @@ QString FbScheme::type() const QString result = attribute("type"); if (!result.isEmpty()) return result; FbScheme child = firstChildElement("xs:complexType").firstChildElement(); + QString tag; while (!child.isNull()) { - QString tag = child.tagName(); + tag = child.tagName(); if (tag == "xs:complexContent" || tag == "xs:simpleContent") { return child.firstChildElement("xs:extension").attribute("base"); } @@ -231,7 +232,7 @@ FbHeadItem::FbHeadItem(QWebElement &element, FbHeadItem *parent) FbHeadItem::~FbHeadItem() { - foreach (FbHeadItem * item, m_list) { + for (FbHeadItem * item: m_list) { delete item; } } @@ -319,7 +320,7 @@ QString FbHeadItem::value() const } break; case Cover: { QString text; - foreach (FbHeadItem * item, m_list) { + for (FbHeadItem * item: m_list) { if (item->m_name == "image") { if (!text.isEmpty()) text += ", "; text += item->value(); @@ -381,7 +382,7 @@ bool FbHeadItem::canEditExtra() const QString FbHeadItem::sub(const QString &key) const { - foreach (FbHeadItem * item, m_list) { + for (FbHeadItem * item: m_list) { if (item->m_name == key) return item->value(); } return QString(); @@ -424,13 +425,13 @@ void FbHeadModel::expand(QTreeView *view) { QModelIndex parent = QModelIndex(); int count = rowCount(parent); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { QModelIndex child = index(i, 0, parent); FbHeadItem *node = item(child); if (!node) continue; view->expand(child); int count = rowCount(child); - for (int j = 0; j < count; j++) { + for (int j = 0; j < count; ++j) { QModelIndex ch = index(j, 0, child); FbHeadItem *node = item(ch); if (node) view->expand(ch); diff --git a/source/fb2html.cpp b/source/fb2html.cpp index 128452e..daee268 100644 --- a/source/fb2html.cpp +++ b/source/fb2html.cpp @@ -70,7 +70,7 @@ FbTextElement::Sublist::Sublist(const TypeList &list, const QString &name) { while (m_pos != list.end()) { if (m_pos->name() == name) break; - m_pos++; + ++m_pos; } } @@ -88,7 +88,7 @@ bool FbTextElement::Sublist::operator <(const FbTextElement &element) const { if (element.isNull()) return true; const QString name = element.tagName(); - for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) { + for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); ++it) { if (it->name() == name) return m_pos < it; } return false; @@ -142,7 +142,7 @@ int FbTextElement::childIndex() const FbElementList::const_iterator it; for (it = list.constBegin(); it != list.constEnd(); ++it) { if (*it == *this) return result; - result++; + ++result; } return -1; } @@ -161,7 +161,7 @@ const FbTextElement::TypeList * FbTextElement::subtypes() const bool FbTextElement::hasSubtype(const QString &style) const { if (const TypeList * list = subtypes()) { - for (TypeList::const_iterator item = list->begin(); item != list->end(); item++) { + for (TypeList::const_iterator item = list->begin(); item != list->end(); ++item) { if (item->name() == style) return true; } } @@ -170,7 +170,7 @@ bool FbTextElement::hasSubtype(const QString &style) const FbTextElement::TypeList::const_iterator FbTextElement::subtype(const TypeList &list, const QString &style) { - for (TypeList::const_iterator item = list.begin(); item != list.end(); item++) { + for (TypeList::const_iterator item = list.begin(); item != list.end(); ++item) { if (item->name() == style) return item; } return list.end(); @@ -253,7 +253,7 @@ int FbTextElement::index() const FbTextElement prior = *this; while (!prior.isNull()) { prior = prior.previousSibling(); - result++; + ++result; } return result; } @@ -263,7 +263,7 @@ FbTextElement FbTextElement::child(int index) const FbTextElement result = firstChild(); while (index > 0) { result = result.nextSibling(); - index--; + --index; } return index ? FbTextElement() : result; } diff --git a/source/fb2imgs.cpp b/source/fb2imgs.cpp index dae7d51..c70d24f 100644 --- a/source/fb2imgs.cpp +++ b/source/fb2imgs.cpp @@ -103,7 +103,7 @@ QString FbStore::newName(const QString &path) if (!exists(name)) return name; QString base = info.baseName(); QString suff = info.suffix(); - for (int i = 1; ; i++) { + for (int i = 1; ; ++i) { QString name = QString("%1(%2).%3").arg(base).arg(i).arg(suff); if (exists(name)) continue; return name; diff --git a/source/fb2logs.cpp b/source/fb2logs.cpp index d42b11f..c185022 100644 --- a/source/fb2logs.cpp +++ b/source/fb2logs.cpp @@ -24,7 +24,7 @@ QVariant FbLogModel::FbLogItem::icon() const FbLogModel::FbLogModel(QObject *parent)
: QAbstractListModel(parent)
{
- foreach (FbLogItem *item, m_list) delete item;
+ for (FbLogItem *item: m_list) delete item;
}
QVariant FbLogModel::data(const QModelIndex &index, int role) const
diff --git a/source/fb2main.cpp b/source/fb2main.cpp index 504ccd8..ff62e48 100644 --- a/source/fb2main.cpp +++ b/source/fb2main.cpp @@ -600,7 +600,7 @@ FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName) { QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath(); - foreach (QWidget *widget, qApp->topLevelWidgets()) { + for (QWidget *widget: qApp->topLevelWidgets()) { FbMainWindow *mainWin = qobject_cast<FbMainWindow *>(widget); if (mainWin && mainWin->curFile == canonicalFilePath) return mainWin; diff --git a/source/fb2mode.cpp b/source/fb2mode.cpp index c40fe23..c07b759 100644 --- a/source/fb2mode.cpp +++ b/source/fb2mode.cpp @@ -6,14 +6,14 @@ void FbActionMap::connect()
{
- foreach (QAction *action, *this) {
+ for (QAction *action: *this) {
action->setEnabled(true);
}
}
void FbActionMap::disconnect()
{
- foreach (QAction *action, *this) {
+ for (QAction *action: *this) {
if (action->isCheckable()) action->setChecked(false);
action->setEnabled(false);
action->disconnect();
diff --git a/source/fb2read.cpp b/source/fb2read.cpp index cd44969..6394547 100644 --- a/source/fb2read.cpp +++ b/source/fb2read.cpp @@ -283,7 +283,7 @@ void FbReadHandler::TextHandler::Init(const QString &name, const QXmlAttributes Keyword key = toKeyword(name); writer().writeStartElement(m_tag); int count = atts.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { QString name = atts.qName(i); switch (key) { case Anchor: { if (atts.localName(i) == "href") name = "href"; break; } diff --git a/source/fb2read.hpp b/source/fb2read.hpp index a73f8cf..c885ca6 100644 --- a/source/fb2read.hpp +++ b/source/fb2read.hpp @@ -16,7 +16,7 @@ class FbReadThread : public QThread public: static void execute(QObject *parent, QXmlInputSource *source, QIODevice *device); - ~FbReadThread(); + virtual ~FbReadThread(); signals: void binary(const QString &name, const QByteArray &data); diff --git a/source/fb2save.cpp b/source/fb2save.cpp index f29191e..d0e2c95 100644 --- a/source/fb2save.cpp +++ b/source/fb2save.cpp @@ -45,7 +45,7 @@ FbSaveDialog::FbSaveDialog(QWidget *parent, const QString &caption, const QStrin void FbSaveDialog::init() { QMap<QString, QString> codecMap; - foreach (int mib, QTextCodec::availableMibs()) { + for (const int &mib: QTextCodec::availableMibs()) { QTextCodec *codec = QTextCodec::codecForMib(mib); QString sortKey = codec->name().toUpper(); @@ -74,7 +74,7 @@ void FbSaveDialog::init() setNameFilters(filters); combo = new QComboBox(this); - foreach (QString codec, codecMap) { + for (const QString &codec: codecMap) { combo->addItem(codec); } combo->setCurrentIndex(0); @@ -89,7 +89,7 @@ void FbSaveDialog::init() QString FbSaveDialog::fileName() const { - foreach (QString filename, selectedFiles()) { + for (const QString &filename: selectedFiles()) { return filename; } return QString(); @@ -200,7 +200,7 @@ void FbSaveWriter::writeStartElement(const QString &name, int level) #ifndef XMLAutoFormatting Q_UNUSED(level) if (level) writeLineEnd(); - for (int i = 1; i < level; i++) writeCharacters(" "); + for (int i = 1; i < level; ++i) writeCharacters(" "); #endif QXmlStreamWriter::writeStartElement(name); } @@ -210,7 +210,7 @@ void FbSaveWriter::writeEndElement(int level) #ifndef XMLAutoFormatting Q_UNUSED(level) if (level) writeLineEnd(); - for (int i = 1; i < level; i++) writeCharacters(" "); + for (int i = 1; i < level; ++i) writeCharacters(" "); #endif QXmlStreamWriter::writeEndElement(); } @@ -275,8 +275,9 @@ void FbSaveWriter::writeStyle() writeCharacters(postfix); QStringList list = m_style.split("}", QString::SkipEmptyParts); - foreach (const QString &str, list) { - QString line = str.simplified(); + QString line; + for (const QString &str: list) { + line = str.simplified(); if (line.isEmpty()) continue; writeCharacters(" " + line + "}" + postfix); } @@ -388,7 +389,7 @@ FbSaveHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name void FbSaveHandler::TextHandler::writeAtts(const QXmlAttributes &atts) { int count = atts.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { QString name = atts.qName(i); QString value = atts.value(i); if (m_tag == "image") { @@ -493,7 +494,7 @@ FbSaveHandler::ParagHandler::ParagHandler(TextHandler *parent, const QString &na , m_empty(true) { int count = atts.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { QString qName = atts.qName(i); QString value = atts.value(i); if (qName == "fb:class") { diff --git a/source/fb2text.cpp b/source/fb2text.cpp index aa2d276..e47ce61 100644 --- a/source/fb2text.cpp +++ b/source/fb2text.cpp @@ -259,7 +259,7 @@ void FbTextEdit::connectActions(QToolBar *tool) { m_actions.connect(); - foreach (QAction *action, m_actions) { + for (QAction *action: m_actions) { if (FbTextAction *a = qobject_cast<FbTextAction*>(action)) { a->connectAction(); } @@ -330,7 +330,7 @@ void FbTextEdit::connectActions(QToolBar *tool) void FbTextEdit::disconnectActions() { m_actions.disconnect(); - foreach (QAction *action, m_actions) { + for (QAction *action: m_actions) { if (FbTextAction *a = qobject_cast<FbTextAction*>(action)) { a->disconnectAction(); } @@ -363,7 +363,7 @@ void FbTextEdit::exportHtml() if (!m) return; int count = m->count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { QFile file(dirName + m->info(i, 0).toString()); if (file.open(QFile::WriteOnly)) { file.write(m->data(i)); diff --git a/source/fb2tree.cpp b/source/fb2tree.cpp index 3828dbc..0794749 100644 --- a/source/fb2tree.cpp +++ b/source/fb2tree.cpp @@ -30,7 +30,7 @@ FbTreeItem::FbTreeItem(QWebElement &element, FbTreeItem *parent, int number) FbTreeItem::~FbTreeItem() { - foreach (FbTreeItem * item, m_list) { + for (FbTreeItem * item: m_list) { delete item; } } @@ -90,7 +90,7 @@ QString FbTreeItem::selector() const QWebElement child = parent.firstChild(); int index = -1; while (!child.isNull()) { - index++; + ++index; if (child == element) break; child = child.nextSibling(); } @@ -107,10 +107,10 @@ FbTreeItem * FbTreeItem::content(int number) const FbTextElement element = m_element.firstChild(); while (number-- > 0) element = element.nextSibling(); FbTreeList::const_iterator it; - for (it = m_list.constBegin(); it != m_list.constEnd(); it++) { + for (it = m_list.constBegin(); it != m_list.constEnd(); ++it) { if ((*it)->element() == element) return *it; } - return 0; + return nullptr; } //--------------------------------------------------------------------------- @@ -307,7 +307,7 @@ bool FbTreeModel::removeRows(int row, int count, const QModelIndex &parent) if (!owner) return false; int last = row + count - 1; beginRemoveRows(parent, row, last); - for (int i = last; i >= row; i--) { + for (int i = last; i >= row; --i) { if (FbTreeItem * child = owner->takeAt(i)) { QUndoCommand * command = new FbDeleteCmd(child->element()); m_view.page()->push(command, "Delete element"); @@ -326,11 +326,11 @@ void FbTreeModel::update(FbTreeItem &owner) int pos = 0; QModelIndex index = this->index(&owner); - for (FbElementList::iterator it = list.begin(); it != list.end(); it++) { - FbTreeItem * child = 0; + for (FbElementList::iterator it = list.begin(); it != list.end(); ++it) { + FbTreeItem * child = nullptr; QWebElement element = *it; int count = owner.count(); - for (int i = pos; i < count; i++) { + for (int i = pos; i < count; ++i) { if (owner.item(i)->element() == element) { child = owner.item(i); if (i > pos) { @@ -355,13 +355,13 @@ void FbTreeModel::update(FbTreeItem &owner) endInsertRows(); update(*child); } - pos++; + ++pos; } int last = owner.count() - 1; if (pos <= last) { beginRemoveRows(index, pos, last); - for (int i = last; i >= pos; i--) delete owner.takeAt(i); + for (int i = last; i >= pos; --i) delete owner.takeAt(i); endRemoveRows(); } } @@ -564,7 +564,7 @@ void FbTreeView::contextMenu(const QPoint &pos) if (!e.hasTitle()) menu.addAction(actionTitle); menu.addAction(actionEpigraph); } - + else if (tag == "FB:SECTION") { if (!e.hasTitle()) menu.addAction(actionTitle); menu.addAction(actionEpigraph); @@ -572,7 +572,7 @@ void FbTreeView::contextMenu(const QPoint &pos) if (!e.hasChild("FB:ANNOTATION")) menu.addAction(actionAnnot); menu.addAction(actionText); } - + else if (tag == "FB:POEM") { if (!e.hasTitle()) menu.addAction(actionTitle); menu.addAction(actionEpigraph); @@ -580,15 +580,15 @@ void FbTreeView::contextMenu(const QPoint &pos) menu.addAction(actionAuthor); if (!e.hasChild("date")) menu.addAction(actionDate); } - + else if (tag == "FB:STANZA") { if (!e.hasTitle()) menu.addAction(actionTitle); } - + else if (tag == "FB:EPIGRAPH") { menu.addAction(actionAuthor); } - + else if (tag == "FB:CITE") { menu.addAction(actionAuthor); } diff --git a/source/fb2xml.cpp b/source/fb2xml.cpp index 9682c43..c0892e7 100644 --- a/source/fb2xml.cpp +++ b/source/fb2xml.cpp @@ -8,7 +8,7 @@ QString FbXmlHandler::NodeHandler::Value(const QXmlAttributes &attributes, const QString &name) { int count = attributes.count(); - for (int i = 0; i < count; i++ ) { + for (int i = 0; i < count; ++i ) { if (attributes.localName(i).compare(name, Qt::CaseInsensitive) == 0) { return attributes.value(i); } diff --git a/source/js/export.js b/source/js/export.js index f02afdf..bb5684b 100644 --- a/source/js/export.js +++ b/source/js/export.js @@ -12,7 +12,7 @@ } else { var atts = node.attributes; var count = atts.length; - for (var i = 0; i < count; i++) handler.onAttr(atts[i].name, atts[i].value); + for (var i = 0; i < count; ++i) handler.onAttr(atts[i].name, atts[i].value); handler.onNew(node.nodeName); for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n); handler.onEnd(node.nodeName); |