66 */
77
88#include " dictmodel.h"
9+ #include < QAbstractListModel>
910#include < QFile>
11+ #include < QIODevice>
12+ #include < QMap>
13+ #include < QObject>
1014#include < QSet>
15+ #include < QString>
1116#include < QStringList>
17+ #include < QVariant>
18+ #include < Qt>
1219#include < QtGlobal>
13- #include < fcitx-utils/standardpath .h>
14- # include < fcntl.h >
20+ #include < fcitx-utils/standardpaths .h>
21+
1522namespace fcitx {
1623
1724DictModel::DictModel (QObject *parent) : QAbstractListModel(parent) {
@@ -23,17 +30,16 @@ DictModel::DictModel(QObject *parent) : QAbstractListModel(parent) {
2330DictModel::~DictModel () {}
2431
2532void DictModel::defaults () {
26- auto path =
27- StandardPath::global ().fcitxPath (" pkgdatadir" , " kkc/dictionary_list" );
28- QFile f (path.data ());
33+ auto path = StandardPaths::fcitxPath (" pkgdatadir" , " kkc/dictionary_list" );
34+ QFile f (path);
2935 if (f.open (QIODevice::ReadOnly)) {
3036 load (f);
3137 }
3238}
3339
3440void DictModel::load () {
35- auto file = StandardPath ::global ().open (StandardPath::Type ::PkgData,
36- " kkc/dictionary_list" , O_RDONLY );
41+ auto file = StandardPaths ::global ().open (StandardPathsType ::PkgData,
42+ " kkc/dictionary_list" );
3743 if (file.fd () < 0 ) {
3844 return ;
3945 }
@@ -60,7 +66,7 @@ void DictModel::load(QFile &file) {
6066
6167 bool failed = false ;
6268 QMap<QString, QString> dict;
63- Q_FOREACH (const QString &item, items) {
69+ for (const QString &item : items) {
6470 if (!item.contains (' =' )) {
6571 failed = true ;
6672 break ;
@@ -83,18 +89,18 @@ void DictModel::load(QFile &file) {
8389}
8490
8591bool DictModel::save () {
86- return StandardPath ::global ().safeSave (
87- StandardPath::Type ::PkgData, " kkc/dictionary_list" , [this ](int fd) {
92+ return StandardPaths ::global ().safeSave (
93+ StandardPathsType ::PkgData, " kkc/dictionary_list" , [this ](int fd) {
8894 QFile tempFile;
8995 if (!tempFile.open (fd, QIODevice::WriteOnly)) {
9096 return false ;
9197 }
9298
93- typedef QMap<QString, QString> DictType ;
99+ using DictType = QMap<QString, QString>;
94100
95- Q_FOREACH (const DictType &dict, dicts_) {
101+ for (const DictType &dict : dicts_) {
96102 bool first = true ;
97- Q_FOREACH (const QString &key, dict.keys ()) {
103+ for (const QString &key : dict.keys ()) {
98104 if (first) {
99105 first = false ;
100106 } else {
@@ -135,28 +141,26 @@ bool DictModel::removeRows(int row, int count, const QModelIndex &parent) {
135141
136142QVariant DictModel::data (const QModelIndex &index, int role) const {
137143 if (!index.isValid ()) {
138- return QVariant () ;
144+ return {} ;
139145 }
140146
141147 if (index.row () >= dicts_.size () || index.column () != 0 ) {
142- return QVariant () ;
148+ return {} ;
143149 }
144150
145151 switch (role) {
146152 case Qt::DisplayRole:
147153 return dicts_[index.row ()][" file" ];
154+ default :
155+ return {};
148156 }
149- return QVariant () ;
157+ return {} ;
150158}
151159
152160bool DictModel::moveUp (const QModelIndex ¤tIndex) {
153161 if (currentIndex.row () > 0 && currentIndex.row () < dicts_.size ()) {
154162 beginResetModel ();
155- #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
156- dicts_.swap (currentIndex.row () - 1 , currentIndex.row ());
157- #else
158163 dicts_.swapItemsAt (currentIndex.row () - 1 , currentIndex.row ());
159- #endif
160164 endResetModel ();
161165 return true ;
162166 }
@@ -166,11 +170,7 @@ bool DictModel::moveUp(const QModelIndex ¤tIndex) {
166170bool DictModel::moveDown (const QModelIndex ¤tIndex) {
167171 if (currentIndex.row () >= 0 && currentIndex.row () + 1 < dicts_.size ()) {
168172 beginResetModel ();
169- #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
170- dicts_.swap (currentIndex.row () + 1 , currentIndex.row ());
171- #else
172173 dicts_.swapItemsAt (currentIndex.row () + 1 , currentIndex.row ());
173- #endif
174174 endResetModel ();
175175 return true ;
176176 }
0 commit comments