Skip to content

Commit f966e5f

Browse files
committed
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
1 parent e47db4d commit f966e5f

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

projects/gui/src/mainwindow.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ MainWindow::TabData::TabData(ChessGame* game, Tournament* tournament)
7474
}
7575

7676
MainWindow::MainWindow(ChessGame* game)
77-
: m_game(nullptr),
77+
: m_tournamentDlg(nullptr),
78+
m_game(nullptr),
7879
m_closing(false),
7980
m_readyToClose(false),
8081
m_firstTabAutoCloseEnabled(true)
@@ -783,15 +784,39 @@ void MainWindow::onGameFinished(ChessGame* game)
783784
}
784785
}
785786

787+
void MainWindow::resetTournamentDialog()
788+
{
789+
if (!m_tournamentDlg.isNull())
790+
{
791+
m_tournamentDlg->disconnect();
792+
m_tournamentDlg->deleteLater();
793+
}
794+
m_tournamentDlg.clear();
795+
newTournament();
796+
}
797+
786798
void MainWindow::newTournament()
787799
{
788-
NewTournamentDialog dlg(CuteChessApplication::instance()->engineManager(), this);
789-
if (dlg.exec() != QDialog::Accepted)
800+
if (m_tournamentDlg.isNull())
801+
m_tournamentDlg = new NewTournamentDialog(
802+
CuteChessApplication::instance()->engineManager(),
803+
this);
804+
m_tournamentDlg->disconnect();
805+
connect(m_tournamentDlg, &NewTournamentDialog::finished,
806+
this, &MainWindow::onTournamentDialog);
807+
connect(m_tournamentDlg, &NewTournamentDialog::reset,
808+
this, &MainWindow::resetTournamentDialog);
809+
m_tournamentDlg->open();
810+
}
811+
812+
void MainWindow::onTournamentDialog()
813+
{
814+
if (static_cast<NewTournamentDialog *>(sender())->result() != QDialog::Accepted)
790815
return;
791816

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

794-
Tournament* t = dlg.createTournament(manager);
819+
Tournament* t = m_tournamentDlg->createTournament(manager);
795820
auto resultsDialog = CuteChessApplication::instance()->tournamentResultsDialog();
796821
connect(t, SIGNAL(finished()),
797822
this, SLOT(onTournamentFinished()));

projects/gui/src/mainwindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QMenu;
3131
class QAction;
3232
class QCloseEvent;
3333
class QTabBar;
34+
class NewTournamentDialog;
3435
class GameViewer;
3536
class MoveList;
3637
class PlainTextLog;
@@ -57,6 +58,8 @@ class MainWindow : public QMainWindow
5758

5859
public slots:
5960
void addGame(ChessGame* game);
61+
void resetTournamentDialog();
62+
void onTournamentDialog();
6063

6164
protected:
6265
virtual void closeEvent(QCloseEvent* event);
@@ -135,6 +138,8 @@ class MainWindow : public QMainWindow
135138
MoveList* m_moveList;
136139
PgnTagsModel* m_tagsModel;
137140

141+
QPointer<NewTournamentDialog> m_tournamentDlg;
142+
138143
QAction* m_quitGameAct;
139144
QAction* m_newGameAct;
140145
QAction* m_adjudicateBlackWinAct;

projects/gui/src/newtournamentdialog.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ NewTournamentDialog::NewTournamentDialog(EngineManager* engineManager,
123123
ui->m_gameSettings->onHumanCountChanged(0);
124124
onVariantChanged(ui->m_gameSettings->chessVariant());
125125
readSettings();
126+
127+
ui->buttonBox->addButton(QDialogButtonBox::Reset);
128+
connect(ui->buttonBox->button(QDialogButtonBox::Reset),
129+
&QAbstractButton::clicked, this, [=]()
130+
{
131+
emit reset();
132+
});
126133
}
127134

128135
NewTournamentDialog::~NewTournamentDialog()
@@ -316,21 +323,14 @@ Tournament* NewTournamentDialog::createTournament(GameManager* gameManager) cons
316323

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

321-
QString pgnName = ui->m_pgnoutEdit->text();
322-
if (pgnName.isEmpty())
323-
{
324-
pgnName = QSettings().value("tournament/default_pgn_output_file",
329+
QString pgnName = QSettings().value("tournament/default_pgn_output_file",
325330
QString()).toString();
326-
ui->m_pgnoutEdit->setText(pgnName);
327-
}
331+
ui->m_pgnoutEdit->setText(pgnName);
328332

329-
QString epdName = ui->m_epdoutEdit->text();
330-
if (epdName.isEmpty())
331-
{
332-
epdName = QSettings().value("tournament/default_epd_output_file",
333+
QString epdName = QSettings().value("tournament/default_epd_output_file",
333334
QString()).toString();
334-
ui->m_epdoutEdit->setText(epdName);
335-
}
335+
ui->m_epdoutEdit->setText(epdName);
336336
}

projects/gui/src/newtournamentdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class NewTournamentDialog : public QDialog
4545

4646
Tournament* createTournament(GameManager* gameManager) const;
4747

48+
signals:
49+
void reset();
50+
4851
private slots:
4952
void addEngineOnDblClick(const QModelIndex& index);
5053
void addEngine();

0 commit comments

Comments
 (0)