Convert most of the remaining foreach cases.

This commit is contained in:
Andrius Štikonas 2016-08-11 14:26:54 +01:00
parent 9c524c40fe
commit 40ff0861a8
11 changed files with 39 additions and 34 deletions

View File

@ -65,10 +65,10 @@ void DeviceScanner::scan()
const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices(); const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices();
const QList<LvmDevice*> lvmList = LvmDevice::scanSystemLVM(); const QList<LvmDevice*> lvmList = LvmDevice::scanSystemLVM();
for (auto const &d : deviceList) for (const auto &d : deviceList)
operationStack().addDevice(d); operationStack().addDevice(d);
for (auto const &d : lvmList) for (const auto &d : lvmList)
operationStack().addDevice(d); operationStack().addDevice(d);
operationStack().sortDevices(); operationStack().sortDevices();

View File

@ -96,7 +96,7 @@ qint32 OperationRunner::numJobs() const
{ {
qint32 result = 0; qint32 result = 0;
for (auto const &op : operationStack().operations()) for (const auto &op : operationStack().operations())
result += op->jobs().size(); result += op->jobs().size();
return result; return result;

View File

@ -457,7 +457,7 @@ bool OperationStack::contains(const Partition* p) const
{ {
Q_ASSERT(p); Q_ASSERT(p);
for (auto const &o : operations()) { for (const auto &o : operations()) {
if (o->targets(*p)) if (o->targets(*p))
return true; return true;
@ -503,15 +503,17 @@ Device* OperationStack::findDeviceForPartition(const Partition* p)
{ {
QReadLocker lockDevices(&lock()); QReadLocker lockDevices(&lock());
foreach(Device *d, previewDevices()) { const auto devices = previewDevices();
for (Device *d : devices) {
if (d->partitionTable() == nullptr) if (d->partitionTable() == nullptr)
continue; continue;
foreach (auto const *part, d->partitionTable()->children()) { const auto partitions = d->partitionTable()->children();
for (const auto *part : partitions) {
if (part == p) if (part == p)
return d; return d;
for (auto const &child : part->children()) for (const auto &child : part->children())
if (child == p) if (child == p)
return d; return d;
} }

View File

@ -106,7 +106,7 @@ Partition::Partition(const Partition& other) :
m_State(other.m_State) m_State(other.m_State)
{ {
setPartitionPath(other.m_PartitionPath); setPartitionPath(other.m_PartitionPath);
for (auto const &child : other.children()) { for (const auto &child : other.children()) {
Partition* p = new Partition(*child); Partition* p = new Partition(*child);
p->setParent(this); p->setParent(this);
m_Children.append(p); m_Children.append(p);
@ -121,7 +121,7 @@ Partition& Partition::operator=(const Partition& other)
clearChildren(); clearChildren();
for (auto const &child : other.children()) { for (const auto &child : other.children()) {
Partition* p = new Partition(*child); Partition* p = new Partition(*child);
p->setParent(this); p->setParent(this);
m_Children.append(p); m_Children.append(p);
@ -179,7 +179,7 @@ qint64 Partition::sectorsUsed() const
return fileSystem().sectorsUsed(); return fileSystem().sectorsUsed();
qint64 result = 0; qint64 result = 0;
for (auto const &p : children()) for (const auto &p : children())
if (!p->roles().has(PartitionRole::Unallocated)) if (!p->roles().has(PartitionRole::Unallocated))
result += p->length(); result += p->length();
@ -210,12 +210,12 @@ qint64 Partition::maximumSectors() const
@param deletedNumber the number of a deleted logical or -1 if none has been deleted @param deletedNumber the number of a deleted logical or -1 if none has been deleted
@param insertedNumber the number of an inserted logical or -1 if none has been inserted @param insertedNumber the number of an inserted logical or -1 if none has been inserted
*/ */
void Partition::adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber) void Partition::adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber) const
{ {
if (!roles().has(PartitionRole::Extended)) if (!roles().has(PartitionRole::Extended))
return; return;
foreach(auto const &p, children()) { for (const auto &p : children()) {
QString path = p->partitionPath(); QString path = p->partitionPath();
path.remove(QRegularExpression(QStringLiteral("(\\d+$)"))); path.remove(QRegularExpression(QStringLiteral("(\\d+$)")));
if (deletedNumber > 4 && p->number() > deletedNumber) if (deletedNumber > 4 && p->number() > deletedNumber)
@ -230,7 +230,7 @@ qint64 Partition::maxFirstSector() const
{ {
qint64 rval = -1; qint64 rval = -1;
for (auto const &child : children()) for (const auto &child : children())
if (!child->roles().has(PartitionRole::Unallocated) && (child->firstSector() < rval || rval == -1)) if (!child->roles().has(PartitionRole::Unallocated) && (child->firstSector() < rval || rval == -1))
rval = child->firstSector(); rval = child->firstSector();
@ -242,7 +242,7 @@ qint64 Partition::minLastSector() const
{ {
qint64 rval = -1; qint64 rval = -1;
for (auto const &child : children()) for (const auto &child : children())
if (!child->roles().has(PartitionRole::Unallocated) && child->lastSector() > rval) if (!child->roles().has(PartitionRole::Unallocated) && child->lastSector() > rval)
rval = child->lastSector(); rval = child->lastSector();
@ -252,7 +252,7 @@ qint64 Partition::minLastSector() const
/** @return true if the Partition has children */ /** @return true if the Partition has children */
bool Partition::hasChildren() const bool Partition::hasChildren() const
{ {
for (auto const &child : children()) for (const auto &child : children())
if (!child->roles().has(PartitionRole::Unallocated)) if (!child->roles().has(PartitionRole::Unallocated))
return true; return true;
@ -365,7 +365,7 @@ QTextStream& operator<<(QTextStream& stream, const Partition& p)
{ {
QStringList flagList; QStringList flagList;
for (auto const &f : PartitionTable::flagList()) { for (const auto &f : PartitionTable::flagList()) {
if (p.activeFlags() & f) if (p.activeFlags() & f)
flagList.append(PartitionTable::flagName(f)); flagList.append(PartitionTable::flagName(f));
} }

View File

@ -215,7 +215,7 @@ public:
bool canMount() const; bool canMount() const;
bool canUnmount() const; bool canUnmount() const;
void adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber); void adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber) const;
void checkChildrenMounted(); void checkChildrenMounted();
void setFirstSector(qint64 s) { void setFirstSector(qint64 s) {

View File

@ -139,9 +139,11 @@ void PartitionNode::clearChildren()
*/ */
Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& role) Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& role)
{ {
foreach(auto & p, children()) { const auto partitions = children();
for (auto &p : partitions) {
// (women and) children first. ;-) // (women and) children first. ;-)
foreach(auto &child, p->children()) const auto pChildren = p->children();
for (auto &child : pChildren)
if ((child->roles().roles() & role.roles()) && s >= child->firstSector() && s <= child->lastSector()) if ((child->roles().roles() & role.roles()) && s >= child->firstSector() && s <= child->lastSector())
return child; return child;
@ -158,7 +160,7 @@ Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& r
const Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& role) const const Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& role) const
{ {
for (const auto *p : children()) { for (const auto *p : children()) {
for (auto const &child : p->children()) for (const auto &child : p->children())
if ((child->roles().roles() & role.roles()) && s >= child->firstSector() && s <= child->lastSector()) if ((child->roles().roles() & role.roles()) && s >= child->firstSector() && s <= child->lastSector())
return child; return child;

View File

@ -92,7 +92,7 @@ qint64 PartitionTable::freeSectorsAfter(const Partition& p) const
qint64 PartitionTable::freeSectors() const qint64 PartitionTable::freeSectors() const
{ {
qint64 sectors = 0; qint64 sectors = 0;
for (auto const &p : children()) { for (const auto &p : children()) {
if (p->roles().has(PartitionRole::Unallocated)) { if (p->roles().has(PartitionRole::Unallocated)) {
sectors += p->length(); sectors += p->length();
} }
@ -104,7 +104,7 @@ qint64 PartitionTable::freeSectors() const
/** @return true if the PartitionTable has an extended Partition */ /** @return true if the PartitionTable has an extended Partition */
bool PartitionTable::hasExtended() const bool PartitionTable::hasExtended() const
{ {
for (auto const &p : children()) for (const auto &p : children())
if (p->roles().has(PartitionRole::Extended)) if (p->roles().has(PartitionRole::Extended))
return true; return true;
@ -114,7 +114,7 @@ bool PartitionTable::hasExtended() const
/** @return pointer to the PartitionTable's extended Partition or nullptr if none exists */ /** @return pointer to the PartitionTable's extended Partition or nullptr if none exists */
Partition* PartitionTable::extended() const Partition* PartitionTable::extended() const
{ {
for (auto const &p : children()) for (const auto &p : children())
if (p->roles().has(PartitionRole::Extended)) if (p->roles().has(PartitionRole::Extended))
return p; return p;
@ -142,7 +142,7 @@ int PartitionTable::numPrimaries() const
{ {
int result = 0; int result = 0;
for (auto const &p : children()) for (const auto &p : children())
if (p->roles().has(PartitionRole::Primary) || p->roles().has(PartitionRole::Extended)) if (p->roles().has(PartitionRole::Primary) || p->roles().has(PartitionRole::Extended))
result++; result++;
@ -285,7 +285,6 @@ bool PartitionTable::getUnallocatedRange(const Device& d, PartitionNode& parent,
} }
/** Creates a new unallocated Partition on the given Device. /** Creates a new unallocated Partition on the given Device.
@param device the Device to create the new Partition on @param device the Device to create the new Partition on
@param parent the parent PartitionNode for the new Partition @param parent the parent PartitionNode for the new Partition
@ -360,7 +359,7 @@ void PartitionTable::insertUnallocated(const Device& d, PartitionNode* p, qint64
if (d.type() == Device::LVM_Device && !p->children().isEmpty()) { if (d.type() == Device::LVM_Device && !p->children().isEmpty()) {
// rearranging all the partitions sector to keep all the unallocated space at the end // rearranging all the partitions sector to keep all the unallocated space at the end
lastEnd = 0; lastEnd = 0;
for (auto &child : children()) { for (const auto &child : children()) {
qint64 totalSector = child->length(); qint64 totalSector = child->length();
child->setFirstSector(lastEnd); child->setFirstSector(lastEnd);
child->setLastSector(lastEnd + totalSector - 1); child->setLastSector(lastEnd + totalSector - 1);
@ -368,7 +367,8 @@ void PartitionTable::insertUnallocated(const Device& d, PartitionNode* p, qint64
lastEnd += totalSector; lastEnd += totalSector;
} }
} else { } else {
foreach(auto &child, p->children()) { const auto pChildren = p->children();
for (const auto &child : pChildren) {
p->insert(createUnallocated(d, *p, lastEnd, child->firstSector() - 1)); p->insert(createUnallocated(d, *p, lastEnd, child->firstSector() - 1));
if (child->roles().has(PartitionRole::Extended)) if (child->roles().has(PartitionRole::Extended))
@ -544,12 +544,12 @@ QTextStream& operator<<(QTextStream& stream, const PartitionTable& ptable)
QList<const Partition*> partitions; QList<const Partition*> partitions;
for (auto const &p : ptable.children()) { for (const auto &p : ptable.children()) {
if (!p->roles().has(PartitionRole::Unallocated)) { if (!p->roles().has(PartitionRole::Unallocated)) {
partitions.append(p); partitions.append(p);
if (p->roles().has(PartitionRole::Extended)) if (p->roles().has(PartitionRole::Extended))
for (auto const &child : p->children()) { for (const auto &child : p->children()) {
if (!child->roles().has(PartitionRole::Unallocated)) if (!child->roles().has(PartitionRole::Unallocated))
partitions.append(child); partitions.append(child);
} }
@ -558,7 +558,7 @@ QTextStream& operator<<(QTextStream& stream, const PartitionTable& ptable)
qSort(partitions.begin(), partitions.end(), isPartitionLessThan); qSort(partitions.begin(), partitions.end(), isPartitionLessThan);
foreach(auto const &p, partitions) foreach(const auto &p, partitions)
stream << *p; stream << *p;
return stream; return stream;

View File

@ -56,7 +56,7 @@ void PartWidget::init(const Partition* p)
void PartWidget::updateChildren() void PartWidget::updateChildren()
{ {
if (partition()) { if (partition()) {
foreach(auto &w, childWidgets()) { for (const auto &w : childWidgets()) {
w->setVisible(false); w->setVisible(false);
w->deleteLater(); w->deleteLater();
w->setParent(nullptr); w->setParent(nullptr);

View File

@ -142,7 +142,7 @@ void PartWidgetBase::positionChildren(const QWidget* destWidget, const Partition
} }
} }
QList<PartWidget*> PartWidgetBase::childWidgets() const QList<PartWidget*> PartWidgetBase::childWidgets() const
{ {
QList<PartWidget*> rval; QList<PartWidget*> rval;

View File

@ -55,7 +55,7 @@ public:
return m_MinWidth; /**< @return minimum width for a Partition widget */ return m_MinWidth; /**< @return minimum width for a Partition widget */
} }
virtual QList<PartWidget*> childWidgets(); virtual const QList<PartWidget*> childWidgets() const;
protected: protected:
virtual void positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*> widgets) const; virtual void positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*> widgets) const;

View File

@ -162,7 +162,8 @@ bool Operation::execute(Report& parent)
Report* report = parent.newChild(description()); Report* report = parent.newChild(description());
foreach(Job * job, jobs()) const auto Jobs = jobs();
for (const auto &job : Jobs)
if (!(rval = job->run(*report))) if (!(rval = job->run(*report)))
break; break;