Commit 73ec6200 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Introduce ILanguage interface

parent 869f4a16
......@@ -76,7 +76,7 @@ void TestIResourceRepository::performInterfaceTests(IResourceRepository *interfa
// test access of courses grouped by language
auto languages = interface->languages();
std::shared_ptr<Language> german;
std::shared_ptr<ILanguage> german;
for (auto language : interface->languages()) {
if (language->id() == "de") {
german = language;
......
......@@ -30,14 +30,14 @@
class CourseStub : public ICourse
{
public:
CourseStub(std::shared_ptr<Language> language, QVector<std::shared_ptr<Unit>> units)
CourseStub(std::shared_ptr<ILanguage> language, QVector<std::shared_ptr<Unit>> units)
: m_language(language)
, m_units(units)
{
}
~CourseStub() override;
static std::shared_ptr<ICourse> create(std::shared_ptr<Language> language, QVector<std::shared_ptr<Unit>> units)
static std::shared_ptr<ICourse> create(std::shared_ptr<ILanguage> language, QVector<std::shared_ptr<Unit>> units)
{
auto course = std::make_shared<CourseStub>(language, units);
course->setSelf(course);
......@@ -74,7 +74,7 @@ public:
{
return "description of the course";
}
std::shared_ptr<Language> language() const override
std::shared_ptr<ILanguage> language() const override
{
return m_language;
}
......@@ -90,7 +90,7 @@ public:
private:
QString m_title{ "title" };
std::weak_ptr<ICourse> m_self;
std::shared_ptr<Language> m_language;
std::shared_ptr<ILanguage> m_language;
QVector<std::shared_ptr<Unit>> m_units;
};
......
......@@ -26,7 +26,7 @@
#include <QObject>
#include <QVector>
class Language;
class ILanguage;
class SkeletonResource;
/**
......@@ -37,7 +37,7 @@ class EditableRepositoryStub : public IEditableRepository
Q_OBJECT
public:
EditableRepositoryStub(
std::vector<std::shared_ptr<Language>> languages,
std::vector<std::shared_ptr<ILanguage>> languages,
std::vector<std::shared_ptr<IEditableCourse>> skeletons,
std::vector<std::shared_ptr<IEditableCourse>> courses)
{
......@@ -77,7 +77,7 @@ public:
Q_UNUSED(languageId);
return QVector<std::shared_ptr<ICourse>>();
}
std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<Language> language, int index) const override
std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<ILanguage> language, int index) const override
{
Q_UNUSED(language);
Q_UNUSED(index);
......@@ -87,7 +87,7 @@ public:
{
// do nothing
}
QVector<std::shared_ptr<Language>> languages() const override
QVector<std::shared_ptr<ILanguage>> languages() const override
{
return m_languages;
}
......@@ -98,7 +98,7 @@ public:
}
private:
QVector<std::shared_ptr<Language>> m_languages;
QVector<std::shared_ptr<ILanguage>> m_languages;
QVector<std::shared_ptr<IEditableCourse>> m_skeletons;
QVector<std::shared_ptr<IEditableCourse>> m_courses;
};
......
......@@ -36,21 +36,21 @@ class ResourceRepositoryStub : public IResourceRepository
{
Q_OBJECT
public:
ResourceRepositoryStub(std::vector<std::unique_ptr<Language>> languages)
ResourceRepositoryStub(std::vector<std::unique_ptr<ILanguage>> languages)
{
for (auto &language : languages) {
m_languages.append(std::move(language));
}
}
ResourceRepositoryStub(std::vector<std::shared_ptr<Language>> languages)
ResourceRepositoryStub(std::vector<std::shared_ptr<ILanguage>> languages)
{
for (auto &language : languages) {
m_languages.append(language);
}
}
ResourceRepositoryStub(std::vector<std::shared_ptr<Language>> languages, std::vector<std::shared_ptr<ICourse>> courses)
ResourceRepositoryStub(std::vector<std::shared_ptr<ILanguage>> languages, std::vector<std::shared_ptr<ICourse>> courses)
{
for (auto &language : languages) {
m_languages.append(language);
......@@ -83,7 +83,7 @@ public:
; // do nothing, stub shall only provide languages
}
QVector<std::shared_ptr<Language>> languages() const override
QVector<std::shared_ptr<ILanguage>> languages() const override
{
return m_languages;
}
......@@ -108,7 +108,7 @@ public:
private:
QString m_storageLocation;
QVector<std::shared_ptr<Language>> m_languages;
QVector<std::shared_ptr<ILanguage>> m_languages;
QVector<std::shared_ptr<ICourse>> m_courses;
};
......
......@@ -41,9 +41,9 @@ void TestCourseModel::cleanup()
void TestCourseModel::testInit()
{
// boilerplate
std::shared_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::shared_ptr<Language>> languages;
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
std::vector<std::shared_ptr<ILanguage>> languages;
languages.push_back(language);
auto course = CourseStub::create(language, QVector<std::shared_ptr<Unit>>({}));
ResourceRepositoryStub repository(languages, {course});
......@@ -58,9 +58,9 @@ void TestCourseModel::testInit()
void TestCourseModel::testAddRemoveOperations()
{
// boilerplate
std::shared_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::shared_ptr<Language>> languages;
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
std::vector<std::shared_ptr<ILanguage>> languages;
languages.push_back(language);
ResourceRepositoryStub repository(languages, {});
......@@ -98,9 +98,9 @@ void TestCourseModel::testAddRemoveOperations()
void TestCourseModel::testDataChangedSignals()
{
// boilerplate
std::shared_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::shared_ptr<Language>> languages;
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
std::vector<std::shared_ptr<ILanguage>> languages;
languages.push_back(language);
auto course = CourseStub::create(language, QVector<std::shared_ptr<Unit>>({}));
ResourceRepositoryStub repository(languages, {course});
......
......@@ -25,7 +25,7 @@
#include "core/phrase.h"
#include "core/phonemegroup.h"
#include "core/resources/courseresource.h"
#include <memory>
#include <QTest>
#include <QDebug>
#include <QTemporaryFile>
......@@ -50,14 +50,14 @@ void TestCourseResource::cleanup()
void TestCourseResource::loadCourseResource()
{
std::unique_ptr<Language> language(new Language);
language->setId("de");
auto group = language->addPhonemeGroup("id", "title");
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
auto group = std::static_pointer_cast<Language>(language)->addPhonemeGroup("id", "title");
group->addPhoneme("g", "G");
group->addPhoneme("u", "U");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::vector<std::shared_ptr<ILanguage>> languages;
languages.push_back(language);
ResourceRepositoryStub repository(languages);
const QString courseDirectory = "data/courses/de/";
const QString courseFile = courseDirectory + "de.xml";
......@@ -95,11 +95,9 @@ void TestCourseResource::loadCourseResource()
void TestCourseResource::unitAddAndRemoveHandling()
{
// boilerplate
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
const QString courseDirectory = "data/courses/de/";
const QString courseFile = courseDirectory + "de.xml";
......@@ -124,11 +122,9 @@ void TestCourseResource::unitAddAndRemoveHandling()
void TestCourseResource::coursePropertyChanges()
{
// boilerplate
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
const QString courseDirectory = "data/courses/de/";
const QString courseFile = courseDirectory + "de.xml";
......
......@@ -51,11 +51,9 @@ void TestEditableCourseResource::cleanup()
void TestEditableCourseResource::loadCourseResource()
{
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
auto course = EditableCourseResource::create(QUrl::fromLocalFile(":/courses/de.xml"), &repository);
QCOMPARE(course->file().toLocalFile(), ":/courses/de.xml");
......@@ -90,11 +88,9 @@ void TestEditableCourseResource::loadCourseResource()
void TestEditableCourseResource::unitAddAndRemoveHandling()
{
// boilerplate
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
auto course = EditableCourseResource::create(QUrl::fromLocalFile(":/courses/de.xml"), &repository);
// begin of test
......@@ -116,11 +112,9 @@ void TestEditableCourseResource::unitAddAndRemoveHandling()
void TestEditableCourseResource::coursePropertyChanges()
{
// boilerplate
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
auto course = CourseResource::create(QUrl::fromLocalFile(":/courses/de.xml"), &repository);
// id
......@@ -187,11 +181,9 @@ void TestEditableCourseResource::coursePropertyChanges()
void TestEditableCourseResource::fileLoadSaveCompleteness()
{
// boilerplate
std::unique_ptr<Language> language(new Language);
language->setId("de");
std::vector<std::unique_ptr<Language>> languages;
languages.push_back(std::move(language));
ResourceRepositoryStub repository(std::move(languages));
std::shared_ptr<ILanguage> language(new Language);
std::static_pointer_cast<Language>(language)->setId("de");
ResourceRepositoryStub repository({language});
auto course = EditableCourseResource::create(QUrl::fromLocalFile(":/courses/de.xml"), &repository);
QTemporaryFile outputFile;
......
......@@ -92,11 +92,11 @@ public:
m_description = description;
emit descriptionChanged();
}
std::shared_ptr<Language> language() const override
std::shared_ptr<ILanguage> language() const override
{
return m_language;
}
void setLanguage(std::shared_ptr<Language> language) override
void setLanguage(std::shared_ptr<ILanguage> language) override
{
m_language = language;
emit languageChanged();
......@@ -133,7 +133,7 @@ private:
QString m_title{ "title" };
QString m_i18nTitle{ "i18n title" };
QString m_description{ "description of the course" };
std::shared_ptr<Language> m_language;
std::shared_ptr<ILanguage> m_language;
QVector<std::shared_ptr<Unit>> m_units;
};
......
......@@ -69,7 +69,7 @@ void TestResourceRepository::iResourceRepositoryCompatability()
// test access of courses grouped by language
auto languages = interface->languages();
std::shared_ptr<Language> german;
std::shared_ptr<ILanguage> german;
for (auto language : interface->languages()) {
if (language->id() == "de") {
german = language;
......
......@@ -44,6 +44,7 @@ set(artikulateCore_SRCS
core/icourse.h
core/ieditablecourse.h
core/ieditablerepository.h
core/ilanguage.h
core/iresourcerepository.h
core/drawertrainingactions.cpp
core/resourcerepository.cpp
......
......@@ -21,11 +21,12 @@
#include "application.h"
#include "core/iresourcerepository.h"
#include "core/ilanguage.h"
#include "core/language.h"
#include "core/contributorrepository.h"
#include "core/drawertrainingactions.h"
#include "core/trainingaction.h"
#include "core/editorsession.h"
#include "core/language.h"
#include "core/phoneme.h"
#include "core/phonemegroup.h"
#include "core/phrase.h"
......@@ -110,6 +111,7 @@ void Application::registerQmlTypes()
qmlRegisterInterface<IResourceRepository>("IEditableRepository");
qmlRegisterInterface<ICourse>("ICourse");
qmlRegisterInterface<IEditableCourse>("IEditableCourse");
qmlRegisterInterface<ICourse>("ILanguage");
// concrete instantiable types
qmlRegisterType<LearnerProfile::Learner>("artikulate", 1, 0, "Learner");
......
......@@ -116,18 +116,18 @@ void ContributorRepository::setStorageLocation(const QString &path)
m_storageLocation = path;
}
QVector<std::shared_ptr<Language>> ContributorRepository::languages() const
QVector<std::shared_ptr<ILanguage>> ContributorRepository::languages() const
{
return m_languages;
}
std::shared_ptr<Language> ContributorRepository::language(int index) const
std::shared_ptr<ILanguage> ContributorRepository::language(int index) const
{
Q_ASSERT(index >= 0 && index < m_languages.count());
return m_languages.at(index);
}
Language * ContributorRepository::language(LearnerProfile::LearningGoal *learningGoal) const
ILanguage * ContributorRepository::language(LearnerProfile::LearningGoal *learningGoal) const
{
if (!learningGoal) {
return nullptr;
......@@ -145,7 +145,7 @@ Language * ContributorRepository::language(LearnerProfile::LearningGoal *learnin
return nullptr;
}
QVector<std::shared_ptr<EditableCourseResource>> ContributorRepository::courseResources(std::shared_ptr<Language> language)
QVector<std::shared_ptr<EditableCourseResource>> ContributorRepository::courseResources(std::shared_ptr<ILanguage> language)
{
if (!language) {
QVector<std::shared_ptr<EditableCourseResource>> courses;
......@@ -198,7 +198,7 @@ QVector<std::shared_ptr<ICourse>> ContributorRepository::courses(const QString &
return courses;
}
std::shared_ptr<IEditableCourse> ContributorRepository::editableCourse(std::shared_ptr<Language> language, int index) const
std::shared_ptr<IEditableCourse> ContributorRepository::editableCourse(std::shared_ptr<ILanguage> language, int index) const
{
Q_ASSERT(m_courses.contains(language->id()));
Q_ASSERT(index >= 0 && index < m_courses[language->id()].count());
......@@ -400,7 +400,7 @@ void ContributorRepository::removeCourse(std::shared_ptr<ICourse> course)
}
}
IEditableCourse * ContributorRepository::createCourse(std::shared_ptr<Language> language, std::shared_ptr<SkeletonResource> skeleton)
IEditableCourse * ContributorRepository::createCourse(std::shared_ptr<ILanguage> language, std::shared_ptr<SkeletonResource> skeleton)
{
// set path
QString path = QStringLiteral("%1/%2/%3/%4/%4.xml")
......
......@@ -76,17 +76,17 @@ public:
*/
void setStorageLocation(const QString &path);
QVector<std::shared_ptr<Language>> languages() const override;
QVector<std::shared_ptr<ILanguage>> languages() const override;
/**
* \return language by \p index
*/
std::shared_ptr<Language> language(int index) const;
std::shared_ptr<ILanguage> language(int index) const;
/**
* \return language by \p learningGoal
*/
Q_INVOKABLE Language * language(LearnerProfile::LearningGoal* learningGoal) const;
Q_INVOKABLE ILanguage * language(LearnerProfile::LearningGoal* learningGoal) const;
QVector<std::shared_ptr<ICourse>> courses() const override;
QVector<std::shared_ptr<ICourse>> courses(const QString &languageId) const override;
......@@ -95,9 +95,9 @@ public:
/**
* \return list of all loaded courses for language \p language
*/
QVector<std::shared_ptr<EditableCourseResource>> courseResources(std::shared_ptr<Language> language);
QVector<std::shared_ptr<EditableCourseResource>> courseResources(std::shared_ptr<ILanguage> language);
std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<Language> language, int index) const override;
std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<ILanguage> language, int index) const override;
/**
* Reset the file for this course or skeleton.
......@@ -149,7 +149,7 @@ public:
*
* \return created course
*/
Q_INVOKABLE IEditableCourse * createCourse(std::shared_ptr<Language> language, std::shared_ptr<SkeletonResource> skeleton);
Q_INVOKABLE IEditableCourse * createCourse(std::shared_ptr<ILanguage> language, std::shared_ptr<SkeletonResource> skeleton);
/**
* Adds skeleton resource to resource manager
......@@ -170,7 +170,7 @@ public:
Q_SIGNALS:
void languageResourceAdded();
void languageResourceAboutToBeAdded(std::shared_ptr<Language>,int);
void languageResourceAboutToBeAdded(std::shared_ptr<ILanguage>,int);
void languageResourceRemoved();
void languageResourceAboutToBeRemoved(int);
void repositoryChanged();
......@@ -187,7 +187,7 @@ private:
*/
void loadLanguageResources();
QString m_storageLocation;
QVector<std::shared_ptr<Language>> m_languages;
QVector<std::shared_ptr<ILanguage>> m_languages;
QMap<QString, QVector<std::shared_ptr<EditableCourseResource>> > m_courses; //!> (language-id, course-resource)
QVector<std::shared_ptr<IEditableCourse>> m_skeletonResources;
QStringList m_loadedResources;
......
......@@ -86,7 +86,7 @@ void EditorSession::setSkeleton(IEditableCourse *skeleton)
emit skeletonChanged();
}
Language * EditorSession::language() const
ILanguage * EditorSession::language() const
{
return m_language;
}
......@@ -125,7 +125,7 @@ void EditorSession::setCourse(IEditableCourse *course)
emit courseChanged();
}
void EditorSession::setCourseByLanguage(Language *language)
void EditorSession::setCourseByLanguage(ILanguage *language)
{
if (!skeletonMode() || m_skeleton == nullptr) {
qDebug() << "Course selection by language is only available in skeleton mode";
......
......@@ -24,7 +24,7 @@
#include "artikulatecore_export.h"
#include "phrase.h"
class Language;
class ILanguage;
class IEditableCourse;
class Unit;
class SkeletonResource;
......@@ -64,7 +64,7 @@ class ARTIKULATECORE_EXPORT EditorSession : public QObject
* @brief the displayed course (skeleton or course) depending on the user selection
*/
Q_PROPERTY(IEditableCourse *displayedCourse READ displayedCourse NOTIFY displayedCourseChanged)
Q_PROPERTY(Language *language READ language NOTIFY languageChanged)
Q_PROPERTY(ILanguage *language READ language NOTIFY languageChanged)
Q_PROPERTY(Unit *unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(Phrase *phrase READ phrase WRITE setPhrase NOTIFY phraseChanged)
Q_PROPERTY(bool hasNextPhrase READ hasNextPhrase NOTIFY phraseChanged)
......@@ -79,14 +79,14 @@ public:
bool isEditSkeleton() const;
IEditableCourse * skeleton() const;
void setSkeleton(IEditableCourse *skeleton);
Language * language() const;
ILanguage * language() const;
IEditableCourse * course() const;
void setCourse(IEditableCourse *course);
/**
* @brief Open course resource by specifying the language
* @param language the target language
*/
Q_INVOKABLE void setCourseByLanguage(Language *language);
Q_INVOKABLE void setCourseByLanguage(ILanguage *language);
IEditableCourse * displayedCourse() const;
Q_DECL_DEPRECATED Unit * unit() const;
Unit * activeUnit() const;
......@@ -124,7 +124,7 @@ private:
IEditableRepository * m_repository{ nullptr };
bool m_editSkeleton{ false };
IEditableCourse *m_skeleton{ nullptr };
Language *m_language{ nullptr };
ILanguage *m_language{ nullptr };
IEditableCourse *m_course{ nullptr };
Unit *m_unit{ nullptr };
Phrase *m_phrase{ nullptr };
......
......@@ -28,7 +28,7 @@
#include <memory>
class QString;
class Language;
class ILanguage;
class Unit;
class Phoneme;
......@@ -47,7 +47,7 @@ public:
virtual QString title() const = 0;
virtual QString i18nTitle() const = 0;
virtual QString description() const = 0;
virtual std::shared_ptr<Language> language() const = 0;
virtual std::shared_ptr<ILanguage> language() const = 0;
/**
* @brief Lazy loading unit list
* @return list of units in course
......
......@@ -27,7 +27,7 @@
#include <QObject>
class QString;
class Language;
class ILanguage;
class ARTIKULATECORE_EXPORT IEditableCourse : public ICourse
{
......@@ -38,7 +38,7 @@ public:
virtual void setTitle(QString title) = 0;
virtual void setI18nTitle(QString title) = 0;
virtual void setDescription(QString description) = 0;
virtual void setLanguage(std::shared_ptr<Language> language) = 0;
virtual void setLanguage(std::shared_ptr<ILanguage> language) = 0;
virtual std::shared_ptr<Unit> addUnit(std::unique_ptr<Unit> unit) = 0;
virtual bool exportToFile(const QUrl &filePath) const = 0;
virtual bool isModified() const = 0;
......
......@@ -26,7 +26,7 @@
#include <memory>
class IEditableCourse;
class Language;
class ILanguage;
/**
* \class IEditableRepository
......@@ -39,7 +39,7 @@ class ARTIKULATECORE_EXPORT IEditableRepository : public IResourceRepository
public:
virtual ~IEditableRepository() = default;
virtual QVector<std::shared_ptr<IEditableCourse>> editableCourses() const = 0;
virtual std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<Language> language, int index) const = 0;
virtual std::shared_ptr<IEditableCourse> editableCourse(std::shared_ptr<ILanguage> language, int index) const = 0;
virtual QVector<std::shared_ptr<IEditableCourse>> skeletons() const = 0;
/**
* Imports units and phrases from skeleton, deassociates removed ones.
......
/*
* 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