* @brief Generates a Serial Studio project from the configured register groups. */
| 844 | * @brief Generates a Serial Studio project from the configured register groups. |
| 845 | */ |
| 846 | void IO::Drivers::Modbus::generateProject() |
| 847 | { |
| 848 | if (m_registerGroups.isEmpty()) { |
| 849 | Misc::Utilities::showMessageBox( |
| 850 | tr("No register groups configured"), |
| 851 | tr("Add at least one register group before generating a project."), |
| 852 | QMessageBox::Warning, |
| 853 | tr("Modbus Project Generator")); |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | const auto project = buildProject(); |
| 858 | |
| 859 | auto& pm = DataModel::ProjectModel::instance(); |
| 860 | AppState::instance().setOperationMode(SerialStudio::ProjectFile); |
| 861 | if (!pm.loadFromJsonDocument(QJsonDocument(project), QString())) { |
| 862 | Misc::Utilities::showMessageBox(tr("Failed to load generated project"), |
| 863 | tr("The generated project JSON could not be loaded."), |
| 864 | QMessageBox::Critical, |
| 865 | tr("Modbus Project Generator")); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | pm.setModified(true); |
| 870 | |
| 871 | int total_datasets = 0; |
| 872 | for (const auto& g : m_registerGroups) |
| 873 | total_datasets += g.count; |
| 874 | |
| 875 | const int groupCount = m_registerGroups.count(); |
| 876 | QObject::connect( |
| 877 | &pm, |
| 878 | &DataModel::ProjectModel::saveDialogCompleted, |
| 879 | this, |
| 880 | [groupCount, total_datasets](bool accepted) { |
| 881 | if (!accepted) |
| 882 | return; |
| 883 | |
| 884 | Misc::Utilities::showMessageBox( |
| 885 | tr("Successfully generated project with %1 groups and %2 datasets.") |
| 886 | .arg(groupCount) |
| 887 | .arg(total_datasets), |
| 888 | tr("The project editor is now open for customization."), |
| 889 | QMessageBox::Information, |
| 890 | tr("Modbus Project Generator")); |
| 891 | }, |
| 892 | Qt::SingleShotConnection); |
| 893 | |
| 894 | (void)pm.saveJsonFile(true); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * @brief Assembles the complete project JSON object. |
nothing calls this directly
no test coverage detected