From e07f49323a1936c90605d06f6f63e4c39b4c4aca Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 7 Mar 2002 23:40:58 +0000 Subject: [PATCH] Added the possibility to add new battles. --- bs/bs.cpp | 7 +++--- bs/bs.h | 8 +++--- bs/bsdoc.cpp | 21 ++++++++++++++++ bs/bsdoc.h | 27 +++++++++++++++++++-- bs/bsview.cpp | 58 +++++++++++++++++++++++++++++++++++--------- bs/bsview.h | 1 + bs/fleet.cpp | 16 ++++++++++++ bs/fleet.h | 4 +++ bs/ui/bsappbase.ui | 40 ++++++++++++++++++++---------- bs/ui/bsappbase.ui.h | 22 +++++++++++++++-- 10 files changed, 168 insertions(+), 36 deletions(-) diff --git a/bs/bs.cpp b/bs/bs.cpp index eeea37a..1998441 100644 --- a/bs/bs.cpp +++ b/bs/bs.cpp @@ -1,9 +1,9 @@ #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' @@ -11,9 +11,10 @@ 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); + */ } /* diff --git a/bs/bs.h b/bs/bs.h index 3ccaa42..e25c338 100644 --- a/bs/bs.h +++ b/bs/bs.h @@ -3,8 +3,8 @@ #include "ui/bsappbase.h" //My own forwards -class BSView; -class BSDoc; +//class BSView; +//class BSDoc; class BSApp : public BSAppBase { @@ -32,8 +32,8 @@ public slots: void helpAbout(); protected: - BSView* view; - BSDoc* doc; +// BSView* view; +// BSDoc* doc; }; diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index 3d32cad..e3e0469 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -50,3 +50,24 @@ bool BSDoc::isModified() const { return modified; } + +/////////////////////////////////////////////////////////////////////////// +// + +int BSDoc::newBattle(QString name) +{ + m_Battles[name]["Friendly"]["Home Planet"]; + m_Battles[name]["Hostile"]; + + emit documentChanged(); + return 0; +} + +///////////////////////////////////////////////////////////////////////// +// + +std::map > >& BSDoc::Battles() +{ + return m_Battles; +} + diff --git a/bs/bsdoc.h b/bs/bsdoc.h index 0c02c6f..eac45f4 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -20,10 +20,19 @@ // include files for QT #include +// standard library +#include + // 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 @@ -39,11 +48,25 @@ 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 > >& Battles(); + signals: void documentChanged(); protected: bool modified; + + std::map > > m_Battles; }; #endif diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 5da0e06..9af428d 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -17,24 +17,31 @@ #include "bsview.h" -#include "battlesum.h" -#include "scanview.h" -#include "ui/infoview.h" -#include "tickview.h" -#include "ui/fleetviewbase.h" +//standard library +#include +#include +#include +#include + +using namespace std; //QT includes #include #include -#include -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 > >& battles = m_doc->Battles(); + + for (map > >::iterator i = battles.begin(); i != battles.end(); i++) + { + QString b = (*i).first; + QListViewItem* battle = new QListViewItem(m_NumberView, b); + for (map >::iterator j = battles[b].begin(); j != battles[b].end(); j++) + { + QString g = (*j).first; + QListViewItem* group = new QListViewItem(battle, g); + + for (map::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); } diff --git a/bs/bsview.h b/bs/bsview.h index da4f562..86f277e 100644 --- a/bs/bsview.h +++ b/bs/bsview.h @@ -62,6 +62,7 @@ class BSView : public QSplitter TickView *m_TickView; QWidgetStack *m_FleetViews; FleetViewBase *m_FleetView; + BSDoc *m_doc; public slots: // Public slots /** No descriptions */ diff --git a/bs/fleet.cpp b/bs/fleet.cpp index b562b81..4989573 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -67,4 +67,20 @@ string Fleet::Race() 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 >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++) + { + total += m_Fleet[(*i).first][0]; + } + + return total; +} diff --git a/bs/fleet.h b/bs/fleet.h index 88c7884..0d81fd2 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -60,6 +60,10 @@ public: */ std::string Race(); + /**Returns the total number of ships in this fleet + */ + int NumberOfShips(); + protected: std::string m_sName; diff --git a/bs/ui/bsappbase.ui b/bs/ui/bsappbase.ui index f2714b5..fa0d859 100644 --- a/bs/ui/bsappbase.ui +++ b/bs/ui/bsappbase.ui @@ -25,7 +25,7 @@ 0 0 726 - 30 + 29 @@ -33,7 +33,6 @@ - @@ -55,6 +54,9 @@ + + + @@ -84,7 +86,7 @@ &New - 4194382 + 0 @@ -312,13 +314,13 @@ - KulSak + battleNewAction - Kul sak + New - 0 + 4194382 @@ -409,12 +411,6 @@ BSAppBase editCut() - - editCopyAction - activated() - BSAppBase - editCopy() - editPasteAction activated() @@ -445,10 +441,27 @@ BSAppBase helpAbout() + + battleNewAction + activated() + BSAppBase + battleNew() + + ../bsdoc.h + ../bsview.h + qinputdialog.h bsappbase.ui.h + + class BSDoc + class BSView + + + BSDoc* doc + BSView* view + fileNew() fileOpen() @@ -459,12 +472,13 @@ editUndo() editRedo() editCut() - editCopy() + init() editPaste() editFind() helpIndex() helpContents() helpAbout() + battleNew() diff --git a/bs/ui/bsappbase.ui.h b/bs/ui/bsappbase.ui.h index 4d70a19..e725744 100644 --- a/bs/ui/bsappbase.ui.h +++ b/bs/ui/bsappbase.ui.h @@ -6,6 +6,7 @@ ** a constructor, and a destroy() slot in place of a destructor. *****************************************************************************/ + void BSAppBase::fileNew() { @@ -52,9 +53,11 @@ void BSAppBase::editCut() } -void BSAppBase::editCopy() +void BSAppBase::init() { - + doc = new BSDoc(); + view = new BSView(this,doc); + setCentralWidget(view); } void BSAppBase::editPaste() @@ -80,4 +83,19 @@ void BSAppBase::helpContents() 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 -- 2.39.2