Commit 2657910f authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Introduce ICourse interface

This interface is supposed to provide a future abstraction between
editor and trainer.
parent f95a1176
......@@ -39,6 +39,8 @@ include_directories(
# set the source code files from which Artikulate is compiled
set(artikulateCore_SRCS
core/icourse.h
core/drawertrainingactions.cpp
core/course.cpp
core/resourcemanager.cpp
......
......@@ -85,6 +85,7 @@ void Application::registerQmlTypes()
"artikulate", 1, 0,
"ProfileManager",
QStringLiteral("ProfileManager is unique object provided by the backend"));
qmlRegisterUncreatableType<ICourse>("artikulate", 1, 0, "ICourse", "Courses are managed by repository");
qmlRegisterType<LearnerProfile::Learner>("artikulate", 1, 0, "Learner");
qmlRegisterType<LearnerProfile::LearningGoal>("artikulate", 1, 0, "LearningGoal");
......
......@@ -33,7 +33,7 @@
#include <QUuid>
Course::Course(ResourceInterface *resource)
: QObject(resource)
: ICourse(resource)
, m_resource(qobject_cast<CourseResource*>(resource))
, m_language(nullptr)
, m_modified(false)
......
......@@ -22,6 +22,7 @@
#define COURSE_H
#include "artikulatecore_export.h"
#include "icourse.h"
#include <QObject>
#include <QMap>
#include <QUrl>
......@@ -35,9 +36,11 @@ class Phrase;
class PhonemeGroup;
class Phoneme;
class ARTIKULATECORE_EXPORT Course : public QObject
class ARTIKULATECORE_EXPORT Course : public ICourse
{
Q_OBJECT
Q_INTERFACES(ICourse)
Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString i18nTitle READ i18nTitle NOTIFY titleChanged)
......@@ -46,22 +49,22 @@ class ARTIKULATECORE_EXPORT Course : public QObject
Q_PROPERTY(Language * language READ language NOTIFY languageChanged)
public:
explicit Course(ResourceInterface *resource=0);
~Course();
QString id() const;
explicit Course(ResourceInterface *resource = nullptr);
~Course() override;
QString id() const override;
void setId(const QString &id);
QString foreignId() const;
void setForeignId(const QString &id);
QString title() const;
QString i18nTitle() const;
QString title() const override;
QString i18nTitle() const override;
void setTitle(const QString &title);
Language * language() const;
Language * language() const override;
void setLanguage(Language *language);
QString description() const;
QString description() const override;
void setDescription(const QString &description);
QUrl file() const;
void setFile(const QUrl &file);
QList<Unit *> unitList() const;
QList<Unit *> unitList() const override;
QList<Unit *> phonemeUnitList(PhonemeGroup *phonemeGroup) const;
/**
* \return the corresponding unit for phoneme \p phoneme
......@@ -109,11 +112,7 @@ public Q_SLOTS:
void registerPhrasePhonemes(Phrase *phrase);
Q_SIGNALS:
void idChanged();
void titleChanged();
void descriptionChanged();
void modifiedChanged();
void languageChanged();
void unitAdded();
void unitAboutToBeAdded(Unit*,int);
void unitsRemoved();
......
/*
* Copyright 2019 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef ICOURSE_H
#define ICOURSE_H
#include "artikulatecore_export.h"
#include <QObject>
#include <QMap>
#include <QUrl>
class QString;
class Language;
class Unit;
class ARTIKULATECORE_EXPORT ICourse : public QObject
{
Q_OBJECT
Q_PROPERTY(QString id READ id NOTIFY idChanged)
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
Q_PROPERTY(QString i18nTitle NOTIFY titleChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
Q_PROPERTY(Language * language NOTIFY languageChanged)
public:
ICourse(QObject *parent = nullptr)
: QObject(parent)
{
}
virtual ~ICourse() = default;
virtual QString id() const = 0;
virtual QString title() const = 0;
virtual QString i18nTitle() const = 0;
virtual QString description() const = 0;
virtual Language * language() const = 0;
virtual QList<Unit *> unitList() const = 0;
Q_SIGNALS:
void idChanged();
void titleChanged();
void descriptionChanged();
void languageChanged();
void unitAdded();
void unitAboutToBeAdded(Unit*,int);
void unitsRemoved();
void unitsAboutToBeRemoved(int,int);
};
Q_DECLARE_INTERFACE(ICourse, "com.kde.artikulate.ICourse/1.0")
#endif // COURSE_H
......@@ -38,7 +38,7 @@ class ARTIKULATECORE_EXPORT Language : public QObject
Q_PROPERTY(QString i18nTitle READ i18nTitle WRITE seti18nTitle NOTIFY i18nTitleChanged)
public:
explicit Language(QObject *parent = 0);
explicit Language(QObject *parent = nullptr);
~Language();
QString id() const;
......@@ -54,7 +54,7 @@ public:
QList<PhonemeGroup *> phonemeGroups() const;
PhonemeGroup * addPhonemeGroup(const QString &identifier, const QString &title);
signals:
Q_SIGNALS:
void idChanged();
void associatedLanguageItemChanged();
void titleChanged();
......
......@@ -20,7 +20,7 @@
#include "trainingsession.h"
#include "core/language.h"
#include "core/course.h"
#include "core/icourse.h"
#include "core/unit.h"
#include "core/phrase.h"
#include "profilemanager.h"
......@@ -45,12 +45,12 @@ void TrainingSession::setProfileManager(LearnerProfile::ProfileManager *manager)
m_profileManager = manager;
}
Course * TrainingSession::course() const
ICourse * TrainingSession::course() const
{
return m_course;
}
void TrainingSession::setCourse(Course *course)
void TrainingSession::setCourse(ICourse *course)
{
if (!course) {
return;
......
......@@ -22,13 +22,12 @@
#define TRAININGSESSION_H
#include "artikulatecore_export.h"
#include "course.h"
#include "phrase.h"
#include <QVector>
class QString;
class Language;
class Course;
class ICourse;
class Unit;
class TrainingAction;
......@@ -42,7 +41,7 @@ namespace LearnerProfile {
class ARTIKULATECORE_EXPORT TrainingSession : public QObject
{
Q_OBJECT
Q_PROPERTY(Course *course READ course WRITE setCourse NOTIFY courseChanged)
Q_PROPERTY(ICourse *course READ course WRITE setCourse NOTIFY courseChanged)
Q_PROPERTY(Unit *unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(Phrase *phrase READ activePhrase WRITE setPhrase NOTIFY phraseChanged)
Q_PROPERTY(bool hasNext READ hasNext NOTIFY phraseChanged)
......@@ -51,8 +50,8 @@ public:
explicit TrainingSession(QObject *parent = nullptr);
void setProfileManager(LearnerProfile::ProfileManager *manager);
Course * course() const;
void setCourse(Course *course);
ICourse * course() const;
void setCourse(ICourse *course);
Unit * unit() const;
void setUnit(Unit *unit);
TrainingAction * activeAction() const;
......@@ -79,7 +78,7 @@ private:
Phrase * nextPhrase() const;
void updateGoal();
LearnerProfile::ProfileManager *m_profileManager;
Course *m_course;
ICourse *m_course;
Unit *m_unit;
QVector<TrainingAction*> m_actions;
......
......@@ -68,12 +68,12 @@ void Unit::setForeignId(const QString &id)
m_foreignId = id;
}
Course * Unit::course() const
ICourse *Unit::course() const
{
return m_course;
}
void Unit::setCourse(Course *course)
void Unit::setCourse(ICourse *course)
{
if (course == m_course) {
return;
......
......@@ -30,14 +30,14 @@
class QSignalMapper;
class QString;
class Phrase;
class Course;
class ICourse;
class ARTIKULATECORE_EXPORT Unit : public QObject
{
Q_OBJECT
Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(Course *course READ course WRITE setCourse NOTIFY courseChanged)
Q_PROPERTY(ICourse *course READ course WRITE setCourse NOTIFY courseChanged)
public:
explicit Unit(QObject *parent = nullptr);
......@@ -47,8 +47,8 @@ public:
void setId(const QString &id);
QString foreignId() const;
void setForeignId(const QString &id);
Course * course() const;
void setCourse(Course* course);
ICourse * course() const;
void setCourse(ICourse* course);
QString title() const;
void setTitle(const QString &title);
QList<Phrase *> phraseList() const;
......@@ -79,7 +79,7 @@ private:
Q_DISABLE_COPY(Unit)
QString m_id;
QString m_foreignId;
Course *m_course;
ICourse *m_course;
QString m_title;
QList<Phrase *> m_phraseList;
QSignalMapper *m_phraseSignalMapper;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment