File indexing completed on 2024-04-21 03:50:59

0001 /*
0002     SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #ifndef VOCABULARYMODEL_H
0006 #define VOCABULARYMODEL_H
0007 
0008 #include <KEduVocExpression>
0009 #include <KEduVocTranslation>
0010 #include <QAbstractTableModel>
0011 
0012 class KEduVocDocument;
0013 class KEduVocLesson;
0014 
0015 /**
0016     @author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0017 */
0018 class VocabularyModel : public QAbstractTableModel
0019 {
0020     Q_OBJECT
0021 public:
0022     enum entryColumns {
0023         Translation = 0,
0024         Pronunciation,
0025         WordClass,
0026         Synonym,
0027         Antonym,
0028         Example,
0029         Comment,
0030         Paraphrase,
0031         //         Audio,
0032         //         Image,
0033         EntryColumnsMAX
0034 
0035     };
0036 
0037     enum roles { TranslationRole = Qt::UserRole, EntryRole, LocaleRole, AudioRole, ImageRole };
0038 
0039     explicit VocabularyModel(QObject *parent = nullptr);
0040 
0041     ~VocabularyModel() override;
0042 
0043     int rowCount(const QModelIndex &) const override;
0044     int columnCount(const QModelIndex &) const override;
0045     QVariant data(const QModelIndex &, int) const override;
0046     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0047     Qt::ItemFlags flags(const QModelIndex &index) const override;
0048 
0049     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0050 
0051     /**
0052      * Returns the name of the entryColumns column
0053      * @param document KEduVocDocument document
0054      * @param translation the number of translation
0055      * @param column the column index
0056      * @param addLocaleSuffix controls if locale name should be added to column title
0057      */
0058     static QString columnTitle(KEduVocDocument *document, int translation, int column, bool addLocaleSuffix);
0059 
0060     /**
0061      * Returns which translation this column matches. It starts from 0 and increases every
0062      * EntryColumnMax columns
0063      */
0064     static int translation(int column);
0065 
0066     /**
0067      * Returns the type of the column specified. Translation types are multiples of
0068      * EntryColumnsMAX
0069      */
0070     static int columnType(int column);
0071 
0072     QModelIndex appendEntry(KEduVocExpression *expression = nullptr);
0073 
0074     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0075 
0076     QStringList mimeTypes() const override;
0077     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0078     //     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0079     //         int row, int column, const QModelIndex &parent);
0080 
0081     void resetLanguages();
0082 
0083 public Q_SLOTS:
0084     void setDocument(KEduVocDocument *doc);
0085 
0086     /**
0087      * Whatever the contents, the model will now display it.
0088      * @param container
0089      */
0090     void showContainer(KEduVocContainer *container);
0091 
0092     /**
0093      *
0094      * @param lessonContainer
0095      */
0096     void setLesson(KEduVocLesson *lessonContainer);
0097 
0098     KEduVocLesson *lesson();
0099 
0100     /**
0101      * Show the entries of child lessons in selected lessons
0102      * @param show
0103      */
0104     void showEntriesOfSubcontainers(bool show);
0105 
0106     /**
0107      * Set automatic translation to enabled/disabled
0108      * @param enabled
0109      */
0110     void automaticTranslation(bool enabled);
0111 
0112 private:
0113     KEduVocContainer *m_container;
0114     KEduVocLesson *m_lesson;
0115 
0116     KEduVocDocument *m_document;
0117     KEduVocContainer::EnumEntriesRecursive m_recursive;
0118 };
0119 
0120 Q_DECLARE_METATYPE(KEduVocExpression *)
0121 
0122 #endif