]> ruin.nu Git - hbs.git/blobdiff - bs/bsview.cpp
Added the possibility to add new battles.
[hbs.git] / bs / bsview.cpp
index 5da0e0654c36b0b323b6a9aa23678453da303336..9af428df1fed72e90c88ebc4599c2e6521c7de81 100644 (file)
 
 #include "bsview.h"
 
-#include "battlesum.h"
-#include "scanview.h"
-#include "ui/infoview.h"
-#include "tickview.h"
-#include "ui/fleetviewbase.h"
+//standard library
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+using namespace std;
 
 //QT includes
 #include <qlistview.h>
 #include <qwidgetstack.h>
 
-#include <iostream>
-using namespace std;
+#include "battlesum.h"
+#include "scanview.h"
+#include "ui/infoview.h"
+#include "tickview.h"
+#include "ui/fleetviewbase.h"
+#include "fleet.h"
 
 BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
 {
   /** connect doc with the view*/
   connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged()));
        
+       m_doc = doc;
        
        m_LeftSplit = new QSplitter(QSplitter::Vertical, this);
        m_RightSplit = new QSplitter(QSplitter::Vertical, this);
@@ -67,6 +74,8 @@ BSView::~BSView()
 {
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
 void BSView::addBattle(QString name)
 {
        QListViewItem* battle = new QListViewItem(m_NumberView, name);
@@ -75,12 +84,37 @@ void BSView::addBattle(QString name)
        (void) new QListViewItem(def, tr("Home Planet"), "","","1");
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//
+/***This function clears the listview and then iterates through the battles
+ * and recreates the listview hierarchy.
+ */
 void BSView::slotDocumentChanged()
 {
-  //TODO update the view
+       m_NumberView->clear();
+       
+       map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();  
+
+       for (map<QString, map<QString, map<QString, Fleet> > >::iterator i = battles.begin(); i != battles.end(); i++)
+       {
+               QString b = (*i).first;
+               QListViewItem* battle = new QListViewItem(m_NumberView, b);
 
+               for (map<QString, map<QString, Fleet> >::iterator j = battles[b].begin(); j != battles[b].end(); j++)
+               {
+                       QString g = (*j).first;
+                       QListViewItem* group = new QListViewItem(battle, g);
+
+                       for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
+                       {                               
+                               (void) new QListViewItem(group, (*k).first);
+                       }
+               }
+       }
 }
-/** No descriptions */
+
+//////////////////////////////////////////////////////////////////////////////
+//
 void BSView::slotFleetSelection(QListViewItem *lvi)
 {
        //cout << lvi->parent()->text(2).toLocal8bit() << endl;
@@ -95,7 +129,7 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        else if (lvi->parent()->parent() == '\0')
        {
                        m_FleetView->slotHomePlanet(false);
-               if (lvi->text(3) == "1")
+               if (lvi->text(0) == tr("Friendly"))
                {
                        m_FleetView->slotAttacker(false);
                }
@@ -108,11 +142,11 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        }
        else
        {
-               if (lvi->parent()->text(3) == "1")
+               if (lvi->parent()->text(0) == tr("Friendly"))
                {
                        m_FleetView->slotAttacker(false);
                        m_FleetView->slotHomePlanet(false);
-                       if (lvi->text(3) == "1")
+                       if (lvi->text(0) == tr("Home Planet"))
                        {
                                m_FleetView->slotHomePlanet(true);
                        }