uic: Accept an -include argument to generate a #include.
Change-Id: I2854619ab995b4ba3c820fec58e998ad04ac9858 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
a4446c299a
commit
459fb11481
@ -127,6 +127,9 @@ void WriteIncludes::acceptUI(DomUI *node)
|
||||
|
||||
TreeWalker::acceptUI(node);
|
||||
|
||||
if (!m_uic->option().includeFile.isEmpty())
|
||||
m_globalIncludes.insert(m_uic->option().includeFile, true);
|
||||
|
||||
writeHeaders(m_globalIncludes, true);
|
||||
writeHeaders(m_localIncludes, false);
|
||||
|
||||
|
@ -95,6 +95,11 @@ int runUic(int argc, char *argv[])
|
||||
translateOption.setValueName(QStringLiteral("function"));
|
||||
parser.addOption(translateOption);
|
||||
|
||||
QCommandLineOption includeOption(QStringList() << QStringLiteral("include"));
|
||||
includeOption.setDescription(QStringLiteral("Add #include <include-file> to <file>."));
|
||||
includeOption.setValueName(QStringLiteral("include-file"));
|
||||
parser.addOption(includeOption);
|
||||
|
||||
QCommandLineOption generatorOption(QStringList() << QStringLiteral("g") << QStringLiteral("generator"));
|
||||
generatorOption.setDescription(QStringLiteral("Select generator."));
|
||||
generatorOption.setValueName(QStringLiteral("java|cpp"));
|
||||
@ -110,6 +115,7 @@ int runUic(int argc, char *argv[])
|
||||
driver.option().implicitIncludes = !parser.isSet(noImplicitIncludesOption);
|
||||
driver.option().postfix = parser.value(postfixOption);
|
||||
driver.option().translateFunction = parser.value(translateOption);
|
||||
driver.option().includeFile = parser.value(includeOption);
|
||||
driver.option().generator = (parser.value(generatorOption).toLower() == QLatin1String("java")) ? Option::JavaGenerator : Option::CppGenerator;
|
||||
|
||||
QString inputFile;
|
||||
|
@ -73,6 +73,7 @@ struct Option
|
||||
QString prefix;
|
||||
QString postfix;
|
||||
QString translateFunction;
|
||||
QString includeFile;
|
||||
#ifdef QT_UIC_JAVA_GENERATOR
|
||||
QString javaPackage;
|
||||
QString javaOutputDirectory;
|
||||
|
@ -0,0 +1,50 @@
|
||||
/********************************************************************************
|
||||
** Form generated from reading UI file 'Dialog_without_Buttons.ui'
|
||||
**
|
||||
** Created by: Qt User Interface Compiler version 5.3.0
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef DIALOG_WITHOUT_BUTTONS_TR_H
|
||||
#define DIALOG_WITHOUT_BUTTONS_TR_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <ki18n.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Ui_Dialog
|
||||
{
|
||||
public:
|
||||
|
||||
void setupUi(QDialog *Dialog)
|
||||
{
|
||||
if (Dialog->objectName().isEmpty())
|
||||
Dialog->setObjectName(QStringLiteral("Dialog"));
|
||||
Dialog->resize(400, 300);
|
||||
|
||||
retranslateUi(Dialog);
|
||||
|
||||
QMetaObject::connectSlotsByName(Dialog);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *Dialog)
|
||||
{
|
||||
Dialog->setWindowTitle(i18n("Dialog", 0));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class Dialog: public Ui_Dialog {};
|
||||
} // namespace Ui
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // DIALOG_WITHOUT_BUTTONS_TR_H
|
@ -64,9 +64,13 @@ private Q_SLOTS:
|
||||
void run();
|
||||
void run_data() const;
|
||||
|
||||
void runTranslation();
|
||||
|
||||
void compare();
|
||||
void compare_data() const;
|
||||
|
||||
void runCompare();
|
||||
|
||||
private:
|
||||
const QString m_command;
|
||||
QString m_baseline;
|
||||
@ -220,5 +224,53 @@ void tst_uic::compare_data() const
|
||||
}
|
||||
}
|
||||
|
||||
void tst_uic::runTranslation()
|
||||
{
|
||||
QProcess process;
|
||||
|
||||
QDir baseline(m_baseline);
|
||||
|
||||
QDir generated(m_generated.path());
|
||||
generated.mkdir(QLatin1String("translation"));
|
||||
QString generatedFile = generated.absolutePath() + QLatin1String("/translation/Dialog_without_Buttons_tr.h");
|
||||
|
||||
process.start(m_command, QStringList(baseline.filePath("Dialog_without_Buttons.ui"))
|
||||
<< QString(QLatin1String("-tr")) << "i18n"
|
||||
<< QString(QLatin1String("-include")) << "ki18n.h"
|
||||
<< QString(QLatin1String("-o")) << generatedFile);
|
||||
QVERIFY2(process.waitForStarted(), msgProcessStartFailed(m_command, process.errorString()));
|
||||
QVERIFY(process.waitForFinished());
|
||||
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
||||
QCOMPARE(process.exitCode(), 0);
|
||||
QCOMPARE(QFileInfo(generatedFile).exists(), true);
|
||||
}
|
||||
|
||||
|
||||
void tst_uic::runCompare()
|
||||
{
|
||||
QFile orgFile(m_baseline + QLatin1String("/translation/Dialog_without_Buttons_tr.h"));
|
||||
|
||||
QDir generated(m_generated.path());
|
||||
QFile genFile(generated.absolutePath() + QLatin1String("/translation/Dialog_without_Buttons_tr.h"));
|
||||
|
||||
if (!orgFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString err(QLatin1String("Could not read file: %1..."));
|
||||
QFAIL(err.arg(orgFile.fileName()).toUtf8());
|
||||
}
|
||||
|
||||
if (!genFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString err(QLatin1String("Could not read file: %1..."));
|
||||
QFAIL(err.arg(genFile.fileName()).toUtf8());
|
||||
}
|
||||
|
||||
QString originalFile = orgFile.readAll();
|
||||
originalFile.replace(QRegExp(QLatin1String("Created by: Qt User Interface Compiler version [.\\d]{5,5}")), "");
|
||||
|
||||
QString generatedFile = genFile.readAll();
|
||||
generatedFile.replace(QRegExp(QLatin1String("Created by: Qt User Interface Compiler version [.\\d]{5,5}")), "");
|
||||
|
||||
QCOMPARE(generatedFile, originalFile);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_uic)
|
||||
#include "tst_uic.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user