Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kcm/ui/SelectLayoutSheet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Kirigami.OverlaySheet {
}

Kirigami.FormLayout {
implicitWidth: Kirigami.Units.gridUnit * 45
implicitWidth: Kirigami.Units.gridUnit * 30

ComboBox {
id: languageComboBox
Expand Down
2 changes: 1 addition & 1 deletion src/lib/configlib/addonmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
33 changes: 20 additions & 13 deletions src/lib/configlib/layoutmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@
*
*/
#include "layoutmodel.h"
#include <QHash>
#include <QObject>
#include <QStandardItem>
#include <QStringList>
#include <Qt>
#include <fcitx-utils/i18n.h>
#include <fcitxqtdbustypes.h>
#include <utility>

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();
}
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;
Expand Down Expand Up @@ -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<int, QByteArray> LayoutInfoModel::roleNames() const {
Expand Down Expand Up @@ -157,5 +165,4 @@ int VariantInfoModel::rowCount(const QModelIndex &parent) const {
return variantInfo_.size();
}

} // namespace kcm
} // namespace fcitx
} // namespace fcitx::kcm
42 changes: 37 additions & 5 deletions src/lib/configlib/layoutmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,57 @@
#ifndef _CONFIGLIB_LAYOUTMODEL_H_
#define _CONFIGLIB_LAYOUTMODEL_H_

#include <QAbstractItemModel>
#include <QHash>
#include <QObject>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QString>
#include <Qt>
#include <fcitx-utils/i18n.h>
#include <fcitxqtdbustypes.h>
#include <qdebug.h>
#include <qlogging.h>
#include <qnamespace.h>

namespace fcitx {
namespace kcm {
namespace fcitx::kcm {

enum { LayoutLanguageRole = 0x3423545, LayoutInfoRole };

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<int, QByteArray> 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);
Expand Down Expand Up @@ -89,7 +122,6 @@ class VariantInfoModel : public QAbstractListModel {
FcitxQtVariantInfoList variantInfo_;
};

} // namespace kcm
} // namespace fcitx
} // namespace fcitx::kcm

#endif // _CONFIGLIB_LAYOUTMODEL_H_
24 changes: 19 additions & 5 deletions src/lib/configlib/layoutprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
*/
#include "layoutprovider.h"
#include "dbusprovider.h"
#include "layoutmodel.h"
#include <QDBusPendingReply>
#include <QObject>
#include <QSet>
#include <QStandardItem>
#include <QString>
#include <QStringList>
#include <Qt>
#include <algorithm>
#include <fcitx-utils/i18n.h>
#include <fcitxqtdbustypes.h>
#include <iterator>
#include <utility>

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();
Expand Down Expand Up @@ -154,5 +169,4 @@ QString LayoutProvider::layoutDescription(const QString &layoutString) {
.arg(iter->description(), variantIter->description());
}

} // namespace kcm
} // namespace fcitx
} // namespace fcitx::kcm
11 changes: 8 additions & 3 deletions src/lib/configlib/layoutprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@

#include "iso639.h"
#include "layoutmodel.h"
#include <QAbstractItemModel>
#include <QObject>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QString>
#include <QStringListModel>
#include <QStringLiteral>
#include <Qt>
#include <fcitxqtdbustypes.h>

class QDBusPendingCallWatcher;
Expand All @@ -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_; }

Expand Down Expand Up @@ -83,6 +87,7 @@ private Q_SLOTS:
DBusProvider *dbus_;
bool loaded_ = false;
LanguageModel *languageModel_;
SortedLanguageModel *sortedLanguageModel_;
LayoutInfoModel *layoutModel_;
VariantInfoModel *variantModel_;
LanguageFilterModel *layoutFilterModel_;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/configlib/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/lib/configwidgetslib/layoutselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
20 changes: 13 additions & 7 deletions src/lib/configwidgetslib/layoutselector.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>600</width>
<height>300</height>
</rect>
</property>
Expand All @@ -16,31 +16,37 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QComboBox" name="languageComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Layout:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="layoutComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
Expand All @@ -50,14 +56,14 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Variant:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="variantComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
Expand Down
Loading