Skip to content

Commit bd8c941

Browse files
committed
Port to StandardPath and drop Qt5
1 parent 95f71e9 commit bd8c941

File tree

13 files changed

+161
-107
lines changed

13 files changed

+161
-107
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
build/*
1+
build*/
2+
.*
3+
!.git*
4+
.git/
5+
*.tar.*
26
*.kdev4
37
.kdev_include_paths
48
.directory

CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,23 @@ include(ECMUninstallTarget)
1212
option(ENABLE_QT "Enable Qt based macro editor" On)
1313
option(ENABLE_TEST "Build Test" On)
1414
option(ENABLE_COVERAGE "Build the project with gcov support (Need ENABLE_TEST=On)" Off)
15-
option(USE_QT6 "Use Qt6" On)
1615

1716
find_package(PkgConfig REQUIRED)
1817
find_package(Fcitx5Core ${REQUIRED_FCITX_VERSION} REQUIRED)
1918
find_package(Fcitx5Module REQUIRED COMPONENTS TestFrontend)
2019
find_package(Gettext REQUIRED)
2120

21+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
22+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
23+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
24+
2225
include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")
2326
add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-unikey\")
2427
fcitx5_add_i18n_definition()
2528

2629
if (ENABLE_QT)
27-
if (USE_QT6)
28-
set(QT_MAJOR_VERSION 6)
29-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
30-
else()
31-
set(QT_MAJOR_VERSION 5)
32-
find_package(Qt5 5.7 REQUIRED COMPONENTS Core Gui Widgets)
33-
endif()
30+
set(QT_MAJOR_VERSION 6)
31+
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
3432
find_package(Fcitx5Qt${QT_MAJOR_VERSION}WidgetsAddons 5.0.12 REQUIRED)
3533
add_subdirectory(macro-editor)
3634
add_subdirectory(keymap-editor)

keymap-editor/editor.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,28 @@
66
*/
77
#include "editor.h"
88
#include "actions.h"
9-
#include "inputproc.h"
9+
#include "keycons.h"
1010
#include "model.h"
11-
#include "ui_editor.h"
11+
#include <QAbstractItemModel>
1212
#include <QCloseEvent>
13+
#include <QComboBox>
1314
#include <QDebug>
1415
#include <QFileDialog>
16+
#include <QItemSelectionModel>
17+
#include <QList>
1518
#include <QMessageBox>
19+
#include <QObject>
20+
#include <QOverload>
21+
#include <QPushButton>
22+
#include <QStandardItem>
23+
#include <QWidget>
24+
#include <Qt>
1625
#include <fcitx-utils/charutils.h>
17-
#include <fcitx-utils/standardpath.h>
26+
#include <fcitx-utils/i18n.h>
27+
#include <fcitx-utils/key.h>
28+
#include <fcitx-utils/standardpaths.h>
29+
#include <fcitxqtconfiguiwidget.h>
1830
#include <fcitxqtkeysequencewidget.h>
19-
#include <tuple>
2031

2132
namespace fcitx::unikey {
2233

@@ -137,10 +148,7 @@ bool KeymapEditor::keySequenceValid() const {
137148
return false;
138149
}
139150
auto key = keySequenceEdit->keySequence()[0];
140-
if (!key.isValid() || !key.isSimple()) {
141-
return false;
142-
}
143-
return true;
151+
return key.isValid() && key.isSimple();
144152
}
145153

