]> ruin.nu Git - hbs.git/blobdiff - bs/bsview.cpp
Added the possibility to add new battles.
[hbs.git] / bs / bsview.cpp
index 76d812fa57567d6d061eb975344b80af325953be..9af428df1fed72e90c88ebc4599c2e6521c7de81 100644 (file)
 
 #include "bsview.h"
 
+//standard library
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+using namespace std;
+
+//QT includes
+#include <qlistview.h>
+#include <qwidgetstack.h>
+
 #include "battlesum.h"
 #include "scanview.h"
 #include "ui/infoview.h"
 #include "tickview.h"
 #include "ui/fleetviewbase.h"
-
-//QT includes
-#include <qlistview.h>
-#include <qwidgetstack.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);
@@ -64,27 +74,91 @@ BSView::~BSView()
 {
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
 void BSView::addBattle(QString name)
 {
-       QListViewItem *battle = new QListViewItem(m_NumberView, name);
-       (void) new QListViewItem(battle, "Defenders");
-       (void) new QListViewItem(battle, "Attackers");
+       QListViewItem* battle = new QListViewItem(m_NumberView, name);
+       QListViewItem* def = new QListViewItem(battle, tr("Defenders"),"", "","1");
+       (void) new QListViewItem(battle, tr("Attackers"),"", "","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);
+
+                       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){
+
+//////////////////////////////////////////////////////////////////////////////
+//
+void BSView::slotFleetSelection(QListViewItem *lvi)
+{
+       //cout << lvi->parent()->text(2).toLocal8bit() << endl;
+//     for (int i = 0; i < 5; i++)
+//             cout << lvi->text(i).local8Bit() << endl;
+       
+
        if (lvi->parent() == '\0')
        {
                m_FleetViews->raiseWidget(0);
        }
        else if (lvi->parent()->parent() == '\0')
        {
+                       m_FleetView->slotHomePlanet(false);
+               if (lvi->text(0) == tr("Friendly"))
+               {
+                       m_FleetView->slotAttacker(false);
+               }
+               else
+               {
+                       m_FleetView->slotAttacker(true);
+               }
                m_FleetViews->raiseWidget(1);
+               
        }
+       else
+       {
+               if (lvi->parent()->text(0) == tr("Friendly"))
+               {
+                       m_FleetView->slotAttacker(false);
+                       m_FleetView->slotHomePlanet(false);
+                       if (lvi->text(0) == tr("Home Planet"))
+                       {
+                               m_FleetView->slotHomePlanet(true);
+                       }
+               }
+               else
+               {
+                       m_FleetView->slotAttacker(true);
+                       m_FleetView->slotHomePlanet(false);
+               }
+               m_FleetViews->raiseWidget(1);
+                               
+       }
+
        
 }