Freeciv21
Develop your civilization from humble roots to a global empire
tileset_options.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Louis Moureaux
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #include "tileset_options.h"
5 
6 #include "name_translation.h"
7 #include "tileset/tilespec.h"
8 
9 #include <QCheckBox>
10 #include <QDialogButtonBox>
11 #include <QPushButton>
12 #include <QVBoxLayout>
13 
14 namespace freeciv {
15 
23  QWidget *parent)
24  : QDialog(parent)
25 {
26  setModal(true);
27  setMinimumWidth(300); // For the title to be fully visible
28  setWindowTitle(_("Tileset Options"));
29 
30  auto layout = new QVBoxLayout;
31  setLayout(layout);
32 
33  for (const auto &[name_, option] : tileset_get_options(t)) {
34  // https://stackoverflow.com/q/46114214 (TODO C++20)
35  auto name = name_;
36 
37  auto check = new QCheckBox(option.description);
38 
39  // Sync check box state with the tileset
40  check->setChecked(tileset_option_is_enabled(t, name));
41  connect(check, &QCheckBox::toggled, [name](bool checked) {
42  tileset_set_option(tileset, name, checked);
43  });
44 
45  m_checks[name] = check;
46  layout->addWidget(check);
47  }
48 
49  layout->addSpacing(6);
50 
51  auto buttons = new QDialogButtonBox(QDialogButtonBox::Close
52  | QDialogButtonBox::Reset);
53  connect(buttons->button(QDialogButtonBox::Close), &QPushButton::clicked,
54  this, &QDialog::accept);
55  connect(buttons->button(QDialogButtonBox::Reset), &QPushButton::clicked,
57  layout->addWidget(buttons);
58 }
59 
64 {
65  for (const auto &[name, option] : tileset_get_options(tileset)) {
66  // Changes are propagated though the clicked() signal.
67  m_checks[name]->setChecked(option.enabled_by_default);
68  }
69 }
70 
71 } // namespace freeciv
tileset_options_dialog(struct tileset *t, QWidget *parent=0)
Sets up the tileset options dialog.
std::map< QString, QCheckBox * > m_checks
void reset()
Resets all options to the tileset defaults.
#define _(String)
Definition: fcintl.h:50
const char * name
Definition: inputfile.cpp:118
Definition: path.cpp:10
The base class for options.
Definition: options.cpp:209
bool tileset_option_is_enabled(const struct tileset *t, const QString &name)
Checks if an user-settable tileset option is enabled.
Definition: tilespec.cpp:3799
std::map< QString, tileset_option > tileset_get_options(const struct tileset *t)
Gets the user-settable options of the tileset.
Definition: tilespec.cpp:3789
bool tileset_set_option(struct tileset *t, const QString &name, bool enabled)
Enable or disable a user-settable tileset option.
Definition: tilespec.cpp:3812