Author: mir3x
Date: Fri Feb  5 12:11:25 2016
New Revision: 31758

URL: http://svn.gna.org/viewcvs/freeciv?rev=31758&view=rev
Log:
Fixed selection not restored after updating nations dialog.

Reported by Jacob Nevins <jtn>

See bug #24369


Modified:
    branches/S2_6/client/gui-qt/plrdlg.cpp
    branches/S2_6/client/gui-qt/plrdlg.h

Modified: branches/S2_6/client/gui-qt/plrdlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/plrdlg.cpp?rev=31758&r1=31757&r2=31758&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/plrdlg.cpp      (original)
+++ branches/S2_6/client/gui-qt/plrdlg.cpp      Fri Feb  5 12:11:25 2016
@@ -271,6 +271,7 @@
 {
   plr = pr;
   other_player = NULL;
+  selected_player = nullptr;
   pid = new plr_item_delegate(this);
   setItemDelegate(pid);
   list_model = new plr_model(this);
@@ -298,6 +299,34 @@
 }
 
 /**************************************************************************
+  Restores selection of previously selected nation
+**************************************************************************/
+void plr_widget::restore_selection()
+{
+  QItemSelection selection;
+  QModelIndex i;
+  struct player *pplayer;
+  QVariant qvar;
+
+  if (selected_player == nullptr) {
+    return;
+  }
+  for (int j = 0; j < filter_model->rowCount(); j++) {
+    i = filter_model->index(j, 0);
+    qvar = i.data(Qt::UserRole);
+    if (qvar.isNull()) {
+      continue;
+    }
+    pplayer = reinterpret_cast<struct player *>(qvar.value<void *>());
+    if (selected_player == pplayer) {
+      selection.append(QItemSelectionRange(i));
+    }
+  }
+  selectionModel()->select(selection, QItemSelectionModel::Rows
+                           | QItemSelectionModel::SelectCurrent);
+}
+
+/**************************************************************************
   Displays menu on header by right clicking
 **************************************************************************/
 void plr_widget::display_header_menu(const QPoint &)
@@ -379,12 +408,14 @@
   tech_str.clear();
   ally_str.clear();
   if (indexes.isEmpty()) {
+    selected_player = nullptr;
     plr->update_report(false);
     return;
   }
   index = indexes.at(0);
   qvar = index.data(Qt::UserRole);
   pplayer = reinterpret_cast<player *>(qvar.value<void *>());
+  selected_player = pplayer;
   other_player = pplayer;
   if (pplayer->is_alive == false) {
     plr->update_report(false);
@@ -715,6 +746,7 @@
   if (can_meet_with_player(other_player) == true) {
     meet_but->setEnabled(true);
   }
+  plr_wdg->restore_selection();
 }
 
 /**************************************************************************

Modified: branches/S2_6/client/gui-qt/plrdlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/plrdlg.h?rev=31758&r1=31757&r2=31758&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/plrdlg.h        (original)
+++ branches/S2_6/client/gui-qt/plrdlg.h        Fri Feb  5 12:11:25 2016
@@ -116,9 +116,11 @@
   plr_report *plr;
   QString techs_known;
   QString techs_unknown;
+  struct player *selected_player;
 public:
   plr_widget(plr_report *pr);
   ~plr_widget();
+  void restore_selection();
   plr_model *get_model() const;
   QString intel_str;
   QString ally_str;


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

Reply via email to