Author: cazfi
Date: Tue Feb  9 14:04:54 2016
New Revision: 31831

URL: http://svn.gna.org/viewcvs/freeciv?rev=31831&view=rev
Log:
Added radio button to automate the usual rule_name -> display name update

See patch #6914

Modified:
    branches/S2_6/tools/ruledit/tab_building.cpp
    branches/S2_6/tools/ruledit/tab_building.h
    branches/S2_6/tools/ruledit/tab_tech.cpp
    branches/S2_6/tools/ruledit/tab_tech.h
    branches/S2_6/tools/ruledit/tab_unit.cpp
    branches/S2_6/tools/ruledit/tab_unit.h

Modified: branches/S2_6/tools/ruledit/tab_building.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_building.cpp?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_building.cpp        (original)
+++ branches/S2_6/tools/ruledit/tab_building.cpp        Tue Feb  9 14:04:54 2016
@@ -21,6 +21,7 @@
 #include <QListWidget>
 #include <QMenu>
 #include <QPushButton>
+#include <QRadioButton>
 #include <QToolButton>
 
 // utility
@@ -59,21 +60,24 @@
 
   bldg_layout->setSizeConstraint(QLayout::SetMaximumSize);
 
-  label = new QLabel(QString::fromUtf8(R__("Name")));
-  label->setParent(this);
-  name = new QLineEdit(this);
-  name->setText("None");
-  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
-  bldg_layout->addWidget(label, 0, 0);
-  bldg_layout->addWidget(name, 0, 1);
-
   label = new QLabel(QString::fromUtf8(R__("Rule Name")));
   label->setParent(this);
   rname = new QLineEdit(this);
   rname->setText("None");
   connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
+  bldg_layout->addWidget(label, 0, 0);
+  bldg_layout->addWidget(rname, 0, 2);
+
+  label = new QLabel(QString::fromUtf8(R__("Name")));
+  label->setParent(this);
+  same_name = new QRadioButton();
+  connect(same_name, SIGNAL(toggled(bool)), this, 
SLOT(same_name_toggle(bool)));
+  name = new QLineEdit(this);
+  name->setText("None");
+  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
   bldg_layout->addWidget(label, 1, 0);
-  bldg_layout->addWidget(rname, 1, 1);
+  bldg_layout->addWidget(same_name, 1, 1);
+  bldg_layout->addWidget(name, 1, 2);
 
   add_button = new QPushButton(QString::fromUtf8(R__("Add Building")), this);
   connect(add_button, SIGNAL(pressed()), this, SLOT(add_now2()));
@@ -82,7 +86,7 @@
 
   delete_button = new QPushButton(QString::fromUtf8(R__("Remove this 
Building")), this);
   connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
-  bldg_layout->addWidget(delete_button, 5, 1);
+  bldg_layout->addWidget(delete_button, 5, 2);
   show_experimental(delete_button);
 
   refresh();
@@ -116,11 +120,23 @@
   selected = pimpr;
 
   if (selected != 0) {
-    name->setText(QString::fromUtf8(untranslated_name(&(pimpr->name))));
-    rname->setText(QString::fromUtf8(improvement_rule_name(pimpr)));
+    QString dispn = QString::fromUtf8(untranslated_name(&(pimpr->name)));
+    QString rulen = QString::fromUtf8(improvement_rule_name(pimpr));
+
+    name->setText(dispn);
+    rname->setText(rulen);
+    if (dispn == rulen) {
+      name->setEnabled(false);
+      same_name->setChecked(true);
+    } else {
+      same_name->setChecked(false);
+      name->setEnabled(true);
+    }
   } else {
     name->setText("None");
     rname->setText("None");
+    same_name->setChecked(true);
+    name->setEnabled(false);
   }
 }
 
@@ -150,6 +166,11 @@
         }
       }
     } improvement_iterate_end;