146154
void KeymapEditor::deleteKeymap() {

keymap-editor/model.cpp

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88

99
#include "actions.h"
1010
#include "editor.h"
11+
#include "inputproc.h"
12+
#include "keycons.h"
1113
#include "model.h"
1214
#include "usrkeymap.h"
15+
#include <QAbstractItemModel>
16+
#include <QObject>
17+
#include <QString>
18+
#include <Qt>
19+
#include <algorithm>
20+
#include <cstddef>
1321
#include <fcitx-utils/charutils.h>
22+
#include <fcitx-utils/fs.h>
1423
#include <fcitx-utils/i18n.h>
15-
#include <fcitx-utils/standardpath.h>
24+
#include <fcitx-utils/standardpaths.h>
1625
#include <fcitx-utils/unixfd.h>
1726
#include <fcntl.h>
27+
#include <iterator>
28+
#include <utility>
1829

19-
namespace fcitx {
20-
namespace unikey {
30+
namespace fcitx::unikey {
2131

22-
typedef QPair<QString, QString> ItemType;
32+
using ItemType = std::pair<QString, QString>;
2333

2434
KeymapModel::KeymapModel(QObject *parent)
2535
: QAbstractTableModel(parent), needSave_(false) {}
@@ -29,17 +39,21 @@ KeymapModel::~KeymapModel() {}
2939
QVariant KeymapModel::headerData(int section, Qt::Orientation orientation,
3040
int role) const {
3141
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
32-
if (section == 0)
42+
if (section == 0) {
3343
return _("Keymap");
34-
else if (section == 1)
44+
}
45+
if (section == 1) {
3546
return _("Word");
47+
}
3648
}
37-
return QVariant();
49+
return {};
3850
}
3951

40-
int KeymapModel::rowCount(const QModelIndex &) const { return list_.size(); }
52+
int KeymapModel::rowCount(const QModelIndex & /*parent*/) const {
53+
return list_.size();
54+
}
4155

42-
int KeymapModel::columnCount(const QModelIndex &) const { return 2; }
56+
int KeymapModel::columnCount(const QModelIndex & /*parent*/) const { return 2; }
4357

4458
QVariant KeymapModel::data(const QModelIndex &index, int role) const {
4559
if (index.row() >= static_cast<int>(list_.size()) || index.row() < 0) {
@@ -49,14 +63,16 @@ QVariant KeymapModel::data(const QModelIndex &index, int role) const {
4963
if (role == Qt::DisplayRole) {
5064
if (index.column() == 0) {
5165
return QString(QChar(list_[index.row()].key));
52-
} else if (index.column() == 1) {
66+
}
67+
if (index.column() == 1) {
5368
return QString::fromStdString(
5469
_(actionName(list_[index.row()].action)));
5570
}
5671
} else if (role == Qt::UserRole) {
5772
if (index.column() == 0) {
5873
return QChar(list_[index.row()].key);
59-
} else if (index.column() == 1) {
74+
}
75+
if (index.column() == 1) {
6076
return list_[index.row()].action;
6177
}
6278
}
@@ -70,7 +86,7 @@ QModelIndex KeymapModel::addItem(unsigned char key, int action) {
7086
key = charutils::toupper(key);
7187
checkBoth = true;
7288
}
73-
const auto lower = charutils::tolower(key);
89+
const unsigned char lower = charutils::tolower(key);
7490
bool updated = false;
7591
auto match = [key, checkBoth, lower](const UkKeyMapping &item) {
7692
if (item.action < vneCount &&
@@ -83,7 +99,7 @@ QModelIndex KeymapModel::addItem(unsigned char key, int action) {
8399
auto iter = list_.begin();
84100
for (; iter != list_.end(); iter++) {
85101
if (match(*iter)) {
86-
*iter = UkKeyMapping{key, action};
102+
*iter = UkKeyMapping{.key = key, .action = action};
87103
updated = true;
88104
break;
89105
}
@@ -128,17 +144,19 @@ void KeymapModel::moveDown(int row) {
128144
}
129145

130146
void KeymapModel::deleteItem(int row) {
131-
if (row >= static_cast<int>(list_.size()))
147+
if (row >= static_cast<int>(list_.size())) {
132148
return;
149+
}
133150
beginRemoveRows(QModelIndex(), row, row);
134151
list_.erase(list_.begin() + row);
135152
endRemoveRows();
136153
setNeedSave(true);
137154
}
138155

139156
void KeymapModel::deleteAllItem() {
140-
if (!list_.empty())
157+
if (!list_.empty()) {
141158
setNeedSave(true);
159+
}
142160
beginResetModel();
143161
list_.clear();
144162
endResetModel();
@@ -151,12 +169,12 @@ void KeymapModel::setNeedSave(bool needSave) {
151169
}
152170
}
153171

154-
bool KeymapModel::needSave() { return needSave_; }
172+
bool KeymapModel::needSave() const { return needSave_; }
155173

156174
void KeymapModel::load() {
157175
beginResetModel();
158-
auto keymapFile = StandardPath::global().open(
159-
StandardPath::Type::PkgConfig, "unikey/keymap.txt", O_RDONLY);
176+
auto keymapFile = StandardPaths::global().open(StandardPathsType::PkgConfig,
177+
"unikey/keymap.txt");
160178
if (keymapFile.isValid()) {
161179
list_ = UkLoadKeyOrderMap(keymapFile.fd());
162180
} else {
@@ -166,9 +184,9 @@ void KeymapModel::load() {
166184
}
167185

168186
void KeymapModel::save() {
169-
StandardPath::global().safeSave(StandardPath::Type::PkgConfig,
170-
"unikey/keymap.txt",
171-
[this](int fd) { return saveToFd(fd); });
187+
StandardPaths::global().safeSave(StandardPathsType::PkgConfig,
188+
"unikey/keymap.txt",
189+
[this](int fd) { return saveToFd(fd); });
172190
setNeedSave(false);
173191
}
174192

@@ -189,9 +207,9 @@ void KeymapModel::save(const QString &file) {
189207
if (!file.startsWith("/")) {
190208
return;
191209
}
192-
StandardPath::global().safeSave(StandardPath::Type::PkgConfig,
193-
file.toLocal8Bit().constData(),
194-
[this](int fd) { return saveToFd(fd); });
210+
StandardPaths::global().safeSave(StandardPathsType::PkgConfig,
211+
file.toLocal8Bit().constData(),
212+
[this](int fd) { return saveToFd(fd); });
195213
setNeedSave(false);
196214
}
197215

@@ -226,6 +244,8 @@ void KeymapModel::load(int profile) {
226244
case UkMsVi:
227245
mapping = MsViMethodMapping;
228246
break;
247+
default:
248+
break;
229249
}
230250
if (!mapping) {
231251
return;
@@ -240,5 +260,4 @@ void KeymapModel::load(int profile) {
240260
setNeedSave(true);
241261
}
242262

243-
} // namespace unikey
244-
} // namespace fcitx
263+
} // namespace fcitx::unikey

keymap-editor/model.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,36 @@
77
#ifndef _KEYMAP_EDITOR_MODEL_H_
88
#define _KEYMAP_EDITOR_MODEL_H_
99

10-
#include "mactab.h"
11-
#include "usrkeymap.h"
10+
#include "inputproc.h"
1211
#include <QAbstractItemModel>
12+
#include <QObject>
1313
#include <QSet>
14+
#include <QString>
15+
#include <QVariant>
16+
#include <Qt>
17+
#include <vector>
1418

15-
namespace fcitx {
16-
namespace unikey {
19+
namespace fcitx::unikey {
1720
class KeymapModel : public QAbstractTableModel {
1821
Q_OBJECT
1922
public:
2023
explicit KeymapModel(QObject *parent = 0);
2124
virtual ~KeymapModel();
2225

23-
virtual QVariant headerData(int section, Qt::Orientation orientation,
24-
int role = Qt::DisplayRole) const;
25-
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
26-
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
27-
virtual QVariant data(const QModelIndex &index,
28-
int role = Qt::DisplayRole) const;
26+
QVariant headerData(int section, Qt::Orientation orientation,
27+
int role = Qt::DisplayRole) const override;
28+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
29+
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
30+
QVariant data(const QModelIndex &index,
31+
int role = Qt::DisplayRole) const override;
2932
void load();
3033
QModelIndex addItem(unsigned char key, int action);
31-
void moveUp(int index);
32-
void moveDown(int index);
34+
void moveUp(int row);
35+
void moveDown(int row);
3336
void deleteItem(int row);
3437
void deleteAllItem();
3538
void save();
36-
bool needSave();
39+
bool needSave() const;
3740
void load(const QString &fileName);
3841
void save(const QString &fileName);
3942
void load(int profile);
@@ -47,7 +50,6 @@ class KeymapModel : public QAbstractTableModel {
4750
bool needSave_;
4851
std::vector<UkKeyMapping> list_;
4952
};
50-
} // namespace unikey
51-
} // namespace fcitx
53+
} // namespace fcitx::unikey
5254

5355
#endif // _MACRO_EDITOR_MODEL_H_

0 commit comments

Comments
 (0)