00001 #include "owncapitalcalculationdialog.h"
00002 #include <QMessageBox>
00003 #include <QDebug>
00004 #include "../Models/owncapitalcalculationmodel.h"
00005
00006 OwnCapitalCalculationDialog::OwnCapitalCalculationDialog(QWidget *parent) : QDialog(parent)
00007 {
00008 setupUi(this);
00009 setAttribute(Qt::WA_DeleteOnClose, true);
00010
00011 model = new OwnCapitalCalculationModel();
00012 connect(model, SIGNAL(newTotalAvailable(QString)), textTotalSum, SLOT(setText(QString)));
00013 tableViewAssets->setModel(model);
00014
00015 connect(buttonAddAsset, SIGNAL(clicked()), this, SLOT(addPosition()));
00016 connect(buttonRemoveAsset, SIGNAL(clicked()), this, SLOT(removePosition()));
00017
00018 connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
00019 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
00020 }
00021
00022 void OwnCapitalCalculationDialog::addPosition()
00023 {
00024 if(textName->text() != "")
00025 {
00026 bool ok;
00027 textReplacementValue->text().toDouble(&ok) && textRevenues->text().toDouble(&ok) && textUsefulLife->text().toDouble(&ok) && textLifetime->text().toDouble(&ok);
00028 if(!ok)
00029 {
00030 QMessageBox::warning(this, tr("Fehler"), tr("Sie haben eine ungültige Eingabe gemacht!"));
00031 }
00032 else
00033 {
00034 double wbw = textReplacementValue->text().toDouble();
00035 double erl = textRevenues->text().toDouble();
00036 double tnd = textUsefulLife->text().toDouble();
00037 double bnd = textLifetime->text().toDouble();
00038
00039 if(wbw > 0 && erl > 0 && tnd > 0 && bnd > 0 && tnd >= bnd)
00040 {
00041 double ergebnis = wbw - (((wbw-erl) / tnd) * bnd);
00042
00043 model->addRow(textName->text(), QString::number(ergebnis), QString::number(wbw), QString::number(erl), QString::number(tnd), QString::number(bnd));
00044 tableViewAssets->resizeColumnsToContents();
00045 }
00046 else
00047 {
00048 QMessageBox::warning(this, tr("Fehler"), tr("Alle Angaben müssen > 0 sein und die tatsächliche Nutzungsdauer muss größer oder gleich der bisherigen Nutzungsdauer sein!"));
00049 return;
00050 }
00051 }
00052 }
00053 else
00054 {
00055 QMessageBox::warning(this, tr("Fehler"), tr("Sie müssen einen Namen eingeben!"));
00056 return ;
00057 }
00058 }
00059
00060 void OwnCapitalCalculationDialog::removePosition()
00061 {
00062 QItemSelectionModel *selection = tableViewAssets->selectionModel();
00063 QModelIndexList indexlist = selection->selectedRows();
00064 for(int i = 0; i < indexlist.count(); i++)
00065 {
00066 model->removeRows(indexlist.value(i).row(), 1, QModelIndex());
00067 }
00068
00069 }
00070
00071 void OwnCapitalCalculationDialog::ok()
00072 {
00073 emit sendingData(textTotalSum->text());
00074 hide();
00075 }
00076
00077 void OwnCapitalCalculationDialog::cancel()
00078 {
00079 hide();
00080 }