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. Only values read from
.ini-file are restored.

Simplify and correct NewTournamentDialog::readSettings.

Resolves #209
  • Loading branch information
alwey committed Jan 22, 2022
commit 7353eeac00db86d06ca56d2232bd281fc2c6bee7
3 changes: 1 addition & 2 deletions projects/gui/src/gamesettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GameSettingsWidget : public QWidget

void applyEngineConfiguration(EngineConfiguration* config);
void enableSettingsUpdates();
void readSettings();

public slots:
void onHumanCountChanged(int count);
Expand All @@ -67,8 +68,6 @@ class GameSettingsWidget : public QWidget
void showTimeControlDialog();

private:
void readSettings();

Ui::GameSettingsWidget *ui;
TimeControl m_timeControl;
Chess::Board* m_board;
Expand Down
13 changes: 9 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 @@ -785,13 +786,17 @@ void MainWindow::onGameFinished(ChessGame* game)

void MainWindow::newTournament()
{
NewTournamentDialog dlg(CuteChessApplication::instance()->engineManager(), this);
if (dlg.exec() != QDialog::Accepted)
if (m_tournamentDlg == nullptr)
m_tournamentDlg = new NewTournamentDialog(
CuteChessApplication::instance()->engineManager(),
this);

if (m_tournamentDlg->exec() != 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
3 changes: 3 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 Down Expand Up @@ -135,6 +136,8 @@ class MainWindow : public QMainWindow
MoveList* m_moveList;
PgnTagsModel* m_tagsModel;

NewTournamentDialog* m_tournamentDlg;

QAction* m_quitGameAct;
QAction* m_newGameAct;
QAction* m_adjudicateBlackWinAct;
Expand Down
28 changes: 16 additions & 12 deletions projects/gui/src/newtournamentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ 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, [=]()
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
readSettings();
ui->m_tournamentSettings->readSettings();
ui->m_gameSettings->readSettings();
m_addedEnginesManager->setEngines({});
});
}

NewTournamentDialog::~NewTournamentDialog()
Expand Down Expand Up @@ -316,21 +327,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: 1 addition & 2 deletions projects/gui/src/tournamentsettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ class TournamentSettingsWidget : public QWidget
QString resultFormat() const;

void enableSettingsUpdates();
void readSettings();

signals:
void tournamentTypeChanged(const QString& tournamentType);

private:
void readSettings();

Ui::TournamentSettingsWidget *ui;
};

Expand Down