uic: Accept an -idbased argument

When we want to use qtTrId function instead QApplication::translate in
generated files it's not possible to use custom function with presented by
the --tr argument due to signature difference between qtTrId and
QApplication::translate function.

With this argument present, uic will generate qtTrId function with second
argument empty. When used together with --tr parameter it will use
presented function instead.

Change-Id: I0d986e4ea25ce58917fd9a2866b1eac0a4671502
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
This commit is contained in:
Pavel Geiger 2016-01-05 13:05:47 +01:00 committed by Jarek Kobus
parent eea8494fa0
commit eedf16c96f
6 changed files with 510 additions and 8 deletions

View File

@ -2309,18 +2309,25 @@ QString WriteInitialization::trCall(const QString &str, const QString &commentHi
const QString comment = commentHint.isEmpty() ? QString(QLatin1Char('0')) : fixString(commentHint, m_dindent);
if (m_option.translateFunction.isEmpty()) {
result = QLatin1String("QApplication::translate(\"");
result += m_generatedClass;
result += QLatin1Char('"');
result += QLatin1String(", ");
if (m_option.idBased) {
result = QLatin1String("qtTrId(");
} else {
result = QLatin1String("QApplication::translate(\"");
result += m_generatedClass;
result += QLatin1Char('"');
result += QLatin1String(", ");
}
} else {
result = m_option.translateFunction;
result += QLatin1Char('(');
}
result += fixString(str, m_dindent);
result += QLatin1String(", ");
result += comment;
if (!m_option.idBased) {
result += QLatin1String(", ");
result += comment;
}
result += QLatin1Char(')');
return result;

View File

@ -95,6 +95,10 @@ int runUic(int argc, char *argv[])
generatorOption.setValueName(QStringLiteral("java|cpp"));
parser.addOption(generatorOption);
QCommandLineOption idBasedOption(QStringLiteral("idbased"));
idBasedOption.setDescription(QStringLiteral("Use id based function for i18n"));
parser.addOption(idBasedOption);
parser.addPositionalArgument(QStringLiteral("[uifile]"), QStringLiteral("Input file (*.ui), otherwise stdin."));
parser.process(app);
@ -103,6 +107,7 @@ int runUic(int argc, char *argv[])
driver.option().outputFile = parser.value(outputOption);
driver.option().headerProtection = !parser.isSet(noProtOption);
driver.option().implicitIncludes = !parser.isSet(noImplicitIncludesOption);
driver.option().idBased = parser.isSet(idBasedOption);
driver.option().postfix = parser.value(postfixOption);
driver.option().translateFunction = parser.value(translateOption);
driver.option().includeFile = parser.value(includeOption);

View File

@ -51,6 +51,7 @@ struct Option
unsigned int extractImages : 1;
unsigned int limitXPM_LineLength : 1;
unsigned int implicitIncludes: 1;
unsigned int idBased: 1;
Generator generator;
QString inputFile;
@ -76,6 +77,7 @@ struct Option
extractImages(0),
limitXPM_LineLength(0),
implicitIncludes(1),
idBased(0),
generator(CppGenerator),
prefix(QLatin1String("Ui_"))
{ indent.fill(QLatin1Char(' '), 4); }

View File

@ -0,0 +1,228 @@
<ui version="4.0" >
<class>RemoteControlClass</class>
<widget class="QMainWindow" name="RemoteControlClass" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>344</width>
<height>364</height>
</rect>
</property>
<property name="windowTitle" >
<string>RemoteControl</string>
</property>
<widget class="QWidget" name="centralWidget" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Start URL:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="startUrlLineEdit" />
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="launchButton" >
<property name="text" >
<string>Launch Qt HelpViewer</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>101</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" >
<size>
<width>113</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="3" >
<widget class="QGroupBox" name="actionGroupBox" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="title" >
<string>Actions</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Search in Index:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="indexLineEdit" />
</item>
<item>
<widget class="QToolButton" name="indexButton" >
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>Identifier:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="identifierLineEdit" />
</item>
<item>
<widget class="QToolButton" name="identifierButton" >
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Show URL:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="urlLineEdit" />
</item>
<item>
<widget class="QToolButton" name="urlButton" >
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1" >
<widget class="QPushButton" name="syncContentsButton" >
<property name="text" >
<string>Sync Contents</string>
</property>
</widget>
</item>
<item row="3" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>81</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3" >
<widget class="QCheckBox" name="contentsCheckBox" >
<property name="text" >
<string>Show Contents</string>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QCheckBox" name="indexCheckBox" >
<property name="text" >
<string>Show Index</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3" >
<widget class="QCheckBox" name="bookmarksCheckBox" >
<property name="text" >
<string>Show Bookmarks</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>344</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile" >
<property name="title" >
<string>File</string>
</property>
<addaction name="actionQuit" />
</widget>
<addaction name="menuFile" />
</widget>
<widget class="QStatusBar" name="statusBar" />
<action name="actionQuit" >
<property name="text" >
<string>Quit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11" />
<resources>
<include location="remotecontrol.qrc" />
</resources>
<connections/>
</ui>

View File

@ -0,0 +1,252 @@
/********************************************************************************
** Form generated from reading UI file 'qttrid.ui'
**
** Created by: Qt User Interface Compiler version 5.5.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef QTTRID_H
#define QTTRID_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolButton>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_RemoteControlClass
{
public:
QAction *actionQuit;
QWidget *centralWidget;
QGridLayout *gridLayout;
QLabel *label;
QLineEdit *startUrlLineEdit;
QPushButton *launchButton;
QSpacerItem *spacerItem;
QSpacerItem *spacerItem1;
QGroupBox *actionGroupBox;
QGridLayout *gridLayout1;
QLabel *label_2;
QHBoxLayout *hboxLayout;
QLineEdit *indexLineEdit;
QToolButton *indexButton;
QLabel *label_4;
QHBoxLayout *hboxLayout1;
QLineEdit *identifierLineEdit;
QToolButton *identifierButton;
QLabel *label_3;
QHBoxLayout *hboxLayout2;
QLineEdit *urlLineEdit;
QToolButton *urlButton;
QPushButton *syncContentsButton;
QSpacerItem *spacerItem2;
QCheckBox *contentsCheckBox;
QCheckBox *indexCheckBox;
QCheckBox *bookmarksCheckBox;
QMenuBar *menuBar;
QMenu *menuFile;
QStatusBar *statusBar;
void setupUi(QMainWindow *RemoteControlClass)
{
if (RemoteControlClass->objectName().isEmpty())
RemoteControlClass->setObjectName(QStringLiteral("RemoteControlClass"));
RemoteControlClass->resize(344, 364);
actionQuit = new QAction(RemoteControlClass);
actionQuit->setObjectName(QStringLiteral("actionQuit"));
centralWidget = new QWidget(RemoteControlClass);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
label = new QLabel(centralWidget);
label->setObjectName(QStringLiteral("label"));
gridLayout->addWidget(label, 0, 0, 1, 1);
startUrlLineEdit = new QLineEdit(centralWidget);
startUrlLineEdit->setObjectName(QStringLiteral("startUrlLineEdit"));
gridLayout->addWidget(startUrlLineEdit, 0, 1, 1, 2);
launchButton = new QPushButton(centralWidget);
launchButton->setObjectName(QStringLiteral("launchButton"));
gridLayout->addWidget(launchButton, 1, 1, 1, 1);
spacerItem = new QSpacerItem(101, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(spacerItem, 1, 2, 1, 1);
spacerItem1 = new QSpacerItem(113, 16, QSizePolicy::Minimum, QSizePolicy::Fixed);
gridLayout->addItem(spacerItem1, 2, 1, 1, 1);
actionGroupBox = new QGroupBox(centralWidget);
actionGroupBox->setObjectName(QStringLiteral("actionGroupBox"));
actionGroupBox->setEnabled(false);
gridLayout1 = new QGridLayout(actionGroupBox);
gridLayout1->setSpacing(6);
gridLayout1->setContentsMargins(11, 11, 11, 11);
gridLayout1->setObjectName(QStringLiteral("gridLayout1"));
label_2 = new QLabel(actionGroupBox);
label_2->setObjectName(QStringLiteral("label_2"));
gridLayout1->addWidget(label_2, 0, 0, 1, 1);
hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(0);
hboxLayout->setObjectName(QStringLiteral("hboxLayout"));
indexLineEdit = new QLineEdit(actionGroupBox);
indexLineEdit->setObjectName(QStringLiteral("indexLineEdit"));
hboxLayout->addWidget(indexLineEdit);
indexButton = new QToolButton(actionGroupBox);
indexButton->setObjectName(QStringLiteral("indexButton"));
const QIcon icon = QIcon(QString::fromUtf8(":/remotecontrol/enter.png"));
indexButton->setIcon(icon);
hboxLayout->addWidget(indexButton);
gridLayout1->addLayout(hboxLayout, 0, 1, 1, 2);
label_4 = new QLabel(actionGroupBox);
label_4->setObjectName(QStringLiteral("label_4"));
gridLayout1->addWidget(label_4, 1, 0, 1, 1);
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(0);
hboxLayout1->setObjectName(QStringLiteral("hboxLayout1"));
identifierLineEdit = new QLineEdit(actionGroupBox);
identifierLineEdit->setObjectName(QStringLiteral("identifierLineEdit"));
hboxLayout1->addWidget(identifierLineEdit);
identifierButton = new QToolButton(actionGroupBox);
identifierButton->setObjectName(QStringLiteral("identifierButton"));
identifierButton->setIcon(icon);
hboxLayout1->addWidget(identifierButton);
gridLayout1->addLayout(hboxLayout1, 1, 1, 1, 2);
label_3 = new QLabel(actionGroupBox);
label_3->setObjectName(QStringLiteral("label_3"));
gridLayout1->addWidget(label_3, 2, 0, 1, 1);
hboxLayout2 = new QHBoxLayout();
hboxLayout2->setSpacing(0);
hboxLayout2->setObjectName(QStringLiteral("hboxLayout2"));
urlLineEdit = new QLineEdit(actionGroupBox);
urlLineEdit->setObjectName(QStringLiteral("urlLineEdit"));
hboxLayout2->addWidget(urlLineEdit);
urlButton = new QToolButton(actionGroupBox);
urlButton->setObjectName(QStringLiteral("urlButton"));
urlButton->setIcon(icon);
hboxLayout2->addWidget(urlButton);
gridLayout1->addLayout(hboxLayout2, 2, 1, 1, 2);
syncContentsButton = new QPushButton(actionGroupBox);
syncContentsButton->setObjectName(QStringLiteral("syncContentsButton"));
gridLayout1->addWidget(syncContentsButton, 3, 1, 1, 1);
spacerItem2 = new QSpacerItem(81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout1->addItem(spacerItem2, 3, 2, 1, 1);
contentsCheckBox = new QCheckBox(actionGroupBox);
contentsCheckBox->setObjectName(QStringLiteral("contentsCheckBox"));
gridLayout1->addWidget(contentsCheckBox, 4, 0, 1, 3);
indexCheckBox = new QCheckBox(actionGroupBox);
indexCheckBox->setObjectName(QStringLiteral("indexCheckBox"));
gridLayout1->addWidget(indexCheckBox, 5, 0, 1, 1);
bookmarksCheckBox = new QCheckBox(actionGroupBox);
bookmarksCheckBox->setObjectName(QStringLiteral("bookmarksCheckBox"));
gridLayout1->addWidget(bookmarksCheckBox, 6, 0, 1, 3);
gridLayout->addWidget(actionGroupBox, 3, 0, 1, 3);
RemoteControlClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(RemoteControlClass);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 344, 21));
menuFile = new QMenu(menuBar);
menuFile->setObjectName(QStringLiteral("menuFile"));
RemoteControlClass->setMenuBar(menuBar);
statusBar = new QStatusBar(RemoteControlClass);
statusBar->setObjectName(QStringLiteral("statusBar"));
RemoteControlClass->setStatusBar(statusBar);
menuBar->addAction(menuFile->menuAction());
menuFile->addAction(actionQuit);
retranslateUi(RemoteControlClass);
QMetaObject::connectSlotsByName(RemoteControlClass);
} // setupUi
void retranslateUi(QMainWindow *RemoteControlClass)
{
RemoteControlClass->setWindowTitle(qtTrId("RemoteControl"));
actionQuit->setText(qtTrId("Quit"));
label->setText(qtTrId("Start URL:"));
launchButton->setText(qtTrId("Launch Qt HelpViewer"));
actionGroupBox->setTitle(qtTrId("Actions"));
label_2->setText(qtTrId("Search in Index:"));
indexButton->setText(QString());
label_4->setText(qtTrId("Identifier:"));
identifierButton->setText(QString());
label_3->setText(qtTrId("Show URL:"));
urlButton->setText(QString());
syncContentsButton->setText(qtTrId("Sync Contents"));
contentsCheckBox->setText(qtTrId("Show Contents"));
indexCheckBox->setText(qtTrId("Show Index"));
bookmarksCheckBox->setText(qtTrId("Show Bookmarks"));
menuFile->setTitle(qtTrId("File"));
} // retranslateUi
};
namespace Ui {
class RemoteControlClass: public Ui_RemoteControlClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // QTTRID_H

View File

@ -142,10 +142,11 @@ void tst_uic::run()
{
QFETCH(QString, originalFile);
QFETCH(QString, generatedFile);
QFETCH(QStringList, options);
QProcess process;
process.start(m_command, QStringList(originalFile)
<< QString(QLatin1String("-o")) << generatedFile);
<< QString(QLatin1String("-o")) << generatedFile << options);
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
QVERIFY(process.waitForFinished());
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
@ -157,6 +158,7 @@ void tst_uic::run_data() const
{
QTest::addColumn<QString>("originalFile");
QTest::addColumn<QString>("generatedFile");
QTest::addColumn<QStringList>("options");
QDir generated(m_generated.path());
QDir baseline(m_baseline);
@ -165,9 +167,15 @@ void tst_uic::run_data() const
const QString generatedFile = generated.absolutePath()
+ QLatin1Char('/') + baselineFile.fileName()
+ QLatin1String(".h");
QStringList options;
if (baselineFile.fileName() == QLatin1String("qttrid.ui"))
options << QStringList(QLatin1String("-idbased"));
QTest::newRow(qPrintable(baselineFile.baseName()))
<< baselineFile.absoluteFilePath()
<< generatedFile;
<< generatedFile
<< options;
}
}