]> ruin.nu Git - hbs.git/blobdiff - bs/bsview.cpp
initial commit of the BSConf class.
[hbs.git] / bs / bsview.cpp
index 5da0e0654c36b0b323b6a9aa23678453da303336..4f050c03601967fa42c1eb43a362dc8d84c220cb 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);
 
        //setting up the listview
        m_NumberView = new QListView(m_LeftSplit);
+       m_NumberView->setRootIsDecorated(true);  
        m_NumberView->addColumn("Name");
        m_NumberView->addColumn("Number");
        m_NumberView->addColumn("ETA");
-       addBattle("test");
+       //addBattle("NO BATTLES");
 
        m_InfoView = new InfoView(m_LeftSplit);
        
@@ -67,20 +75,51 @@ BSView::~BSView()
 {
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
 void BSView::addBattle(QString name)
 {
        QListViewItem* battle = new QListViewItem(m_NumberView, name);
-       QListViewItem* def = new QListViewItem(battle, tr("Defenders"),"", "","1");
-       (void) new QListViewItem(battle, tr("Attackers"),"", "","2");
+       QListViewItem* def = new QListViewItem(battle, tr("Friendly"),"", "","1");
+       (void) new QListViewItem(battle, tr("Hostile"),"", "","2");
        (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);
+                       int groupShips = 0;
+
+                       for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
+                       {       
+                               int ships = battles[b][g][(*k).first].NumberOfShips();
+                               groupShips += ships;
+                               (void) new QListViewItem(group, (*k).first, QString("%1").arg(ships), QString("%1").arg(battles[b][g][(*k).first].ETA()));
+                       }
+                       group->setText(1, QString("%1").arg(groupShips));
+               }
+       }
 }
-/** No descriptions */
+
+//////////////////////////////////////////////////////////////////////////////
+//
 void BSView::slotFleetSelection(QListViewItem *lvi)
 {
        //cout << lvi->parent()->text(2).toLocal8bit() << endl;
@@ -95,7 +134,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 +147,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);
                        }