#include "bs.h"
//Own includes
-#include "bsview.h"
-#include "bsdoc.h"
+#include "bsdoc.h"
+#include "bsview.h"
/*
* Constructs a BSApp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
BSApp::BSApp( QWidget* parent, const char* name, WFlags fl )
: BSAppBase( parent, name, fl )
{
- doc = new BSDoc();
+/* doc = new BSDoc();
view = new BSView(this,doc);
setCentralWidget(view);
+ */
}
/*
#include "ui/bsappbase.h"
//My own forwards
-class BSView;
-class BSDoc;
+//class BSView;
+//class BSDoc;
class BSApp : public BSAppBase
{
void helpAbout();
protected:
- BSView* view;
- BSDoc* doc;
+// BSView* view;
+// BSDoc* doc;
};
{
return modified;
}
+
+///////////////////////////////////////////////////////////////////////////
+//
+
+int BSDoc::newBattle(QString name)
+{
+ m_Battles[name]["Friendly"]["Home Planet"];
+ m_Battles[name]["Hostile"];
+
+ emit documentChanged();
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////
+//
+
+std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles()
+{
+ return m_Battles;
+}
+
// include files for QT
#include <qobject.h>
+// standard library
+#include <map>
+
// application specific includes
+#include "fleet.h"
-/**
- * the Document Class
+//! The document class
+/** This class is holding all the data, handles the transportation of the
+ * data to a couple of different mediums and informs users of the data
+ * if it's changed (through the documentChnaged() signal)
+ * \bug it's too open..
+ * \todo make this class more closed.
+ * \author Michael Andreen
*/
class BSDoc : public QObject
bool load(const QString &filename);
bool isModified() const;
+ /**Adds a new battle to the dokument and emits documentChanged.
+ * \todo add some checks to see if the battle exist and so and return the status.
+ * \return returns 0 if everything is ok.
+ */
+ int newBattle(QString name);
+
+ /**This returns the the data structure, so other can work on it, but not supposed
+ * change it.
+ * \todo remove this, and replace it with a better more closed interface.
+ */
+ std::map<QString, std::map<QString, std::map<QString, Fleet> > >& Battles();
+
signals:
void documentChanged();
protected:
bool modified;
+
+ std::map<QString, std::map<QString, std::map<QString, Fleet> > > m_Battles;
};
#endif
#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);
{
}
+//////////////////////////////////////////////////////////////////////////
+//
void BSView::addBattle(QString name)
{
QListViewItem* battle = new QListViewItem(m_NumberView, 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;
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);
}
}
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);
}
TickView *m_TickView;
QWidgetStack *m_FleetViews;
FleetViewBase *m_FleetView;
+ BSDoc *m_doc;
public slots: // Public slots
/** No descriptions */
return m_sRace;
}
+//////////////////////////////////////////////////////////////////////////
+//
+/** This function iterates through m_Fleet and adds all numbers together to
+ * produce a total.
+ */
+int Fleet::NumberOfShips()
+{
+ int total = 0;
+
+ for (map<string, vector<int> >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++)
+ {
+ total += m_Fleet[(*i).first][0];
+ }
+
+ return total;
+}
*/
std::string Race();
+ /**Returns the total number of ships in this fleet
+ */
+ int NumberOfShips();
+
protected:
std::string m_sName;
<x>0</x>
<y>0</y>
<width>726</width>
- <height>30</height>
+ <height>29</height>
</rect>
</property>
<item text="&File" name="fileMenu">
<action name="fileOpenAction"/>
<action name="fileSaveAction"/>
<action name="fileSaveAsAction"/>
- <action name="KulSak"/>
<separator/>
<action name="filePrintAction"/>
<separator/>
<separator/>
<action name="helpAboutAction"/>
</item>
+ <item text="Battle" name="PopupMenu">
+ <action name="battleNewAction"/>
+ </item>
</menubar>
<toolbars>
<toolbar dock="2">
<string>&New</string>
</property>
<property name="accel">
- <number>4194382</number>
+ <number>0</number>
</property>
</action>
<action>
</action>
<action>
<property name="name">
- <cstring>KulSak</cstring>
+ <cstring>battleNewAction</cstring>
</property>
<property name="text">
- <string>Kul sak</string>
+ <string>New</string>
</property>
<property name="accel">
- <number>0</number>
+ <number>4194382</number>
</property>
</action>
</actions>
<receiver>BSAppBase</receiver>
<slot>editCut()</slot>
</connection>
- <connection>
- <sender>editCopyAction</sender>
- <signal>activated()</signal>
- <receiver>BSAppBase</receiver>
- <slot>editCopy()</slot>
- </connection>
<connection>
<sender>editPasteAction</sender>
<signal>activated()</signal>
<receiver>BSAppBase</receiver>
<slot>helpAbout()</slot>
</connection>
+ <connection>
+ <sender>battleNewAction</sender>
+ <signal>activated()</signal>
+ <receiver>BSAppBase</receiver>
+ <slot>battleNew()</slot>
+ </connection>
</connections>
<includes>
+ <include location="local" impldecl="in implementation">../bsdoc.h</include>
+ <include location="local" impldecl="in implementation">../bsview.h</include>
+ <include location="global" impldecl="in implementation">qinputdialog.h</include>
<include location="local" impldecl="in implementation">bsappbase.ui.h</include>
</includes>
+<forwards>
+ <forward>class BSDoc</forward>
+ <forward>class BSView</forward>
+</forwards>
+<variables>
+ <variable>BSDoc* doc</variable>
+ <variable>BSView* view</variable>
+</variables>
<slots>
<slot>fileNew()</slot>
<slot>fileOpen()</slot>
<slot>editUndo()</slot>
<slot>editRedo()</slot>
<slot>editCut()</slot>
- <slot>editCopy()</slot>
+ <slot>init()</slot>
<slot>editPaste()</slot>
<slot>editFind()</slot>
<slot>helpIndex()</slot>
<slot>helpContents()</slot>
<slot>helpAbout()</slot>
+ <slot>battleNew()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>
** a constructor, and a destroy() slot in place of a destructor.
*****************************************************************************/
+
void BSAppBase::fileNew()
{
}
-void BSAppBase::editCopy()
+void BSAppBase::init()
{
-
+ doc = new BSDoc();
+ view = new BSView(this,doc);
+ setCentralWidget(view);
}
void BSAppBase::editPaste()
void BSAppBase::helpAbout()
{
+}
+
+void BSAppBase::battleNew()
+{
+ bool ok = FALSE;
+ QString text = QInputDialog::getText(
+ tr( "Harvalen's Battlesystem" ),
+ tr( "Please enter the name of the battle (for example coords)" ),
+ QLineEdit::Normal, QString::null, &ok, this );
+ if ( ok && !text.isEmpty() )
+ doc->newBattle(text);
+ else
+ {
+ // user entered nothing or pressed Cancel
+ }
}
\ No newline at end of file