Prechádzať zdrojové kódy

Delete Model Property generation.

Tatyana Borisova 6 rokov pred
rodič
commit
b0e4109cf8

+ 14 - 2
src/generator/classgeneratorbase.cpp

@@ -81,7 +81,7 @@ void ClassGeneratorBase::printPreamble()
     mPrinter.Print(PreambleTemplate);
 }
 
-void ClassGeneratorBase::printIncludes(const Descriptor *message)
+void ClassGeneratorBase::printIncludes(const Descriptor *message, std::set<std::string> listModel)
 {
     PropertyMap properties;
     std::set<std::string> existingIncludes;
@@ -114,6 +114,17 @@ void ClassGeneratorBase::printIncludes(const Descriptor *message)
             }
         }
     }
+
+    // Print List model class name
+    if (listModel.size() > 0) {
+        mPrinter.Print(ListModelsIncludeTemplate);
+    }
+
+    for(auto modelTypeName : listModel) {
+        std::string modelTypeNameLower(modelTypeName);
+        std::transform(std::begin(modelTypeNameLower), std::end(modelTypeNameLower), std::begin(modelTypeNameLower), ::tolower);
+        mPrinter.Print({{"type_lower", modelTypeNameLower}}, InternalIncludeTemplate);
+    }
 }
 
 void ClassGeneratorBase::printNamespaces(const std::string &package)
@@ -205,7 +216,8 @@ std::string ClassGeneratorBase::getTypeName(const FieldDescriptor *field)
     if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
         typeName = field->message_type()->name();
         if (field->is_repeated()) {
-            typeName = typeName.append("Model");
+            std::string list("QList<");
+            typeName = list.append(typeName).append(">");
         }
     } else if (field->type() == FieldDescriptor::TYPE_ENUM) {
         if (field->is_repeated()) {

+ 1 - 1
src/generator/classgeneratorbase.h

@@ -53,7 +53,7 @@ protected:
 
     bool producePropertyMap(const ::google::protobuf::FieldDescriptor *field, PropertyMap &propertyMap);
     void printPreamble();
-    void printIncludes(const ::google::protobuf::Descriptor *message);
+    void printIncludes(const ::google::protobuf::Descriptor *message, std::set<std::string> listModel);
     void printNamespaces(const std::string &package);
     void printClass();
     void printField(const ::google::protobuf::FieldDescriptor *field, const char *fieldTemplate);

+ 2 - 23
src/generator/generator.cpp

@@ -68,12 +68,7 @@ public:
         }
 
         printPreamble();
-        printIncludes(mMessage);
-
-        if (mExtractedModels.size() > 0) {
-            mPrinter.Print(ListModelsIncludeTemplate);
-        }
-
+        printIncludes(mMessage, mExtractedModels);
         printNamespaces(mPackage);
         printClass();
         printProperties(mMessage);
@@ -119,6 +114,7 @@ public:
         std::transform(std::begin(includeFileName), std::end(includeFileName), std::begin(includeFileName), ::tolower);
         mPrinter.Print({{"type_lower", includeFileName}}, InternalIncludeTemplate);
     }
+
     void printFieldsOrdering() {
         mPrinter.Print({{"type", mClassName}}, FieldsOrderingContainerTemplate);
         Indent();
@@ -191,22 +187,5 @@ bool QtGenerator::Generate(const FileDescriptor *file,
     GlobalEnumsGenerator enumGen(file, std::move(std::unique_ptr<io::ZeroCopyOutputStream>(generatorContext->Open(globalEnumsFilename))));
     enumGen.run();
 
-    //TODO: move to separate class also slipt definitions
-    //Print list models
-    std::unique_ptr<io::ZeroCopyOutputStream> out(generatorContext->Open("listmodels.h"));
-    io::Printer printer(out.get(), '$');
-    printer.Print(PreambleTemplate);
-
-    for(auto modelTypeName : extractedModels) {
-        std::string modelTypeNameLower(modelTypeName);
-        std::transform(std::begin(modelTypeNameLower), std::end(modelTypeNameLower), std::begin(modelTypeNameLower), ::tolower);
-        printer.Print({{"type_lower", modelTypeNameLower}}, InternalIncludeTemplate);
-    }
-
-    printer.Print(UniversalListModelIncludeTemplate);
-    for(auto modelTypeName : extractedModels) {
-        printer.Print({{"type", modelTypeName}}, ModelClassTemplate);
-    }
-
     return true;
 }

+ 1 - 3
src/generator/templates.h

@@ -39,8 +39,7 @@ static const char *PreambleTemplate = "/* This file is autogenerated. DO NOT CHA
 
 static const char *InternalIncludeTemplate =  "#include \"$type_lower$.h\"\n";
 static const char *ExternalIncludeTemplate = "#include <$type$>\n";
-static const char *ListModelsIncludeTemplate = "\n#include \"listmodels.h\"\n";
-static const char *UniversalListModelIncludeTemplate = "\n#include <universallistmodel.h>\n";
+static const char *ListModelsIncludeTemplate = "#include <QList>\n";
 
 static const char *NamespaceTemplate = "\nnamespace $namespace$ {\n";
 
@@ -96,7 +95,6 @@ static const char *FieldsOrderingContainerTemplate = "const std::unordered_map<i
 static const char *FieldOrderTemplate = "{$field_number$,$property_number$}";
 
 static const char *EnumTemplate = "$type$";
-static const char *ModelClassTemplate = "using $type$Model = UniversalListModel<$type$>;\n";
 
 static const char *SimpleBlockEnclosureTemplate = "}\n\n";
 static const char *SemicolonBlockEnclosureTemplate = "};\n";