55 *
66 */
77
8+ #include " dictmodel.h"
9+ #include < QAbstractListModel>
10+ #include < QByteArray>
811#include < QDebug>
912#include < QFile>
13+ #include < QObject>
1014#include < QSet>
1115#include < QStringList>
1216#include < QTemporaryFile>
17+ #include < Qt>
1318#include < QtGlobal>
14- #include < fcitx-utils/standardpath.h>
15-
16- #include < fcntl.h>
17- #include " dictmodel.h"
19+ #include < fcitx-utils/standardpaths.h>
1820
1921namespace fcitx {
2022
@@ -28,17 +30,16 @@ SkkDictModel::SkkDictModel(QObject *parent) : QAbstractListModel(parent) {
2830}
2931
3032void SkkDictModel::defaults () {
31- auto path =
32- StandardPath::global ().fcitxPath (" pkgdatadir" , " skk/dictionary_list" );
33- QFile f (path.data ());
33+ auto path = StandardPaths::fcitxPath (" pkgdatadir" , " skk/dictionary_list" );
34+ QFile f (path);
3435 if (f.open (QIODevice::ReadOnly)) {
3536 load (f);
3637 }
3738}
3839
3940void SkkDictModel::load () {
40- auto file = StandardPath ::global ().open (StandardPath::Type ::PkgData,
41- " skk/dictionary_list" , O_RDONLY );
41+ auto file = StandardPaths ::global ().open (StandardPathsType ::PkgData,
42+ " skk/dictionary_list" );
4243 if (file.fd () < 0 ) {
4344 return ;
4445 }
@@ -66,7 +67,7 @@ void SkkDictModel::load(QFile &file) {
6667
6768 bool failed = false ;
6869 QMap<QString, QString> dict;
69- Q_FOREACH (const QString &item, items) {
70+ for (const QString &item : items) {
7071 if (!item.contains (' =' )) {
7172 failed = true ;
7273 break ;
@@ -89,18 +90,18 @@ void SkkDictModel::load(QFile &file) {
8990}
9091
9192bool SkkDictModel::save () {
92- return StandardPath ::global ().safeSave (
93- StandardPath::Type ::PkgData, " skk/dictionary_list" , [this ](int fd) {
93+ return StandardPaths ::global ().safeSave (
94+ StandardPathsType ::PkgData, " skk/dictionary_list" , [this ](int fd) {
9495 QFile tempFile;
9596 if (!tempFile.open (fd, QIODevice::WriteOnly)) {
9697 return false ;
9798 }
9899
99- typedef QMap<QString, QString> DictType ;
100+ using DictType = QMap<QString, QString>;
100101
101- Q_FOREACH (const DictType &dict, m_dicts) {
102+ for (const DictType &dict : m_dicts) {
102103 bool first = true ;
103- Q_FOREACH (const QString &key, dict.keys ()) {
104+ for (const QString &key : dict.keys ()) {
104105 if (first) {
105106 first = false ;
106107 } else {
@@ -141,11 +142,11 @@ bool SkkDictModel::removeRows(int row, int count, const QModelIndex &parent) {
141142
142143QVariant SkkDictModel::data (const QModelIndex &index, int role) const {
143144 if (!index.isValid ()) {
144- return QVariant () ;
145+ return {} ;
145146 }
146147
147148 if (index.row () >= m_dicts.size () || index.column () != 0 ) {
148- return QVariant () ;
149+ return {} ;
149150 }
150151
151152 switch (role) {
@@ -156,18 +157,16 @@ QVariant SkkDictModel::data(const QModelIndex &index, int role) const {
156157 return QString (" %1:%2" ).arg (m_dicts[index.row ()][" host" ],
157158 m_dicts[index.row ()][" port" ]);
158159 }
160+ default :
161+ break ;
159162 }
160- return QVariant () ;
163+ return {} ;
161164}
162165
163166bool SkkDictModel::moveUp (const QModelIndex ¤tIndex) {
164167 if (currentIndex.row () > 0 && currentIndex.row () < m_dicts.size ()) {
165168 beginResetModel ();
166- #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
167- m_dicts.swap (currentIndex.row () - 1 , currentIndex.row ());
168- #else
169169 m_dicts.swapItemsAt (currentIndex.row () - 1 , currentIndex.row ());
170- #endif
171170 endResetModel ();
172171 return true ;
173172 }
@@ -177,11 +176,7 @@ bool SkkDictModel::moveUp(const QModelIndex ¤tIndex) {
177176bool SkkDictModel::moveDown (const QModelIndex ¤tIndex) {
178177 if (currentIndex.row () >= 0 && currentIndex.row () + 1 < m_dicts.size ()) {
179178 beginResetModel ();
180- #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
181- m_dicts.swap (currentIndex.row () + 1 , currentIndex.row ());
182- #else
183179 m_dicts.swapItemsAt (currentIndex.row () + 1 , currentIndex.row ());
184- #endif
185180 endResetModel ();
186181 return true ;
187182 }
0 commit comments