klipper: Add named role types to HistoryModel

This makes the expressions more clear.
wilder-5.25
Fushan Wen 4 years ago
parent c1e5628f4f
commit 87faa4a6f5
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 14
      klipper/historymodel.cpp
  2. 9
      klipper/historymodel.h

@ -70,15 +70,15 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
return item->text(); return item->text();
case Qt::DecorationRole: case Qt::DecorationRole:
return item->image(); return item->image();
case Qt::UserRole: case HistoryItemConstPtrRole:
return QVariant::fromValue<HistoryItemConstPtr>(qSharedPointerConstCast<const HistoryItem>(item)); return QVariant::fromValue<HistoryItemConstPtr>(qSharedPointerConstCast<const HistoryItem>(item));
case Qt::UserRole + 1: case UuidRole:
return item->uuid(); return item->uuid();
case Qt::UserRole + 2: case TypeRole:
return QVariant::fromValue<HistoryItemType>(type); return QVariant::fromValue<HistoryItemType>(type);
case Qt::UserRole + 3: case Base64UuidRole:
return item->uuid().toBase64(); return item->uuid().toBase64();
case Qt::UserRole + 4: case TypeIntRole:
return int(type); return int(type);
} }
return QVariant(); return QVariant();
@ -200,7 +200,7 @@ QHash<int, QByteArray> HistoryModel::roleNames() const
QHash<int, QByteArray> hash; QHash<int, QByteArray> hash;
hash.insert(Qt::DisplayRole, QByteArrayLiteral("DisplayRole")); hash.insert(Qt::DisplayRole, QByteArrayLiteral("DisplayRole"));
hash.insert(Qt::DecorationRole, QByteArrayLiteral("DecorationRole")); hash.insert(Qt::DecorationRole, QByteArrayLiteral("DecorationRole"));
hash.insert(Qt::UserRole + 3, QByteArrayLiteral("UuidRole")); hash.insert(Base64UuidRole, QByteArrayLiteral("UuidRole"));
hash.insert(Qt::UserRole + 4, QByteArrayLiteral("TypeRole")); hash.insert(TypeIntRole, QByteArrayLiteral("TypeRole"));
return hash; return hash;
} }

@ -20,6 +20,15 @@ class HistoryModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum RoleType {
HistoryItemConstPtrRole = Qt::UserRole,
UuidRole,
TypeRole,
Base64UuidRole,
TypeIntRole,
};
Q_ENUM(RoleType)
explicit HistoryModel(QObject *parent = nullptr); explicit HistoryModel(QObject *parent = nullptr);
~HistoryModel() override; ~HistoryModel() override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

Loading…
Cancel
Save