Freeciv21
Develop your civilization from humble roots to a global empire
edit_utype.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 <QMenu>
17 #include <QToolButton>
18 
19 // common
20 #include "unittype.h"
21 
22 // ruledit
23 #include "ruledit.h"
24 #include "ruledit_qt.h"
25 #include "tab_tech.h"
26 
27 #include "edit_utype.h"
28 
32 edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in)
33  : QDialog()
34 {
35  QVBoxLayout *main_layout = new QVBoxLayout(this);
36  QGridLayout *unit_layout = new QGridLayout();
37  QLabel *label;
38  QMenu *req;
39 
40  ui = ui_in;
41  utype = utype_in;
42 
43  setWindowTitle(QString::fromUtf8(utype_rule_name(utype)));
44 
45  label = new QLabel(QString::fromUtf8(R__("Requirement")));
46  label->setParent(this);
47 
48  req = new QMenu();
49  req_button = new QToolButton();
50  req_button->setParent(this);
51  req_button->setMenu(req);
53  connect(req_button, &QToolButton::triggered, this, &edit_utype::req_menu);
54 
55  unit_layout->addWidget(label, 0, 0);
56  unit_layout->addWidget(req_button, 0, 1);
57 
58  refresh();
59 
60  main_layout->addLayout(unit_layout);
61 
62  setLayout(main_layout);
63 }
64 
69 {
71 }
72 
77 {
78  struct advance *padv;
79  QByteArray an_bytes;
80 
81  an_bytes = action->text().toUtf8();
82  padv = advance_by_rule_name(an_bytes.data());
83 
84  if (padv != nullptr) {
85  utype->require_advance = padv;
86 
87  refresh();
88  }
89 }
edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in)
Setup edit_utype object.
Definition: edit_utype.cpp:32
void refresh()
Refresh the information.
Definition: edit_utype.cpp:68
ruledit_gui * ui
Definition: edit_utype.h:32
void req_menu(QAction *action)
User selected tech to be req of utype.
Definition: edit_utype.cpp:76
struct unit_type * utype
Definition: edit_utype.h:33
QToolButton * req_button
Definition: edit_utype.h:34
static void techs_to_menu(QMenu *fill_menu)
Fill menu with all possible tech values.
Definition: tab_tech.cpp:191
static QString tech_name(struct advance *padv)
Display name of the tech.
Definition: tab_tech.cpp:202
#define R__(String)
Definition: fcintl.h:58
Definition: tech.h:113
struct advance * require_advance
Definition: unittype.h:484
struct advance * advance_by_rule_name(const char *name)
Does a linear search of advances[].name.vernacular Returns nullptr when none match.
Definition: tech.cpp:180
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
Definition: unittype.cpp:1274