diff --git a/src/core/drawertrainingactions.cpp b/src/core/drawertrainingactions.cpp index b99fff5..9787b12 100644 --- a/src/core/drawertrainingactions.cpp +++ b/src/core/drawertrainingactions.cpp @@ -1,67 +1,71 @@ /* * Copyright 2018-2019 Andreas Cord-Landwehr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "drawertrainingactions.h" #include "trainingaction.h" #include "course.h" +#include #include #include DrawerTrainingActions::DrawerTrainingActions(QObject* parent) - : QObject(parent) + : QObject{parent} + , m_defaultAction{new TrainingAction(i18n("Please select a course"), this)} { } void DrawerTrainingActions::setSession(TrainingSession *session) { if (session == m_session) { return; } if (m_session) { disconnect(m_session, &TrainingSession::courseChanged, this, &DrawerTrainingActions::actionsChanged); disconnect(m_session, &TrainingSession::phraseChanged, this, &DrawerTrainingActions::triggerTrainingView); } m_session = session; connect(m_session, &TrainingSession::courseChanged, this, &DrawerTrainingActions::actionsChanged); connect(m_session, &TrainingSession::phraseChanged, this, &DrawerTrainingActions::triggerTrainingView); emit sessionChanged(); emit actionsChanged(); } TrainingSession * DrawerTrainingActions::session() const { return m_session; } QList DrawerTrainingActions::actions() const { - if (!m_session) { - return QList(); + if (!m_session || m_session->trainingActions().isEmpty()) { + QList list; + list << qobject_cast(m_defaultAction); + return list; } QList actions; const auto trainingActions = m_session->trainingActions(); for (const auto &action : qAsConst(trainingActions)) { actions.append(qobject_cast(action)); } return actions; } diff --git a/src/core/drawertrainingactions.h b/src/core/drawertrainingactions.h index b4c86c6..8323ebe 100644 --- a/src/core/drawertrainingactions.h +++ b/src/core/drawertrainingactions.h @@ -1,54 +1,55 @@ /* * Copyright 2018-2019 Andreas Cord-Landwehr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef DRAWERTRAININGACTIONS_H #define DRAWERTRAININGACTIONS_H #include "artikulatecore_export.h" #include "trainingaction.h" #include class Course; class ARTIKULATECORE_EXPORT DrawerTrainingActions : public QObject { Q_OBJECT Q_PROPERTY(TrainingSession *session READ session WRITE setSession NOTIFY sessionChanged) Q_PROPERTY(QList actions READ actions NOTIFY actionsChanged) public: DrawerTrainingActions(QObject *parent = nullptr); void setSession(TrainingSession *session); TrainingSession * session() const; QList actions() const; Q_SIGNALS: void actionsChanged(); void sessionChanged(); /** * Notify that training view shall be displayed. */ void triggerTrainingView(); private: TrainingSession *m_session{nullptr}; + TrainingAction *m_defaultAction{nullptr}; }; #endif