From 8e40050efed8bc5bf262123c59a36f6a47594bab Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 4 Jul 2017 13:04:59 +0200 Subject: uic: Don't clear and readd combobox items in retranslateUi Task-number: QTBUG-61778 Change-Id: If7a15ef69fcfe459f177ff8b671f53a6022ab335 Reviewed-by: Friedemann Kleint Reviewed-by: Qt CI Bot --- src/tools/uic/cpp/cppwriteinitialization.cpp | 62 +++++++--------------------- 1 file changed, 16 insertions(+), 46 deletions(-) (limited to 'src/tools') diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp index ad9e040824..cc7e8fc9e3 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.cpp +++ b/src/tools/uic/cpp/cppwriteinitialization.cpp @@ -1899,63 +1899,34 @@ QString WriteInitialization::pixCall(const QString &t, const QString &text) cons void WriteInitialization::initializeComboBox(DomWidget *w) { const QString varName = m_driver->findOrInsertWidget(w); - const QString className = w->attributeClass(); const auto &items = w->elementItem(); if (items.isEmpty()) return; - // If possible use qcombobox's addItems() which is much faster then a bunch of addItem() calls - bool makeStringListCall = true; - bool translatable = false; - QStringList list; - for (int i=0; ielementProperty()); const DomProperty *text = properties.value(QLatin1String("text")); - const DomProperty *pixmap = properties.value(QLatin1String("icon")); - bool needsTr = needsTranslation(text->elementString()); - if (pixmap != 0 || (i > 0 && translatable != needsTr)) { - makeStringListCall = false; - break; - } - translatable = needsTr; - list.append(autoTrCall(text->elementString())); // fix me here - } + const DomProperty *icon = properties.value(QLatin1String("icon")); - if (makeStringListCall) { - QTextStream &o = translatable ? m_refreshOut : m_output; - if (translatable) - o << m_indent << varName << "->clear();\n"; - o << m_indent << varName << "->insertItems(0, QStringList()" << '\n'; - for (int i = 0; i < list.size(); ++i) - o << m_indent << " << " << list.at(i) << "\n"; - o << m_indent << ");\n"; - } else { - for (int i = 0; i < items.size(); ++i) { - const DomItem *item = items.at(i); - const DomPropertyMap properties = propertyMap(item->elementProperty()); - const DomProperty *text = properties.value(QLatin1String("text")); - const DomProperty *icon = properties.value(QLatin1String("icon")); - - QString iconValue; - if (icon) - iconValue = iconCall(icon); - - m_output << m_indent << varName << "->addItem("; - if (icon) - m_output << iconValue << ", "; - - if (needsTranslation(text->elementString())) { - m_output << "QString());\n"; - m_refreshOut << m_indent << varName << "->setItemText(" << i << ", " << trCall(text->elementString()) << ");\n"; - } else { - m_output << noTrCall(text->elementString()) << ");\n"; - } + QString iconValue; + if (icon) + iconValue = iconCall(icon); + + m_output << m_indent << varName << "->addItem("; + if (icon) + m_output << iconValue << ", "; + + if (needsTranslation(text->elementString())) { + m_output << "QString());\n"; + m_refreshOut << m_indent << varName << "->setItemText(" << i << ", " << trCall(text->elementString()) << ");\n"; + } else { + m_output << noTrCall(text->elementString()) << ");\n"; } - m_refreshOut << "\n"; } + m_refreshOut << "\n"; } QString WriteInitialization::disableSorting(DomWidget *w, const QString &varName) @@ -2090,7 +2061,6 @@ void WriteInitialization::addCommonInitializers(Item *item, void WriteInitialization::initializeListWidget(DomWidget *w) { const QString varName = m_driver->findOrInsertWidget(w); - const QString className = w->attributeClass(); const auto &items = w->elementItem(); -- cgit v1.2.3