1 /* 2 SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 #ifndef VOCABULARYMODEL_H 6 #define VOCABULARYMODEL_H 7 8 #include <KEduVocExpression> 9 #include <KEduVocTranslation> 10 #include <QAbstractTableModel> 11 12 class KEduVocDocument; 13 class KEduVocLesson; 14 15 /** 16 @author Frederik Gladhorn <frederik.gladhorn@kdemail.net> 17 */ 18 class VocabularyModel : public QAbstractTableModel 19 { 20 Q_OBJECT 21 public: 22 enum entryColumns { 23 Translation = 0, 24 Pronunciation, 25 WordClass, 26 Synonym, 27 Antonym, 28 Example, 29 Comment, 30 Paraphrase, 31 // Audio, 32 // Image, 33 EntryColumnsMAX 34 35 }; 36 37 enum roles { TranslationRole = Qt::UserRole, EntryRole, LocaleRole, AudioRole, ImageRole }; 38 39 explicit VocabularyModel(QObject *parent = nullptr); 40 41 ~VocabularyModel() override; 42 43 int rowCount(const QModelIndex &) const override; 44 int columnCount(const QModelIndex &) const override; 45 QVariant data(const QModelIndex &, int) const override; 46 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 47 Qt::ItemFlags flags(const QModelIndex &index) const override; 48 49 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 50 51 /** 52 * Returns the name of the entryColumns column 53 * @param document KEduVocDocument document 54 * @param translation the number of translation 55 * @param column the column index 56 * @param addLocaleSuffix controls if locale name should be added to column title 57 */ 58 static QString columnTitle(KEduVocDocument *document, int translation, int column, bool addLocaleSuffix); 59 60 /** 61 * Returns which translation this column matches. It starts from 0 and increases every 62 * EntryColumnMax columns 63 */ 64 static int translation(int column); 65 66 /** 67 * Returns the type of the column specified. Translation types are multiples of 68 * EntryColumnsMAX 69 */ 70 static int columnType(int column); 71 72 QModelIndex appendEntry(KEduVocExpression *expression = 0); 73 74 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 75 76 QStringList mimeTypes() const override; 77 QMimeData *mimeData(const QModelIndexList &indexes) const override; 78 // bool dropMimeData(const QMimeData *data, Qt::DropAction action, 79 // int row, int column, const QModelIndex &parent); 80 81 void resetLanguages(); 82 83 public slots: 84 void setDocument(KEduVocDocument *doc); 85 86 /** 87 * Whatever the contents, the model will now display it. 88 * @param container 89 */ 90 void showContainer(KEduVocContainer *container); 91 92 /** 93 * 94 * @param lessonContainer 95 */ 96 void setLesson(KEduVocLesson *lessonContainer); 97 98 KEduVocLesson *lesson(); 99 100 /** 101 * Show the entries of child lessons in selected lessons 102 * @param show 103 */ 104 void showEntriesOfSubcontainers(bool show); 105 106 /** 107 * Set automatic translation to enabled/disabled 108 * @param enabled 109 */ 110 void automaticTranslation(bool enabled); 111 112 private: 113 KEduVocContainer *m_container; 114 KEduVocLesson *m_lesson; 115 116 KEduVocDocument *m_document; 117 KEduVocContainer::EnumEntriesRecursive m_recursive; 118 }; 119 120 Q_DECLARE_METATYPE(KEduVocExpression *) 121 122 #endif 123