feat(RD): add roleNames and Q_PROPERTY to ResourceModel

in preparation for QML interop.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-12-18 16:55:09 -03:00
parent 45d1319891
commit 0e207aba6c
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 18 additions and 0 deletions

View File

@ -79,6 +79,21 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
return {};
}
QHash<int, QByteArray> ResourceModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[Qt::ToolTipRole] = "toolTip";
roles[Qt::DecorationRole] = "decoration";
roles[Qt::SizeHintRole] = "sizeHint";
roles[Qt::UserRole] = "pack";
roles[UserDataTypes::TITLE] = "title";
roles[UserDataTypes::DESCRIPTION] = "description";
roles[UserDataTypes::SELECTED] = "selected";
return roles;
}
bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
int pos = index.row();

View File

@ -21,11 +21,14 @@ namespace ResourceDownload {
class ResourceModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString search_term MEMBER m_search_term WRITE setSearchTerm)
public:
ResourceModel(BaseInstance const&, ResourceAPI* api);
~ResourceModel() override;
[[nodiscard]] auto data(const QModelIndex&, int role) const -> QVariant override;
[[nodiscard]] auto roleNames() const -> QHash<int, QByteArray> override;
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
[[nodiscard]] virtual auto debugName() const -> QString;