MCPcopy Create free account
hub / github.com/analogdevicesinc/scopy / collectChapters

Method collectChapters

gui/src/tutorialbuilder.cpp:86–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86uint16_t TutorialBuilder::collectChapters()
87{
88 if(!m_topWidget) {
89 throw std::runtime_error("No top widget was provided.");
90 }
91
92 uint16_t chaptersCollected = 0; // number of objects that are part of the tutorial
93 uint16_t totalChaptersCollected = 0; // total number of objects collected, used only as debug statistic
94
95 // collect all children objects from m_topWidget recursively
96 QObjectList childrenList =
97 m_topWidget->findChildren<QObject *>(QRegularExpression(".*"), Qt::FindChildrenRecursively);
98
99 for(auto child : childrenList) {
100 QString currentObjectName = child->property("tutorial_name").toString();
101
102 // if the object has no property named "tutorial_name", then it is not part of the tutorial
103 if(!currentObjectName.isEmpty()) {
104 try {
105 // get the chapters that use the widget with the property name currentObjectName
106 QList<TutorialBuilder::ChapterInstructions *> chapters =
107 this->getChapterInstructionFromName(currentObjectName);
108 for(auto chapter : chapters) {
109 chapter->widgets[currentObjectName] = qobject_cast<QWidget *>(child);
110 }
111 ++chaptersCollected;
112 } catch(std::runtime_error &error) {
113 qCritical(CAT_TUTORIALBUILDER) << error.what();
114 }
115 }
116 ++totalChaptersCollected;
117 }
118 qDebug(CAT_TUTORIALBUILDER) << "Collected a total of" << totalChaptersCollected << "in the" << m_jsonEntry
119 << "entry.";
120
121 // add the now sorted chapters into the tutorial overlay
122 for(const ChapterInstructions *chapter : qAsConst(m_chapters)) {
123 // if there is no mainWidget specified, the first widget from the list will be set to be the mainWidget
124 this->addChapter(chapter->widgets.values(), chapter->description,
125 (chapter->mainWidget.isNull()) ? chapter->widgets.first()
126 : chapter->widgets[chapter->mainWidget],
127 chapter->x_offset, chapter->y_offset, chapter->anchor, chapter->content);
128 }
129
130 return chaptersCollected;
131}
132
133void TutorialBuilder::readTutorialRequirements()
134{

Callers 1

startMethod · 0.95

Calls 3

addChapterMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected