Commit da015547 authored by Daniel Nicoletti's avatar Daniel Nicoletti

Make use of new for range loops

parent 0c0bce67
......@@ -310,11 +310,9 @@ QStandardItem *DevicesModel::createItem(const QString &device_class,
void DevicesModel::getGroupedDevicesSuccess(const QDBusMessage &message)
{
if (message.type() == QDBusMessage::ReplyMessage && message.arguments().size() == 1) {
QDBusArgument argument;
argument = message.arguments().first().value<QDBusArgument>();
QList<QStringList> groupeDevices;
groupeDevices = qdbus_cast<QList<QStringList> >(argument);
foreach (const QStringList &list, groupeDevices) {
const auto argument = message.arguments().first().value<QDBusArgument>();
const auto groupeDevices = qdbus_cast<QList<QStringList> >(argument);
for (const QStringList &list : groupeDevices) {
if (list.isEmpty()) {
continue;
}
......
......@@ -101,7 +101,7 @@ void PageChoosePPD::setValues(const QVariantHash &args)
}
// Get the make from the device id
foreach (const QString &pair, deviceId.split(QLatin1Char(';'))) {
for (const QString &pair : deviceId.split(QLatin1Char(';'))) {
if (pair.startsWith(QStringLiteral("MFG:"))) {
make = pair.section(QLatin1Char(':'), 1);
break;
......@@ -110,7 +110,7 @@ void PageChoosePPD::setValues(const QVariantHash &args)
if (makeAndModel.isEmpty()) {
// Get the model from the device id
foreach (const QString &pair, deviceId.split(QLatin1Char(';'))) {
for (const QString &pair : deviceId.split(QLatin1Char(';'))) {
if (pair.startsWith(QStringLiteral("MDL:"))) {
// Build the make and model string
if (make.isNull()) {
......
......@@ -168,13 +168,14 @@ void PageDestinations::deviceChanged()
ui->connectionsGB->setVisible(false);
} else if (uris.type() == QVariant::StringList) {
ui->connectionsCB->clear();
foreach (const QString &uri, uris.toStringList()) {
for (const QString &uri : uris.toStringList()) {
ui->connectionsCB->addItem(uriText(uri), uri);
}
ui->connectionsGB->setVisible(true);
} else {
ui->connectionsCB->clear();
foreach (const KCupsPrinter &printer, uris.value<KCupsPrinters>()) {
const auto printers = uris.value<KCupsPrinters>();
for (const KCupsPrinter &printer : printers) {
ui->connectionsCB->addItem(printer.name(), qVariantFromValue(printer));
}
ui->connectionsGB->setVisible(true);
......
......@@ -57,7 +57,8 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
{
int defaultChoice;
ui->errorPolicyCB->clear();
foreach (const QString &value, printer.errorPolicySupported()) {
const QStringList errorPolicySupported = printer.errorPolicySupported();
for (const QString &value : errorPolicySupported) {
ui->errorPolicyCB->addItem(errorPolicyString(value), value);
}
QStringList errorPolicy = printer.errorPolicy();
......@@ -68,7 +69,8 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
}
ui->operationPolicyCB->clear();
foreach (const QString &value, printer.opPolicySupported()) {
const QStringList opPolicySupported = printer.opPolicySupported();
for (const QString &value : opPolicySupported) {
ui->operationPolicyCB->addItem(operationPolicyString(value), value);
}
QStringList operationPolicy = printer.opPolicy();
......@@ -80,7 +82,8 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
ui->startingBannerCB->clear();
ui->endingBannerCB->clear();
foreach (const QString &value, printer.jobSheetsSupported()) {
const QStringList jobSheetsSupported = printer.jobSheetsSupported();
for (const QString &value : jobSheetsSupported) {
ui->startingBannerCB->addItem(jobSheetsString(value), value);
ui->endingBannerCB->addItem(jobSheetsString(value), value);
}
......
......@@ -89,11 +89,11 @@ void ClassListWidget::loadFinished(KCupsRequest *request)
m_busySeq->stop(); // Stop spining
KCupsPrinters printers = m_request->printers();
m_request->deleteLater();
const KCupsPrinters printers = request->printers();
request->deleteLater();
m_request = 0;
foreach (const KCupsPrinter &printer, printers) {
for (const KCupsPrinter &printer : printers) {
QString destName = printer.name();
if (destName != m_printerName) {
auto item = new QStandardItem;
......
......@@ -451,7 +451,7 @@ QMimeData* JobModel::mimeData(const QModelIndexList &indexes) const
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (const QModelIndex &index, indexes) {
for (const QModelIndex &index : indexes) {
if (index.isValid() && index.column() == 0) {
// serialize the jobId and fromDestName
stream << data(index, RoleJobId).toInt()
......
......@@ -152,10 +152,9 @@ void KCupsRequest::getPrinters(QStringList attributes, int mask)
request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE_MASK, mask);
}
ReturnArguments ret;
ret = m_connection->request(request, IPP_TAG_PRINTER);
const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER);
foreach (const QVariantHash &arguments, ret) {
for (const QVariantHash &arguments : ret) {
m_printers << KCupsPrinter(arguments);
}
......@@ -175,10 +174,9 @@ void KCupsRequest::getPrinterAttributes(const QString &printerName, bool isClass
request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE, CUPS_PRINTER_LOCAL);
request.addStringList(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_REQUESTED_ATTRIBUTES, attributes);
ReturnArguments ret;
ret = m_connection->request(request, IPP_TAG_PRINTER);
const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER);
foreach (const QVariantHash &arguments, ret) {
for (const QVariantHash &arguments : ret) {
// Inject the printer name back to the arguments hash
QVariantHash args = arguments;
args[KCUPS_PRINTER_NAME] = printerName;
......@@ -210,10 +208,9 @@ void KCupsRequest::getJobs(const QString &printerName, bool myJobs, int whichJob
request.addString(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_WHICH_JOBS, "all");
}
ReturnArguments ret;
ret = m_connection->request(request, IPP_TAG_JOB);
const ReturnArguments ret = m_connection->request(request, IPP_TAG_JOB);
foreach (const QVariantHash &arguments, ret) {
for (const QVariantHash &arguments : ret) {
m_jobs << KCupsJob(arguments);
}
......@@ -235,10 +232,9 @@ void KCupsRequest::getJobAttributes(int jobId, const QString &printerUri, QStrin
request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId);
ReturnArguments ret;
ret = m_connection->request(request, IPP_TAG_PRINTER);
const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER);
foreach (const QVariantHash &arguments, ret) {
for (const QVariantHash &arguments : ret) {
m_jobs << KCupsJob(arguments);
}
......
......@@ -223,7 +223,8 @@ void KIppRequestPrivate::addRawRequestsToIpp(ipp_t *ipp) const
// sort the values as CUPS requires it
qSort(rawRequests.begin(), rawRequests.end(), rawRequestGroupLessThan);
foreach (const KCupsRawRequest &request, rawRequests) {
const QList<KCupsRawRequest> &requests = rawRequests;
for (const KCupsRawRequest &request :requests) {
switch (request.value.type()) {
case QVariant::Bool:
ippAddBoolean(ipp,
......
......@@ -35,9 +35,9 @@ void PPDModel::setPPDs(const QList<QVariantHash> &ppds, const DriverMatchList &d
clear();
QStandardItem *recommended = 0;
foreach (const DriverMatch &driver, driverMatch) {
for (const DriverMatch &driver : driverMatch) {
// Find the matched PPD on the PPDs list
foreach (const QVariantHash &ppd, ppds) {
for (const QVariantHash &ppd : ppds) {
if (ppd["ppd-name"].toString() == driver.ppd) {
// Create the PPD
QStandardItem *ppdItem = createPPDItem(ppd, true);
......@@ -54,7 +54,7 @@ void PPDModel::setPPDs(const QList<QVariantHash> &ppds, const DriverMatchList &d
}
}
foreach (const QVariantHash &ppd, ppds) {
for (const QVariantHash &ppd : ppds) {
// Find or create the PPD parent (printer Make)
QStandardItem *makeItem = findCreateMake(ppd["ppd-make"].toString());
......
......@@ -437,7 +437,8 @@ void PrinterModel::insertUpdatePrinter(const QString &text,
void PrinterModel::insertUpdatePrinterFinished(KCupsRequest *request)
{
if (!request->hasError()) {
foreach (const KCupsPrinter &printer, request->printers()) {
const KCupsPrinters printers = request->printers();
for (const KCupsPrinter &printer : printers) {
// If there is a printer and it's not the current one add it
// as a new destination
int dest_row = destRow(printer.name());
......
......@@ -224,9 +224,10 @@ void SelectMakeModel::getBestDriversFinished(const QDBusMessage &message)
{
if (message.type() == QDBusMessage::ReplyMessage && message.arguments().size() == 1) {
QDBusArgument argument = message.arguments().first().value<QDBusArgument>();
m_driverMatchList = qdbus_cast<DriverMatchList>(argument);
const DriverMatchList driverMatchList = qdbus_cast<DriverMatchList>(argument);
m_driverMatchList = driverMatchList;
m_hasRecommended = !m_driverMatchList.isEmpty();
foreach (const DriverMatch &driverMatch, m_driverMatchList) {
for (const DriverMatch &driverMatch : driverMatchList) {
qCDebug(LIBKCUPS) << driverMatch.ppd << driverMatch.match;
}
} else {
......@@ -277,8 +278,8 @@ void SelectMakeModel::selectFirstMake()
void SelectMakeModel::selectMakeModelPPD()
{
QList<QStandardItem*> makes = m_sourceModel->findItems(m_make);
foreach (QStandardItem *make, makes) {
const QList<QStandardItem*> makes = m_sourceModel->findItems(m_make);
for (QStandardItem *make : makes) {
// Check if the item is in this make
for (int i = 0; i < make->rowCount(); i++) {
if (make->child(i)->data(PPDModel::PPDMakeAndModel).toString() == m_makeAndModel) {
......
......@@ -43,7 +43,7 @@ void PrintQueue::showQueues(const QStringList &queues, const QString &cwd)
Q_UNUSED(cwd)
if (!queues.isEmpty()) {
foreach (const QString & queue, queues) {
for (const QString &queue : queues) {
showQueue(queue);
}
} else {
......
......@@ -270,7 +270,8 @@ void PrintQueueUi::showContextMenu(const QPoint &point)
selection = m_proxyModel->mapSelectionToSource(ui->jobsView->selectionModel()->selection());
// if the selection is empty the user clicked on an empty space
if (!selection.indexes().isEmpty()) {
foreach (const QModelIndex &index, selection.indexes()) {
const QModelIndexList indexes = selection.indexes();
for (const QModelIndex &index : indexes) {
if (index.column() == 0 && index.flags() & Qt::ItemIsDragEnabled) {
// Found a move to item
moveTo = true;
......@@ -294,10 +295,10 @@ void PrintQueueUi::showContextMenu(const QPoint &point)
if (!request) {
return;
}
KCupsPrinters printers = request->printers();
const KCupsPrinters printers = request->printers();
request->deleteLater();
foreach (const KCupsPrinter &printer, printers) {
for (const KCupsPrinter &printer : printers) {
// If there is a printer and it's not the current one add it
// as a new destination
if (printer.name() != m_destName) {
......@@ -437,7 +438,8 @@ void PrintQueueUi::updateButtons()
selection = m_proxyModel->mapSelectionToSource(ui->jobsView->selectionModel()->selection());
// enable or disable the job action buttons if something is selected
if (!selection.indexes().isEmpty()) {
foreach (const QModelIndex &index, selection.indexes()) {
const QModelIndexList indexes = selection.indexes();
for (const QModelIndex &index : indexes) {
if (index.column() == 0) {
switch (static_cast<ipp_jstate_t>(index.data(JobModel::RoleJobState).toInt())) {
case IPP_JOB_CANCELED :
......@@ -472,7 +474,8 @@ void PrintQueueUi::modifyJob(int action, const QString &destName)
QItemSelection selection;
// we need to map the selection to source to get the real indexes
selection = m_proxyModel->mapSelectionToSource(ui->jobsView->selectionModel()->selection());
foreach (const QModelIndex &index, selection.indexes()) {
const QModelIndexList indexes = selection.indexes();
for (const QModelIndex &index : indexes) {
if (index.column() == 0) {
KCupsRequest *request;
request = m_model->modifyJob(index.row(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment