Browse Source

Fix namespace definition to avoid using namespace in headers

Alexey Edelev 6 years ago
parent
commit
1b014b2549

+ 5 - 3
src/generator/classgeneratorbase.cpp

@@ -127,9 +127,6 @@ void ClassGeneratorBase::printIncludes(const Descriptor *message, std::set<std::
         std::transform(std::begin(modelTypeNameLower), std::end(modelTypeNameLower), std::begin(modelTypeNameLower), ::tolower);
         mPrinter.Print({{"type_lower", modelTypeNameLower}}, InternalIncludeTemplate);
     }
-
-    // Add using of template for correct build of autogenerated classes
-    mPrinter.Print(UsingQtPeotobufNamespaceTemplate);
 }
 
 void ClassGeneratorBase::printNamespaces(const std::string &package)
@@ -241,8 +238,13 @@ std::string ClassGeneratorBase::getTypeName(const FieldDescriptor *field)
         if (it != std::end(TypeReflection)) {
             typeName = it->second;
             if (field->is_repeated()) {
+                std::string namespaceDefinition("qtprotobuf::");
                 typeName[0] = ::toupper(typeName[0]);
                 typeName.append("List");
+                if (typeName != "QStringList"
+                        && typeName != "QByteArrayList") {
+                    typeName = namespaceDefinition.append(typeName);
+                }
             }
         }
     }

+ 4 - 4
src/generator/templates.h

@@ -41,13 +41,13 @@ static const char *InternalIncludeTemplate =  "#include \"$type_lower$.h\"\n";
 static const char *ExternalIncludeTemplate = "#include <$type$>\n";
 static const char *ListModelsIncludeTemplate = "#include <QList>\n";
 
-static const char *UsingQtPeotobufNamespaceTemplate = "\nusing namespace qtprotobuf;\n";
+static const char *UsingQtProtobufNamespaceTemplate = "\nusing namespace qtprotobuf;\n";
 static const char *NamespaceTemplate = "\nnamespace $namespace$ {\n";
 
 static const char *NonProtoClassDefinitionTemplate = "\nclass $classname$ : public QObject\n"
                                                      "{\n"
                                                      "    Q_OBJECT\n";
-static const char *ClassDefinitionTemplate = "\nclass $classname$ : public ProtobufObject<$classname$>\n"
+static const char *ClassDefinitionTemplate = "\nclass $classname$ : public qtprotobuf::ProtobufObject<$classname$>\n"
                                              "{\n"
                                              "    Q_OBJECT\n";
 
@@ -115,8 +115,8 @@ static const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::
     //        {FieldDescriptor::TYPE_INT64, "int"},//Not supported see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
     //        {FieldDescriptor::TYPE_UINT64,"int"},//Not supported see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
     {::google::protobuf::FieldDescriptor::TYPE_INT32, "int"},
-    {::google::protobuf::FieldDescriptor::TYPE_FIXED64, "FixedInt64"},
-    {::google::protobuf::FieldDescriptor::TYPE_FIXED32, "FixedInt32"},
+    {::google::protobuf::FieldDescriptor::TYPE_FIXED64, "qtprotobuf::FixedInt64"},
+    {::google::protobuf::FieldDescriptor::TYPE_FIXED32, "qtprotobuf::FixedInt32"},
     {::google::protobuf::FieldDescriptor::TYPE_BOOL, "bool"},
     {::google::protobuf::FieldDescriptor::TYPE_STRING, "QString"},
     {::google::protobuf::FieldDescriptor::TYPE_GROUP, ""},//Not supported and deprecated in protobuf

+ 1 - 2
src/lib/qtprotobuftypes.h

@@ -35,8 +35,7 @@ using FloatList = QList<float>;
 using DoubleList = QList<double>;
 
 using FixedInt32 = unsigned int;
-using FixedInt64 = unsigned long;
-
+using FixedInt64 = uint64_t;
 }
 
 Q_DECLARE_METATYPE(qtprotobuf::IntList)

+ 1 - 1
tests/proto/simpletest.proto

@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package qtprotobuf.tests;
+package qtprotobufnamespace.tests;
 
 message SimpleIntMessage {
     int32 testFieldInt = 1;

+ 1 - 0
tests/serializationtest.cpp

@@ -40,6 +40,7 @@
 #include "repeatedcomplexmessage.h"
 #include "qtprotobuf.h"
 
+using namespace qtprotobufnamespace::tests;
 using namespace qtprotobuf::tests;
 using namespace qtprotobuf;
 

+ 1 - 0
tests/simpletest.cpp

@@ -39,6 +39,7 @@
 #include <QVariantList>
 #include <QMetaProperty>
 
+using namespace qtprotobufnamespace::tests;
 using namespace qtprotobuf::tests;
 
 using namespace qtprotobuf;