summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-29 10:04:55 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-02 10:44:23 +0000
commit04e76ec857efea1c28322cd44cb04f15134944fe (patch)
tree34b51313e0978b9d13600110d4eb835cad97f663
parentbe94e009ae5d89d97456f5d1389d2a017dd2e69e (diff)
QUnixPrintWidget: fix some poor uses of the QComboBox API
- populate the widget with addItems(QStringList) instead of looping over addItem(QString) - Use findText() instead of looping over itemText(int). QComboBox::findText() delegates searching to the model (via QAbstractItemModel::match()), so is potentially much faster. I say potentially, because match() isn't properly reimplemented in most models, yet. But that is something to fix in the models. Change-Id: I6e52cf5af810ab7869c0270504a241868a5ca281 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
index 9633032a0f..c6c84ca701 100644
--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -661,18 +661,16 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *
widget.setupUi(parent);
int currentPrinterIndex = 0;
- QStringList printers;
- QString defaultPrinter;
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
- printers = ps->availablePrintDeviceIds();
- defaultPrinter = ps->defaultPrintDeviceId();
- }
+ const QStringList printers = ps->availablePrintDeviceIds();
+ const QString defaultPrinter = ps->defaultPrintDeviceId();
+
+ widget.printers->addItems(printers);
- for (int i = 0; i < printers.size(); ++i) {
- widget.printers->addItem(printers.at(i));
- if (printers.at(i) == defaultPrinter)
- currentPrinterIndex = i;
+ const int idx = printers.indexOf(defaultPrinter);
+ if (idx >= 0)
+ currentPrinterIndex = idx;
}
widget.properties->setEnabled(true);
@@ -827,12 +825,9 @@ void QUnixPrintWidgetPrivate::applyPrinterProperties()
widget.filename->setText( printer->outputFileName() );
QString printerName = printer->printerName();
if (!printerName.isEmpty()) {
- for (int i = 0; i < widget.printers->count(); ++i) {
- if (widget.printers->itemText(i) == printerName) {
- widget.printers->setCurrentIndex(i);
- break;
- }
- }
+ const int i = widget.printers->findText(printerName);
+ if (i >= 0)
+ widget.printers->setCurrentIndex(i);
}
// PDF printer not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget