瀏覽代碼

Merge topic 'autogen_brace'

50b3837c Autogen: Q_OBJECT behind brace test
01d2b745 Autogen: Check for Q_OBJECT/Q_GADGET after brace

Acked-by: Kitware Robot <[email protected]>
Merge-request: !986
Brad King 8 年之前
父節點
當前提交
d7c694b2e7

+ 4 - 2
Source/cmQtAutoGenerators.cxx

@@ -281,9 +281,11 @@ cmQtAutoGenerators::cmQtAutoGenerators()
 
   // Moc macro filters
   this->MocMacroFilters[0].first = "Q_OBJECT";
-  this->MocMacroFilters[0].second.compile("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
+  this->MocMacroFilters[0].second.compile(
+    "[\n][ \t]*{?[ \t]*Q_OBJECT[^a-zA-Z0-9_]");
   this->MocMacroFilters[1].first = "Q_GADGET";
-  this->MocMacroFilters[1].second.compile("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]");
+  this->MocMacroFilters[1].second.compile(
+    "[\n][ \t]*{?[ \t]*Q_GADGET[^a-zA-Z0-9_]");
 
   // Precompile regular expressions
   this->MocRegExpInclude.compile(

+ 15 - 9
Tests/QtAutogen/CMakeLists.txt

@@ -60,6 +60,21 @@ if(NON_ASCII_BDIR AND WIN32)
   set(ALLOW_WRAP_CPP FALSE)
 endif()
 
+# -- Test
+# MOC only
+add_executable(mocOnly mocOnlySource/main.cpp mocOnlySource/StyleA.cpp mocOnlySource/StyleB.cpp)
+set_property(TARGET mocOnly PROPERTY AUTOMOC ON)
+target_link_libraries(mocOnly ${QT_LIBRARIES})
+
+# -- Test
+# UIC only
+if(ALLOW_WRAP_CPP)
+  qtx_wrap_cpp(uicOnlyMoc uicOnlySource/uiconly.h)
+  add_executable(uicOnly uicOnlySource/uiconly.cpp ${uicOnlyMoc})
+  set_property(TARGET uicOnly PROPERTY AUTOUIC ON)
+  target_link_libraries(uicOnly ${QT_LIBRARIES})
+endif()
+
 # -- Test
 # RCC only
 add_executable(rccOnly rccOnly.cpp rccOnlyRes.qrc)
@@ -72,15 +87,6 @@ add_executable(rccEmpty rccEmpty.cpp rccEmptyRes.qrc)
 set_property(TARGET rccEmpty PROPERTY AUTORCC ON)
 target_link_libraries(rccEmpty ${QT_QTCORE_TARGET})
 
-# -- Test
-# UIC only
-if(ALLOW_WRAP_CPP)
-  qtx_wrap_cpp(uicOnlyMoc uicOnlySource/uiconly.h)
-  add_executable(uicOnly uicOnlySource/uiconly.cpp ${uicOnlyMoc})
-  set_property(TARGET uicOnly PROPERTY AUTOUIC ON)
-  target_link_libraries(uicOnly ${QT_LIBRARIES})
-endif()
-
 # -- Test
 # Add not_generated_file.qrc to the source list to get the file-level
 # dependency, but don't generate a c++ file from it.  Disable the AUTORCC

+ 5 - 0
Tests/QtAutogen/mocOnlySource/StyleA.cpp

@@ -0,0 +1,5 @@
+#include "StyleA.hpp"
+
+StyleA::StyleA()
+{
+}

+ 15 - 0
Tests/QtAutogen/mocOnlySource/StyleA.hpp

@@ -0,0 +1,15 @@
+#ifndef STYLEA_HPP
+#define STYLEA_HPP
+
+#include <QObject>
+
+/// Q_OBJECT on a single new line
+///
+class StyleA : public QObject
+{
+  Q_OBJECT
+public:
+  StyleA();
+};
+
+#endif

+ 5 - 0
Tests/QtAutogen/mocOnlySource/StyleB.cpp

@@ -0,0 +1,5 @@
+#include "StyleB.hpp"
+
+StyleB::StyleB()
+{
+}

+ 16 - 0
Tests/QtAutogen/mocOnlySource/StyleB.hpp

@@ -0,0 +1,16 @@
+#ifndef STYLEB_HPP
+#define STYLEB_HPP
+
+#include <QObject>
+
+/* clang-format off */
+/// Q_OBJECT behind a brace
+///
+class StyleB : public QObject
+{ Q_OBJECT
+public:
+  StyleB();
+};
+/* clang-format on */
+
+#endif

+ 9 - 0
Tests/QtAutogen/mocOnlySource/main.cpp

@@ -0,0 +1,9 @@
+#include "StyleA.hpp"
+#include "StyleB.hpp"
+
+int main(int argv, char** args)
+{
+  StyleA styleA;
+  StyleB styleB;
+  return 0;
+}