Debian Codegraph @

src/model/UserphraseModel.h

raw symbols SCIP
1 /*
2 * chewing-editor: Chewing userphrase editor
3 * Copyright (C) 2014 Chewing Development Team
4
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 };