diff --git a/src/core/unit.cpp b/src/core/unit.cpp index 9894e19..3fed3f5 100644 --- a/src/core/unit.cpp +++ b/src/core/unit.cpp @@ -1,184 +1,171 @@ /* * Copyright 2013-2015 Andreas Cord-Landwehr * Copyright 2013 Oindrila Gupta * * 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 "unit.h" #include "phrase.h" #include -#include -#include #include #include #include #include "artikulate_debug.h" #include #include Unit::Unit(QObject *parent) : IEditableUnit(parent) - , m_phraseSignalMapper(new QSignalMapper(this)) { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); } -Unit::~Unit() -{ - for (auto phrase : m_phrases) { - phrase->deleteLater(); - } - m_phrases.clear(); - m_phraseSignalMapper->deleteLater(); -} +Unit::~Unit() = default; std::shared_ptr Unit::create() { std::shared_ptr unit(new Unit); unit->setSelf(unit); return unit; } void Unit::setSelf(std::shared_ptr self) { m_self = self; } std::shared_ptr Unit::self() const { return m_self.lock(); } QString Unit::id() const { return m_id; } void Unit::setId(const QString &id) { if (id != m_id) { m_id = id; emit idChanged(); emit modified(); } } QString Unit::foreignId() const { return m_foreignId; } void Unit::setForeignId(const QString &id) { m_foreignId = id; } std::shared_ptr Unit::course() const { return m_course.lock(); } void Unit::setCourse(std::shared_ptr course) { if (course == m_course.lock()) { return; } m_course = course; emit courseChanged(); } QString Unit::title() const { return m_title; } void Unit::setTitle(const QString &title) { if (QString::compare(title, m_title) != 0) { m_title = title; emit titleChanged(); emit modified(); } } QVector> Unit::phrases() const { return m_phrases; } void Unit::addPhrase(std::shared_ptr phrase) { auto iter = m_phrases.constBegin(); while (iter != m_phrases.constEnd()) { if (phrase->id() == (*iter)->id()) { qCWarning(ARTIKULATE_LOG()) << "Phrase is already contained in this unit, aborting"; return; } ++iter; } phrase->setUnit(m_self.lock()); emit phraseAboutToBeAdded(phrase, m_phrases.length()); m_phrases.append(phrase); - m_phraseSignalMapper->setMapping(phrase.get(), phrase->id()); emit phraseAdded(phrase); - connect(phrase.get(), &Phrase::typeChanged, m_phraseSignalMapper, - static_cast(&QSignalMapper::map)); connect(phrase.get(), &Phrase::modified, this, &Unit::modified); emit modified(); } QList Unit::excludedSkeletonPhraseList() const { QList excludedPhraseList; //TODO this should not be handled on unit level // for (auto phrase : m_phrases) { // if (phrase->isExcluded() == true) { // excludedPhraseList.append(phrase); // } // } return excludedPhraseList; } void Unit::excludeSkeletonPhrase(const QString &phraseId) { // for (auto phrase : m_phrases) { // if (phrase->id() == phraseId) { // phrase->setExcluded(true); // emit modified(); // return; // } // } qCWarning(ARTIKULATE_LOG) << "Could not exclude phrase with ID " << phraseId << ", no phrase with this ID."; } void Unit::includeSkeletonPhrase(const QString &phraseId) { // for (auto phrase : m_phrases) { // if (phrase->id() == phraseId) { // phrase->setExcluded(false); // emit modified(); // return; // } // } qCWarning(ARTIKULATE_LOG) << "Could not include phrase with ID " << phraseId << ", no phrase with this ID."; } diff --git a/src/core/unit.h b/src/core/unit.h index 86b695f..fef8019 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -1,84 +1,82 @@ /* * Copyright 2013 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 UNIT_H #define UNIT_H #include "artikulatecore_export.h" #include "ieditableunit.h" #include #include #include #include -class QSignalMapper; class QString; class Phrase; class IPhrase; class ICourse; class ARTIKULATECORE_EXPORT Unit : public IEditableUnit { Q_OBJECT Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) public: static std::shared_ptr create(); ~Unit() override; QString id() const override; void setId(const QString &id) override; QString foreignId() const override; void setForeignId(const QString &id) override; std::shared_ptr course() const override; void setCourse(std::shared_ptr course) override; QString title() const override; void setTitle(const QString &title) override; QVector> phrases() const override; void addPhrase(std::shared_ptr phrase) override; QList excludedSkeletonPhraseList() const; std::shared_ptr self() const override; /** * Removes phrase with ID \p phraseId from unit and adds ID to set * of excluded IDs. * * \param phraseId is the UID of the to be excluded phrase */ Q_INVOKABLE void excludeSkeletonPhrase(const QString &phraseId); Q_INVOKABLE void includeSkeletonPhrase(const QString &phraseId); protected: explicit Unit(QObject *parent = nullptr); private: void setSelf(std::shared_ptr self) override; Q_DISABLE_COPY(Unit) std::weak_ptr m_self; QString m_id; QString m_foreignId; std::weak_ptr m_course; QString m_title; QVector> m_phrases; - QSignalMapper *m_phraseSignalMapper; }; #endif // UNIT_H