| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
|
| 24 |
#include <QAbstractListModel> |
| 25 |
#include <QString> |
| 26 |
|
| 27 |
#include <chewing.h> |
| 28 |
|
| 29 |
#include "Userphrase.h" |
| 30 |
#include "UserphraseExporter.h" |
| 31 |
#include "UserphraseImporter.h" |
| 32 |
#include "UserphraseSet.h" |
| 33 |
|
| 34 |
class UserphraseModel final: public QAbstractListModel { |
| 35 |
Q_OBJECT |
| 36 |
|
| 37 |
public: |
| 38 |
UserphraseModel(QObject * parent = 0, const char *path = nullptr); |
| 39 |
UserphraseModel(const UserphraseModel& x) = delete; |
| 40 |
UserphraseModel& operator=(const UserphraseModel& x) = delete; |
| 41 |
virtual ~UserphraseModel() = default; |
| 42 |
|
| 43 |
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 44 |
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 45 |
|
| 46 |
const Userphrase *getUserphrase(const QModelIndex& idx); |
| 47 |
|
| 48 |
int getAddResult() const {return addresult_;} |
| 49 |
signals: |
| 50 |
void importCompleted( |
| 51 |
bool result, |
| 52 |
const QString& file, |
| 53 |
size_t imported, |
| 54 |
size_t total); |
| 55 |
void exportCompleted( |
| 56 |
bool result, |
| 57 |
const QString& file, |
| 58 |
size_t exported); |
| 59 |
void addNewPhraseCompleted(const Userphrase& userphrase); |
| 60 |
void removePhraseCompleted(size_t count); |
| 61 |
void refreshCompleted(size_t count); |
| 62 |
void addNewPhraseFailed(); |
| 63 |
void undoCompleted(const QString &phrase); |
| 64 |
|
| 65 |
public slots: |
| 66 |
void refresh(); |
| 67 |
void add(const QString &phrase, const QString &bopomofo); |
| 68 |
void importUserphrase(std::shared_ptr<UserphraseImporter> importer); |
| 69 |
void exportUserphrase(std::shared_ptr<UserphraseExporter> exporter); |
| 70 |
void remove(QModelIndexList indexList); |
| 71 |
void undo(); |
| 72 |
|
| 73 |
private: |
| 74 |
QString checkBopomofo(const QString &bopomofo) const; |
| 75 |
|
| 76 |
std::unique_ptr<ChewingContext, void (*)(ChewingContext*)> ctx_; |
| 77 |
UserphraseSet userphrase_; |
| 78 |
std::vector<Userphrase> removerecord_; |
| 79 |
int addresult_; |
| 80 |
}; |