Author: cazfi Date: Sat May 20 01:35:32 2017 New Revision: 35668 URL: http://svn.gna.org/viewcvs/freeciv?rev=35668&view=rev Log: Prevent opening multiple req_edit dialogs for the same requirement vector
See hrm Feature #660194 Modified: trunk/tools/ruledit/effect_edit.cpp trunk/tools/ruledit/req_edit.cpp trunk/tools/ruledit/req_edit.h trunk/tools/ruledit/ruledit_qt.cpp trunk/tools/ruledit/ruledit_qt.h trunk/tools/ruledit/tab_building.cpp trunk/tools/ruledit/tab_enablers.cpp trunk/tools/ruledit/tab_extras.cpp trunk/tools/ruledit/tab_gov.cpp Modified: trunk/tools/ruledit/effect_edit.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/effect_edit.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/effect_edit.cpp (original) +++ trunk/tools/ruledit/effect_edit.cpp Sat May 20 01:35:32 2017 @@ -29,8 +29,8 @@ #include "effects.h" // ruledit -#include "req_edit.h" #include "ruledit.h" +#include "ruledit_qt.h" #include "validity.h" #include "effect_edit.h" @@ -221,13 +221,10 @@ { if (selected != nullptr) { char buf[128]; - req_edit *redit; fc_snprintf(buf, sizeof(buf), R__("%s effect #%d"), name.toUtf8().data(), selected_nbr); - redit = new req_edit(ui, QString::fromUtf8(buf), &selected->reqs); - - redit->show(); - } -} + ui->open_req_edit(QString::fromUtf8(buf), &selected->reqs); + } +} Modified: trunk/tools/ruledit/req_edit.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/req_edit.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/req_edit.cpp (original) +++ trunk/tools/ruledit/req_edit.cpp Sat May 20 01:35:32 2017 @@ -31,6 +31,7 @@ // ruledit #include "ruledit.h" +#include "ruledit_qt.h" #include "univ_value.h" #include "req_edit.h" @@ -177,6 +178,7 @@ **************************************************************************/ void req_edit::close_now() { + ui->unregister_req_edit(this); done(0); } @@ -361,3 +363,11 @@ refresh(); } } + +/************************************************************************** + User clicked windows close button. +**************************************************************************/ +void req_edit::closeEvent(QCloseEvent *event) +{ + ui->unregister_req_edit(this); +} Modified: trunk/tools/ruledit/req_edit.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/req_edit.h?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/req_edit.h (original) +++ trunk/tools/ruledit/req_edit.h Sat May 20 01:35:32 2017 @@ -35,11 +35,12 @@ void refresh(); void add(const char *msg); + struct requirement_vector *req_vector; + private: ruledit_gui *ui; QListWidget *req_list; - struct requirement_vector *req_vector; struct requirement *selected; @@ -62,6 +63,9 @@ void req_present_menu(QAction *action); void univ_value_enum_menu(QAction *action); void univ_value_edit(); + + protected: + void closeEvent(QCloseEvent *event); }; #endif // FC__REQ_EDIT_H Modified: trunk/tools/ruledit/ruledit_qt.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/ruledit_qt.cpp (original) +++ trunk/tools/ruledit/ruledit_qt.cpp Sat May 20 01:35:32 2017 @@ -40,6 +40,7 @@ // ruledit #include "requirers_dlg.h" +#include "req_edit.h" #include "ruledit.h" #include "tab_building.h" #include "tab_enablers.h" @@ -192,6 +193,8 @@ full_layout->addWidget(msg_dspl); central->setLayout(full_layout); + + req_edits = req_edit_list_new(); } /************************************************************************** @@ -269,6 +272,35 @@ } /************************************************************************** + Open req_edit dialog +**************************************************************************/ +void ruledit_gui::open_req_edit(QString target, struct requirement_vector *preqs) +{ + req_edit *redit; + + req_edit_list_iterate(req_edits, old_edit) { + if (old_edit->req_vector == preqs) { + // Already open + return; + } + } req_edit_list_iterate_end; + + redit = new req_edit(this, target, preqs); + + redit->show(); + + req_edit_list_append(req_edits, redit); +} + +/************************************************************************** + Unregisted closed req_edit dialog +**************************************************************************/ +void ruledit_gui::unregister_req_edit(class req_edit *redit) +{ + req_edit_list_remove(req_edits, redit); +} + +/************************************************************************** Main window constructor **************************************************************************/ ruledit_main::ruledit_main(QApplication *qapp_in, QWidget *central_in) : QMainWindow() Modified: trunk/tools/ruledit/ruledit_qt.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.h?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/ruledit_qt.h (original) +++ trunk/tools/ruledit/ruledit_qt.h Sat May 20 01:35:32 2017 @@ -38,6 +38,7 @@ class tab_enabler; class tab_extras; class tab_terrains; +class req_edit; class ruledit_main : public QMainWindow { @@ -55,6 +56,15 @@ void closeEvent(QCloseEvent *cevent); }; +/* get 'struct req_edit_list' and related functions: */ +#define SPECLIST_TAG req_edit +#define SPECLIST_TYPE class req_edit +#include "speclist.h" + +#define req_edit_list_iterate(reqeditlist, preqedit) \ + TYPED_LIST_ITERATE(class req_edit, reqeditlist, preqedit) +#define req_edit_list_iterate_end LIST_ITERATE_END + class ruledit_gui : public QObject { Q_OBJECT @@ -65,6 +75,9 @@ requirers_dlg *create_requirers(const char *title); void show_required(requirers_dlg *requirers, const char *msg); void flush_widgets(); + + void open_req_edit(QString target, struct requirement_vector *preqs); + void unregister_req_edit(class req_edit *redit); struct rule_data data; @@ -86,6 +99,8 @@ tab_terrains *terrains; tab_nation *nation; + struct req_edit_list *req_edits; + private slots: void launch_now(); }; Modified: trunk/tools/ruledit/tab_building.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_building.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/tab_building.cpp (original) +++ trunk/tools/ruledit/tab_building.cpp Sat May 20 01:35:32 2017 @@ -34,7 +34,6 @@ // ruledit #include "effect_edit.h" -#include "req_edit.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -278,10 +277,8 @@ void tab_building::edit_reqs() { if (selected != nullptr) { - req_edit *redit = new req_edit(ui, QString::fromUtf8(improvement_rule_name(selected)), - &selected->reqs); - - redit->show(); + ui->open_req_edit(QString::fromUtf8(improvement_rule_name(selected)), + &selected->reqs); } } Modified: trunk/tools/ruledit/tab_enablers.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/tab_enablers.cpp (original) +++ trunk/tools/ruledit/tab_enablers.cpp Sat May 20 01:35:32 2017 @@ -34,7 +34,6 @@ #include "government.h" // ruledit -#include "req_edit.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -273,10 +272,8 @@ void tab_enabler::edit_target_reqs() { if (selected != nullptr) { - req_edit *redit = new req_edit(ui, QString::fromUtf8(R__("Enabler (target)")), - &selected->target_reqs); - - redit->show(); + ui->open_req_edit(QString::fromUtf8(R__("Enabler (target)")), + &selected->target_reqs); } } @@ -286,10 +283,8 @@ void tab_enabler::edit_actor_reqs() { if (selected != nullptr) { - req_edit *redit = new req_edit(ui, QString::fromUtf8(R__("Enabler (actor)")), - &selected->actor_reqs); - - redit->show(); - } -} - + ui->open_req_edit(QString::fromUtf8(R__("Enabler (actor)")), + &selected->actor_reqs); + } +} + Modified: trunk/tools/ruledit/tab_extras.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_extras.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/tab_extras.cpp (original) +++ trunk/tools/ruledit/tab_extras.cpp Sat May 20 01:35:32 2017 @@ -33,7 +33,6 @@ #include "extras.h" // ruledit -#include "req_edit.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -273,9 +272,7 @@ void tab_extras::edit_reqs() { if (selected != nullptr) { - req_edit *redit = new req_edit(ui, QString::fromUtf8(extra_rule_name(selected)), - &selected->reqs); - - redit->show(); - } -} + ui->open_req_edit(QString::fromUtf8(extra_rule_name(selected)), + &selected->reqs); + } +} Modified: trunk/tools/ruledit/tab_gov.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_gov.cpp?rev=35668&r1=35667&r2=35668&view=diff ============================================================================== --- trunk/tools/ruledit/tab_gov.cpp (original) +++ trunk/tools/ruledit/tab_gov.cpp Sat May 20 01:35:32 2017 @@ -33,7 +33,6 @@ #include "government.h" // ruledit -#include "req_edit.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -273,9 +272,7 @@ void tab_gov::edit_reqs() { if (selected != nullptr) { - req_edit *redit = new req_edit(ui, QString::fromUtf8(government_rule_name(selected)), - &selected->reqs); - - redit->show(); - } -} + ui->open_req_edit(QString::fromUtf8(government_rule_name(selected)), + &selected->reqs); + } +} _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits