Skip to content

Commit

Permalink
add realqmlmodules.cmake generation
Browse files Browse the repository at this point in the history
Change qml options in qleany.yaml
  • Loading branch information
jacquetc committed Jan 19, 2024
1 parent 3ac2f47 commit 460ca22
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 17 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,10 @@ presenter:

### QML Configuration

Specifies paths for QML mock and real imports.
Specifies paths for QML folder. The folders mock_imports and real_imports will be created in it.

```yaml
qml:
mock_imports_folder_path: path/to/mock/imports
real_imports_folder_path: path/to/real/imports
folder_path: path/to/qml/folder
```
3 changes: 1 addition & 2 deletions examples/simple/qleany.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,4 @@ presenter:


qml:
mock_imports_folder_path: src/gui/qml_application/mock_imports/
real_imports_folder_path: src/gui/qml_application/real_imports/
folder_path: src/gui/qml_application/
116 changes: 105 additions & 11 deletions tools/qleany/generator/qml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


def _get_generation_dict(
real_imports_folder_path: str,
mock_imports_folder_path: str,
folder_path,
feature_by_name: dict,
entities_by_name: dict,
has_undo_redo: bool,
Expand All @@ -22,6 +21,10 @@ def _get_generation_dict(
application_name: str,
application_cpp_domain_name: str,
) -> dict:

real_imports_folder_path = os.path.join(folder_path, "real_imports")
mock_imports_folder_path = os.path.join(folder_path, "mock_imports")

# generating controller files

generation_dict = {}
Expand Down Expand Up @@ -141,6 +144,18 @@ def _get_generation_dict(

generation_dict["controller_qmldir_file"] = controller_qmldir_file

# add common real CmakeLists.txt file
common_real_cmakelists_file = os.path.join(
real_imports_folder_path, "CMakeLists.txt"
)
generation_dict["common_real_cmakelists_file"] = common_real_cmakelists_file

# add realqmlmodules.cmake file
real_qml_modules_file = os.path.join(
folder_path, "realqmlmodules.cmake"
)
generation_dict["real_qml_modules_file"] = real_qml_modules_file

# add CMakelists.txt:
controller_cmakelists_file = os.path.join(
real_imports_folder_path, "controllers", "CMakeLists.txt"
Expand Down Expand Up @@ -770,6 +785,69 @@ def _generate_real_event_dispatcher_file(

print(f"Successfully wrote file {event_dispatcher_file}")

def _generate_real_common_cmakelists_file(
root_path: str, generation_dict: dict, files_to_be_generated: dict[str, bool]
):
common_real_cmakelists_file = generation_dict["common_real_cmakelists_file"]

# generate the real cmakelists file if in the files_to_be_generated dict the value is True
if not files_to_be_generated.get(common_real_cmakelists_file, False):
return

output_file = os.path.join(root_path, common_real_cmakelists_file)

# Create the jinja2 environment
env = Environment(
loader=FileSystemLoader("templates/QML/real_imports/")
)
# Load the template
template = env.get_template("cmakelists.txt.jinja2")

# Render the template
output = template.render()

# Create the directory if it does not exist
os.makedirs(os.path.dirname(output_file), exist_ok=True)

# Write the output to the file
with open(output_file, "w") as fh:
fh.write(output)

print(f"Successfully wrote file {output_file}")


def _generate_real_qml_modules_file(
root_path: str, generation_dict: dict, files_to_be_generated: dict[str, bool]
):
real_qml_modules_file = generation_dict["real_qml_modules_file"]

# generate the real cmakelists file if in the files_to_be_generated dict the value is True
if not files_to_be_generated.get(real_qml_modules_file, False):
return

output_file = os.path.join(root_path, real_qml_modules_file)

# Create the jinja2 environment
env = Environment(
loader=FileSystemLoader("templates/QML/")
)
# Load the template
template = env.get_template("realqmlmodules.cmake.jinja2")

# Render the template
output = template.render(
application_name=generation_dict["application_name"],
)

# Create the directory if it does not exist
os.makedirs(os.path.dirname(output_file), exist_ok=True)

# Write the output to the file
with open(output_file, "w") as fh:
fh.write(output)

print(f"Successfully wrote file {output_file}")


def _generate_real_controllers_cmakelists_file(
root_path: str, generation_dict: dict, files_to_be_generated: dict[str, bool]
Expand Down Expand Up @@ -1007,10 +1085,10 @@ def generate_qml_files(
singles = presenter_data.get("singles", [])

qml_data = manifest_data.get("qml", [])
folder_path = qml_data["folder_path"]

generation_dict = _get_generation_dict(
qml_data["real_imports_folder_path"],
qml_data["mock_imports_folder_path"],
folder_path,
feature_by_name,
entities_by_name,
has_undo_redo,
Expand Down Expand Up @@ -1072,6 +1150,16 @@ def generate_qml_files(
root_path, generation_dict, files_to_be_generated
)

# generate real common CMakeLists.txt file
_generate_real_common_cmakelists_file(
root_path, generation_dict, files_to_be_generated
)

# generate real qmlmodules.cmake file
_generate_real_qml_modules_file(
root_path, generation_dict, files_to_be_generated
)

# generate real CMakeLists.txt file
_generate_real_controllers_cmakelists_file(
root_path, generation_dict, files_to_be_generated
Expand Down Expand Up @@ -1143,11 +1231,11 @@ def get_files_to_be_generated(
feature_by_name = {feature["name"]: feature for feature in feature_list}

qml_data = manifest_data.get("qml", [])
folder_path = qml_data["folder_path"]

files = []
generation_dict = _get_generation_dict(
qml_data["real_imports_folder_path"],
qml_data["mock_imports_folder_path"],
folder_path,
feature_by_name,
entities_by_name,
has_undo_redo,
Expand All @@ -1157,6 +1245,7 @@ def get_files_to_be_generated(
application_name,
application_cpp_domain_name,
)

files += generation_dict["real_controller_files"]
files += generation_dict["mock_controller_files"]

Expand All @@ -1183,6 +1272,14 @@ def get_files_to_be_generated(
model_qmldir_file = generation_dict["model_qmldir_file"]
files.append(model_qmldir_file)

# add common real CMakeLists.txt file
common_real_cmakelists_file = generation_dict["common_real_cmakelists_file"]
files.append(common_real_cmakelists_file)

# add realqmlmodules.cmake file
real_qml_modules_file = generation_dict["real_qml_modules_file"]
files.append(real_qml_modules_file)

# strip from files if the value in files_to_be_generated is False
if files_to_be_generated:
for path, generate in files_to_be_generated.items():
Expand All @@ -1209,11 +1306,8 @@ def preview_qml_files(
manifest = yaml.safe_load(fh)

# remove .. from the path
manifest["qml"]["mock_imports_folder_path"] = manifest["qml"][
"mock_imports_folder_path"
].replace("..", "")
manifest["qml"]["real_imports_folder_path"] = manifest["qml"][
"real_imports_folder_path"
manifest["qml"]["folder_path"] = manifest["qml"][
"folder_path"
].replace("..", "")

# write the modified manifest file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file was generated automatically by Qleany's generator, edit at your own risk!
# If you do, be careful to not overwrite it when you run the generator again.

add_subdirectory(models)
add_subdirectory(controllers)
add_subdirectory(singles)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

add_subdirectory(real_imports)

target_link_libraries(${APP_NAME} PRIVATE
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
{{ application_name }}-qml-controllersplugin
{{ application_name }}-qml-modelsplugin
{{ application_name }}-qml-singlesplugin
Expand Down

0 comments on commit 460ca22

Please sign in to comment.