Convert to C++11 for loop where it is safe to do so.

This commit is contained in:
Andrius Štikonas 2016-08-08 19:39:20 +01:00
parent fe01d6c2e2
commit 561269a2e6
19 changed files with 74 additions and 70 deletions

View File

@ -35,29 +35,29 @@ AdvancedPageWidget::AdvancedPageWidget(QWidget* parent) :
QString AdvancedPageWidget::backend() const
{
KService::List services = CoreBackendManager::self()->list();
const KService::List services = CoreBackendManager::self()->list();
foreach(KService::Ptr p, services)
if (p->name() == comboBackend().currentText())
return p->library();
for (auto const &p : services)
if (p->name() == comboBackend().currentText())
return p->library();
return QString();
}
void AdvancedPageWidget::setBackend(const QString& name)
{
KService::List services = CoreBackendManager::self()->list();
const KService::List services = CoreBackendManager::self()->list();
foreach(KService::Ptr p, services)
if (p->library() == name)
comboBackend().setCurrentIndex(comboBackend().findText(p->name()));
for (auto const &p : services)
if (p->library() == name)
comboBackend().setCurrentIndex(comboBackend().findText(p->name()));
}
void AdvancedPageWidget::setupDialog()
{
KService::List services = CoreBackendManager::self()->list();
foreach(KService::Ptr p, services)
comboBackend().addItem(p->name());
const KService::List services = CoreBackendManager::self()->list();
for (auto const &p : services)
comboBackend().addItem(p->name());
setBackend(Config::backend());
}

View File

