Author: mir3x
Date: Wed Dec  2 13:11:41 2015
New Revision: 30836

URL: http://svn.gna.org/viewcvs/freeciv?rev=30836&view=rev
Log:
Qt client network page selection 
was not updated when switching tabs.
Fixed.

See bug #24127


Modified:
    branches/S2_5/client/gui-qt/fc_client.h
    branches/S2_5/client/gui-qt/pages.cpp

Modified: branches/S2_5/client/gui-qt/fc_client.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/fc_client.h?rev=30836&r1=30835&r2=30836&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/fc_client.h     (original)
+++ branches/S2_5/client/gui-qt/fc_client.h     Wed Dec  2 13:11:41 2015
@@ -260,6 +260,7 @@
   void browse_saves();
   void browse_scenarios();
   void clear_status_bar();
+  void network_tab_changed(int index);
 
 public slots:
   void switch_page(int i);

Modified: branches/S2_5/client/gui-qt/pages.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/pages.cpp?rev=30836&r1=30835&r2=30836&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/pages.cpp       (original)
+++ branches/S2_5/client/gui-qt/pages.cpp       Wed Dec  2 13:11:41 2015
@@ -285,10 +285,12 @@
   lan_widget->setRowCount(0);
   lan_widget->setColumnCount(servers_list.count());
   lan_widget->verticalHeader()->setVisible(false);
+  lan_widget->setAutoScroll(false);
 
   wan_widget->setRowCount(0);
   wan_widget->setColumnCount(servers_list.count());
   wan_widget->verticalHeader()->setVisible(false);
+  wan_widget->setAutoScroll(false);
 
   info_widget->setRowCount(0);
   info_widget->setColumnCount(server_info.count());
@@ -305,6 +307,10 @@
   wan_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
   connect(wan_widget->selectionModel(),
+          SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection 
&)), this,
+          SLOT(slot_selection_changed(const QItemSelection &, const 
QItemSelection &)));
+
+  connect(lan_widget->selectionModel(),
           SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection 
&)), this,
           SLOT(slot_selection_changed(const QItemSelection &, const 
QItemSelection &)));
 
@@ -368,6 +374,8 @@
   page_network_layout->addWidget(connect_tab_widget, 1);
   connect_tab_widget->addTab(connect_lan, _("LAN"));
   connect_tab_widget->addTab(connect_metaserver, _("NETWORK"));
+  connect(connect_tab_widget, SIGNAL(currentChanged(int)),
+         this, SLOT(network_tab_changed(int)));
   page_network_grid_layout->setColumnStretch(3, 4);
   pages_layout[PAGE_NETWORK]->addLayout(page_network_layout, 1, 1);
   pages_layout[PAGE_NETWORK]->addLayout(page_network_grid_layout, 2, 1);
@@ -712,6 +720,8 @@
   QTableWidget* sel = NULL;
   QString host, portstr;
   int port;
+  int row;
+  int old_row_count;
 
   switch (sstype) {
   case SERVER_SCAN_LOCAL:
@@ -735,12 +745,14 @@
   host = connect_host_edit->text();
   portstr = connect_port_edit->text();
   port = portstr.toInt();
+  old_row_count = sel->rowCount();
   sel->clearContents();
-  sel->setRowCount(0);
-  int row = 0;
+  row = 0;
   server_list_iterate(list, pserver) {
     char buf[20];
-    sel->insertRow(row);
+    if (old_row_count <= row) {
+      sel->insertRow(row);
+    }
 
     if (pserver->humans >= 0) {
       fc_snprintf(buf, sizeof(buf), "%d", pserver->humans);
@@ -777,7 +789,6 @@
       default:
         break;
       }
-
       sel->setItem(row, col, item);
     }
 
@@ -787,8 +798,14 @@
 
     row++;
   } server_list_iterate_end;
-}
-
+
+  /* Remove unneeded rows, if there are any */
+  while (old_row_count - row > 0) {
+    sel->removeRow(old_row_count - 1);
+    old_row_count--;
+  }
+
+}
 
 /**************************************************************************
   Callback function for when there's an error in the server scan.
@@ -812,6 +829,25 @@
   }
 }
 
+/***************************************************************************
+  Tab in network page has been changed.
+  Force current selection change to emit signal.
+***************************************************************************/
+void fc_client::network_tab_changed(int index)
+{
+  QWidget *w;
+  QHBoxLayout *l;
+  QTableWidget *tw;
+  int i;
+
+  w = connect_tab_widget->currentWidget();
+  l = qobject_cast<QHBoxLayout *>(w->layout());
+  tw = qobject_cast<QTableWidget *>(l->itemAt(0)->widget());
+  i = tw->currentRow();
+  tw->clearSelection();
+  tw->selectRow(i);
+}
+
 /**************************************************************************
   Free the server scans.
 **************************************************************************/
@@ -962,6 +998,9 @@
   QStringList sl;
   QModelIndex index;
   QTableWidgetItem *item;
+  QWidget *w;
+  QHBoxLayout *l;
+  QTableWidget *tw;
   QVariant qvar;
   int k, col, n;
   client_pages i = current_page();
@@ -979,6 +1018,13 @@
     index = indexes.at(1);
     connect_port_edit->setText(index.data().toString());
 
+    w = connect_tab_widget->currentWidget();
+    l = qobject_cast<QHBoxLayout *>(w->layout());
+    tw = qobject_cast<QTableWidget *>(l->itemAt(0)->widget());
+
+    if (tw == lan_widget) {
+      return;
+    }
     srvrs = server_scan_get_list(meta_scan);
     if (!holding_srv_list_mutex) {
       fc_allocate_mutex(&srvrs->mutex);


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

Reply via email to