Skip to content

Commit

Permalink
add "hidden" and "read_only" option
Browse files Browse the repository at this point in the history
fix conflict with update function
  • Loading branch information
jacquetc committed Jan 22, 2024
1 parent 6a241d0 commit 12b460a
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 51 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ entities:
# basic:
- type: DataType
name: fieldName
hidden: true/false (default: false)
# one-to-one relationship:
- type: OtherEntityName
name: fieldName
strong: true/false
hidden: true/false (default: false)
# one-to-many relationship:
- type: QList<OtherEntityName>
name: fieldName
strong: true/false
ordered: true/false
# other fields
hidden: true/false (default: false)
# other fields ...
# other entities
export: EXPORT_MACRO_NAME
export_header_file: header_file_name.h
Expand Down Expand Up @@ -255,15 +258,17 @@ presenter:
export_header_file: header_file_name.h
create_undo_and_redo_singles: true/false (default false)
singles:
- name: SingleName
- name: SingleName (or "auto")
entity: EntityName
read_only: true/false (default: false)
# Additional singles...
list_models:
- name: ListModelName (or auto)
entity: EntityName
displayed_field: fieldName
in_relation_of: RelationEntity
relation_field_name: relationFieldName
read_only: true/false (default: false)
# Additional list models...
```
Expand Down
2 changes: 1 addition & 1 deletion tools/qleany/generator/application_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_generation_dict(
}
update_data = crud_data.get("update", {})
if update_data.get("enabled", False) and update_data.get("generate", True):
crud_handlers["update"] = {
crud_handlers["update_"] = {
"generate": True,
"templates": [
"update_handler.cpp.jinja2",
Expand Down
10 changes: 6 additions & 4 deletions tools/qleany/generator/controller_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def get_other_entities_relation_fields(

fields = data["fields"]
for field in fields:
if field.get("hidden", False):
continue
field_type = field["type"]
if tools.is_unique_foreign_entity(
field_type, entities_by_name
Expand Down Expand Up @@ -116,7 +118,7 @@ def get_generation_dict(
final_feature_dict["crud"]["entity_name_camel"] = entity_camel_name
final_feature_dict["crud"][
"entity_has_relation_fields"
] = tools.does_entity_have_relation_fields(entity_name, entities_by_name)
] = tools.does_entity_have_relation_fields(entity_name, entities_by_name, False)

final_feature_dict["crud"]["get"] = (
feature["CRUD"].get("get", {}).get("enabled", False)
Expand All @@ -130,7 +132,7 @@ def get_generation_dict(
final_feature_dict["crud"]["create"] = (
feature["CRUD"].get("create", {}).get("enabled", False)
)
final_feature_dict["crud"]["update"] = (
final_feature_dict["crud"]["update_"] = (
feature["CRUD"].get("update", {}).get("enabled", False)
)
final_feature_dict["crud"]["remove"] = (
Expand Down Expand Up @@ -460,7 +462,7 @@ def generate_event_dispatcher_files(
print(f"Successfully wrote file {event_dispatcher_file}")


def generate_controller_h_and_cpp_files(
def _generate_controller_h_and_cpp_files(
root_path: str, generation_dict: dict, files_to_be_generated: dict[str, bool] = None
):
template_env = Environment(loader=FileSystemLoader("templates/controller"))
Expand Down Expand Up @@ -882,7 +884,7 @@ def generate_controller_files(
generate_cmakelists(root_path, generation_dict, files_to_be_generated)
generate_export_header_file(root_path, generation_dict, files_to_be_generated)
generate_signal_files(root_path, generation_dict, files_to_be_generated)
generate_controller_h_and_cpp_files(
_generate_controller_h_and_cpp_files(
root_path, generation_dict, files_to_be_generated
)
if create_undo_redo_controller:
Expand Down
51 changes: 39 additions & 12 deletions tools/qleany/generator/dto_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields without foreign entities

dto_dict[dto_type_name]["fields"] = tools.get_fields_without_foreign_entities(
fields = tools.get_fields_without_foreign_entities(
entities_by_name[entity_mappable_with]["fields"],
entities_by_name,
entity_mappable_with,
)
# remove if hidden
fields = [field for field in fields if not field["hidden"]]

dto_dict[dto_type_name]["fields"] = fields

dto_dict[dto_type_name]["dto_dependencies"] = []

Expand All @@ -76,12 +79,15 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
entities_by_name[entity_mappable_with]["fields"],
entities_by_name,
entity_mappable_with,
)
# remove if hidden
fields = [field for field in fields if not field["hidden"]]

dto_dict[dto_type_name]["fields"] = fields
dto_dict[dto_type_name][
"dto_dependencies"
] = determine_dto_dependencies_from_fields(
Expand All @@ -101,8 +107,8 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
if crud_data["enabled"]:
generate_create = crud_data.get("create", {}).get("enabled", False)
generate_update = crud_data.get("update", {}).get("enabled", False)
generate_insert_relation = crud_data.get("insert_relation", {}).get(
"enabled", False
generate_insert_relation = tools.does_entity_have_relation_fields(
entity_mappable_with, entities_by_name, False
)
generate_move = crud_data.get("move_in_relative", {}).get(
"enabled", False
Expand All @@ -119,11 +125,14 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities but without id
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
entities_by_name[entity_mappable_with]["fields"],
entities_by_name,
entity_mappable_with,
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]
dto_dict[dto_type_name]["fields"] = fields

# remove id field
dto_dict[dto_type_name]["fields"] = [
Expand Down Expand Up @@ -183,11 +192,15 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
entities_by_name[entity_mappable_with]["fields"],
entities_by_name,
entity_mappable_with,
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]

dto_dict[dto_type_name]["fields"] = fields

dto_dict[dto_type_name][
"dto_dependencies"
Expand Down Expand Up @@ -239,7 +252,7 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
"is_foreign": False,
"type": "int",
}
)
)

# add relationship fields

Expand Down Expand Up @@ -268,9 +281,13 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
dto_in["fields"], entities_by_name
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]
dto_dict[dto_type_name]["fields"] = fields

dto_dict[dto_type_name][
"dto_dependencies"
] = determine_dto_dependencies_from_fields(
Expand All @@ -289,9 +306,12 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
dto_out["fields"], entities_by_name
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]
dto_dict[dto_type_name]["fields"] = fields
dto_dict[dto_type_name][
"dto_dependencies"
] = determine_dto_dependencies_from_fields(
Expand All @@ -313,9 +333,13 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
dto_in["fields"], entities_by_name
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]
dto_dict[dto_type_name]["fields"] = fields

dto_dict[dto_type_name][
"dto_dependencies"
] = determine_dto_dependencies_from_fields(
Expand All @@ -334,9 +358,12 @@ def determine_dto_dependencies_from_fields(fields: list) -> list:
}

# add fields with foreign entities
dto_dict[dto_type_name]["fields"] = tools.get_fields_with_foreign_entities(
fields = tools.get_fields_with_foreign_entities(
dto_out["fields"], entities_by_name
)
# remove hidden fields
fields = [field for field in fields if not field["hidden"]]
dto_dict[dto_type_name]["fields"] = fields
dto_dict[dto_type_name][
"dto_dependencies"
] = determine_dto_dependencies_from_fields(
Expand Down
7 changes: 6 additions & 1 deletion tools/qleany/generator/generation_dict_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def is_list_foreign_entity(field_type: str, entities_by_name: dict) -> bool:
return False


def does_entity_have_relation_fields(entity_name: str, entities_by_name: dict) -> bool:
def does_entity_have_relation_fields(entity_name: str, entities_by_name: dict, keep_hidden: bool = True) -> bool:
entity = entities_by_name.get(entity_name, None)
if entity is None:
return False

fields = entity["fields"]
for field in fields:
field_type = field["type"]
if keep_hidden is False and field.get("hidden", False):
continue
if is_unique_foreign_entity(
field_type, entities_by_name
) or is_list_foreign_entity(field_type, entities_by_name):
Expand Down Expand Up @@ -61,6 +63,7 @@ def determine_owner(entity_name: str, entities_by_name: dict) -> dict:
owner_dict["name"] = possible_owner_name
owner_dict["field"] = field["name"]
owner_dict["ordered"] = field.get("ordered", False)
owner_dict["hidden"] = field.get("hidden", False)
owner_dict["is_list"] = field["type"] == f"QList<{entity_name}>"
return owner_dict

Expand Down Expand Up @@ -92,6 +95,7 @@ def get_fields_with_foreign_entities(
# add fields with foreign entities
for field in fields:
field["pascal_name"] = stringcase.pascalcase(field["name"])
field["hidden"] = field.get("hidden", False)

if is_unique_foreign_entity(
field["type"], entities_by_name
Expand Down Expand Up @@ -140,6 +144,7 @@ def get_fields_without_foreign_entities(
for field in fields:
field["pascal_name"] = stringcase.pascalcase(field["name"])
field["camel_name"] = stringcase.camelcase(field["name"])
field["hidden"] = field.get("hidden", False)

if is_unique_foreign_entity(
field["type"], entities_by_name
Expand Down
7 changes: 7 additions & 0 deletions tools/qleany/generator/presenter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def get_fields_without_foreign_entities(
generation_dict["singles_list"] = []

for single in singles_list:
read_only = single.get("read_only", False)

entity_name = single["entity"]
entity_name_snake = stringcase.snakecase(entity_name)
entity_name_pascal = stringcase.pascalcase(entity_name)
Expand Down Expand Up @@ -117,6 +119,7 @@ def get_fields_without_foreign_entities(
entities_by_name,
single["entity"],
),
"read_only": read_only,
}
)
generation_dict["all_presenter_files"].append(
Expand All @@ -138,6 +141,8 @@ def get_fields_without_foreign_entities(
generation_dict["list_models"] = []

for model in list_models_list:
read_only = model.get("read_only", False)

entity_name = model["entity"]
entity_name_snake = stringcase.snakecase(entity_name)
entity_name_pascal = stringcase.pascalcase(entity_name)
Expand Down Expand Up @@ -220,6 +225,8 @@ def get_fields_without_foreign_entities(
),
"is_ordered_list": is_ordered_list,
"is_related_list": is_related_list,
"read_only": read_only,

}
)
generation_dict["all_presenter_files"].append(
Expand Down
4 changes: 2 additions & 2 deletions tools/qleany/generator/qml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def _get_generation_dict(
"get_with_details": get_with_details_enabled,
"get_all": get_all_enabled,
"create": create_enabled,
"update": update_enabled,
"update_": update_enabled,
"remove": remove_enabled,
"entity_has_relation_fields": tools.does_entity_have_relation_fields(
feature_pascal_name, entities_by_name
feature_pascal_name, entities_by_name, False
),
},
"custom_commands": custom_commands,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QtObject {
return task
}
{% endif -%}
{% if controller.crud.update %}
{% if controller.crud.update_ %}
function getUpdateDTO() {
return {
"id": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QtObject {
{%- if controller.crud.create %}
signal created(var dto)
{%- endif %}
{%- if controller.crud.update %}
{%- if controller.crud.update_ %}
signal updated(var dto)
signal allRelationsInvalidated(int itemId)
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public:
}
{% endif %}

{%if controller.crud.update %}
{%if controller.crud.update_ %}
Q_INVOKABLE Update{{ controller.feature_pascal_name }}DTO getUpdateDTO()
{
return s_controllerInstance->getUpdateDTO();
Expand All @@ -75,7 +75,7 @@ public:
}
{% endif %}

{% if controller.crud.update %}
{% if controller.crud.update_ %}
Q_INVOKABLE QCoro::QmlTask update(const Update{{ controller.feature_pascal_name }}DTO &dto)
{
return s_controllerInstance->update(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
struct Foreign{{ model.list_model_pascal_name}}
{
Q_GADGET
QML_FOREIGN(Simple::Presenter::{{ model.list_model_pascal_name}})
QML_FOREIGN({{ application_cpp_domain_name }}::Presenter::{{ model.list_model_pascal_name}})
QML_NAMED_ELEMENT({{ model.list_model_pascal_name}})
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
struct Foreign{{ single.class_name_pascal}}
{
Q_GADGET
QML_FOREIGN(Simple::Presenter::{{ single.class_name_pascal}})
QML_FOREIGN({{ application_cpp_domain_name }}::Presenter::{{ single.class_name_pascal}})
QML_NAMED_ELEMENT({{ single.class_name_pascal}})
};
Loading

0 comments on commit 12b460a

Please sign in to comment.