summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <[email protected]>2018-02-06 22:41:37 -0200
committerDaniel Nicoletti <[email protected]>2018-02-06 22:41:37 -0200
commita7f1ca98ce53450ddfb758c857c48807b3a913c5 (patch)
tree0e6679f78159f47da13a23f9ff9e5132ba99499c
parent8771d213301bad628e60895e4b56649a01e9d352 (diff)
A few code improvements on configure-printerPM_0_4_0
-rw-r--r--configure-printer/ConfigurePrinterInterface.cpp8
-rw-r--r--configure-printer/PrinterBehavior.cpp24
-rw-r--r--configure-printer/PrinterOptions.cpp23
-rw-r--r--configure-printer/main.cpp2
4 files changed, 30 insertions, 27 deletions
diff --git a/configure-printer/ConfigurePrinterInterface.cpp b/configure-printer/ConfigurePrinterInterface.cpp
index 22f0d68..696a86d 100644
--- a/configure-printer/ConfigurePrinterInterface.cpp
+++ b/configure-printer/ConfigurePrinterInterface.cpp
@@ -72,10 +72,10 @@ void ConfigurePrinterInterface::ConfigurePrinter(const QString &destName)
bool found = false;
KCupsPrinter printer;
- KCupsPrinters printers = request->printers();
- for (int i = 0; i < printers.size(); i++) {
- if (printers.at(i).name() == destName) {
- printer = printers.at(i);
+ const KCupsPrinters printers = request->printers();
+ for (const KCupsPrinter &p : printers) {
+ if (p.name() == destName) {
+ printer = p;
found = true;
break;
}
diff --git a/configure-printer/PrinterBehavior.cpp b/configure-printer/PrinterBehavior.cpp
index 85208d0..b4807f9 100644
--- a/configure-printer/PrinterBehavior.cpp
+++ b/configure-printer/PrinterBehavior.cpp
@@ -60,7 +60,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
for (const QString &value : errorPolicySupported) {
ui->errorPolicyCB->addItem(errorPolicyString(value), value);
}
- QStringList errorPolicy = printer.errorPolicy();
+ const QStringList errorPolicy = printer.errorPolicy();
if (!errorPolicy.isEmpty()) {
defaultChoice = ui->errorPolicyCB->findData(errorPolicy.first());
ui->errorPolicyCB->setCurrentIndex(defaultChoice);
@@ -72,7 +72,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
for (const QString &value : opPolicySupported) {
ui->operationPolicyCB->addItem(operationPolicyString(value), value);
}
- QStringList operationPolicy = printer.opPolicy();
+ const QStringList operationPolicy = printer.opPolicy();
if (!errorPolicy.isEmpty()) {
defaultChoice = ui->operationPolicyCB->findData(operationPolicy.first());
ui->operationPolicyCB->setCurrentIndex(defaultChoice);
@@ -86,7 +86,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
ui->startingBannerCB->addItem(jobSheetsString(value), value);
ui->endingBannerCB->addItem(jobSheetsString(value), value);
}
- QStringList bannerPolicy = printer.jobSheetsDefault();
+ const QStringList bannerPolicy = printer.jobSheetsDefault();
if (bannerPolicy.size() == 2) {
defaultChoice = ui->startingBannerCB->findData(bannerPolicy.at(0));
ui->startingBannerCB->setCurrentIndex(defaultChoice);
@@ -147,11 +147,10 @@ void PrinterBehavior::userListChanged()
ui-> usersELB->setEnabled(true);
}
- QStringList currentList, defaultList;
- currentList = ui->usersELB->items();
+ QStringList currentList = ui->usersELB->items();
// sort the list so we can be sure it's different
currentList.sort();
- defaultList = ui->usersELB->property("defaultList").value<QStringList>();
+ const QStringList defaultList = ui->usersELB->property("defaultList").toStringList();
bool isDifferent = currentList != defaultList;
if (isDifferent == false && currentList.isEmpty() == false) {
@@ -175,23 +174,26 @@ void PrinterBehavior::currentIndexChangedCB(int index)
{
auto comboBox = qobject_cast<QComboBox*>(sender());
bool isDifferent = comboBox->property("defaultChoice").toInt() != index;
+ qCDebug(PM_CONFIGURE_PRINTER) << Q_FUNC_INFO << "isDifferent" << isDifferent << this;
if (isDifferent != comboBox->property("different").toBool()) {
// it's different from the last time so add or remove changes
isDifferent ? m_changes++ : m_changes--;
comboBox->setProperty("different", isDifferent);
+ qCDebug(PM_CONFIGURE_PRINTER) << Q_FUNC_INFO << m_changes << this;
+
emit changed(m_changes);
}
- QString attribute = comboBox->property("AttributeName").toString();
+ const QString attribute = comboBox->property("AttributeName").toString();
QVariant value;
// job-sheets-default has always two values
if (attribute == QLatin1String("job-sheets-default")) {
- QStringList values;
- values << ui->startingBannerCB->itemData(ui->startingBannerCB->currentIndex()).toString();
- values << ui->endingBannerCB->itemData(ui->endingBannerCB->currentIndex()).toString();
- value = values;
+ value = QStringList({
+ ui->startingBannerCB->itemData(ui->startingBannerCB->currentIndex()).toString(),
+ ui->endingBannerCB->itemData(ui->endingBannerCB->currentIndex()).toString()
+ });
} else {
value = comboBox->itemData(index).toString();
}
diff --git a/configure-printer/PrinterOptions.cpp b/configure-printer/PrinterOptions.cpp
index 44e9f76..43e5301 100644
--- a/configure-printer/PrinterOptions.cpp
+++ b/configure-printer/PrinterOptions.cpp
@@ -249,8 +249,8 @@ QWidget* PrinterOptions::pickBoolean(ppd_option_t *option, const QString &keywor
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
- QString choiceName = m_codec->toUnicode(choice->choice);
- QString cText = m_codec->toUnicode(choice->text);
+ const QString choiceName = m_codec->toUnicode(choice->choice);
+ const QString cText = m_codec->toUnicode(choice->text);
auto button = new QRadioButton(cText, widget);
button->setChecked(defChoice == choiceName);
@@ -307,13 +307,13 @@ QWidget* PrinterOptions::pickMany(ppd_option_t *option, const QString &keyword,
int i;
ppd_choice_t *choice;
- QString oDefChoice = m_codec->toUnicode(option->defchoice);
+ const QString oDefChoice = m_codec->toUnicode(option->defchoice);
// Iterate over the choices in the option
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
- QString cName = m_codec->toUnicode(choice->choice);
- QString cText = m_codec->toUnicode(choice->text);
+ const QString cName = m_codec->toUnicode(choice->choice);
+ const QString cText = m_codec->toUnicode(choice->text);
auto item = new QStandardItem(cText);
item->setData(cName);
@@ -333,14 +333,14 @@ QWidget* PrinterOptions::pickOne(ppd_option_t *option, const QString &keyword, Q
{
int i;
ppd_choice_t *choice;
- QString defChoice = m_codec->toUnicode(option->defchoice);
+ const QString defChoice = m_codec->toUnicode(option->defchoice);
auto comboBox = new QComboBox(parent);
// Iterate over the choices in the option
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
- QString cName = m_codec->toUnicode(choice->choice);
- QString cText = m_codec->toUnicode(choice->text);
+ const QString cName = m_codec->toUnicode(choice->choice);
+ const QString cText = m_codec->toUnicode(choice->text);
comboBox->addItem(cText, cName);
}
@@ -400,9 +400,10 @@ PrinterOptions::~PrinterOptions()
const char * /* O - Value of variable */
PrinterOptions::getVariable(const char *name) const /* I - Name of variable */
{
- QString keyword = m_codec->toUnicode(name);
- if (m_customValues.contains(keyword)) {
- QString value = m_customValues[keyword]->property("currentChoice").toString();
+ const QString keyword = m_codec->toUnicode(name);
+ auto it = m_customValues.constFind(keyword);
+ if (it != m_customValues.constEnd()) {
+ const QString value = it.value()->property("currentChoice").toString();
return m_codec->fromUnicode(value).constData();
} else {
return NULL;
diff --git a/configure-printer/main.cpp b/configure-printer/main.cpp
index 8ad8a00..9894837 100644
--- a/configure-printer/main.cpp
+++ b/configure-printer/main.cpp
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
app.configurePrinter(printerName);
} else {
qCWarning(PM_CONFIGURE_PRINTER) << "No printer was specified";
- return 1;
+ parser.showHelp(1);
}
return app.exec();