Skip to content

Commit

Permalink
Added api property for video tutorial
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Lie <[email protected]>
  • Loading branch information
liealex committed Oct 31, 2024
1 parent 5fc6e16 commit 58571e4
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 9 deletions.
1 change: 1 addition & 0 deletions gui/include/gui/tutorialbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Q_SLOTS:
int y_offset;
HoverPosition anchor;
HoverPosition content;
QString api_call;
};

QMap<uint16_t, ChapterInstructions *> m_chapters;
Expand Down
6 changes: 5 additions & 1 deletion gui/include/gui/tutorialchapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SCOPY_GUI_EXPORT TutorialChapter : public QObject

static TutorialChapter *build(const QList<QWidget *> &subjects, const QString &description,
QWidget *mainSubject, int x_offset, int y_offset, HoverPosition anchor,
HoverPosition content, QObject *parent = nullptr);
HoverPosition content, QString api_call, QObject *parent = nullptr);

void addSubject(QWidget *s);

Expand All @@ -48,6 +48,7 @@ class SCOPY_GUI_EXPORT TutorialChapter : public QObject
int y_offset;
HoverPosition anchor;
HoverPosition content;
QString api_call;

int getXOffset() const;
void setXOffset(int xOffset);
Expand All @@ -67,6 +68,9 @@ class SCOPY_GUI_EXPORT TutorialChapter : public QObject
QWidget *getMainSubject() const;
void setMainSubject(QWidget *mainSubject);

QString getApi() const;
void setApi(QString apiCall);

Q_SIGNALS:
void chapterStarted();
void chapterFinished();
Expand Down
2 changes: 1 addition & 1 deletion gui/include/gui/tutorialoverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SCOPY_GUI_EXPORT TutorialOverlay : public QWidget
TutorialChapter *addChapter(const QList<QWidget *> &subjects, const QString &description,
QWidget *mainWidget = nullptr, int x_offset = 0, int y_offset = 0,
HoverPosition anchor = HoverPosition::HP_CENTER,
HoverPosition content = HoverPosition::HP_CENTER);
HoverPosition content = HoverPosition::HP_CENTER, QString api_call = "");
TutorialChapter *addChapter(QWidget *subject, QString description);
void addChapter(TutorialChapter *ch);

Expand Down
6 changes: 5 additions & 1 deletion gui/src/tutorialbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ uint16_t TutorialBuilder::collectChapters()
this->addChapter(chapter->widgets.values(), chapter->description,
(chapter->mainWidget.isNull()) ? chapter->widgets.first()
: chapter->widgets[chapter->mainWidget],
chapter->x_offset, chapter->y_offset, chapter->anchor, chapter->content);
chapter->x_offset, chapter->y_offset, chapter->anchor, chapter->content,
chapter->api_call);
}