@ -54,7 +54,7 @@ CreateVolumeDialog::CreateVolumeDialog(QWidget* parent, QString& vgname, QString
void CreateVolumeDialog::setupDialog()
{
foreach (QString pvpath, FS::lvm2_pv::getFreePV()) {
for (const auto &pvpath : FS::lvm2_pv::getFreePV()) {
if (!LvmDevice::s_DirtyPVs.contains(pvpath)) {
dialogWidget().listPV().addPartition(pvpath, false);
}

View File

@ -58,7 +58,7 @@ QStringList EditMountOptionsDialog::options()
{
QStringList rval;
const QStringList lines = widget().editOptions().toPlainText().split(QStringLiteral("\n"));
foreach(const QString & line, lines)
rval.append(line.simplified().toLower());
for (auto const &line : lines)
rval.append(line.simplified().toLower());
return rval;
}

View File

@ -25,6 +25,6 @@ EditMountOptionsDialogWidget::EditMountOptionsDialogWidget(QWidget* parent, cons
{
setupUi(this);
foreach(const QString & o, options)
editOptions().appendPlainText(o);
for (auto const &o : options)
editOptions().appendPlainText(o);
}

View File

@ -135,11 +135,12 @@ void EditMountPointDialogWidget::setupOptions(const QStringList& options)
{
QStringList optTmpList;
foreach(const QString & o, options)
if (boxOptions().find(o) != boxOptions().end())
boxOptions()[o]->setChecked(true);
else
optTmpList.append(o);
for (auto const &o : options) {
if (boxOptions().find(o) != boxOptions().end())
boxOptions()[o]->setChecked(true);
else
optTmpList.append(o);
}
m_Options = optTmpList.join(QStringLiteral(","));
}
@ -165,9 +166,9 @@ QStringList EditMountPointDialogWidget::options()
{
QStringList optList = m_Options.split(QStringLiteral(","), QString::SkipEmptyParts);
foreach(const QString & s, boxOptions().keys())
if (boxOptions()[s]->isChecked())
optList.append(s);
foreach(auto const &s, boxOptions().keys())
if (boxOptions()[s]->isChecked())
optList.append(s);
return optList;
}
@ -265,8 +266,8 @@ bool EditMountPointDialogWidget::writeMountpoints(const QString& filename)
qWarning() << "could not open output file " << newFilename;
rval = false;
} else {
foreach(const MountEntry * me, mountPoints())
writeEntry(out, me);
foreach(auto const &me, mountPoints())
writeEntry(out, me);
out.close();

View File

@ -71,7 +71,7 @@ void FileSystemSupportDialog::setupDialog()
dialogWidget().tree().clear();
foreach(const FileSystem * fs, FileSystemFactory::map()) {
for (auto const &fs : FileSystemFactory::map()) {
if (fs->type() == FileSystem::Unknown || fs->type() == FileSystem::Extended || fs->type() == FileSystem::Luks)
continue;

View File

@ -49,12 +49,12 @@ ListDevices::ListDevices(QWidget* parent) :
setupUi(this);
}
void ListDevices::updateDevices(OperationStack::Devices& devices)
void ListDevices::updateDevices(const OperationStack::Devices& devices)
{
listDevices().clear();
foreach(const Device * d, devices)
listDevices().addItem(new ListDeviceWidgetItem(*d));
for (const auto &d : devices)
listDevices().addItem(new ListDeviceWidgetItem(*d));
}
void ListDevices::on_m_ListDevices_itemSelectionChanged()

View File

@ -50,7 +50,7 @@ public:
}
bool setSelectedDevice(const QString& device_node);
void updateDevices(OperationStack::Devices& devices);
void updateDevices(const OperationStack::Devices& devices);
QListWidget& listDevices() {
Q_ASSERT(m_ListDevices);

View File

@ -40,7 +40,7 @@ void ListOperations::updateOperations(const OperationStack::Operations& ops)
{
listOperations().clear();
foreach(const Operation * op, ops) {
for (auto const &op : ops) {
QListWidgetItem* item = new QListWidgetItem(QIcon::fromTheme(op->iconName()).pixmap(IconSize(KIconLoader::Small)), op->description());
item->setToolTip(op->description());
listOperations().addItem(item);

View File

@ -44,7 +44,7 @@ ListPhysicalVolumes::ListPhysicalVolumes(QWidget* parent) :
void ListPhysicalVolumes::addPartitionList(const QStringList& partlist, bool checked)
{
foreach (const QString part, partlist) {
for (auto const &part : partlist) {
addPartition(part, checked);
}
}

View File

@ -734,7 +734,7 @@ void MainWindow::updateSeletedDeviceMenu()
devicesMenu->setEnabled(!operationStack().previewDevices().isEmpty());
foreach(const Device * d, operationStack().previewDevices()) {
foreach(auto const &d, operationStack().previewDevices()) {
QAction* action = new QAction(d->prettyName(), devicesMenu);
action->setCheckable(true);
action->setChecked(d->deviceNode() == pmWidget().selectedDevice()->deviceNode());
@ -752,8 +752,8 @@ void MainWindow::onSelectedDeviceMenuTriggered(bool)
if (action == nullptr || action->parent() != devicesMenu)
return;
foreach(QAction * entry, devicesMenu->findChildren<QAction*>())
entry->setChecked(entry == action);
foreach(auto &entry, devicesMenu->findChildren<QAction*>())
entry->setChecked(entry == action);
listDevices().setSelectedDevice(action->data().toString());
}
@ -762,8 +762,8 @@ void MainWindow::on_m_ListDevices_selectionChanged(const QString& device_node)
{
QMenu* devicesMenu = static_cast<QMenu*>(guiFactory()->container(QStringLiteral("selectedDevice"), this));
foreach(QAction * entry, devicesMenu->findChildren<QAction*>())
entry->setChecked(entry->data().toString() == device_node);
foreach(auto &entry, devicesMenu->findChildren<QAction*>())
entry->setChecked(entry->data().toString() == device_node);
}
void MainWindow::onRefreshDevices()
@ -783,8 +783,8 @@ void MainWindow::onApplyAllOperations()
{
QStringList opList;
foreach(const Operation * op, operationStack().operations())
opList.append(op->description());
foreach(const auto &op, operationStack().operations())
opList.append(op->description());
if (KMessageBox::warningContinueCancelList(this,
xi18nc("@info",
@ -1205,7 +1205,7 @@ static KLocalizedString checkSupportInNode(const PartitionNode* parent)
KLocalizedString rval;
foreach(const PartitionNode * node, parent->children()) {
for (auto const &node : parent->children()) {
const Partition* p = dynamic_cast<const Partition*>(node);
if (p == nullptr)
@ -1248,7 +1248,7 @@ void MainWindow::checkFileSystemSupport()
KLocalizedString supportList, supportInNode;
bool missingSupportTools = false;
foreach(const Device * d, operationStack().previewDevices()) {
foreach(auto const &d, operationStack().previewDevices()) {
supportInNode = checkSupportInNode(d->partitionTable());
if (!supportInNode.isEmpty() && !supportList.isEmpty()) {
missingSupportTools = true;

View File

@ -73,15 +73,16 @@ NewDialog::~NewDialog()
void NewDialog::setupDialog()
{
QStringList fsNames;
foreach (const FileSystem * fs, FileSystemFactory::map())
for (auto const &fs : FileSystemFactory::map()) {
if (fs->supportCreate() != FileSystem::cmdSupportNone &&
fs->type() != FileSystem::Extended &&
fs->type() != FileSystem::Luks)
fsNames.append(fs->name());
}
qSort(fsNames.begin(), fsNames.end(), caseInsensitiveLessThan);
foreach (const QString & fsName, fsNames)
foreach (auto const &fsName, fsNames)
dialogWidget().comboFileSystem().addItem(createFileSystemColor(FileSystem::typeForName(fsName), 8), fsName);
QString selected = FileSystem::nameForType(GuiHelpers::defaultFileSystem());

View File

@ -186,14 +186,15 @@ Partition* PartitionManagerWidget::selectedPartition()
return selectedDevice()->partitionTable()->findPartitionBySector(activePartition->firstSector(), PartitionRole(PartitionRole::Any));
}
void PartitionManagerWidget::setSelectedDevice(const QString& device_node)
void PartitionManagerWidget::setSelectedDevice(const QString& deviceNode)
{
QReadLocker lockDevices(&operationStack().lock());
foreach(Device * d, operationStack().previewDevices())
if (d->deviceNode() == device_node) {
setSelectedDevice(d);
return;
foreach(auto &d, operationStack().previewDevices()) {
if (d->deviceNode() == deviceNode) {
setSelectedDevice(d);
return;
}
}
setSelectedDevice(nullptr);
@ -266,10 +267,10 @@ void PartitionManagerWidget::updatePartitions()
treePartitions().addTopLevelItem(deviceItem);
if (selectedDevice()->partitionTable() != nullptr) {
foreach(const Partition * p, selectedDevice()->partitionTable()->children()) {
foreach(auto const &p, selectedDevice()->partitionTable()->children()) {
QTreeWidgetItem* item = createTreeWidgetItem(*p);
foreach(const Partition * child, p->children()) {
for (auto const &child : p->children()) {
QTreeWidgetItem* childItem = createTreeWidgetItem(*child);
item->addChild(childItem);
}

View File

@ -56,7 +56,7 @@ Q_SIGNALS:
public:
void setSelectedDevice(Device* d);
void setSelectedDevice(const QString& device_node);
void setSelectedDevice(const QString& deviceNode);
void onNewPartition();
void onResizePartition();

View File

@ -35,7 +35,7 @@ public:
m_PartWidget->setFileSystemColorCode(GuiHelpers::fileSystemColorCodesFromSettings());
MainWindow* mw = nullptr;
foreach( QWidget* widget, qApp->topLevelWidgets() )
foreach( auto &widget, qApp->topLevelWidgets() )
{
mw = qobject_cast< MainWindow* >( widget );
if ( mw )

View File

@ -51,7 +51,7 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
m_PartitionTable = ptable;
if (partitionTable() != nullptr) {
foreach(const Partition * p, partitionTable()->children()) {
for (auto const &p : partitionTable()->children()) {
PartWidget* w = new PartWidget(this, p);
w->setVisible(true);
w->setFileSystemColorCode(GuiHelpers::fileSystemColorCodesFromSettings());
@ -72,18 +72,18 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
PartWidget* PartTableWidget::activeWidget()
{
foreach(PartWidget * pw, findChildren<PartWidget*>())
if (pw->isActive())
return pw;
foreach(auto &pw, findChildren<PartWidget*>())
if (pw->isActive())
return pw;
return nullptr;
}
const PartWidget* PartTableWidget::activeWidget() const
{
foreach(const PartWidget * pw, findChildren<PartWidget*>())
if (pw->isActive())
return pw;
foreach(auto const &pw, findChildren<PartWidget*>())
if (pw->isActive())
return pw;
return nullptr;
}
@ -115,10 +115,11 @@ void PartTableWidget::setActivePartition(const Partition* p)
if (isReadOnly())
return;
foreach(PartWidget * pw, findChildren<PartWidget*>())
if (pw->partition() == p) {
setActiveWidget(pw);
return;
foreach(auto &pw, findChildren<PartWidget*>()) {
if (pw->partition() == p) {
setActiveWidget(pw);
return;
}
}
setActiveWidget(nullptr);
@ -135,7 +136,7 @@ void PartTableWidget::clear()
// that its event handler is currently running. therefore, do not delete
// the part widgets here but schedule them for deletion once the app
// returns to the main loop (and the event handler has finished).
foreach(PartWidget * p, childWidgets()) {
foreach(auto &p, childWidgets()) {
p->setVisible(false);
p->deleteLater();
p->setParent(nullptr);

View File

@ -39,7 +39,7 @@
/** Creates a new ResizeVolumeDialog
@param parent pointer to the parent widget
@param d the Device to show properties for
@param dev the Device to show properties for
*/
ResizeVolumeDialog::ResizeVolumeDialog(QWidget* parent, QString& vgname, QStringList& partlist, VolumeManagerDevice& dev) :
VolumeDialog(parent, vgname, partlist),
@ -58,7 +58,7 @@ void ResizeVolumeDialog::setupDialog()
{
if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
dialogWidget().listPV().addPartitionList(device().deviceNodeList(), true);
foreach (QString pvpath, FS::lvm2_pv::getFreePV()) {
for (auto const &pvpath : FS::lvm2_pv::getFreePV()) {
if (!LvmDevice::s_DirtyPVs.contains(pvpath)) {
dialogWidget().listPV().addPartition(pvpath, false);
}

View File

@ -337,7 +337,7 @@ void SizeDialogBase::onAlignToggled(bool align)
dialogWidget().spinCapacity().setSingleStep(capacityStep);
// if align is on, turn off keyboard tracking for all spin boxes to avoid the two clashing
foreach(QAbstractSpinBox * box, dialogWidget().findChildren<QAbstractSpinBox*>() +
foreach(auto &box, dialogWidget().findChildren<QAbstractSpinBox*>() +
detailsWidget().findChildren<QAbstractSpinBox*>())
box->setKeyboardTracking(!align);

View File

@ -115,7 +115,7 @@ void SmartDialog::setupDialog()
const QString st = QStringLiteral("<span style=\"font-family:%1;font-size:%2;\">").arg(f.family()).arg(size);
foreach(const SmartAttribute & a, device().smartStatus().attributes()) {
for (auto const &a : device().smartStatus().attributes()) {
QTreeWidgetItem* item = new QTreeWidgetItem(
QStringList()
<< QLocale().toString(a.id())
@ -180,7 +180,7 @@ QString SmartDialog::toHtml() const
s << "<table>\n";
foreach(const SmartAttribute & a, device().smartStatus().attributes()) {
for (auto const &a : device().smartStatus().attributes()) {
s << "<tr>\n";
s << "<td>" << QLocale().toString(a.id()) << "</td>\n"