File indexing completed on 2022-10-04 13:56:33

0001 /*
0002  * SPDX-FileCopyrightText: 2007 Jeremy Whiting <jpwhiting@kde.org>
0003  * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KEDUVOCCONTAINER_H
0008 #define KEDUVOCCONTAINER_H
0009 
0010 #include "keduvocdocument_export.h"
0011 
0012 #include "keduvoctext.h"
0013 
0014 #include <QList>
0015 #include <QUrl>
0016 
0017 class KEduVocDocument;
0018 class KEduVocExpression;
0019 
0020 /** class to store information about a container - that can be a lesson or word types */
0021 class KEDUVOCDOCUMENT_EXPORT KEduVocContainer
0022 {
0023     // make this a template?
0024 
0025 public:
0026     enum EnumContainerType{
0027         Container,
0028         Lesson,
0029         WordType,
0030         Leitner
0031     };
0032 
0033     enum EnumEntriesRecursive{
0034         NotRecursive = 0,
0035         Recursive = 1
0036     };
0037 
0038     /** default constructor */
0039     explicit KEduVocContainer(const QString& name, EnumContainerType type,
0040                   KEduVocContainer *parent = nullptr);
0041 
0042     void appendChildContainer(KEduVocContainer *child);
0043     void insertChildContainer(int row, KEduVocContainer *child);
0044     void deleteChildContainer(int row);
0045     void removeChildContainer(int row);
0046     KEduVocContainer *childContainer(int row);
0047 
0048     /**
0049      * Retrieve a child container by its name
0050      * Returns 0 if no container is found
0051      * @param name container name
0052      * @return the child container
0053      */
0054     KEduVocContainer *childContainer(const QString& name);
0055 
0056     QList<KEduVocContainer *> childContainers();
0057 
0058     /**
0059      * Find a child container
0060      * @param name
0061      * @return
0062      */
0063 //     KEduVocContainer *childContainer(const QString& name);
0064 
0065     int childContainerCount() const;
0066 
0067     int row() const;
0068     virtual KEduVocContainer *parent();
0069 
0070     /** copy constructor for d-pointer safe copying */
0071     KEduVocContainer( const KEduVocContainer &other );
0072 
0073     /** destructor */
0074     virtual ~KEduVocContainer();
0075 
0076     /** assignment operator */
0077     KEduVocContainer& operator= ( const KEduVocContainer& );
0078 
0079     /** @return the containing KEduVocDocument */
0080     KEduVocDocument *document() const;
0081 
0082     /** set the container name
0083      * @param name text to set for the name
0084      */
0085     void setName( const QString &name );
0086 
0087     /** get the container name */
0088     QString name();
0089 
0090     /** get a list of all entries in the container */
0091     virtual QList < KEduVocExpression* > entries(EnumEntriesRecursive recursive = NotRecursive) =0;
0092     virtual int entryCount(EnumEntriesRecursive recursive = NotRecursive) =0;
0093     virtual KEduVocExpression* entry(int row, EnumEntriesRecursive recursive = NotRecursive) =0;
0094 
0095     /**
0096      * Removes a translation. This has to be called when a language is removed from a document.
0097      * @param translation
0098      */
0099     void removeTranslation(int translation);
0100 
0101     bool inPractice();
0102     void setInPractice( bool inPractice );
0103 
0104     /** equality operator */
0105     bool operator==(const KEduVocContainer &other) const;
0106 
0107     /**
0108      * The type of this container. @see EnumContainerType
0109      * @return
0110      */
0111     KEduVocContainer::EnumContainerType containerType();
0112 
0113     /**
0114      * Set the type of container.
0115      * For convenience by default this is taken over from the parent, so no need to set.
0116      * @param type the new type
0117      */
0118     void setContainerType(KEduVocContainer::EnumContainerType type);
0119 
0120 
0121     /** get the image url for this container if it exists */
0122     QUrl imageUrl();
0123 
0124     /** set the image url for this container
0125      * @param url               url of the image
0126      */
0127     void setImageUrl(const QUrl &url);
0128 
0129     double averageGrade(int translation, EnumEntriesRecursive recursive);
0130 
0131     int expressionsOfGrade(int translation, grade_t grade, EnumEntriesRecursive recursive);
0132 
0133     /**
0134      * Remove grades from all entries of this lessons
0135      * @param translation which translation to remove. -1 for all.
0136      * @param recursive whether to include child lessons
0137      */
0138     void resetGrades(int translation, EnumEntriesRecursive recursive);
0139 
0140 protected:
0141     QList< KEduVocExpression * > entriesRecursive();
0142 
0143     /**
0144      * Set the child entry cache to invalid
0145      */
0146     void invalidateChildLessonEntries();
0147 
0148     /**
0149      * Recreate the cache of entries in this lesson's child lessons.
0150      */
0151     void updateChildLessonEntries();
0152 
0153     // Used by KEduVocLesson when the Document creates the top level lesson.
0154     explicit KEduVocContainer(const QString& name, EnumContainerType type,
0155                   KEduVocDocument *document);
0156 private:
0157     class Private;
0158     Private * const d;
0159 };
0160 
0161 #endif