equal team names huge bug fixed for multiple clients
authordisplacer
Wed, 17 Jan 2007 21:32:52 +0000
changeset 348 c91b983de18f
parent 347 6521e1b2cd40
child 349 5b37d6a39829
equal team names huge bug fixed for multiple clients
QTfrontend/frameTeam.cpp
QTfrontend/frameTeam.h
QTfrontend/newnetclient.cpp
QTfrontend/team.cpp
QTfrontend/team.h
QTfrontend/teamselect.cpp
--- a/QTfrontend/frameTeam.cpp	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/frameTeam.cpp	Wed Jan 17 21:32:52 2007 +0000
@@ -48,7 +48,7 @@
 {
   TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this);
 //  int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height();
-  teamToWidget.insert(make_pair(team, pTeamShowWidget));
+  teamToWidget.insert(team, pTeamShowWidget);
   mainLayout.addWidget(pTeamShowWidget);
   QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size());
   QCoreApplication::postEvent(parentWidget(), pevent);
@@ -57,15 +57,15 @@
 void FrameTeams::removeTeam(HWTeam team)
 {
   tmapTeamToWidget::iterator it=teamToWidget.find(team);
-  mainLayout.removeWidget(it->second);
-  delete it->second;
-  teamToWidget.erase(team);
+  mainLayout.removeWidget(it.value());
+  delete it.value();
+  teamToWidget.erase(it);
 }
 
 QWidget* FrameTeams::getTeamWidget(HWTeam team)
 {
   tmapTeamToWidget::iterator it=teamToWidget.find(team);
-  QWidget* ret = it!=teamToWidget.end() ? it->second : 0;
+  QWidget* ret = it!=teamToWidget.end() ? it.value() : 0;
   return ret;
 }
 
--- a/QTfrontend/frameTeam.h	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/frameTeam.h	Wed Jan 17 21:32:52 2007 +0000
@@ -22,9 +22,9 @@
 #include <QWidget>
 #include <QList>
 #include <QColor>
+#include <QMultiMap>
 
 #include "teamselect.h"
-#include <map>
 
 class FrameTeams : public QWidget
 {
@@ -50,7 +50,7 @@
   QList<QColor>::Iterator currentColor;
 
   QVBoxLayout mainLayout;
-  typedef map<HWTeam, QWidget*> tmapTeamToWidget;
+  typedef QMultiMap<HWTeam, QWidget*> tmapTeamToWidget;
   tmapTeamToWidget teamToWidget;
 };
 
--- a/QTfrontend/newnetclient.cpp	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Jan 17 21:32:52 2007 +0000
@@ -169,7 +169,7 @@
 
   if (lst[0] == "REMOVETEAM:") {
     if(lst.size()<2) return;
-    m_pTeamSelWidget->removeNetTeam(lst[1]);
+    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], true));
     return;
   }
 
--- a/QTfrontend/team.cpp	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/team.cpp	Wed Jan 17 21:32:52 2007 +0000
@@ -29,9 +29,9 @@
 #include <QStringList>
 #include <QDebug>
 
-HWTeam::HWTeam(const QString & teamname) :
+HWTeam::HWTeam(const QString & teamname, bool isNet) :
   difficulty(0),
-  netTeam(false)
+  netTeam(isNet)
 {
 	TeamName = teamname;
 	OldTeamName = TeamName;
@@ -230,9 +230,9 @@
 }
 
 bool HWTeam::operator==(const HWTeam& t1) const {
-  return TeamName==t1.TeamName;
+  return TeamName==t1.TeamName && netTeam==t1.netTeam;
 }
 
 bool HWTeam::operator<(const HWTeam& t1) const {
-  return TeamName<t1.TeamName;
+  return TeamName<t1.TeamName || (netTeam < t1.netTeam); // if names are equal - test if it is net team
 }
--- a/QTfrontend/team.h	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/team.h	Wed Jan 17 21:32:52 2007 +0000
@@ -33,7 +33,7 @@
 class HWTeam
 {
 	public:
-		HWTeam(const QString & teamname);
+		HWTeam(const QString & teamname, bool isNet=false);
 		HWTeam(const QStringList& strLst);
 		HWTeam(quint8 num);
 
--- a/QTfrontend/teamselect.cpp	Wed Jan 17 19:56:51 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Wed Jan 17 21:32:52 2007 +0000
@@ -31,7 +31,7 @@
   if(team.netTeam) {
     framePlaying->addTeam(team, true);
     curPlayingTeams.push_back(team);
-    QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
+    QObject::connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
 		     this, SLOT(netTeamStatusChanged(const HWTeam&)));
   } else {
     frameDontPlaying->addTeam(team, false);
@@ -43,9 +43,16 @@
 
 void TeamSelWidget::removeNetTeam(const HWTeam& team)
 {
-  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
-  framePlaying->removeTeam(team);
-  curPlayingTeams.erase(itPlay);
+  for(;;) {
+    list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+    if(itPlay==curPlayingTeams.end()) break;
+    if(itPlay->netTeam) {
+      QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam)));
+      framePlaying->removeTeam(team);
+      curPlayingTeams.erase(itPlay);
+      break;
+    }
+  }
 }
 
 void TeamSelWidget::netTeamStatusChanged(const HWTeam& team)