+
+    if (same_name->isChecked()) {
+      name->setText(rname->text());
+    }
+
     names_set(&(selected->name), 0,
               name->text().toUtf8().data(),
               rname->text().toUtf8().data());
@@ -212,3 +233,14 @@
 
   refresh();
 }
+
+/**************************************************************************
+  Toggled whether rule_name and name should be kept identical
+**************************************************************************/
+void tab_building::same_name_toggle(bool checked)
+{
+  name->setEnabled(!checked);
+  if (checked) {
+    name->setText(rname->text());
+  }
+}

Modified: branches/S2_6/tools/ruledit/tab_building.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_building.h?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_building.h  (original)
+++ branches/S2_6/tools/ruledit/tab_building.h  Tue Feb  9 14:04:54 2016
@@ -23,6 +23,7 @@
 
 class QLineEdit;
 class QListWidget;
+class QRadioButton;
 
 class ruledit_gui;
 
@@ -42,6 +43,7 @@
     QLineEdit *name;
     QLineEdit *rname;
     QListWidget *bldg_list;
+    QRadioButton *same_name;
 
     struct impr_type *selected;
 
@@ -50,6 +52,7 @@
     void select_bldg();
     void add_now2();   // "2" in name to workaround segfault on program start. 
Due to compiler bug?
     void delete_now();
+    void same_name_toggle(bool checked);
 };
 
 

Modified: branches/S2_6/tools/ruledit/tab_tech.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_tech.cpp?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_tech.cpp    (original)
+++ branches/S2_6/tools/ruledit/tab_tech.cpp    Tue Feb  9 14:04:54 2016
@@ -21,6 +21,7 @@
 #include <QListWidget>
 #include <QMenu>
 #include <QPushButton>
+#include <QRadioButton>
 #include <QToolButton>
 
 // utility
@@ -59,21 +60,24 @@
 
   tech_layout->setSizeConstraint(QLayout::SetMaximumSize);
 
-  label = new QLabel(QString::fromUtf8(R__("Name")));
-  label->setParent(this);
-  name = new QLineEdit(this);
-  name->setText("None");
-  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
-  tech_layout->addWidget(label, 0, 0);
-  tech_layout->addWidget(name, 0, 1);
-
   label = new QLabel(QString::fromUtf8(R__("Rule Name")));
   label->setParent(this);
   rname = new QLineEdit(this);
   rname->setText("None");
   connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
+  tech_layout->addWidget(label, 0, 0);
+  tech_layout->addWidget(rname, 0, 2);
+
+  label = new QLabel(QString::fromUtf8(R__("Name")));
+  label->setParent(this);
+  same_name = new QRadioButton();
+  connect(same_name, SIGNAL(toggled(bool)), this, 
SLOT(same_name_toggle(bool)));
+  name = new QLineEdit(this);
+  name->setText("None");
+  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
   tech_layout->addWidget(label, 1, 0);
-  tech_layout->addWidget(rname, 1, 1);
+  tech_layout->addWidget(same_name, 1, 1);
+  tech_layout->addWidget(name, 1, 2);
 
   label = new QLabel(QString::fromUtf8(R__("Req1")));
   label->setParent(this);
@@ -82,7 +86,7 @@
   req1 = prepare_req_button(req1_button, AR_ONE);
   connect(req1_button, SIGNAL(pressed()), this, SLOT(req1_jump()));
   tech_layout->addWidget(label, 2, 0);
-  tech_layout->addWidget(req1_button, 2, 1);
+  tech_layout->addWidget(req1_button, 2, 2);
 
   label = new QLabel(QString::fromUtf8(R__("Req2")));
   label->setParent(this);
@@ -90,7 +94,7 @@
   req2 = prepare_req_button(req2_button, AR_TWO);
   connect(req2_button, SIGNAL(pressed()), this, SLOT(req2_jump()));
   tech_layout->addWidget(label, 3, 0);
-  tech_layout->addWidget(req2_button, 3, 1);
+  tech_layout->addWidget(req2_button, 3, 2);
 
   label = new QLabel(QString::fromUtf8(R__("Root Req")));
   label->setParent(this);
