Freeciv21
Develop your civilization from humble roots to a global empire
tab_nation.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // Qt
15 #include <QGridLayout>
16 #include <QLineEdit>
17 #include <QPushButton>
18 
19 // utility
20 #include "fcintl.h"
21 #include "log.h"
22 #include "registry.h"
23 
24 // common
25 #include "game.h"
26 
27 // ruledit
28 #include "ruledit_qt.h"
29 
30 #include "tab_nation.h"
31 
36 {
37  QGridLayout *main_layout = new QGridLayout(this);
38  QLabel *nationlist_label;
39  int row = 0;
40 
41  ui = ui_in;
42 
43  main_layout->setSizeConstraint(QLayout::SetMaximumSize);
44 
45  via_include = new QRadioButton(QString::fromUtf8(R__("Use nationlist")));
46  main_layout->addWidget(via_include, row++, 0);
47  connect(via_include, &QAbstractButton::toggled, this,
49 
50  nationlist_label = new QLabel(QString::fromUtf8(R__("Nationlist")));
51  nationlist_label->setParent(this);
52  main_layout->addWidget(nationlist_label, row, 0);
53  nationlist = new QLineEdit(this);
54  main_layout->addWidget(nationlist, row++, 1);
55 
56  refresh();
57 
58  setLayout(main_layout);
59 }
60 
65 {
66  if (ui->data.nationlist == nullptr) {
67  via_include->setChecked(false);
68  nationlist->setEnabled(false);
69  } else {
70  via_include->setChecked(true);
71  nationlist->setText(ui->data.nationlist);
72  nationlist->setEnabled(true);
73  }
74 }
75 
80 {
81  delete[] ui->data.nationlist;
82  ui->data.nationlist = nullptr;
83 
84  if (via_include->isChecked()) {
85  QByteArray nln_bytes;
86 
87  nln_bytes = nationlist->text().toUtf8();
88  ui->data.nationlist = fc_strdup(nln_bytes.data());
89  } else {
90  ui->data.nationlist = nullptr;
91  }
92 }
93 
98 {
99  if (checked) {
100  if (ui->data.nationlist_saved != nullptr) {
102  } else {
103  ui->data.nationlist = fc_strdup("default/nationlist.ruleset");
104  }
105  } else {
106  QByteArray nln_bytes;
107 
108  delete[] ui->data.nationlist_saved;
109  nln_bytes = nationlist->text().toUtf8();
110  ui->data.nationlist_saved = fc_strdup(nln_bytes.data());
111  ui->data.nationlist = nullptr;
112  }
113 
114  refresh();
115 }
struct rule_data data
Definition: ruledit_qt.h:107
void nationlist_toggle(bool checked)
Toggled nationlist include setting.
Definition: tab_nation.cpp:97
QRadioButton * via_include
Definition: tab_nation.h:36
void flush_widgets()
Flush information from widgets to stores where it can be saved from.
Definition: tab_nation.cpp:79
ruledit_gui * ui
Definition: tab_nation.h:34
void refresh()
Refresh the information.
Definition: tab_nation.cpp:64
QLineEdit * nationlist
Definition: tab_nation.h:37
tab_nation(ruledit_gui *ui_in)
Setup tab_nation object.
Definition: tab_nation.cpp:35
#define R__(String)
Definition: fcintl.h:58
char * nationlist
Definition: rulesave.h:15
char * nationlist_saved
Definition: rulesave.h:16
#define fc_strdup(str)
Definition: support.h:111