Main Page   Class Hierarchy   Data Structures   File List   Data Fields  

summarydialog.cpp

00001 /***************************************************************************
00002                           summarydialog.cpp  -  description
00003                              -------------------
00004     begin                : Thu Jan 30 2003
00005     copyright            : (C) 2003 by Michael Otto
00006     email                : Michael.Otto@saskathex.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "summarydialog.h"
00019 #include "stockmarketvector.h"
00020 #include "stockmarket.h"
00021 #include "stockcontainer.h"
00022 #include "stock.h"
00023 
00024 #include "config.h"
00025 #include <gtkmm/stock.h>
00026 
00031 SummaryDialog::SummaryDialog(const StockMarketVector * const stockMarketVector, int marketNumber) { 
00032 
00033   Gtk::HButtonBox *hButtonBox;
00034   Gtk::Button *buttonOk;
00035   Gtk::Label *label;
00036   Gtk::HSeparator *hSep;
00037 
00038 #ifdef DEBUG
00039   cout << "starting Summary Dialog" << endl;
00040   cout << "  selected market: "<< marketNumber << endl;
00041 #endif  
00042   set_title("Summary");
00043   set_border_width(5);
00044   set_resizable(false);
00045   set_modal(true);
00046   vbox = manage(new Gtk::VBox(false, 0));
00047   vbox->set_spacing(5);
00048   add(*vbox);
00049 
00050   float sumBuy = 0, sumPurchaseCost = 0, sumToday = 0;
00051   string s;
00052   // summary for stockmarket "All"
00053   if (marketNumber == 0) {
00054     label = manage (new Gtk::Label("StockMarket: All"));
00055     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00056     hSep = manage(new Gtk::HSeparator());
00057     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00058     for (int j=0; j < stockMarketVector->getNumberOfStockMarkets(); j++) {
00059       StockMarket *stockMarket = stockMarketVector->getStockMarket(j);
00060       for (int i=0; i < stockMarket->getNumberOfStockContainer(); i++) {
00061         Stock *stock = stockMarket->getStockContainer(i)->getStock();
00062         sumBuy += stock->getAmount() * stock->getBuyingRate();
00063         sumToday += stock->getAmount() * stock->getCurrentMarketPrice();
00064         sumPurchaseCost += stock->getPurchaseCost();
00065       }
00066     }
00067   } else {
00068     StockMarket *stockMarket = stockMarketVector->getStockMarket(marketNumber-1);
00069     s = "StockMarket: "+stockMarket->getMarketName();
00070     label = manage (new Gtk::Label(s));
00071     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00072     hSep = manage(new Gtk::HSeparator());
00073     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00074     for (int i=0; i < stockMarket->getNumberOfStockContainer(); i++) {
00075       Stock *stock = stockMarket->getStockContainer(i)->getStock();
00076       sumBuy += stock->getAmount() * stock->getBuyingRate();
00077       sumToday += stock->getAmount() * stock->getCurrentMarketPrice();
00078       sumPurchaseCost += stock->getPurchaseCost();
00079     }
00080 
00081   }
00082 #ifdef DEBUG
00083   cout << " values: "<< sumBuy << " " << sumToday << " " << sumPurchaseCost << endl;
00084 #endif
00085   char c[20];
00086   sprintf(c,"%.2f", sumBuy);
00087   s = "Total Purchase Value: "+(string) c;
00088   label = manage (new Gtk::Label(s));
00089   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00090   sprintf(c,"%.2f", sumToday);
00091   s = "Total Market Value (today): "+(string) c;
00092   label = manage (new Gtk::Label(s));
00093   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00094   sprintf(c,"%.2f", sumPurchaseCost);
00095   s = "Total Purchase Cost: "+(string) c;
00096   label = manage (new Gtk::Label(s));
00097   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00098   float percent = ((sumToday - sumBuy) / (sumBuy)) * 100 ;
00099   s = "Total Performance: ";
00100   if (sumBuy <= 0) {
00101     s += "n/a";
00102   }
00103   else {
00104     char c[20];       
00105     sprintf(c,"%.1f %%", percent);
00106     s += (string) c;
00107   }
00108   label = manage (new Gtk::Label(s));
00109   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00110   
00111       
00112   hSep = manage(new Gtk::HSeparator());
00113   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00114   hButtonBox = manage( new Gtk::HButtonBox());
00115   hButtonBox->set_spacing(5);
00116   vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00117   buttonOk = manage( new Gtk::Button(Gtk::Stock::OK));
00118   buttonOk->signal_clicked().connect(slot(*this,&SummaryDialog::quit));
00119   hButtonBox->pack_start(*buttonOk, Gtk::PACK_SHRINK, 0);
00120   show_all();
00121 }
00122 
00123 
00127 SummaryDialog::~SummaryDialog(){
00128 }
00129 
00133 void SummaryDialog::quit() {
00134 #ifdef DEBUG
00135   cout << "quiting Summary Dialog" << endl;
00136 #endif
00137   delete this;
00138 }
00139 
00144 bool SummaryDialog::on_delete_event(GdkEventAny *event) {
00145   quit();
00146   return true;
00147 }
00148 

Generated on Tue May 27 21:24:02 2003 for gstockcalc by doxygen1.3-rc3