Convert to C++11 for loop where it is safe (avoid detaching Qt objects).

This commit is contained in:
Andrius Štikonas 2016-08-08 18:37:21 +01:00
parent 9ed640084d
commit a10c8d3aaa
28 changed files with 107 additions and 116 deletions

View File

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

View File

@ -71,7 +71,7 @@ void LvmDevice::initPartitions()
qint64 lastusable = totalPE() - 1; qint64 lastusable = totalPE() - 1;
PartitionTable* pTable = new PartitionTable(PartitionTable::vmd, firstUsable, lastusable); PartitionTable* pTable = new PartitionTable(PartitionTable::vmd, firstUsable, lastusable);
foreach (Partition* p, scanPartitions(pTable)) { for (Partition* p : scanPartitions(pTable)) {
LVSizeMap()->insert(p->partitionPath(), p->length()); LVSizeMap()->insert(p->partitionPath(), p->length());
pTable->append(p); pTable->append(p);
} }
@ -84,10 +84,10 @@ void LvmDevice::initPartitions()
/** /**
* @return sorted Partition(LV) Array * @return sorted Partition(LV) Array
*/ */
QList<Partition*> LvmDevice::scanPartitions(PartitionTable* pTable) const const QList<Partition*> LvmDevice::scanPartitions(PartitionTable* pTable) const
{ {
QList<Partition*> pList; QList<Partition*> pList;
foreach (QString lvPath, lvPathList()) { for (QString lvPath : lvPathList()) {
pList.append(scanPartition(lvPath, pTable)); pList.append(scanPartition(lvPath, pTable));
} }
return pList; return pList;
@ -184,7 +184,7 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
QList<LvmDevice*> LvmDevice::scanSystemLVM() QList<LvmDevice*> LvmDevice::scanSystemLVM()
{ {
QList<LvmDevice*> lvmList; QList<LvmDevice*> lvmList;
foreach (QString vgname, getVGs()) { for (QString vgname : getVGs()) {
lvmList.append(new LvmDevice(vgname)); lvmList.append(new LvmDevice(vgname));
} }
return lvmList; return lvmList;
@ -205,23 +205,23 @@ qint64 LvmDevice::mappedSector(const QString& lvpath, qint64 sector) const
return mSector; return mSector;
} }
QStringList LvmDevice::deviceNodeList() const const QStringList LvmDevice::deviceNodeList() const
{ {
return *PVPathList(); return *PVPathList();
} }
QStringList LvmDevice::lvPathList() const const QStringList LvmDevice::lvPathList() const
{ {
return *LVPathList(); return *LVPathList();
} }
QStringList LvmDevice::getVGs() const QStringList LvmDevice::getVGs()
{ {
QStringList vgList; QStringList vgList;
QString output = getField(QStringLiteral("vg_name")); QString output = getField(QStringLiteral("vg_name"));
if (!output.isEmpty()) { if (!output.isEmpty()) {
QStringList vgnameList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts); const QStringList vgnameList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts);
foreach(QString vgname, vgnameList) { for (QString vgname : vgnameList) {
vgList.append(vgname.trimmed()); vgList.append(vgname.trimmed());
} }
} }
@ -234,8 +234,8 @@ QStringList LvmDevice::getPVs(const QString& vgname)
QString cmdOutput = getField(QStringLiteral("pv_name"), vgname); QString cmdOutput = getField(QStringLiteral("pv_name"), vgname);
if (cmdOutput.size()) { if (cmdOutput.size()) {
QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts); const QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts);
foreach(QString devPath, tempPathList) { for (QString devPath : tempPathList) {
devPathList.append(devPath.trimmed()); devPathList.append(devPath.trimmed());
} }
} }
@ -248,8 +248,8 @@ QStringList LvmDevice::getLVs(const QString& vgname)
QString cmdOutput = getField(QStringLiteral("lv_path"), vgname); QString cmdOutput = getField(QStringLiteral("lv_path"), vgname);
if (cmdOutput.size()) { if (cmdOutput.size()) {
QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts); const QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts);
foreach(QString lvPath, tempPathList) { for (QString lvPath : tempPathList) {
lvPathList.append(lvPath.trimmed()); lvPathList.append(lvPath.trimmed());
} }
} }
@ -424,7 +424,7 @@ bool LvmDevice::movePV(Report& report, LvmDevice& dev, const QString& pvPath, co
args << QStringLiteral("pvmove"); args << QStringLiteral("pvmove");
args << pvPath; args << pvPath;
if (!destinations.isEmpty()) { if (!destinations.isEmpty()) {
foreach (QString destPath, destinations) { for (QString destPath : destinations) {
args << destPath.trimmed(); args << destPath.trimmed();
} }
} }
@ -438,7 +438,7 @@ bool LvmDevice::createVG(Report& report, const QString vgname, const QStringList
QStringList args = QStringList(); QStringList args = QStringList();
args << QStringLiteral("vgcreate") << QStringLiteral("--physicalextentsize") << QString::number(peSize); args << QStringLiteral("vgcreate") << QStringLiteral("--physicalextentsize") << QString::number(peSize);
args << vgname; args << vgname;
foreach (QString pvnode, pvlist) { for (QString pvnode : pvlist) {
args << pvnode.trimmed(); args << pvnode.trimmed();
} }
ExternalCommand cmd(report, QStringLiteral("lvm"), args); ExternalCommand cmd(report, QStringLiteral("lvm"), args);
@ -464,7 +464,7 @@ bool LvmDevice::deactivateVG(Report& report, const LvmDevice& dev)
return deactivate.run(-1) && deactivate.exitCode() == 0; return deactivate.run(-1) && deactivate.exitCode() == 0;
} }
bool LvmDevice::deactivateLV(Report& report, LvmDevice& dev, Partition& part) bool LvmDevice::deactivateLV(Report& report, const LvmDevice& dev, const Partition& part)
{ {
Q_UNUSED(dev); Q_UNUSED(dev);
ExternalCommand deactivate(report, QStringLiteral("lvm"), ExternalCommand deactivate(report, QStringLiteral("lvm"),

View File

@ -49,10 +49,10 @@ public:
~LvmDevice(); ~LvmDevice();
public: public:
QList<Partition*> scanPartitions(PartitionTable* pTable) const; const QList<Partition*> scanPartitions(PartitionTable* pTable) const;
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const; Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
QStringList deviceNodeList() const override; const QStringList deviceNodeList() const override;
QStringList lvPathList() const; const QStringList lvPathList() const;
static QStringList s_DirtyPVs; static QStringList s_DirtyPVs;
public: public:
@ -69,13 +69,13 @@ public:
static QStringList getPVs(const QString& vgname); static QStringList getPVs(const QString& vgname);
static QStringList getLVs(const QString& vgname); static QStringList getLVs(const QString& vgname);
static QStringList getVGs(); static const QStringList getVGs();
static bool removeLV(Report& report, LvmDevice& dev, Partition& part); static bool removeLV(Report& report, LvmDevice& dev, Partition& part);
static bool createLV(Report& report, LvmDevice& dev, Partition& part, const QString& lvname); static bool createLV(Report& report, LvmDevice& dev, Partition& part, const QString& lvname);
static bool createLVSnapshot(Report& report, LvmDevice& dev, Partition& lvpart, const QString& name, const qint64 extents = 0); static bool createLVSnapshot(Report& report, LvmDevice& dev, Partition& lvpart, const QString& name, const qint64 extents = 0);
static bool resizeLV(Report& report, LvmDevice& dev, Partition& part); static bool resizeLV(Report& report, LvmDevice& dev, Partition& part);
static bool deactivateLV(Report& report, LvmDevice& dev, Partition& part); static bool deactivateLV(Report& report, const LvmDevice& dev, const Partition& part);
static bool activateLV(Report& report, LvmDevice& dev, Partition& part); static bool activateLV(Report& report, LvmDevice& dev, Partition& part);
static bool removePV(Report& report, LvmDevice& dev, const QString& pvPath); static bool removePV(Report& report, LvmDevice& dev, const QString& pvPath);
@ -88,7 +88,7 @@ public:
static bool activateVG(Report& report, const LvmDevice& dev); static bool activateVG(Report& report, const LvmDevice& dev);
protected: protected:
void initPartitions(); void initPartitions() override;
qint64 mappedSector(const QString& lvpath, qint64 sector) const override; qint64 mappedSector(const QString& lvpath, qint64 sector) const override;
public: public:
@ -108,7 +108,7 @@ public:
return m_UUID; return m_UUID;
} }
QStringList* LVPathList() const { const QStringList* LVPathList() const {
return m_LVPathList; return m_LVPathList;
} }

View File

@ -96,7 +96,7 @@ qint32 OperationRunner::numJobs() const
{ {
qint32 result = 0; qint32 result = 0;
foreach(const Operation * op, operationStack().operations()) for (const Operation * 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);
foreach(Operation * o, operations()) { for (Operation * o : operations()) {
if (o->targets(*p)) if (o->targets(*p))
return true; return true;
@ -511,9 +511,9 @@ Device* OperationStack::findDeviceForPartition(const Partition* p)
if (part == p) if (part == p)
return d; return d;
foreach(const Partition * child, part->children()) for (const Partition * 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);
foreach(const Partition * child, other.children()) { for (const Partition * 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();
foreach(const Partition * child, other.children()) { for (const Partition * 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;
foreach(const Partition * p, children()) for (const Partition * p : children())
if (!p->roles().has(PartitionRole::Unallocated)) if (!p->roles().has(PartitionRole::Unallocated))
result += p->length(); result += p->length();
@ -230,7 +230,7 @@ qint64 Partition::maxFirstSector() const
{ {
qint64 rval = -1; qint64 rval = -1;
foreach(const Partition * child, children()) for (const Partition * 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;
foreach(const Partition * child, children()) for (const Partition * 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
{ {
foreach(const Partition * child, children()) for (const Partition * 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;
foreach(const PartitionTable::Flag & f, PartitionTable::flagList()) { for (const PartitionTable::Flag & f : PartitionTable::flagList()) {
if (p.activeFlags() & f) if (p.activeFlags() & f)
flagList.append(PartitionTable::flagName(f)); flagList.append(PartitionTable::flagName(f));
} }

View File

@ -142,8 +142,8 @@ Partition* PartitionNode::findPartitionBySector(qint64 s, const PartitionRole& r
foreach(Partition * p, children()) { foreach(Partition * p, children()) {
// (women and) children first. ;-) // (women and) children first. ;-)
foreach(Partition * child, p->children()) foreach(Partition * 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;
if ((p->roles().roles() & role.roles()) && s >= p->firstSector() && s <= p->lastSector()) if ((p->roles().roles() & role.roles()) && s >= p->firstSector() && s <= p->lastSector())
return p; return p;
@ -157,10 +157,10 @@ 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
{ {
foreach(const Partition * p, children()) { for (const Partition * p : children()) {
foreach(const Partition * child, p->children()) for (const Partition * 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;
if ((p->roles().roles() & role.roles()) && s >= p->firstSector() && s <= p->lastSector()) if ((p->roles().roles() & role.roles()) && s >= p->firstSector() && s <= p->lastSector())
return p; return p;
@ -190,9 +190,9 @@ qint32 PartitionNode::highestMountedChild() const
{ {
qint32 result = -1; qint32 result = -1;
foreach(const Partition * p, children()) for (const Partition * p : children())
if (p->number() > result && p->isMounted()) if (p->number() > result && p->isMounted())
result = p->number(); result = p->number();
return result; return result;
} }
@ -200,9 +200,9 @@ qint32 PartitionNode::highestMountedChild() const
/** @return true if any of the partition's children are mounted */ /** @return true if any of the partition's children are mounted */
bool PartitionNode::isChildMounted() const bool PartitionNode::isChildMounted() const
{ {
foreach(const Partition * child, children()) for (const Partition * child : children())
if (child->isMounted() || (child->hasChildren() && child->isChildMounted())) if (child->isMounted() || (child->hasChildren() && child->isChildMounted()))
return true; return true;
return false; return false;
} }

View File

@ -92,9 +92,10 @@ qint64 PartitionTable::freeSectorsAfter(const Partition& p) const
qint64 PartitionTable::freeSectors() const qint64 PartitionTable::freeSectors() const
{ {
qint64 sectors = 0; qint64 sectors = 0;
foreach(const Partition * p, children()) for (const Partition * p : children()) {
if (p->roles().has(PartitionRole::Unallocated)) { if (p->roles().has(PartitionRole::Unallocated)) {
sectors += p->length(); sectors += p->length();
}
} }
return sectors; return sectors;
@ -141,7 +142,7 @@ int PartitionTable::numPrimaries() const
{ {
int result = 0; int result = 0;
foreach(const Partition * p, children()) for (const Partition * 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++;
@ -206,7 +207,7 @@ QString PartitionTable::flagName(Flag f)
} }
/** @return list of all flags */ /** @return list of all flags */
QList<PartitionTable::Flag> PartitionTable::flagList() const QList<PartitionTable::Flag> PartitionTable::flagList()
{ {
QList<PartitionTable::Flag> rval; QList<PartitionTable::Flag> rval;
@ -359,7 +360,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;
foreach (Partition* child, children()) { for (Partition* 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);
@ -505,11 +506,12 @@ bool PartitionTable::isSectorBased(const Device& d) const
// see if we have more cylinder aligned partitions than sector // see if we have more cylinder aligned partitions than sector
// aligned ones. // aligned ones.
foreach(const Partition * p, children()) for (const Partition * p : children()) {
if (p->firstSector() % PartitionAlignment::sectorAlignment(diskDevice) == 0) if (p->firstSector() % PartitionAlignment::sectorAlignment(diskDevice) == 0)
numSectorAligned++; numSectorAligned++;
else if (p->firstSector() % diskDevice.cylinderSize() == 0) else if (p->firstSector() % diskDevice.cylinderSize() == 0)
numCylinderAligned++; numCylinderAligned++;
}
return numSectorAligned >= numCylinderAligned; return numSectorAligned >= numCylinderAligned;
} }
@ -542,15 +544,17 @@ QTextStream& operator<<(QTextStream& stream, const PartitionTable& ptable)
QList<const Partition*> partitions; QList<const Partition*> partitions;
foreach(const Partition * p, ptable.children()) for (const Partition * 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))
foreach(const Partition * child, p->children()) for (const Partition * child : p->children()) {
if (!child->roles().has(PartitionRole::Unallocated)) if (!child->roles().has(PartitionRole::Unallocated))
partitions.append(child); partitions.append(child);
}
} }
}
qSort(partitions.begin(), partitions.end(), isPartitionLessThan); qSort(partitions.begin(), partitions.end(), isPartitionLessThan);

View File

@ -164,7 +164,7 @@ public:
bool isSectorBased(const Device& d) const; bool isSectorBased(const Device& d) const;
static QList<Flag> flagList(); static const QList<Flag> flagList();
static QString flagName(Flag f); static QString flagName(Flag f);
static QStringList flagNames(Flags f); static QStringList flagNames(Flags f);

View File

@ -37,7 +37,7 @@ VolumeManagerDevice::VolumeManagerDevice(const QString& name,
QString VolumeManagerDevice::prettyDeviceNodeList() const QString VolumeManagerDevice::prettyDeviceNodeList() const
{ {
QString rval; QString rval;
foreach (QString devNode, deviceNodeList()) { for (QString devNode : deviceNodeList()) {
rval += devNode + QStringLiteral(","); rval += devNode + QStringLiteral(",");
} }

View File

@ -48,7 +48,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
public: public:
VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device); VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device);
virtual void initPartitions() = 0; virtual void initPartitions() = 0;
virtual QStringList deviceNodeList() const = 0; /** Return list of physical device or partitions that makes up volumeManagerDevice */ virtual const QStringList deviceNodeList() const = 0; /** Return list of physical device or partitions that makes up volumeManagerDevice */
virtual qint64 mappedSector(const QString& devNode, qint64 sector) const = 0; virtual qint64 mappedSector(const QString& devNode, qint64 sector) const = 0;
public: public:

View File

@ -84,7 +84,7 @@ void FileSystemFactory::init()
m_FileSystems.insert(FileSystem::Xfs, new FS::xfs(-1, -1, -1, QString())); m_FileSystems.insert(FileSystem::Xfs, new FS::xfs(-1, -1, -1, QString()));
m_FileSystems.insert(FileSystem::Zfs, new FS::zfs(-1, -1, -1, QString())); m_FileSystems.insert(FileSystem::Zfs, new FS::zfs(-1, -1, -1, QString()));
foreach(FileSystem * fs, FileSystemFactory::map()) { for (FileSystem * fs : FileSystemFactory::map()) {
fs->init(); fs->init();
} }

View File

@ -205,7 +205,7 @@ qint64 lvm2_pv::getTotalPE(const QString& deviceNode)
qint64 lvm2_pv::getTotalPE(const QStringList& deviceNodeList) qint64 lvm2_pv::getTotalPE(const QStringList& deviceNodeList)
{ {
qint64 sum = 0; qint64 sum = 0;
foreach (QString deviceNode, deviceNodeList) { for (QString deviceNode : deviceNodeList) {
qint64 totalPE = getTotalPE(deviceNode); qint64 totalPE = getTotalPE(deviceNode);
if (totalPE < 0) { if (totalPE < 0) {
sum = -1; sum = -1;
@ -224,7 +224,7 @@ qint64 lvm2_pv::getFreePE(const QString& deviceNode)
qint64 lvm2_pv::getFreePE(const QStringList& deviceNodeList) qint64 lvm2_pv::getFreePE(const QStringList& deviceNodeList)
{ {
qint64 sum = 0; qint64 sum = 0;
foreach (QString deviceNode, deviceNodeList) { for (QString deviceNode :deviceNodeList) {
qint64 freePE = getFreePE(deviceNode); qint64 freePE = getFreePE(deviceNode);
if (freePE < 0) { if (freePE < 0) {
sum = -1; sum = -1;
@ -244,7 +244,7 @@ qint64 lvm2_pv::getAllocatedPE(const QString& deviceNode)
qint64 lvm2_pv::getAllocatedPE(const QStringList& deviceNodeList) qint64 lvm2_pv::getAllocatedPE(const QStringList& deviceNodeList)
{ {
qint64 sum = 0; qint64 sum = 0;
foreach (QString deviceNode, deviceNodeList) { for (QString deviceNode : deviceNodeList) {
qint64 allocatedPE = getAllocatedPE(deviceNode); qint64 allocatedPE = getAllocatedPE(deviceNode);
if (allocatedPE < 0) { if (allocatedPE < 0) {
sum = -1; sum = -1;
@ -264,7 +264,7 @@ qint64 lvm2_pv::getPVSize(const QString& deviceNode)
qint64 lvm2_pv::getPVSize(const QStringList& deviceNodeList) qint64 lvm2_pv::getPVSize(const QStringList& deviceNodeList)
{ {
qint64 sum = 0; qint64 sum = 0;
foreach (QString deviceNode, deviceNodeList) { for (QString deviceNode : deviceNodeList) {
qint64 pvsize = getPVSize(deviceNode); qint64 pvsize = getPVSize(deviceNode);
if (pvsize < 0) { if (pvsize < 0) {
sum = -1; sum = -1;
@ -312,8 +312,8 @@ QStringList lvm2_pv::getFreePV()
QStringList rlist; QStringList rlist;
QString output = getpvField(QStringLiteral("pv_name")); QString output = getpvField(QStringLiteral("pv_name"));
QStringList pvList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts); const QStringList pvList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts);
foreach (QString pvnode, pvList) { for (QString pvnode : pvList) {
if (!isUsed(pvnode.trimmed())) { if (!isUsed(pvnode.trimmed())) {
rlist.append(pvnode.trimmed()); rlist.append(pvnode.trimmed());
} }

View File

@ -62,7 +62,7 @@ void PartWidget::updateChildren()
w->setParent(nullptr); w->setParent(nullptr);
} }
foreach(const Partition * child, partition()->children()) { for (const Partition * child : partition()->children()) {
QWidget* w = new PartWidget(this, child); QWidget* w = new PartWidget(this, child);
w->setVisible(true); w->setVisible(true);
} }

View File

@ -31,7 +31,7 @@ template<typename T>
T sum(const QList<T>& list) T sum(const QList<T>& list)
{ {
T rval = 0; T rval = 0;
foreach(const T & val, list) for (const T & val : list)
rval += val; rval += val;
return rval; return rval;
} }
@ -107,7 +107,7 @@ void PartWidgetBase::positionChildren(const QWidget* destWidget, const Partition
return; return;
qint64 totalLength = 0; qint64 totalLength = 0;
foreach(const Partition * p, partitions) for (const Partition * p : partitions)
totalLength += p->length(); totalLength += p->length();
if (totalLength < 1) if (totalLength < 1)
@ -146,7 +146,7 @@ QList<PartWidget*> PartWidgetBase::childWidgets()
{ {
QList<PartWidget*> rval; QList<PartWidget*> rval;
foreach(QObject * o, children()) for (QObject * o : children())
if (PartWidget* w = qobject_cast<PartWidget*>(o)) if (PartWidget* w = qobject_cast<PartWidget*>(o))
rval.append(w); rval.append(w);

View File

@ -51,7 +51,7 @@ bool CreateVolumeGroupJob::run(Report& parent)
QString CreateVolumeGroupJob::description() const QString CreateVolumeGroupJob::description() const
{ {
QString tmp = QString(); QString tmp = QString();
foreach(QString name, pvList()) { for (const QString name : pvList()) {
tmp += QStringLiteral("\n") + name; tmp += QStringLiteral("\n") + name;
} }
return xi18nc("@info/plain", "Create new Volume Group: <filename>%1</filename> with PV: %2", vgName(), tmp); return xi18nc("@info/plain", "Create new Volume Group: <filename>%1</filename> with PV: %2", vgName(), tmp);

View File

@ -26,10 +26,8 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Creates a new DeactivateLogicalVolumeJob /** Creates a new DeactivateLogicalVolumeJob
@param vgname
@parem pvList
*/ */
DeactivateLogicalVolumeJob::DeactivateLogicalVolumeJob(VolumeManagerDevice& dev, QStringList lvPaths) : DeactivateLogicalVolumeJob::DeactivateLogicalVolumeJob(const VolumeManagerDevice& dev, const QStringList lvPaths) :
Job(), Job(),
m_Device(dev), m_Device(dev),
m_LVList(lvPaths) m_LVList(lvPaths)
@ -43,9 +41,9 @@ bool DeactivateLogicalVolumeJob::run(Report& parent)
Report* report = jobStarted(parent); Report* report = jobStarted(parent);
if (device().type() == Device::LVM_Device) { if (device().type() == Device::LVM_Device) {
foreach (Partition* part, device().partitionTable()->children()) { for (const Partition* part : device().partitionTable()->children()) {
if (!part->roles().has(PartitionRole::Unallocated)) { if (!part->roles().has(PartitionRole::Unallocated)) {
if (!LvmDevice::deactivateLV(*report, dynamic_cast<LvmDevice&>(device()), *part)) { if (!LvmDevice::deactivateLV(*report, dynamic_cast<const LvmDevice&>(device()), *part)) {
rval = false; rval = false;
} }
} }

View File

@ -30,16 +30,13 @@ class QString;
class DeactivateLogicalVolumeJob : public Job class DeactivateLogicalVolumeJob : public Job
{ {
public: public:
DeactivateLogicalVolumeJob(VolumeManagerDevice& dev, QStringList lvPaths = {}); DeactivateLogicalVolumeJob(const VolumeManagerDevice& dev, const QStringList lvPaths = {});
public: public:
bool run(Report& parent) override; bool run(Report& parent) override;
QString description() const override; QString description() const override;
protected: protected:
VolumeManagerDevice& device() {
return m_Device;
}
const VolumeManagerDevice& device() const { const VolumeManagerDevice& device() const {
return m_Device; return m_Device;
} }
@ -49,8 +46,8 @@ protected:
} }
private: private:
VolumeManagerDevice& m_Device; const VolumeManagerDevice& m_Device;
QStringList m_LVList; const QStringList m_LVList;
}; };
#endif #endif

View File

@ -24,8 +24,6 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Deactivate LVM Volume Group /** Deactivate LVM Volume Group
@param vgname
@parem pvList
*/ */
DeactivateVolumeGroupJob::DeactivateVolumeGroupJob(VolumeManagerDevice& dev) : DeactivateVolumeGroupJob::DeactivateVolumeGroupJob(VolumeManagerDevice& dev) :
Job(), Job(),

View File

@ -24,8 +24,6 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Creates a new MovePhysicalVolumeJob /** Creates a new MovePhysicalVolumeJob
@param vgname
@parem pvList
*/ */
MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& dev, const QStringList partlist) : MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& dev, const QStringList partlist) :
Job(), Job(),
@ -41,13 +39,13 @@ bool MovePhysicalVolumeJob::run(Report& parent)
Report* report = jobStarted(parent); Report* report = jobStarted(parent);
QStringList destinations = LvmDevice::getPVs(device().name()); QStringList destinations = LvmDevice::getPVs(device().name());
foreach (QString partPath, partList()) { for (const QString partPath : partList()) {
if (destinations.contains(partPath)) { if (destinations.contains(partPath)) {
destinations.removeAll(partPath); destinations.removeAll(partPath);
} }
} }
foreach (QString partPath, partList()) { for (const QString partPath : partList()) {
rval = LvmDevice::movePV(*report, device(), partPath, destinations); rval = LvmDevice::movePV(*report, device(), partPath, destinations);
if (rval == false) { if (rval == false) {
break; break;
@ -62,7 +60,7 @@ bool MovePhysicalVolumeJob::run(Report& parent)
QString MovePhysicalVolumeJob::description() const QString MovePhysicalVolumeJob::description() const
{ {
QString tmp = QString(); QString tmp = QString();
foreach (QString path, partList()) { for (const QString path : partList()) {
tmp += path + QStringLiteral(","); tmp += path + QStringLiteral(",");
} }
return xi18nc("@info/plain", "Move used PE in %1 on %2 to other available Physical Volumes", tmp, device().name()); return xi18nc("@info/plain", "Move used PE in %1 on %2 to other available Physical Volumes", tmp, device().name());

View File

@ -24,8 +24,6 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Creates a new RemoveVolumeGroupJob /** Creates a new RemoveVolumeGroupJob
@param vgname
@parem pvList
*/ */
RemoveVolumeGroupJob::RemoveVolumeGroupJob(VolumeManagerDevice& dev) : RemoveVolumeGroupJob::RemoveVolumeGroupJob(VolumeManagerDevice& dev) :
Job(), Job(),

View File

@ -24,8 +24,6 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Creates a new ResizeVolumeGroupJob /** Creates a new ResizeVolumeGroupJob
@param vgname
@parem pvList
*/ */
ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QStringList partlist, const Type type) : ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QStringList partlist, const Type type) :
Job(), Job(),
@ -41,7 +39,7 @@ bool ResizeVolumeGroupJob::run(Report& parent)
Report* report = jobStarted(parent); Report* report = jobStarted(parent);
foreach (QString pvpath, partList()) { for (const QString pvpath : partList()) {
if (type() == ResizeVolumeGroupJob::Grow) { if (type() == ResizeVolumeGroupJob::Grow) {
rval = LvmDevice::insertPV(*report, device(), pvpath); rval = LvmDevice::insertPV(*report, device(), pvpath);
} else if (type() == ResizeVolumeGroupJob::Shrink) { } else if (type() == ResizeVolumeGroupJob::Shrink) {
@ -60,7 +58,7 @@ bool ResizeVolumeGroupJob::run(Report& parent)
QString ResizeVolumeGroupJob::description() const QString ResizeVolumeGroupJob::description() const
{ {
QString tmp = QString(); QString tmp = QString();
foreach (QString path, partList()) { for (const QString path : partList()) {
tmp += path + QStringLiteral(","); tmp += path + QStringLiteral(",");
} }
if (type() == ResizeVolumeGroupJob::Grow) { if (type() == ResizeVolumeGroupJob::Grow) {

View File

@ -70,7 +70,7 @@ bool SetPartFlagsJob::run(Report& parent)
if (backendPartition) { if (backendPartition) {
quint32 count = 0; quint32 count = 0;
foreach(const PartitionTable::Flag & f, PartitionTable::flagList()) { for (const PartitionTable::Flag & f : PartitionTable::flagList()) {
emit progress(++count); emit progress(++count);
const bool state = (flags() & f) ? true : false; const bool state = (flags() & f) ? true : false;

View File

@ -56,7 +56,7 @@ void CreateVolumeGroupOperation::preview()
void CreateVolumeGroupOperation::undo() void CreateVolumeGroupOperation::undo()
{ {
foreach(QString pvpath, PVList()) { for(QString pvpath : PVList()) {
if (LvmDevice::s_DirtyPVs.contains(pvpath)) { if (LvmDevice::s_DirtyPVs.contains(pvpath)) {
LvmDevice::s_DirtyPVs.removeAll(pvpath); LvmDevice::s_DirtyPVs.removeAll(pvpath);
} }

View File

@ -61,7 +61,7 @@ protected:
return m_CreateVolumeGroupJob; return m_CreateVolumeGroupJob;
} }
QStringList PVList() { const QStringList PVList() {
return m_PVList; return m_PVList;
} }

View File

@ -146,7 +146,7 @@ qint32 Operation::totalProgress() const
{ {
qint32 result = 0; qint32 result = 0;
foreach(const Job * job, jobs()) for (const Job * job : jobs())
result += job->numSteps(); result += job->numSteps();
return result; return result;

View File

@ -46,14 +46,14 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& dev, const QSt
m_CurrentSize = FS::lvm2_pv::getPVSize(currentList()); m_CurrentSize = FS::lvm2_pv::getPVSize(currentList());
QStringList toRemoveList = clist; QStringList toRemoveList = clist;
foreach (QString path, partlist) { for (QString path : partlist) {
if (toRemoveList.contains(path)) { if (toRemoveList.contains(path)) {
toRemoveList.removeAll(path); toRemoveList.removeAll(path);
} }
} }
QStringList toInsertList = partlist; QStringList toInsertList = partlist;
foreach (QString path, clist) { for (QString path : clist) {
if (toInsertList.contains(path)) { if (toInsertList.contains(path)) {
toInsertList.removeAll(path); toInsertList.removeAll(path);
} }
@ -84,12 +84,12 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& dev, const QSt
QString ResizeVolumeGroupOperation::description() const QString ResizeVolumeGroupOperation::description() const
{ {
QString tlist = QString(); QString tlist = QString();
foreach (QString path, targetList()) { for (QString path : targetList()) {
tlist += path + QStringLiteral(","); tlist += path + QStringLiteral(",");
} }
tlist.chop(1); tlist.chop(1);
QString clist = QString(); QString clist = QString();
foreach (QString path, currentList()) { for (QString path : currentList()) {
clist += path + QStringLiteral(","); clist += path + QStringLiteral(",");
} }
clist.chop(1); clist.chop(1);
@ -103,7 +103,7 @@ bool ResizeVolumeGroupOperation::targets(const Device& d) const
bool ResizeVolumeGroupOperation::targets(const Partition& part) const bool ResizeVolumeGroupOperation::targets(const Partition& part) const
{ {
foreach (QString partPath, targetList()) { for (QString partPath : targetList()) {
if (partPath == part.partitionPath()) { if (partPath == part.partitionPath()) {
return true; return true;
} }

View File

@ -80,7 +80,7 @@ QString Report::toHtml() const
if (children().size() == 0) if (children().size() == 0)
s += QStringLiteral("<br/>\n"); s += QStringLiteral("<br/>\n");
else else
foreach(Report * child, children()) for (Report * child : children())
s += child->toHtml(); s += child->toHtml();
if (!status().isEmpty()) if (!status().isEmpty())
@ -109,7 +109,7 @@ QString Report::toText() const
if (!output().isEmpty()) if (!output().isEmpty())
s += output() + QStringLiteral("\n"); s += output() + QStringLiteral("\n");
foreach(Report * child, children()) for (const Report * child : children())
s += child->toText(); s += child->toText();
return s; return s;