MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / generateProject

Method generateProject

app/src/IO/Drivers/Modbus.cpp:846–895  ·  view source on GitHub ↗

* @brief Generates a Serial Studio project from the configured register groups. */

Source from the content-addressed store, hash-verified

844 * @brief Generates a Serial Studio project from the configured register groups.
845 */
846void 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.

Callers

nothing calls this directly

Calls 6

isEmptyMethod · 0.80
loadFromJsonDocumentMethod · 0.80
setModifiedMethod · 0.80
saveJsonFileMethod · 0.80
setOperationModeMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected