[games/chessament] src: Add more details to player suggestions
Manuel Alcaraz Zambrano <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 1fd0b686e63c31628921d54f67438b41a51302a1 by Manuel Alcaraz Zambrano.
Committed on 03/08/2026 at 12:46.
Pushed by manuelal into branch 'master'.
Add more details to player suggestions
M +19 -14 src/qml/AddPlayerDialog.qml
M +23 -2 src/searchplayersmodel.cpp
M +2 -1 src/searchplayersmodel.h
https://invent.kde.org/games/chessament/-/commit/1fd0b686e63c31628921d54f67438b41a51302a1
diff --git a/src/qml/AddPlayerDialog.qml b/src/qml/AddPlayerDialog.qml
index d91859b..455a14e 100644
--- a/src/qml/AddPlayerDialog.qml
+++ b/src/qml/AddPlayerDialog.qml
@@ -64,20 +64,25 @@ QQC2.Dialog {
id: searchModel
}
textRole: "name"
- subtitleRole: "rating"
- field.onSearchTriggered: searchModel.search(nameField.value)
- field.onActivated: function (index: int) {
- const player = searchModel.data(searchModel.index(index, 0), SearchPlayersModel.PlayerRole);
-
- titleField.currentValue = player.title;
- ratingField.value = player.standardRating;
- nationalRatingField.value = player.nationalRating;
- playerIdField.text = player.id;
- nationalIdField.text = player.nationalId;
- birthDateField.text = player.birthDate;
- federationField.text = player.federation;
- originField.text = player.origin;
- genderField.text = player.gender;
+ subtitleRole: "description"
+ field {
+ onSearchTriggered: searchModel.search(nameField.value)
+ onActivated: function (index: int): void {
+ const player = searchModel.data(searchModel.index(index, 0), SearchPlayersModel.PlayerRole);
+
+ titleField.currentValue = player.title;
+ ratingField.value = player.standardRating;
+ nationalRatingField.value = player.nationalRating;
+ playerIdField.text = player.id;
+ nationalIdField.text = player.nationalId;
+ birthDateField.text = player.birthDate;
+ federationField.text = player.federation;
+ originField.text = player.origin;
+ genderField.text = player.gender;
+ Qt.callLater(function (): void {
+ nameField.text = player.name;
+ });
+ }
}
}
diff --git a/src/searchplayersmodel.cpp b/src/searchplayersmodel.cpp
index e721759..f42638b 100644
--- a/src/searchplayersmodel.cpp
+++ b/src/searchplayersmodel.cpp
@@ -3,6 +3,10 @@
#include "searchplayersmodel.h"
+#include <KLocalizedString>
+
+#include "ratinglists/ratinglist.h"
+
SearchPlayersModel::SearchPlayersModel(QObject *parent)
: QAbstractListModel(parent)
{
@@ -22,8 +26,24 @@ QVariant SearchPlayersModel::data(const QModelIndex &index, int role) const
const auto player = m_players[index.row()];
switch (role) {
- case SearchPlayersModel::Role::NameRole:
- return player.name();
+ case SearchPlayersModel::Role::NameRole: {
+ if (player.title().isEmpty()) {
+ return player.name();
+ }
+ return i18nc("%1 is the player's title, %2 is the player's name", "%1 %2", player.title(), player.name());
+ }
+ case SearchPlayersModel::Role::Description: {
+ if (player.standardRating() == 0 && player.origin().isEmpty()) {
+ return QString{};
+ }
+ if (player.standardRating() == 0) {
+ return player.origin();
+ }
+ if (player.origin().isEmpty()) {
+ return i18nc("x", "Rating: %1", player.standardRating());
+ }
+ return i18nc("x", "Rating: %1 · %2", player.standardRating(), player.origin());
+ }
case SearchPlayersModel::Role::RatingRole:
return player.standardRating();
case SearchPlayersModel::Role::PlayerRole:
@@ -37,6 +57,7 @@ QHash<int, QByteArray> SearchPlayersModel::roleNames() const
{
return {
{Role::NameRole, "name"},
+ {Role::Description, "description"},
{Role::RatingRole, "rating"},
{Role::PlayerRole, "player"},
};
diff --git a/src/searchplayersmodel.h b/src/searchplayersmodel.h
index 214f289..5c19284 100644
--- a/src/searchplayersmodel.h
+++ b/src/searchplayersmodel.h
@@ -6,7 +6,7 @@
#include <QAbstractListModel>
#include <qqmlregistration.h>
-#include "ratinglists/ratinglist.h"
+#include "ratinglists/ratinglistplayer.h"
class Tournament;
@@ -18,6 +18,7 @@ class SearchPlayersModel : public QAbstractListModel
public:
enum Role {
NameRole = Qt::UserRole,
+ Description,
RatingRole,
PlayerRole,
};