| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2012~2017 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
* |
| 6 |
*/ |
| 7 |
#ifndef _QUICKPHRASE_EDITOR_MODEL_H_ |
| 8 |
#define _QUICKPHRASE_EDITOR_MODEL_H_ |
| 9 |
|
| 10 |
#include <QAbstractTableModel> |
| 11 |
#include <QFutureWatcher> |
| 12 |
#include <QList> |
| 13 |
#include <QObject> |
| 14 |
#include <QSet> |
| 15 |
#include <QTextStream> |
| 16 |
#include <QVariant> |
| 17 |
#include <Qt> |
| 18 |
#include <utility> |
| 19 |
|
| 20 |
class QFile; |
| 21 |
namespace fcitx { |
| 22 |
|
| 23 |
using QStringPairList = QList<std::pair<QString, QString>>; |
| 24 |
|
| 25 |
class QuickPhraseModel : public QAbstractTableModel { |
| 26 |
Q_OBJECT |
| 27 |
public: |
| 28 |
explicit QuickPhraseModel(QObject *parent = 0); |
| 29 |
virtual ~QuickPhraseModel(); |
| 30 |
|
| 31 |
Qt::ItemFlags flags(const QModelIndex &index) const override; |
| 32 |
bool setData(const QModelIndex &index, const QVariant &value, |
| 33 |
int role = Qt::EditRole) override; |
| 34 |
QVariant headerData(int section, Qt::Orientation orientation, |
| 35 |
int role = Qt::DisplayRole) const override; |
| 36 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 37 |
int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 38 |
QVariant data(const QModelIndex &index, |
| 39 |
int role = Qt::DisplayRole) const override; |
| 40 |
void load(const QString &file, bool append); |
| 41 |
void loadData(QTextStream &stream); |
| 42 |
void addItem(const QString ¯o, const QString &word); |
| 43 |
void deleteItem(int row); |
| 44 |
void deleteAllItem(); |
| 45 |
QFutureWatcher<bool> *save(const QString &file); |
| 46 |
void saveDataToStream(QTextStream &dev); |
| 47 |
bool needSave() const; |
| 48 |
|
| 49 |
Q_SIGNALS: |
| 50 |
void needSaveChanged(bool needSave); |
| 51 |
|
| 52 |
private Q_SLOTS: |
| 53 |
void loadFinished(); |
| 54 |
void saveFinished(); |
| 55 |
|
| 56 |
private: |
| 57 |
QStringPairList parse(const QString &file); |
| 58 |
bool saveData(const QString &file, const fcitx::QStringPairList &list); |
| 59 |
void setNeedSave(bool needSave); |
| 60 |
bool needSave_; |
| 61 |
QStringPairList list_; |
| 62 |
QFutureWatcher<QStringPairList> *futureWatcher_; |
| 63 |
}; |
| 64 |
} // namespace fcitx |
| 65 |
|
| 66 |
#endif // _QUICKPHRASE_EDITOR_MODEL_H_ |