From 33814ef0583ea35a863d61f855d1c715c9fd3f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Fri, 17 Feb 2012 23:50:14 +0100 Subject: [PATCH] Start editing the name directly after adding a player --- qt/fav_players_dialog.cpp | 11 ++--------- qt/new_game.cpp | 2 +- qt/players_table_helper.cpp | 14 +++++++++++++- qt/players_table_helper.h | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/qt/fav_players_dialog.cpp b/qt/fav_players_dialog.cpp index 6f46717..9f940e8 100644 --- a/qt/fav_players_dialog.cpp +++ b/qt/fav_players_dialog.cpp @@ -47,15 +47,8 @@ FavPlayersDialog::FavPlayersDialog(QWidget *iParent) void FavPlayersDialog::addRow() { - m_helper->addPlayer(PlayerDef(_q("New player"), _q(PlayersTableHelper::kHUMAN), "")); - - // Give focus to the newly created cell containing the player name, - // to allow fast edition - tablePlayers->setFocus(); - tablePlayers->setCurrentCell(tablePlayers->rowCount() - 1, 0, - QItemSelectionModel::ClearAndSelect | - QItemSelectionModel::Current | - QItemSelectionModel::Rows); + m_helper->addPlayer(PlayerDef(_q("New player"), _q(PlayersTableHelper::kHUMAN), ""), + true); } diff --git a/qt/new_game.cpp b/qt/new_game.cpp index 21f5ad9..d55efe7 100644 --- a/qt/new_game.cpp +++ b/qt/new_game.cpp @@ -248,7 +248,7 @@ void NewGame::on_pushButtonAdd_clicked() comboBoxType->currentText(), spinBoxLevel->isEnabled() ? QString("%1").arg(spinBoxLevel->value()) : ""); - m_helper->addPlayer(def); + m_helper->addPlayer(def, true); // Increment the player ID static int currPlayer = 2; diff --git a/qt/players_table_helper.cpp b/qt/players_table_helper.cpp index d8b81e3..1517154 100644 --- a/qt/players_table_helper.cpp +++ b/qt/players_table_helper.cpp @@ -223,11 +223,23 @@ void PlayersTableHelper::addPlayers(const QList &iList) } -void PlayersTableHelper::addPlayer(const PlayerDef &iPlayer) +void PlayersTableHelper::addPlayer(const PlayerDef &iPlayer, bool selectAndEdit) { QList tmpList; tmpList.push_back(iPlayer); addPlayers(tmpList); + + if (selectAndEdit) + { + int row = m_tablePlayers->rowCount() - 1; + // Give focus to the newly created cell containing the player name + m_tablePlayers->setCurrentCell(row, 0, + QItemSelectionModel::ClearAndSelect | + QItemSelectionModel::Current | + QItemSelectionModel::Rows); + // Edit the name + m_tablePlayers->editItem(m_tablePlayers->item(row, 0)); + } } diff --git a/qt/players_table_helper.h b/qt/players_table_helper.h index da52a67..1442134 100644 --- a/qt/players_table_helper.h +++ b/qt/players_table_helper.h @@ -63,7 +63,7 @@ public: QList getPlayers(bool onlySelected) const; void addPlayers(const QList &iList); - void addPlayer(const PlayerDef &iPlayer); + void addPlayer(const PlayerDef &iPlayer, bool selectAndEdit = false); static QList getFavPlayers(); static void saveFavPlayers(const QList &iFavPlayers);