Start editing the name directly after adding a player

This commit is contained in:
Olivier Teulière 2012-02-17 23:50:14 +01:00
parent 03f20dd7be
commit 33814ef058
4 changed files with 17 additions and 12 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -223,11 +223,23 @@ void PlayersTableHelper::addPlayers(const QList<PlayerDef> &iList)
}
void PlayersTableHelper::addPlayer(const PlayerDef &iPlayer)
void PlayersTableHelper::addPlayer(const PlayerDef &iPlayer, bool selectAndEdit)
{
QList<PlayerDef> 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));
}
}

View file

@ -63,7 +63,7 @@ public:
QList<PlayerDef> getPlayers(bool onlySelected) const;
void addPlayers(const QList<PlayerDef> &iList);
void addPlayer(const PlayerDef &iPlayer);
void addPlayer(const PlayerDef &iPlayer, bool selectAndEdit = false);
static QList<PlayerDef> getFavPlayers();
static void saveFavPlayers(const QList<PlayerDef> &iFavPlayers);