diff --git a/src/kcm/ui/SelectLayoutSheet.qml b/src/kcm/ui/SelectLayoutSheet.qml index 04d705d..b6011cd 100644 --- a/src/kcm/ui/SelectLayoutSheet.qml +++ b/src/kcm/ui/SelectLayoutSheet.qml @@ -25,7 +25,7 @@ Kirigami.OverlaySheet { } Kirigami.FormLayout { - implicitWidth: Kirigami.Units.gridUnit * 45 + implicitWidth: Kirigami.Units.gridUnit * 30 ComboBox { id: languageComboBox diff --git a/src/lib/configlib/addonmodel.cpp b/src/lib/configlib/addonmodel.cpp index 9147c04..542abd5 100644 --- a/src/lib/configlib/addonmodel.cpp +++ b/src/lib/configlib/addonmodel.cpp @@ -362,7 +362,7 @@ bool AddonProxyModel::lessThan(const QModelIndex &left, QString l = left.data(Qt::DisplayRole).toString(); QString r = right.data(Qt::DisplayRole).toString(); - return QCollator().compare(l, r) < 0; + return QString::localeAwareCompare(l, r) < 0; } void AddonProxyModel::setFilterText(const QString &text) { diff --git a/src/lib/configlib/layoutmodel.cpp b/src/lib/configlib/layoutmodel.cpp index bca2a0f..81804ff 100644 --- a/src/lib/configlib/layoutmodel.cpp +++ b/src/lib/configlib/layoutmodel.cpp @@ -5,15 +5,28 @@ * */ #include "layoutmodel.h" +#include +#include +#include +#include +#include +#include +#include +#include -namespace fcitx { -namespace kcm { +namespace fcitx::kcm { LanguageModel::LanguageModel(QObject *parent) : QStandardItemModel(parent) { setItemRoleNames({{Qt::DisplayRole, "name"}, {Qt::UserRole, "language"}}); } -QString LanguageModel::language(int row) const { +void LanguageModel::append(const QString &name, const QString &language) { + QStandardItem *item = new QStandardItem(name); + item->setData(language, Qt::UserRole); + appendRow(item); +} + +QString SortedLanguageModel::language(int row) const { auto idx = index(row, 0); if (idx.isValid()) { return idx.data(Qt::UserRole).toString(); @@ -21,12 +34,6 @@ QString LanguageModel::language(int row) const { return QString(); } -void LanguageModel::append(const QString &name, const QString &language) { - QStandardItem *item = new QStandardItem(name); - item->setData(language, Qt::UserRole); - appendRow(item); -} - void LanguageFilterModel::setLanguage(const QString &language) { if (language_ != language) { language_ = language; @@ -56,8 +63,9 @@ bool LanguageFilterModel::filterAcceptsRow(int source_row, } bool LanguageFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { - return data(left, Qt::DisplayRole).toString() < - data(right, Qt::DisplayRole).toString(); + return QString::localeAwareCompare(left.data(Qt::DisplayRole).toString(), + right.data(Qt::DisplayRole).toString()) < + 0; } QHash LayoutInfoModel::roleNames() const { @@ -157,5 +165,4 @@ int VariantInfoModel::rowCount(const QModelIndex &parent) const { return variantInfo_.size(); } -} // namespace kcm -} // namespace fcitx +} // namespace fcitx::kcm diff --git a/src/lib/configlib/layoutmodel.h b/src/lib/configlib/layoutmodel.h index bedabf7..e29d114 100644 --- a/src/lib/configlib/layoutmodel.h +++ b/src/lib/configlib/layoutmodel.h @@ -7,13 +7,20 @@ #ifndef _CONFIGLIB_LAYOUTMODEL_H_ #define _CONFIGLIB_LAYOUTMODEL_H_ +#include +#include +#include #include #include +#include +#include #include #include +#include +#include +#include -namespace fcitx { -namespace kcm { +namespace fcitx::kcm { enum { LayoutLanguageRole = 0x3423545, LayoutInfoRole }; @@ -21,10 +28,36 @@ class LanguageModel : public QStandardItemModel { Q_OBJECT public: LanguageModel(QObject *parent = nullptr); - Q_INVOKABLE QString language(int row) const; void append(const QString &name, const QString &language); }; +class SortedLanguageModel : public QSortFilterProxyModel { + Q_OBJECT +public: + using QSortFilterProxyModel::QSortFilterProxyModel; + // Forward role names. + QHash roleNames() const override { + if (sourceModel()) { + return sourceModel()->roleNames(); + } + return QSortFilterProxyModel::roleNames(); + } + Q_INVOKABLE QString language(int row) const; + +protected: + bool lessThan(const QModelIndex &left, + const QModelIndex &right) const override { + const bool leftIsAny = left.data(Qt::UserRole).toString().isEmpty(); + const bool rightIsAny = right.data(Qt::UserRole).toString().isEmpty(); + if (leftIsAny || rightIsAny) { + return leftIsAny > rightIsAny; + } + return QString::localeAwareCompare( + left.data(Qt::DisplayRole).toString(), + right.data(Qt::DisplayRole).toString()) < 0; + } +}; + class LanguageFilterModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(QString language READ language WRITE setLanguage); @@ -89,7 +122,6 @@ class VariantInfoModel : public QAbstractListModel { FcitxQtVariantInfoList variantInfo_; }; -} // namespace kcm -} // namespace fcitx +} // namespace fcitx::kcm #endif // _CONFIGLIB_LAYOUTMODEL_H_ diff --git a/src/lib/configlib/layoutprovider.cpp b/src/lib/configlib/layoutprovider.cpp index 6aa0205..47f21ad 100644 --- a/src/lib/configlib/layoutprovider.cpp +++ b/src/lib/configlib/layoutprovider.cpp @@ -6,19 +6,34 @@ */ #include "layoutprovider.h" #include "dbusprovider.h" +#include "layoutmodel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace fcitx { -namespace kcm { +namespace fcitx::kcm { LayoutProvider::LayoutProvider(DBusProvider *dbus, QObject *parent) : QObject(parent), dbus_(dbus), languageModel_(new LanguageModel(this)), + sortedLanguageModel_(new SortedLanguageModel(this)), layoutModel_(new LayoutInfoModel(this)), variantModel_(new VariantInfoModel(this)), layoutFilterModel_(new LanguageFilterModel(this)), variantFilterModel_(new LanguageFilterModel(this)) { layoutFilterModel_->setSourceModel(layoutModel_); variantFilterModel_->setSourceModel(variantModel_); - + sortedLanguageModel_->setSourceModel(languageModel_); + sortedLanguageModel_->sort(0); + layoutFilterModel_->sort(0); connect(dbus, &DBusProvider::availabilityChanged, this, &LayoutProvider::availabilityChanged); availabilityChanged(); @@ -154,5 +169,4 @@ QString LayoutProvider::layoutDescription(const QString &layoutString) { .arg(iter->description(), variantIter->description()); } -} // namespace kcm -} // namespace fcitx +} // namespace fcitx::kcm diff --git a/src/lib/configlib/layoutprovider.h b/src/lib/configlib/layoutprovider.h index 9e7c9d6..daa6645 100644 --- a/src/lib/configlib/layoutprovider.h +++ b/src/lib/configlib/layoutprovider.h @@ -9,9 +9,14 @@ #include "iso639.h" #include "layoutmodel.h" +#include +#include #include #include +#include #include +#include +#include #include class QDBusPendingCallWatcher; @@ -26,15 +31,14 @@ class VariantInfoModel; class LayoutProvider : public QObject { Q_OBJECT - Q_PROPERTY( - fcitx::kcm::LanguageModel *languageModel READ languageModel CONSTANT) + Q_PROPERTY(QAbstractItemModel *languageModel READ languageModel CONSTANT) Q_PROPERTY(LanguageFilterModel *layoutModel READ layoutModel CONSTANT) Q_PROPERTY(LanguageFilterModel *variantModel READ variantModel CONSTANT) public: LayoutProvider(DBusProvider *dbus, QObject *parent = nullptr); ~LayoutProvider(); - auto languageModel() const { return languageModel_; } + QAbstractItemModel *languageModel() const { return sortedLanguageModel_; } auto layoutModel() const { return layoutFilterModel_; } auto variantModel() const { return variantFilterModel_; } @@ -83,6 +87,7 @@ private Q_SLOTS: DBusProvider *dbus_; bool loaded_ = false; LanguageModel *languageModel_; + SortedLanguageModel *sortedLanguageModel_; LayoutInfoModel *layoutModel_; VariantInfoModel *variantModel_; LanguageFilterModel *layoutFilterModel_; diff --git a/src/lib/configlib/model.cpp b/src/lib/configlib/model.cpp index b9e5865..a07689c 100644 --- a/src/lib/configlib/model.cpp +++ b/src/lib/configlib/model.cpp @@ -342,7 +342,7 @@ bool IMProxyModel::lessThan(const QModelIndex &left, QString l = left.data(Qt::DisplayRole).toString(); QString r = right.data(Qt::DisplayRole).toString(); - return QCollator().compare(l, r) < 0; + return QString::localeAwareCompare(l, r) < 0; } int IMProxyModel::compareCategories(const QModelIndex &left, diff --git a/src/lib/configwidgetslib/layoutselector.cpp b/src/lib/configwidgetslib/layoutselector.cpp index fc2a3ca..e38ad81 100644 --- a/src/lib/configwidgetslib/layoutselector.cpp +++ b/src/lib/configwidgetslib/layoutselector.cpp @@ -95,12 +95,8 @@ void LayoutSelector::setLayout(const QString &layout, const QString &variant) { } ui_->languageComboBox->setCurrentIndex(0); ui_->layoutComboBox->setCurrentIndex(layoutProvider_->layoutIndex(layout)); - if (variant.isEmpty()) { - ui_->variantComboBox->setCurrentIndex(0); - } else { - ui_->variantComboBox->setCurrentIndex( - layoutProvider_->variantIndex(variant)); - } + ui_->variantComboBox->setCurrentIndex( + layoutProvider_->variantIndex(variant)); preSelectLayout_.clear(); preSelectVariant_.clear(); } diff --git a/src/lib/configwidgetslib/layoutselector.ui b/src/lib/configwidgetslib/layoutselector.ui index 8be1965..5743ea8 100644 --- a/src/lib/configwidgetslib/layoutselector.ui +++ b/src/lib/configwidgetslib/layoutselector.ui @@ -6,7 +6,7 @@ 0 0 - 400 + 600 300 @@ -16,14 +16,14 @@ - + Language: - + @@ -31,16 +31,22 @@ 0 + + + 400 + 0 + + - + Layout: - + @@ -50,14 +56,14 @@ - + Variant: - +