presentation/ConflictItemModel.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QAbstractListModel> | ||
| 4 | #include <QList> | ||
| 5 | #include <QVariantMap> | ||
| 6 | |||
| 7 | #include "ConflictRows.h" | ||
| 8 | |||
| 9 | // The rows of the open conflict for QML (Sprint 107 S107.4.2). Choosing a | ||
| 10 | // side changes the plan; setRows() then updates the rows in place | ||
| 11 | // (dataChanged per row) while the row ids stay the same, and resets only | ||
| 12 | // when the set of rows changed (a group separated, a reload). | ||
| 13 | class ConflictItemModel : public QAbstractListModel { | ||
| 14 | Q_OBJECT | ||
| 15 | Q_PROPERTY(int count READ rowCountProperty NOTIFY countChanged) | ||
| 16 | // Every role with its default: what a QML row shows while its list entry | ||
| 17 | // is gone (a reset tears the delegates down after the data). | ||
| 18 | Q_PROPERTY(QVariantMap empty READ empty CONSTANT) | ||
| 19 | |||
| 20 | public: | ||
| 21 | enum Role { | ||
| 22 | IdRole = Qt::UserRole + 1, | ||
| 23 | KindRole, | ||
| 24 | LabelRole, | ||
| 25 | SectionRole, | ||
| 26 | ConflictRole, | ||
| 27 | StateRole, | ||
| 28 | ChoiceRole, | ||
| 29 | LocalTextRole, | ||
| 30 | ServerTextRole, | ||
| 31 | BaseTextRole, | ||
| 32 | ResultTextRole, | ||
| 33 | LocalPresentRole, | ||
| 34 | ServerPresentRole, | ||
| 35 | BasePresentRole, | ||
| 36 | ResultPresentRole, | ||
| 37 | GroupRole, | ||
| 38 | SeparableRole, | ||
| 39 | ValuesRole, | ||
| 40 | HunksRole, | ||
| 41 | SummaryRole, | ||
| 42 | OverlappingRole, | ||
| 43 | LocalSourceRole, | ||
| 44 | ServerSourceRole, | ||
| 45 | BaseSourceRole, | ||
| 46 | InvalidRole, | ||
| 47 | ChangedAgainRole, | ||
| 48 | AccessibleNameRole, | ||
| 49 | }; | ||
| 50 | |||
| 51 | explicit ConflictItemModel(QObject *parent = nullptr); | ||
| 52 | |||
| 53 | int rowCount(const QModelIndex &parent = {}) const override; | ||
| 54 | QVariant data(const QModelIndex &index, int role) const override; | ||
| 55 | QHash<int, QByteArray> roleNames() const override; | ||
| 56 | |||
| 57 | QVariantMap empty() const; | ||
| 58 | void setRows(const QList<ConflictRows::Row> &rows); | ||
| 59 | 831 | const QList<ConflictRows::Row> &rows() const { return m_rows; } | |
| 60 | Q_INVOKABLE int indexOf(const QString &id) const; | ||
| 61 | // The next/previous open question from `fromRow` (wrapping); -1 = none. | ||
| 62 | Q_INVOKABLE int nextOpen(int fromRow, int direction) const; | ||
| 63 | |||
| 64 | signals: | ||
| 65 | void countChanged(); | ||
| 66 | |||
| 67 | private: | ||
| 68 | ✗ | int rowCountProperty() const { return int(m_rows.size()); } | |
| 69 | static QString accessibleName(const ConflictRows::Row &row); | ||
| 70 | static QVariant valueOf(const ConflictRows::Row &row, int role); | ||
| 71 | QList<ConflictRows::Row> m_rows; | ||
| 72 | }; | ||
| 73 |