Differential D14796 Diff 39628 kcms/keyboard/layoutmodel/layout_list_sort_by_priority_proxy_model.cpp
Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/layoutmodel/layout_list_sort_by_priority_proxy_model.cpp
- This file was added.
1 | #include "layout_list_sort_by_priority_proxy_model.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QDebug> | ||||
4 | | ||||
5 | LayoutListSortByPriorityProxyModel::LayoutListSortByPriorityProxyModel(QObject* parent) | ||||
6 | : QSortFilterProxyModel(parent) | ||||
7 | { | ||||
8 | setSortRole(Roles::PriorityRole); | ||||
9 | sort(0); | ||||
10 | } | ||||
11 | | ||||
12 | void LayoutListSortByPriorityProxyModel::applyOrderChanges() | ||||
13 | { | ||||
14 | if (!m_tempMapping.empty()) { | ||||
15 | qDebug() << "applyorderchanges" << m_tempMapping; | ||||
16 | emit enabledOrderChanged(m_tempMapping); | ||||
17 | m_tempMapping.clear(); | ||||
18 | } | ||||
19 | } | ||||
20 | | ||||
21 | void LayoutListSortByPriorityProxyModel::simulateMove(int src, int dst) | ||||
22 | { | ||||
23 | qDebug() << src << dst; | ||||
24 | if (src < 0 || src >= rowCount() || dst < 0 || dst >= rowCount()) { | ||||
25 | return; | ||||
26 | } | ||||
27 | | ||||
28 | int const modelTo = dst + (dst > src); | ||||
29 | if (beginMoveRows(QModelIndex(), src, src, QModelIndex(), modelTo)) { | ||||
30 | if (m_tempMapping.empty()) { | ||||
31 | m_tempMapping.resize(sourceModel()->rowCount()); | ||||
32 | std::iota(m_tempMapping.begin(), m_tempMapping.end(), 0); | ||||
33 | } | ||||
34 | m_tempMapping.move(src, dst); | ||||
35 | qDebug() << m_tempMapping; | ||||
36 | endMoveRows(); | ||||
37 | } | ||||
38 | } | ||||
39 | | ||||
40 | void LayoutListSortByPriorityProxyModel::remove(int idx) | ||||
41 | { | ||||
42 | emit itemRemoved(idx); | ||||
43 | } | ||||
44 | /* | ||||
45 | bool LayoutListSortByPriorityProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const | ||||
46 | { | ||||
47 | bool result; | ||||
48 | if (m_tempMapping.empty()) { | ||||
49 | int left = sourceModel()->data(source_left, Roles::PriorityRole).toInt(); | ||||
50 | int right = sourceModel()->data(source_right, Roles::PriorityRole).toInt(); | ||||
51 | result = left < right; | ||||
52 | } | ||||
53 | else { | ||||
54 | result = m_tempMapping[source_left.row()] < m_tempMapping[source_right.row()]; | ||||
55 | } | ||||
56 | | ||||
57 | QString left, right; | ||||
58 | left = sourceModel()->data(source_left, Roles::NameRole).toString(); | ||||
59 | right = sourceModel()->data(source_right, Roles::NameRole).toString(); | ||||
60 | if (result) { | ||||
61 | qDebug() << left << "<" << right; | ||||
62 | } | ||||
63 | else { | ||||
64 | qDebug() << right << "<" << left; | ||||
65 | } | ||||
66 | | ||||
67 | return result; | ||||
68 | } | ||||
69 | */ |