From 40a0815501ac9a00d6e04a83c828d5edb44ff155 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Sat, 7 Feb 2026 19:42:22 +0100 Subject: [PATCH] Added data(FullNameRole) implementation and minor refactoring. --- libs/BeetRoundCore/model/modelitem.cpp | 21 +++++++++++++++++++-- libs/BeetRoundCore/model/modelitem.h | 1 + libs/BeetRoundCore/model/tablemodel.cpp | 9 +++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libs/BeetRoundCore/model/modelitem.cpp b/libs/BeetRoundCore/model/modelitem.cpp index f725673..97a6024 100644 --- a/libs/BeetRoundCore/model/modelitem.cpp +++ b/libs/BeetRoundCore/model/modelitem.cpp @@ -8,8 +8,21 @@ ModelItem::ModelItem(const ModelItemValues values) : m_values(values) {} -QVariant ModelItem::data(int role) const { return m_values.value(role); } - +QVariant ModelItem::data(int role) const { + switch (role) { + case FullNameRole: + return fullName(); + break; + case ToStringRole: + return toString(); + break; + case JsonObjectRole: + return toJsonObject(); + break; + default: + return m_values.value(role); + } +} bool ModelItem::setData(const QVariant& value, int role) { bool valueChanged = false; if (m_values.contains(role)) { @@ -44,6 +57,10 @@ bool ModelItem::setItemData(const QMap& changedValues) { return valueChanged; } +QString ModelItem::fullName() const { + return QString("%1 %2").arg(data(FirstNameRole).toString(), data(LastNameRole).toString()); +} + QString ModelItem::toString() const { QString result; diff --git a/libs/BeetRoundCore/model/modelitem.h b/libs/BeetRoundCore/model/modelitem.h index 1019296..b6a8ce1 100644 --- a/libs/BeetRoundCore/model/modelitem.h +++ b/libs/BeetRoundCore/model/modelitem.h @@ -14,6 +14,7 @@ class ModelItem { // TODO change return value to list of changed roles bool setItemData(const QMap& changedValues); + QString fullName() const; QString toString() const; QJsonObject toJsonObject() const; diff --git a/libs/BeetRoundCore/model/tablemodel.cpp b/libs/BeetRoundCore/model/tablemodel.cpp index 3a33f9e..94f5334 100644 --- a/libs/BeetRoundCore/model/tablemodel.cpp +++ b/libs/BeetRoundCore/model/tablemodel.cpp @@ -82,11 +82,14 @@ QVariant TableModel::data(const QModelIndex& index, int role) const { return QVariant(); } - int roleForColumn = GET_ROLE_FOR_COLUMN(column); + const int roleForColumn = GET_ROLE_FOR_COLUMN(column); switch (role) { case Qt::DisplayRole: case Qt::EditRole: return m_items.at(row)->data(roleForColumn); + case Qt::ToolTipRole: + return m_items.at(index.row())->data(ToStringRole); + break; case MembershipNumberRole: case LastNameRole: case FirstNameRole: @@ -102,11 +105,9 @@ QVariant TableModel::data(const QModelIndex& index, int role) const { case BiddingTypeRole: case OnlineIdRole: case AccessCodeRole: - return m_items.at(row)->data(role); case ToStringRole: - return m_items.at(row)->toString(); case JsonObjectRole: - return m_items.at(row)->toJsonObject(); + return m_items.at(row)->data(role); } return QVariant();