Skip to content

Commit

Permalink
refactor: refactor the Add Input Method page
Browse files Browse the repository at this point in the history
* Use dcc-widgets and DTK widgets
* Use ListView's rootIndex to implement sub-list and remove complicated logic
* Remove useless refresh logic to optimize the page display speed
* Modify sorting logic, not specialize zh, zh_CN

Fixes linuxdeepin/developer-center#3695
  • Loading branch information
zsien committed Mar 1, 2023
1 parent 89e866f commit 742480b
Show file tree
Hide file tree
Showing 21 changed files with 959 additions and 2,509 deletions.
774 changes: 0 additions & 774 deletions src/addim/configlib/addimmodel.cpp

This file was deleted.

552 changes: 552 additions & 0 deletions src/addim/configlib/model.cpp

Large diffs are not rendered by default.

38 changes: 17 additions & 21 deletions src/addim/configlib/addimmodel.h → src/addim/configlib/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef ADDIMMODEL_H
#define ADDIMMODEL_H
#ifndef MODEL_H
#define MODEL_H

#include <QAbstractListModel>
#include <QSet>
Expand All @@ -21,12 +21,7 @@ enum {
FcitxIMUniqueNameRole,
FcitxIMConfigurableRole,
FcitxIMLayoutRole,

FcitxLanguageCode, // 取得语言编码
FcitxUseIMLanguageRole,// 是否为使用的输入法语言项(有一个输入法子项被使用,语言项则被使用)
FcitxRowIndexRole,
FcitxUseIMRole, // 是否为使用的输入法项
FcitxEnglishNameRole, // 取得语言的英文名称
FcitxIMActiveRole,
};

enum { LanguageType, IMType };
Expand Down Expand Up @@ -68,11 +63,6 @@ class AvailIMModel : public CategorizedItemModel,
filterIMEntryList(const FcitxQtInputMethodEntryList &imEntryList,
const FcitxQtStringKeyValueList &enabledIMs) override;

void getInputMethodEntryList(int row, FcitxQtStringKeyValueList& currentNameList);
void getInputMethodEntryList(int row, FcitxQtStringKeyValueList& currentNameList, FcitxQtStringKeyValueList& currentUseNameList, FcitxQtStringKeyValueList& useIMList);
void getInputMethodEntryList(int row, FcitxQtStringKeyValueList& currentNameList, FcitxQtStringKeyValueList& currentUseNameList, FcitxQtStringKeyValueList& useIMList, QString matchStr);
bool existUseIMEntryList(int row, FcitxQtStringKeyValueList& useIMList) const;

protected:
int listSize() const override { return m_filteredIMEntryList.size(); }
int subListSize(int idx) const override {
Expand All @@ -82,7 +72,6 @@ class AvailIMModel : public CategorizedItemModel,
QVariant dataForCategory(const QModelIndex &index, int role) const override;

private:
QList<QPair<QString, bool>> m_filteredUseIMLanguageList;
QList<QPair<QString, FcitxQtInputMethodEntryList>> m_filteredIMEntryList;
};

Expand All @@ -96,6 +85,7 @@ class IMProxyModel : public QSortFilterProxyModel,
public:
IMProxyModel(QObject *parent = nullptr);

// Forward role names.
QHash<int, QByteArray> roleNames() const override {
if (sourceModel()) {
return sourceModel()->roleNames();
Expand All @@ -113,9 +103,12 @@ class IMProxyModel : public QSortFilterProxyModel,
const FcitxQtStringKeyValueList &enabledIMs) override;

protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
int compareCategories(const QModelIndex &left, const QModelIndex &right) const;
bool filterAcceptsRow(int source_row,
const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &left,
const QModelIndex &right) const override;
int compareCategories(const QModelIndex &left,
const QModelIndex &right) const;

private:
bool filterLanguage(const QModelIndex &index) const;
Expand All @@ -135,21 +128,24 @@ class FilteredIMModel : public QAbstractListModel,
enum Mode { CurrentIM, AvailIM };

FilteredIMModel(Mode mode, QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

QHash<int, QByteArray> roleNames() const override;
void filterIMEntryList(const FcitxQtInputMethodEntryList &imEntryList, const FcitxQtStringKeyValueList &enabledIMs) override;
void
filterIMEntryList(const FcitxQtInputMethodEntryList &imEntryList,
const FcitxQtStringKeyValueList &enabledIMs) override;

int count() const { return rowCount(); }
Q_INVOKABLE QString imAt(int idx) const {
return index(idx).data(FcitxIMUniqueNameRole).toString();
}
public slots:
public Q_SLOTS:
void move(int from, int to);
void remove(int index);

signals:
Q_SIGNALS:
void imListChanged(FcitxQtInputMethodEntryList list);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/addim/configlib/xkbrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ XkbRules &XkbRules::instance() {
bool XkbRules::open(const QString &filename) {
QFile xmlFile(filename);
if (!xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 1;
return false;
}

QDomDocument xmlReader;
Expand Down
2 changes: 1 addition & 1 deletion src/addim/configlib/xkbrules.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class XkbRules {

bool open(const QString &filename);

layout layout(const QString &keyboard) const { return m_keyboardLayoutsMap[keyboard]; }
layout layout(const QString &keyboard) const { return m_keyboardLayoutsMap.value(keyboard); }
static QString tr(const QString &text);

private:
Expand Down
Binary file removed src/addim/img/check_ok.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/addim/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>img/check_ok.png</file>
<file>img/title_img.png</file>
</qresource>
</RCC>
84 changes: 0 additions & 84 deletions src/addim/widgetslib/addimwindow.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions src/addim/widgetslib/addimwindow.h

This file was deleted.

48 changes: 0 additions & 48 deletions src/addim/widgetslib/addimwindow.ui

This file was deleted.

Loading

0 comments on commit 742480b

Please sign in to comment.