Skip to content

Commit

Permalink
less foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Sep 25, 2019
1 parent c019604 commit adc6e38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
30 changes: 11 additions & 19 deletions document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ CDocument* CDox::get_document_by_fname (const QString &fileName)
if (d->file_name == fileName)
return d;
}
/*
foreach (CDocument *d, list)
if (d->file_name == fileName)
return d;
*/

return NULL;
}

Expand Down Expand Up @@ -504,7 +500,6 @@ QString CDocument::get_filename_at_cursor()
x = x.mid (i + 1);

result = cur_dir.cleanPath (cur_dir.absoluteFilePath(x));
//qDebug() << "in cur dir: " << result;
return result;
}
else
Expand Down Expand Up @@ -936,7 +931,6 @@ void CDox::move_cursor_y (double v)
move_cursor (QTextCursor::Up);
if (v > 0)
move_cursor (QTextCursor::Down);
qDebug() << v;
}


Expand Down Expand Up @@ -1121,7 +1115,6 @@ void CSyntaxHighlighterQRegularExpression::load_from_xml (const QString &fname)
HighlightingRule rule;
rule.pattern = rg;
rule.format = fmt;
//highlightingRules.append (rule);
highlightingRules.push_back (rule);
}
}
Expand All @@ -1139,7 +1132,6 @@ void CSyntaxHighlighterQRegularExpression::load_from_xml (const QString &fname)
HighlightingRule rule;
rule.pattern = rg;
rule.format = fmt;
// highlightingRules.append (rule);
highlightingRules.push_back (rule);
}
}
Expand All @@ -1161,9 +1153,7 @@ void CSyntaxHighlighterQRegularExpression::load_from_xml (const QString &fname)
HighlightingRule rule;
rule.pattern = rg;
rule.format = fmt;
// highlightingRules.append (rule);
highlightingRules.push_back (rule);

}
}
else
Expand Down Expand Up @@ -1209,15 +1199,15 @@ void CSyntaxHighlighterQRegularExpression::highlightBlock (const QString &text)
for (std::vector <HighlightingRule>::iterator it = highlightingRules.begin(); it != highlightingRules.end(); ++it)
//for (vector <size_t>::size_type i = 0; i < highlightingRules.size(); i++)
{
QRegularExpressionMatch m = /*highlightingRules[i]*/it->pattern.match (text);
QRegularExpressionMatch m = it->pattern.match (text);

int index = m.capturedStart();

while (index >= 0)
{
int length = m.capturedLength();
setFormat (index, length, /*highlightingRules[i]*/it->format);
m = /*highlightingRules[i]*/it->pattern.match (text, index + length);
setFormat (index, length, it->format);
m = it->pattern.match (text, index + length);
index = m.capturedStart();
}
}
Expand Down Expand Up @@ -1412,18 +1402,20 @@ void CSyntaxHighlighterQRegExp::highlightBlock (const QString &text)
if (highlightingRules.size() == 0)
return;

for (vector <int>::size_type i = 0; i < highlightingRules.size(); i++)
//for (vector <int>::size_type i = 0; i < highlightingRules.size(); i++)
for (std::vector <HighlightingRule>::iterator it = highlightingRules.begin(); it != highlightingRules.end(); ++it)
//foreach (HighlightingRule rule, highlightingRules)
{
int index;

index = text.indexOf (highlightingRules[i].pattern);
//index = text.indexOf (highlightingRules[i].pattern);
index = text.indexOf (it->pattern);

while (index >= 0)
{
int length = highlightingRules[i].pattern.matchedLength();
setFormat (index, length, highlightingRules[i].format);
index = text.indexOf (highlightingRules[i].pattern, index + length);
int length = it->pattern.matchedLength();
setFormat (index, length, it->format);
index = text.indexOf (it->pattern, index + length);
}
}

Expand Down
28 changes: 13 additions & 15 deletions fman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ void CFMan::tv_activated (const QModelIndex &index)
QModelIndex index = mymodel->index (0, 0);
selectionModel()->setCurrentIndex (index, QItemSelectionModel::Select |
QItemSelectionModel::Rows);

return;
}
else
emit file_activated (full_path);
Expand Down Expand Up @@ -299,9 +297,7 @@ void CFMan::cb_fman_currentChanged (const QModelIndex &current, const QModelInde
}

QModelIndex i = model()->index (row, 0);

QString item_string = i.data().toString();

QString full_path = dir.path() + "/" + item_string;

emit current_file_changed (full_path, item_string);
Expand All @@ -327,15 +323,17 @@ QStringList CFMan::get_sel_fnames()
QModelIndexList il = selectionModel()->QItemSelectionModel::selectedRows (0);
QStringList li;

foreach (QModelIndex index, il)
QList<QModelIndex>::iterator i;
for (i = il.begin(); i != il.end(); ++i)
// foreach (QModelIndex index, il)
{
QString item_string = i->data().toString();
if (item_string != "..")
{
QString item_string = index.data().toString();
if (item_string != "..")
{
QString full_path = dir.path() + "/" + item_string;
li.append (full_path);
}
QString full_path = dir.path() + "/" + item_string;
li.append (full_path);
}
}

return li;
}
Expand Down Expand Up @@ -391,12 +389,12 @@ void CFMan::mouseMoveEvent (QMouseEvent *event)
QDrag *drag = new QDrag (this);
QMimeData *mimeData = new QMimeData;

QList <QUrl> list;
QList <QUrl> url_list;

foreach (QString fn, l)
list.append (QUrl::fromLocalFile (fn));
for (int i = 0; i < l.size(); i++)
url_list.append (QUrl::fromLocalFile (l[i]));

mimeData->setUrls (list);
mimeData->setUrls (url_list);
drag->setMimeData (mimeData);

if (drag->exec (Qt::CopyAction |
Expand Down

0 comments on commit adc6e38

Please sign in to comment.