Răsfoiți Sursa

Merge topic 'autogen-first-line-fix'

b4e6911b Autogen: Tests: Extend AUTOUIC include patterns test
ff91a5d5 Autogen: Tests: Extend AUTOMOC include patterns test
a1d491ca Autogen: AUTOMOC/UIC fix for moc/uic include on the first line

Acked-by: Kitware Robot <[email protected]>
Merge-request: !1670
Brad King 7 ani în urmă
părinte
comite
b058d92b33

+ 4 - 4
Source/cmQtAutoGeneratorMocUic.cxx

@@ -221,7 +221,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseMocSource(WorkerT& wrk,
       const char* contentChars = meta.Content.c_str();
       const char* contentChars = meta.Content.c_str();
       cmsys::RegularExpressionMatch match;
       cmsys::RegularExpressionMatch match;
       while (wrk.Moc().RegExpInclude.find(contentChars, match)) {
       while (wrk.Moc().RegExpInclude.find(contentChars, match)) {
-        std::string incString = match.match(1);
+        std::string incString = match.match(2);
         std::string incDir(SubDirPrefix(incString));
         std::string incDir(SubDirPrefix(incString));
         std::string incBase =
         std::string incBase =
           cmSystemTools::GetFilenameWithoutLastExtension(incString);
           cmSystemTools::GetFilenameWithoutLastExtension(incString);
@@ -500,7 +500,7 @@ bool cmQtAutoGeneratorMocUic::JobParseT::ParseUic(WorkerT& wrk,
     const char* contentChars = meta.Content.c_str();
     const char* contentChars = meta.Content.c_str();
     cmsys::RegularExpressionMatch match;
     cmsys::RegularExpressionMatch match;
     while (wrk.Uic().RegExpInclude.find(contentChars, match)) {
     while (wrk.Uic().RegExpInclude.find(contentChars, match)) {
-      if (!ParseUicInclude(wrk, meta, match.match(1))) {
+      if (!ParseUicInclude(wrk, meta, match.match(2))) {
         success = false;
         success = false;
         break;
         break;
       }
       }
@@ -1124,9 +1124,9 @@ cmQtAutoGeneratorMocUic::cmQtAutoGeneratorMocUic()
 {
 {
   // Precompile regular expressions
   // Precompile regular expressions
   Moc_.RegExpInclude.compile(
   Moc_.RegExpInclude.compile(
-    "[\n][ \t]*#[ \t]*include[ \t]+"
+    "(^|\n)[ \t]*#[ \t]*include[ \t]+"
     "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
     "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
-  Uic_.RegExpInclude.compile("[\n][ \t]*#[ \t]*include[ \t]+"
+  Uic_.RegExpInclude.compile("(^|\n)[ \t]*#[ \t]*include[ \t]+"
                              "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
                              "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
 
 
   // Initialize libuv asynchronous iteration request
   // Initialize libuv asynchronous iteration request

+ 1 - 3
Tests/QtAutogen/CommonTests.cmake

@@ -1,9 +1,7 @@
 # Autogen tests common for Qt4 and Qt5
 # Autogen tests common for Qt4 and Qt5
 ADD_AUTOGEN_TEST(MocOnly mocOnly)
 ADD_AUTOGEN_TEST(MocOnly mocOnly)
 ADD_AUTOGEN_TEST(MocOptions mocOptions)
 ADD_AUTOGEN_TEST(MocOptions mocOptions)
-if(QT_TEST_ALLOW_QT_MACROS)
-  ADD_AUTOGEN_TEST(UicOnly uicOnly)
-endif()
+ADD_AUTOGEN_TEST(UicOnly uicOnly)
 ADD_AUTOGEN_TEST(RccOnly rccOnly)
 ADD_AUTOGEN_TEST(RccOnly rccOnly)
 ADD_AUTOGEN_TEST(RccEmpty rccEmpty)
 ADD_AUTOGEN_TEST(RccEmpty rccEmpty)
 ADD_AUTOGEN_TEST(RccOffMocLibrary)
 ADD_AUTOGEN_TEST(RccOffMocLibrary)

+ 9 - 2
Tests/QtAutogen/MocOnly/CMakeLists.txt

@@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.10)
 project(MocOnly)
 project(MocOnly)
 include("../AutogenTest.cmake")
 include("../AutogenTest.cmake")
 
 
-# Test different Q_OBJECT position styles
-add_executable(mocOnly StyleA.cpp StyleB.cpp main.cpp)
+add_executable(mocOnly
+  main.cpp
+  # Test different Q_OBJECT position styles
+  StyleA.cpp
+  StyleB.cpp
+  # Test different moc_/.moc include positions
+  IncA.cpp
+  IncB.cpp
+)
 set_property(TARGET mocOnly PROPERTY AUTOMOC ON)
 set_property(TARGET mocOnly PROPERTY AUTOMOC ON)
 target_link_libraries(mocOnly ${QT_LIBRARIES})
 target_link_libraries(mocOnly ${QT_LIBRARIES})

+ 19 - 0
Tests/QtAutogen/MocOnly/IncA.cpp

@@ -0,0 +1,19 @@
+#include "moc_IncA.cpp"
+/// AUTOMOC moc_ include on the first line of the file!
+#include "IncA.hpp"
+
+/// @brief Source local QObject
+///
+class IncAPrivate : public QObject
+{
+  Q_OBJECT
+public:
+  IncAPrivate(){};
+};
+
+IncA::IncA()
+{
+  IncAPrivate priv;
+}
+
+#include "IncA.moc"

+ 15 - 0
Tests/QtAutogen/MocOnly/IncA.hpp

@@ -0,0 +1,15 @@
+#ifndef INCA_HPP
+#define INCA_HPP
+
+#include <QObject>
+
+/// @brief Test moc include pattern in the source file
+///
+class IncA : public QObject
+{
+  Q_OBJECT
+public:
+  IncA();
+};
+
+#endif

+ 19 - 0
Tests/QtAutogen/MocOnly/IncB.cpp

@@ -0,0 +1,19 @@
+#include "IncB.hpp"
+
+/// @brief Source local QObject
+///
+class IncBPrivate : public QObject
+{
+  Q_OBJECT
+public:
+  IncBPrivate(){};
+};
+
+IncB::IncB()
+{
+  IncBPrivate priv;
+}
+
+/// AUTOMOC moc_ include on the last line of the file!
+#include "IncB.moc"
+#include "moc_IncB.cpp"

+ 15 - 0
Tests/QtAutogen/MocOnly/IncB.hpp

@@ -0,0 +1,15 @@
+#ifndef INCB_HPP
+#define INCB_HPP
+
+#include <QObject>
+
+/// @brief Test moc include pattern in the source file
+///
+class IncB : public QObject
+{
+  Q_OBJECT
+public:
+  IncB();
+};
+
+#endif

+ 5 - 0
Tests/QtAutogen/MocOnly/main.cpp

@@ -1,3 +1,5 @@
+#include "IncA.hpp"
+#include "IncB.hpp"
 #include "StyleA.hpp"
 #include "StyleA.hpp"
 #include "StyleB.hpp"
 #include "StyleB.hpp"
 
 
@@ -5,5 +7,8 @@ int main(int argv, char** args)
 {
 {
   StyleA styleA;
   StyleA styleA;
   StyleB styleB;
   StyleB styleB;
+  IncA incA;
+  IncB incB;
+
   return 0;
   return 0;
 }
 }

+ 1 - 3
Tests/QtAutogen/UicOnly/CMakeLists.txt

@@ -3,8 +3,6 @@ project(UicOnly)
 include("../AutogenTest.cmake")
 include("../AutogenTest.cmake")
 
 
 # Test AUTOUIC being enabled only
 # Test AUTOUIC being enabled only
-# The moc is provided by the Qt macro
-qtx_wrap_cpp(uicOnlyMoc uiconly.h)
-add_executable(uicOnly uiconly.cpp ${uicOnlyMoc})
+add_executable(uicOnly main.cpp UicOnly.cpp)
 set_property(TARGET uicOnly PROPERTY AUTOUIC ON)
 set_property(TARGET uicOnly PROPERTY AUTOUIC ON)
 target_link_libraries(uicOnly ${QT_LIBRARIES})
 target_link_libraries(uicOnly ${QT_LIBRARIES})

+ 18 - 0
Tests/QtAutogen/UicOnly/UicOnly.cpp

@@ -0,0 +1,18 @@
+#include "ui_uiC.h"
+#include "ui_uiD.h"
+// AUTOUIC includes on the first two lines of a source file
+#include "UicOnly.hpp"
+
+UicOnly::UicOnly()
+  : uiA(new Ui::UiA)
+  , uiB(new Ui::UiB)
+{
+  Ui::UiC uiC;
+  Ui::UiD uiD;
+}
+
+UicOnly::~UicOnly()
+{
+  delete uiB;
+  delete uiA;
+}

+ 15 - 0
Tests/QtAutogen/UicOnly/UicOnly.hpp

@@ -0,0 +1,15 @@
+#include "ui_uiA.h"
+#include "ui_uiB.h"
+// AUTOUIC includes on the first two lines of a header file
+#include <QObject>
+
+class UicOnly : public QObject
+{
+public:
+  UicOnly();
+  ~UicOnly();
+
+private:
+  Ui::UiA* uiA;
+  Ui::UiB* uiB;
+};

+ 7 - 0
Tests/QtAutogen/UicOnly/main.cpp

@@ -0,0 +1,7 @@
+#include "UicOnly.hpp"
+
+int main(int argc, char* argv[])
+{
+  UicOnly uicOnly;
+  return 0;
+}

+ 2 - 2
Tests/QtAutogen/UicOnly/uiconly.ui → Tests/QtAutogen/UicOnly/uiA.ui

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
 <ui version="4.0">
- <class>UicOnly</class>
- <widget class="QWidget" name="UicOnly">
+ <class>UiA</class>
+ <widget class="QWidget" name="UiA">
   <property name="geometry">
   <property name="geometry">
    <rect>
    <rect>
     <x>0</x>
     <x>0</x>

+ 24 - 0
Tests/QtAutogen/UicOnly/uiB.ui

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UiB</class>
+ <widget class="QWidget" name="UiB">
+  <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>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 24 - 0
Tests/QtAutogen/UicOnly/uiC.ui

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UiC</class>
+ <widget class="QWidget" name="UiC">
+  <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>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 24 - 0
Tests/QtAutogen/UicOnly/uiD.ui

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UiD</class>
+ <widget class="QWidget" name="UiD">
+  <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>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 0 - 18
Tests/QtAutogen/UicOnly/uiconly.cpp

@@ -1,18 +0,0 @@
-
-#include "uiconly.h"
-
-UicOnly::UicOnly(QWidget* parent)
-  : QWidget(parent)
-  , ui(new Ui::UicOnly)
-{
-}
-
-UicOnly::~UicOnly()
-{
-  delete ui;
-}
-
-int main()
-{
-  return 0;
-}

+ 0 - 20
Tests/QtAutogen/UicOnly/uiconly.h

@@ -1,20 +0,0 @@
-
-#ifndef UIC_ONLY_H
-#define UIC_ONLY_H
-
-#include <QWidget>
-
-#include "ui_uiconly.h"
-
-class UicOnly : public QWidget
-{
-  Q_OBJECT
-public:
-  explicit UicOnly(QWidget* parent = 0);
-  ~UicOnly();
-
-private:
-  Ui::UicOnly* ui;
-};
-
-#endif