@@ -99,7 +103,7 @@
   root_req = prepare_req_button(root_req_button, AR_ROOT);
   connect(root_req_button, SIGNAL(pressed()), this, SLOT(root_req_jump()));
   tech_layout->addWidget(label, 4, 0);
-  tech_layout->addWidget(root_req_button, 4, 1);
+  tech_layout->addWidget(root_req_button, 4, 2);
 
   add_button = new QPushButton(QString::fromUtf8(R__("Add tech")), this);
   connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
@@ -108,7 +112,7 @@
 
   delete_button = new QPushButton(QString::fromUtf8(R__("Remove this tech")), 
this);
   connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
-  tech_layout->addWidget(delete_button, 5, 1);
+  tech_layout->addWidget(delete_button, 5, 2);
   show_experimental(delete_button);
 
   refresh();
@@ -201,8 +205,20 @@
   selected = adv;
 
   if (selected != 0) {
-    name->setText(untranslated_name(&(adv->name)));
-    rname->setText(rule_name(&(adv->name)));
+    QString dispn = QString::fromUtf8(untranslated_name(&(adv->name)));
+    QString rulen = QString::fromUtf8(rule_name(&(adv->name)));
+
+    name->setText(dispn);
+    rname->setText(rulen);
+
+    if (dispn == rulen) {
+      name->setEnabled(false);
+      same_name->setChecked(true);
+    } else {
+      same_name->setChecked(false);
+      name->setEnabled(true);
+    }
+    
     req1_button->setText(tech_name(adv->require[AR_ONE]));
     req2_button->setText(tech_name(adv->require[AR_TWO]));
     root_req_button->setText(tech_name(adv->require[AR_ROOT]));
@@ -212,6 +228,8 @@
     req1_button->setText("None");
     req2_button->setText("None");
     root_req_button->setText("None");
+    same_name->setChecked(true);
+    name->setEnabled(false);
   }
 }
 
@@ -315,6 +333,10 @@
       }
     } advance_iterate_end;
 
+    if (same_name->isChecked()) {
+      name->setText(rname->text());
+    }
+
     names_set(&(selected->name), 0,
               name->text().toUtf8().data(),
               rname->text().toUtf8().data());
@@ -380,3 +402,14 @@
   update_tech_info(new_adv);
   refresh();
 }
+
+/**************************************************************************
+  Toggled whether rule_name and name should be kept identical
+**************************************************************************/
+void tab_tech::same_name_toggle(bool checked)
+{
+  name->setEnabled(!checked);
+  if (checked) {
+    name->setText(rname->text());
+  }
+}

Modified: branches/S2_6/tools/ruledit/tab_tech.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_tech.h?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_tech.h      (original)
+++ branches/S2_6/tools/ruledit/tab_tech.h      Tue Feb  9 14:04:54 2016
@@ -29,6 +29,7 @@
 class QLineEdit;
 class QListWidget;
 class QMenu;
+class QRadioButton;
 class QToolButton;
 
 class ruledit_gui;
@@ -58,6 +59,7 @@
     QMenu *req2;
     QMenu *root_req;
     QListWidget *tech_list;
+    QRadioButton *same_name;
 
     struct advance *selected;
 
@@ -72,6 +74,7 @@
     void root_req_menu(QAction *action);
     void add_now();
     void delete_now();
+    void same_name_toggle(bool checked);
 };
 
 

Modified: branches/S2_6/tools/ruledit/tab_unit.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_unit.cpp?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_unit.cpp    (original)
+++ branches/S2_6/tools/ruledit/tab_unit.cpp    Tue Feb  9 14:04:54 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 #include <QListWidget>
 #include <QMenu>
 #include <QPushButton>
+#include <QRadioButton>
 #include <QToolButton>
 
 // utility
@@ -59,21 +60,24 @@
 
   unit_layout->setSizeConstraint(QLayout::SetMaximumSize);
 
