Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Re-use previous tournament's settings
Do not delete NewTournamentDialog after usage, but re-use it for the
next tournament.

Add reset functionality to NewTournamentDialog.
However, on reset use a new NewTournamentDialog.

Simplify and correct NewTournamentDialog::readSettings.

Resolves #209
  • Loading branch information
alwey committed Feb 2, 2022
commit f966e5fd2290bc79b4d018d3d0113789eeb2833c
33 changes: 29 additions & 4 deletions projects/gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ MainWindow::TabData::TabData(ChessGame* game, Tournament* tournament)
}

MainWindow::MainWindow(ChessGame* game)
: m_game(nullptr),
: m_tournamentDlg(nullptr),
m_game(nullptr),
m_closing(false),
m_readyToClose(false),
m_firstTabAutoCloseEnabled(true)
Expand Down Expand Up @@ -783,15 +784,39 @@ void MainWindow::onGameFinished(ChessGame* game)
}
}

void MainWindow::resetTournamentDialog()
{
if (!m_tournamentDlg.isNull())
{
m_tournamentDlg->disconnect();
m_tournamentDlg->deleteLater();
}
m_tournamentDlg.clear();
newTournament();
}

void MainWindow::newTournament()
{
NewTournamentDialog dlg(CuteChessApplication::instance()->engineManager(), this);
if (dlg.exec() != QDialog::Accepted)
if (m_tournamentDlg.isNull())
m_tournamentDlg = new NewTournamentDialog(
CuteChessApplication::instance()->engineManager(),
this);
m_tournamentDlg->disconnect();
connect(m_tournamentDlg, &NewTournamentDialog::finished,
this, &MainWindow::onTournamentDialog);
connect(m_tournamentDlg, &NewTournamentDialog::reset,
this, &MainWindow::resetTournamentDialog);
m_tournamentDlg->open();
}

void MainWindow::onTournamentDialog()
{
if (static_cast<NewTournamentDialog *>(sender())->result() != QDialog::Accepted)
return;

GameManager* manager = CuteChessApplication::instance()->gameManager();

Tournament* t = dlg.createTournament(manager);
Tournament* t = m_tournamentDlg->createTournament(manager);
auto resultsDialog = CuteChessApplication::instance()->tournamentResultsDialog();
connect(t, SIGNAL(finished()),
this, SLOT(onTournamentFinished()));
Expand Down
5 changes: 5 additions & 0 deletions projects/gui/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QMenu;
class QAction;
class QCloseEvent;
class QTabBar;
class NewTournamentDialog;
class GameViewer;
class MoveList;
class PlainTextLog;
Expand All @@ -57,6 +58,8 @@ class MainWindow : public QMainWindow

public slots:
void addGame(ChessGame* game);
void resetTournamentDialog();
void onTournamentDialog();

protected:
virtual void closeEvent(QCloseEvent* event);
Expand Down Expand Up @@ -135,6 +138,8 @@ class MainWindow : public QMainWindow
MoveList* m_moveList;
PgnTagsModel* m_tagsModel;

QPointer<NewTournamentDialog> m_tournamentDlg;

QAction* m_quitGameAct;
QAction* m_newGameAct;
QAction* m_adjudicateBlackWinAct;
Expand Down
24 changes: 12 additions & 12 deletions projects/gui/src/newtournamentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ NewTournamentDialog::NewTournamentDialog(EngineManager* engineManager,
ui->m_gameSettings->onHumanCountChanged(0);
onVariantChanged(ui->m_gameSettings->chessVariant());
readSettings();

ui->buttonBox->addButton(QDialogButtonBox::Reset);
connect(ui->buttonBox->button(QDialogButtonBox::Reset),
&QAbstractButton::clicked, this, [=]()
{
emit reset();
});
}

NewTournamentDialog::~NewTournamentDialog()
Expand Down Expand Up @@ -316,21 +323,14 @@ Tournament* NewTournamentDialog::createTournament(GameManager* gameManager) cons

void NewTournamentDialog::readSettings()
{
ui->m_nameEdit->setText(QSettings().value("pgn/event", "My Tournament").toString());
ui->m_siteEdit->setText(QSettings().value("pgn/site").toString());

QString pgnName = ui->m_pgnoutEdit->text();
if (pgnName.isEmpty())
{
pgnName = QSettings().value("tournament/default_pgn_output_file",
QString pgnName = QSettings().value("tournament/default_pgn_output_file",
QString()).toString();
ui->m_pgnoutEdit->setText(pgnName);
}
ui->m_pgnoutEdit->setText(pgnName);

QString epdName = ui->m_epdoutEdit->text();
if (epdName.isEmpty())
{
epdName = QSettings().value("tournament/default_epd_output_file",
QString epdName = QSettings().value("tournament/default_epd_output_file",
QString()).toString();
ui->m_epdoutEdit->setText(epdName);
}
ui->m_epdoutEdit->setText(epdName);
}
3 changes: 3 additions & 0 deletions projects/gui/src/newtournamentdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class NewTournamentDialog : public QDialog

Tournament* createTournament(GameManager* gameManager) const;

signals:
void reset();

private slots:
void addEngineOnDblClick(const QModelIndex& index);
void addEngine();
Expand Down