diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-11-20 14:54:39 +0100 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-11-27 19:06:12 +0100 |
commit | 98093c45db3327dc92879670ef22dc4001392480 (patch) | |
tree | 22ecf099ed3a3bca016e22c3ed9f56756b302583 /Tests/QtAutoUicInterface | |
parent | 02542b4cc73a12be8c1d3f583340400dd761ce24 (diff) | |
download | cmake-98093c45db3327dc92879670ef22dc4001392480.tar.gz |
QtAutoUic: Add INTERFACE_AUTOUIC_OPTIONS target property.
Transitively consume the property from linked dependents.
Implement configuration-specific support by following the pattern
set out for compile definitions and includes in cmQtAutoGenerators.
Implement support for origin-tracking with CMAKE_DEBUG_TARGET_PROPERTIES.
This is motivated by the needs of KDE, which provides a separate
translation system based on gettext instead of the Qt linguist
translation system. The Qt uic tool provides command line options
for configuring the method used to translate text, and to add an
include directive to the generated file to provide the method.
http://thread.gmane.org/gmane.comp.kde.devel.frameworks/7930/focus=7992
Implement the interface to provide the uic options as a usage-requirement
on the KI18n target, as designed for KDE.
Diffstat (limited to 'Tests/QtAutoUicInterface')
-rw-r--r-- | Tests/QtAutoUicInterface/CMakeLists.txt | 70 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/klocalizedstring.cpp | 12 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/klocalizedstring.h | 17 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/libwidget.cpp | 9 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/libwidget.h | 24 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/libwidget.ui | 32 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/main.cpp | 75 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/mywidget.cpp | 9 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/mywidget.h | 24 | ||||
-rw-r--r-- | Tests/QtAutoUicInterface/mywidget.ui | 32 |
10 files changed, 304 insertions, 0 deletions
diff --git a/Tests/QtAutoUicInterface/CMakeLists.txt b/Tests/QtAutoUicInterface/CMakeLists.txt new file mode 100644 index 0000000000..555f01689b --- /dev/null +++ b/Tests/QtAutoUicInterface/CMakeLists.txt @@ -0,0 +1,70 @@ + +cmake_minimum_required(VERSION 2.8.12) + +project(QtAutoUicInterface) + +if (QT_TEST_VERSION STREQUAL 4) + find_package(Qt4 REQUIRED) + + include(UseQt4) + + set(QT_CORE_TARGET Qt4::QtCore) + set(QT_GUI_TARGET Qt4::QtGui) +else() + if (NOT QT_TEST_VERSION STREQUAL 5) + message(SEND_ERROR "Invalid Qt version specified.") + endif() + find_package(Qt5Widgets REQUIRED) + + set(QT_CORE_TARGET Qt5::Core) + set(QT_GUI_TARGET Qt5::Widgets) +endif() + +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +# BEGIN Upstream + +set(CMAKE_VERBOSE_MAKEFILE ON) + +add_library(KI18n klocalizedstring.cpp) +target_link_libraries(KI18n ${QT_CORE_TARGET}) + +set(autouic_options + -tr tr2$<$<NOT:$<BOOL:$<TARGET_PROPERTY:NO_KUIT_SEMANTIC>>>:x>i18n +) +if (NOT Qt5Widgets_VERSION VERSION_LESS 5.3.0) + list(APPEND autouic_options -include klocalizedstring.h) +endif() + +set_property(TARGET KI18n APPEND PROPERTY + INTERFACE_AUTOUIC_OPTIONS ${autouic_options} +) + +set(domainProp $<TARGET_PROPERTY:TRANSLATION_DOMAIN>) +set(nameLower $<LOWER_CASE:$<MAKE_C_IDENTIFIER:$<TARGET_PROPERTY:NAME>>>) +set(domain_logic + $<$<BOOL:${domainProp}>:${domainProp}>$<$<NOT:$<BOOL:${domainProp}>>:${nameLower}> +) +set_property(TARGET KI18n APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "TRANSLATION_DOMAIN=${domain_logic}" +) + +# END upstream + +add_library(LibWidget libwidget.cpp) +target_link_libraries(LibWidget KI18n ${QT_GUI_TARGET}) +set_property(TARGET LibWidget PROPERTY NO_KUIT_SEMANTIC ON) +set_property(TARGET LibWidget PROPERTY TRANSLATION_DOMAIN customdomain) + +add_library(MyWidget mywidget.cpp) +target_link_libraries(MyWidget KI18n ${QT_GUI_TARGET}) + +add_executable(QtAutoUicInterface main.cpp) +target_compile_definitions(QtAutoUicInterface + PRIVATE + UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_libwidget.h" + UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/ui_mywidget.h" +) diff --git a/Tests/QtAutoUicInterface/klocalizedstring.cpp b/Tests/QtAutoUicInterface/klocalizedstring.cpp new file mode 100644 index 0000000000..f2324bb096 --- /dev/null +++ b/Tests/QtAutoUicInterface/klocalizedstring.cpp @@ -0,0 +1,12 @@ + +#include "klocalizedstring.h" + +QString tr2xi18n(const char *text, const char *) +{ + return QLatin1String("TranslatedX") + QString::fromLatin1(text); +} + +QString tr2i18n(const char *text, const char *) +{ + return QLatin1String("Translated") + QString::fromLatin1(text); +} diff --git a/Tests/QtAutoUicInterface/klocalizedstring.h b/Tests/QtAutoUicInterface/klocalizedstring.h new file mode 100644 index 0000000000..559058fa32 --- /dev/null +++ b/Tests/QtAutoUicInterface/klocalizedstring.h @@ -0,0 +1,17 @@ + +#ifndef KLOCALIZEDSTRING_H +#define KLOCALIZEDSTRING_H + +#include <QString> + +#ifdef _WIN32 +__declspec(dllexport) +#endif +QString tr2xi18n(const char *text, const char *comment = 0); + +#ifdef _WIN32 +__declspec(dllexport) +#endif +QString tr2i18n(const char *text, const char *comment = 0); + +#endif diff --git a/Tests/QtAutoUicInterface/libwidget.cpp b/Tests/QtAutoUicInterface/libwidget.cpp new file mode 100644 index 0000000000..8a921b397d --- /dev/null +++ b/Tests/QtAutoUicInterface/libwidget.cpp @@ -0,0 +1,9 @@ + +#include "libwidget.h" + +LibWidget::LibWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::LibWidget) +{ + ui->setupUi(this); +} diff --git a/Tests/QtAutoUicInterface/libwidget.h b/Tests/QtAutoUicInterface/libwidget.h new file mode 100644 index 0000000000..8b592ecfc4 --- /dev/null +++ b/Tests/QtAutoUicInterface/libwidget.h @@ -0,0 +1,24 @@ + +#ifndef LIBWIDGET_H +#define LIBWIDGET_H + +#include <QWidget> +#include <memory> + +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#include <klocalizedstring.h> +#endif + +#include "ui_libwidget.h" + +class LibWidget : public QWidget +{ + Q_OBJECT +public: + explicit LibWidget(QWidget *parent = 0); + +private: + const std::auto_ptr<Ui::LibWidget> ui; +}; + +#endif diff --git a/Tests/QtAutoUicInterface/libwidget.ui b/Tests/QtAutoUicInterface/libwidget.ui new file mode 100644 index 0000000000..897371e4a3 --- /dev/null +++ b/Tests/QtAutoUicInterface/libwidget.ui @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>LibWidget</class> + <widget class="QWidget" name="LibWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>180</x> + <y>60</y> + <width>57</width> + <height>15</height> + </rect> + </property> + <property name="text"> + <string>LibLabel</string> + </property> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/QtAutoUicInterface/main.cpp b/Tests/QtAutoUicInterface/main.cpp new file mode 100644 index 0000000000..42d59588e0 --- /dev/null +++ b/Tests/QtAutoUicInterface/main.cpp @@ -0,0 +1,75 @@ + +#include <fstream> +#include <iostream> +#include <string> + +int main(int argc, char **argv) +{ + std::ifstream f; + f.open(UI_LIBWIDGET_H); + if (!f.is_open()) + { + std::cout << "Could not open \"" UI_LIBWIDGET_H "\"." << std::endl; + return -1; + } + + { + bool gotTr2i18n = false; + + while (!f.eof()) + { + std::string output; + getline(f, output); + if (!gotTr2i18n) + { + gotTr2i18n = output.find("tr2i18n") != std::string::npos; + } + if (output.find("tr2xi18n") != std::string::npos) + { + std::cout << "ui_libwidget,h uses tr2xi18n, though it should not." << std::endl; + return -1; + } + } + + if (!gotTr2i18n) + { + std::cout << "Did not find tr2i18n in ui_libwidget.h" << std::endl; + return -1; + } + } + + f.close(); + f.open(UI_MYWIDGET_H); + if (!f.is_open()) + { + std::cout << "Could not open \"" UI_MYWIDGET_H "\"." << std::endl; + return -1; + } + + { + bool gotTr2xi18n = false; + + while (!f.eof()) + { + std::string output; + getline(f, output); + if (!gotTr2xi18n) + { + gotTr2xi18n = output.find("tr2xi18n") != std::string::npos; + } + if (output.find("tr2i18n") != std::string::npos) + { + std::cout << "ui_mywidget,h uses tr2i18n, though it should not." << std::endl; + return -1; + } + } + if (!gotTr2xi18n) + { + std::cout << "Did not find tr2xi18n in ui_mywidget.h" << std::endl; + return -1; + } + } + f.close(); + + return 0; +} diff --git a/Tests/QtAutoUicInterface/mywidget.cpp b/Tests/QtAutoUicInterface/mywidget.cpp new file mode 100644 index 0000000000..b528b1a433 --- /dev/null +++ b/Tests/QtAutoUicInterface/mywidget.cpp @@ -0,0 +1,9 @@ + +#include "mywidget.h" + +MyWidget::MyWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::MyWidget) +{ + ui->setupUi(this); +} diff --git a/Tests/QtAutoUicInterface/mywidget.h b/Tests/QtAutoUicInterface/mywidget.h new file mode 100644 index 0000000000..c96fb98284 --- /dev/null +++ b/Tests/QtAutoUicInterface/mywidget.h @@ -0,0 +1,24 @@ + +#ifndef MYWIDGET_H +#define MYWIDGET_H + +#include <QWidget> +#include <memory> + +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#include <klocalizedstring.h> +#endif + +#include "ui_mywidget.h" + +class MyWidget : public QWidget +{ + Q_OBJECT +public: + explicit MyWidget(QWidget *parent = 0); + +private: + const std::auto_ptr<Ui::MyWidget> ui; +}; + +#endif diff --git a/Tests/QtAutoUicInterface/mywidget.ui b/Tests/QtAutoUicInterface/mywidget.ui new file mode 100644 index 0000000000..b2b9cc5925 --- /dev/null +++ b/Tests/QtAutoUicInterface/mywidget.ui @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MyWidget</class> + <widget class="QWidget" name="MyWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <widget class="QPushButton" name="pushButton"> + <property name="geometry"> + <rect> + <x>110</x> + <y>40</y> + <width>81</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Special button</string> + </property> + </widget> + </widget> + <resources/> + <connections/> +</ui> |