-  label = new QLabel(QString::fromUtf8(R__("Name")));
-  label->setParent(this);
-  name = new QLineEdit(this);
-  name->setText("None");
-  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
-  unit_layout->addWidget(label, 0, 0);
-  unit_layout->addWidget(name, 0, 1);
-
   label = new QLabel(QString::fromUtf8(R__("Rule Name")));
   label->setParent(this);
   rname = new QLineEdit(this);
   rname->setText("None");
   connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
+  unit_layout->addWidget(label, 0, 0);
+  unit_layout->addWidget(rname, 0, 2);
+
+  label = new QLabel(QString::fromUtf8(R__("Name")));
+  label->setParent(this);
+  same_name = new QRadioButton();
+  connect(same_name, SIGNAL(toggled(bool)), this, 
SLOT(same_name_toggle(bool)));
+  name = new QLineEdit(this);
+  name->setText("None");
+  connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
   unit_layout->addWidget(label, 1, 0);
-  unit_layout->addWidget(rname, 1, 1);
+  unit_layout->addWidget(same_name, 1, 1);
+  unit_layout->addWidget(name, 1, 2);
 
   add_button = new QPushButton(QString::fromUtf8(R__("Add Unit")), this);
   connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
@@ -82,7 +86,7 @@
 
   delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Unit")), 
this);
   connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
-  unit_layout->addWidget(delete_button, 5, 1);
+  unit_layout->addWidget(delete_button, 5, 2);
   show_experimental(delete_button);
 
   refresh();
@@ -115,12 +119,24 @@
 {
   selected = ptype;
 
-  if (selected != 0) {
-    name->setText(QString::fromUtf8(untranslated_name(&(ptype->name))));
-    rname->setText(QString::fromUtf8(utype_rule_name(ptype)));
+  if (selected != nullptr) {
+    QString dispn = QString::fromUtf8(untranslated_name(&(ptype->name)));
+    QString rulen = QString::fromUtf8(utype_rule_name(ptype));
+
+    name->setText(dispn);
+    rname->setText(rulen);
+    if (dispn == rulen) {
+      name->setEnabled(false);
+      same_name->setChecked(true);
+    } else {
+      same_name->setChecked(false);
+      name->setEnabled(true);
+    }
   } else {
     name->setText("None");
     rname->setText("None");
+    same_name->setChecked(true);
+    name->setEnabled(false);
   }
 }
 
@@ -151,6 +167,10 @@
       }
     } unit_type_iterate_end;
 
+    if (same_name->isChecked()) {
+      name->setText(rname->text());
+    }
+
     names_set(&(selected->name), 0,
               name->text().toUtf8().data(),
               rname->text().toUtf8().data());
@@ -213,3 +233,14 @@
 
   refresh();
 }
+
+/**************************************************************************
+  Toggled whether rule_name and name should be kept identical
+**************************************************************************/
+void tab_unit::same_name_toggle(bool checked)
+{
+  name->setEnabled(!checked);
+  if (checked) {
+    name->setText(rname->text());
+  }
+}

Modified: branches/S2_6/tools/ruledit/tab_unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/tab_unit.h?rev=31831&r1=31830&r2=31831&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/tab_unit.h      (original)
+++ branches/S2_6/tools/ruledit/tab_unit.h      Tue Feb  9 14:04:54 2016
@@ -23,6 +23,7 @@
 
 class QLineEdit;
 class QListWidget;
+class QRadioButton;
 
 class ruledit_gui;
 
@@ -42,6 +43,7 @@
     QLineEdit *name;
     QLineEdit *rname;
     QListWidget *unit_list;
+    QRadioButton *same_name;
 
     struct unit_type *selected;
 
@@ -50,7 +52,7 @@
     void select_unit();
     void add_now();
     void delete_now();
+    void same_name_toggle(bool checked);
 };
 
-
 #endif // FC__TAB_UNIT_H


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to