return chaptersCollected;
Expand Down Expand Up @@ -171,6 +172,7 @@ void TutorialBuilder::readTutorialRequirements()
// "y_offset": int, optional
// "anchor": string, HoverPosition, optional
// "content": string, HoverPosition, optional
// "api_call": string, api function call, optional
// }
QJsonArray chapters_array = value.toArray();
for(QJsonValueRef item : chapters_array) {
Expand All @@ -189,6 +191,7 @@ void TutorialBuilder::readTutorialRequirements()
QString contentString = item_object.value("content").toString();
HoverPosition anchor = convertStringToHoverPosition(anchorString);
HoverPosition content = convertStringToHoverPosition(contentString);
QString api_call = item_object.value("api_call").toString();

auto *chapterInstructions = new ChapterInstructions;
for(const auto &name : qAsConst(names)) {
Expand All @@ -200,6 +203,7 @@ void TutorialBuilder::readTutorialRequirements()
chapterInstructions->y_offset = y_offset;
chapterInstructions->anchor = anchor;
chapterInstructions->content = content;
chapterInstructions->api_call = api_call;
if(m_chapters.contains(index)) {
qWarning(CAT_TUTORIALBUILDER) << "There is already a chapter with the key" << index;
} else {
Expand Down
7 changes: 6 additions & 1 deletion gui/src/tutorialchapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TutorialChapter::~TutorialChapter() {}

TutorialChapter *TutorialChapter::build(const QList<QWidget *> &subjects, const QString &description,
QWidget *mainSubject, int x_offset, int y_offset, HoverPosition anchor,
HoverPosition content, QObject *parent)
HoverPosition content, QString api_call, QObject *parent)
{
TutorialChapter *ch = new TutorialChapter(parent);
for(QWidget *subject : subjects) {
Expand All @@ -46,6 +46,7 @@ TutorialChapter *TutorialChapter::build(const QList<QWidget *> &subjects, const
ch->setYOffset(y_offset);
ch->setAnchor(anchor);
ch->setContent(content);
ch->setApi(api_call);
return ch;
}

Expand Down Expand Up @@ -81,4 +82,8 @@ scopy::HoverPosition TutorialChapter::getContent() const { return content; }

void TutorialChapter::setContent(scopy::HoverPosition newContent) { content = newContent; }

QString TutorialChapter::getApi() const { return api_call; }

void TutorialChapter::setApi(QString apiCall) { api_call = apiCall; }

#include "moc_tutorialchapter.cpp"
7 changes: 3 additions & 4 deletions gui/src/tutorialoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ TutorialOverlay::~TutorialOverlay() { qDebug(CAT_TUTORIALOVERLAY) << "dtor"; }

TutorialChapter *TutorialOverlay::addChapter(const QList<QWidget *> &subjects, const QString &description,
QWidget *mainWidget, int x_offset, int y_offset, HoverPosition anchor,
HoverPosition content)
HoverPosition content, QString api_call)
{
// in case TutorialOverlay is used without TutorialBuilder
if(!mainWidget) {
mainWidget = subjects[0];
}
TutorialChapter *ch =
TutorialChapter::build(subjects, description, mainWidget, x_offset, y_offset, anchor, content, this);
TutorialChapter *ch = TutorialChapter::build(subjects, description, mainWidget, x_offset, y_offset, anchor,
content, api_call, this);
chapter.append(ch);
ch->setMainSubject(mainWidget);
return ch;
Expand Down Expand Up @@ -91,7 +91,6 @@ void TutorialOverlay::next()
Q_EMIT chapter[cnt - 1]->chapterFinished();

Q_EMIT chapter[cnt]->chapterStarted();

initPopupWidget();
m_popupWidget->setDescription(chapter[cnt]->description);
overlay->raise();
Expand Down
1 change: 1 addition & 0 deletions plugins/datalogger/include/datalogger/datamonitortool.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SCOPY_DATALOGGER_EXPORT DatamonitorTool : public QWidget

void initTutorialProperties();
void startTutorial();
void startVideoTutorial();
};
} // namespace scopy::datamonitor
#endif // DATAMONITORTOOL_H
1 change: 1 addition & 0 deletions plugins/datalogger/resources/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/datamonitor">
<file>tutorial_chapters.json</file>
<file>video_tutorial_chapters.json</file>
</qresource>
</RCC>
29 changes: 29 additions & 0 deletions plugins/datalogger/resources/video_tutorial_chapters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"datamonitor": [
{
"index": 1,
"names": ["MONITOR_MENU"],
"description": "Select the signals you want to log",
"anchor": "HP_RIGHT",
"content": "HP_RIGHT",
"x_offset": 10
},
{
"index": 2,
"names": ["RUN_BUTTON"],
"description": "Starts data collection",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"api_call": "datalogger.setRunning(true)"
},
{
"index": 3,
"names": ["MONITOR_PLOT"],
"description": "Display values on plot ",
"anchor": "HP_RIGHT",
"content": "HP_RIGHT",
"x_offset": 10
}
]
}
13 changes: 12 additions & 1 deletion plugins/datalogger/src/datamonitortool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DatamonitorTool::DatamonitorTool(DataAcquisitionManager *dataAcquisitionManager,
clearBtn = new QPushButton("Clear", this);
PrintBtn *printBtn = new PrintBtn(this);

connect(infoBtn, &QPushButton::clicked, this, &DatamonitorTool::startTutorial);
connect(infoBtn, &QPushButton::clicked, this, &DatamonitorTool::startVideoTutorial);

//// add monitors
addMonitorButton = new AddBtn(this);
Expand Down Expand Up @@ -314,6 +314,8 @@ void DatamonitorTool::initTutorialProperties()
showSegments->setProperty("tutorial_name", "SHOW_7SEG_BUTTON");
settingsButton->setProperty("tutorial_name", "SETTINGS_BUTTON");
monitorsButton->setProperty("tutorial_name", "MONITORS_MENU_BUTTON");
m_monitorPlot->setProperty("tutorial_name", "MONITOR_PLOT");
m_monitorSelectionMenu->setProperty("tutorial_name", "MONITOR_MENU");
}

void DatamonitorTool::startTutorial()
Expand All @@ -325,4 +327,13 @@ void DatamonitorTool::startTutorial()
datamonitorTutorial->start();
}

void DatamonitorTool::startVideoTutorial()
{
QWidget *parent = Util::findContainingWindow(this);
gui::TutorialBuilder *datamonitorTutorial =
new gui::TutorialBuilder(this, ":/datamonitor/video_tutorial_chapters.json", "datamonitor", parent);
datamonitorTutorial->setTitle("Video Tutorial");
datamonitorTutorial->start();
}

#include "moc_datamonitortool.cpp"

0 comments on commit 58571e4

Please sign in to comment.