00001 #include <QUndoStack>
00002 #include <QHeaderView>
00003 #include <QCloseEvent>
00004 #include <QAction>
00005 #include <QVBoxLayout>
00006 #include <QMessageBox>
00007 #include "costtypechild.h"
00008 #include "../Data/project.h"
00009 #include "../Data/datadefinitions.h"
00010 #include "../Models/costtypeselectionmodel.h"
00011
00012 CostTypeChild::CostTypeChild() : ChildWindow()
00013 {
00014 setType(WindowType::CostType);
00015 createActions();
00016
00017 ownCapitalDialog = new OwnCapitalCalculationDialog();
00018 }
00019
00020 void CostTypeChild::setModel(CostTypeModel *model)
00021 {
00022 table = model;
00023 }
00024
00025 void CostTypeChild::createActions()
00026 {
00027 deleteAction = new QAction(this);
00028 deleteAction->setIcon(QIcon(":/project/DeleteDocument"));
00029 deleteAction->setText(tr("Löschen"));
00030 connect(deleteAction, SIGNAL(triggered()), this, SLOT(removeEntry()));
00031
00032 editAction = new QAction(this);
00033 editAction->setIcon(QIcon(":/edit/SelectAll"));
00034 editAction->setText(tr("Bearbeiten"));
00035 connect(editAction, SIGNAL(triggered()), this, SLOT(editEntry()));
00036 }
00037
00038 void CostTypeChild::newFile()
00039 {
00040 QVBoxLayout *layout = new QVBoxLayout;
00041
00042 if(table)
00043 {
00044 filterModel = new CostTypeFilterModel(false, false, false, false, NULL, this);
00045 filterModel->setSourceModel(table);
00046 filterModel->setDynamicSortFilter(true);
00047
00048 connect(table, SIGNAL(sendingOwnCapitalNode(const QDomElement)), ownCapitalDialog->model, SLOT(loadDataNode(const QDomElement)));
00049 connect(table, SIGNAL(changedDataUpdateProxies()), filterModel, SLOT(invalidate()));
00050 table->revenues = 0;
00051
00052 tableView = new QTableView;
00053 tableView->setModel(filterModel);
00054 tableView->setSortingEnabled(true);
00055
00056 tableView->horizontalHeader()->setStretchLastSection(true);
00057 tableView->verticalHeader()->hide();
00058 tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
00059 tableView->addAction(editAction);
00060 tableView->addAction(deleteAction);
00061 tableView->setContextMenuPolicy(Qt::ActionsContextMenu);
00062 tableView->sortByColumn(0, Qt::AscendingOrder);
00063
00064
00065
00066
00067 setWindowTitle(table->fileName());
00068
00069 CostTypeSelectionModel *selectionModel = new CostTypeSelectionModel(filterModel);
00070 tableView->setSelectionModel(selectionModel);
00071 tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
00072 tableView->setSelectionMode(QAbstractItemView::MultiSelection);
00073 connect(selectionModel, SIGNAL(enableEditRemoveActions(bool)), this, SLOT(enableEditRemoveActions(bool)));
00074
00075 layout->addWidget(tableView);
00076 setLayout(layout);
00077 }
00078 }
00079
00080 bool CostTypeChild::loadDocument(const QDomElement document)
00081 {
00082 table->loadDocument(document);
00083 tableView->resizeColumnsToContents();
00084 return true;
00085 }
00086
00087 void CostTypeChild::closeEvent(QCloseEvent *event)
00088 {
00089 if(maybeSave())
00090 {
00091 event->accept();
00092 }
00093 else
00094 {
00095 event->ignore();
00096 }
00097 }
00098
00099 bool CostTypeChild::maybeSave()
00100 {
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 return true;
00117 }
00118
00119 void CostTypeChild::enableEditRemoveActions(bool state)
00120 {
00121 editAction->setEnabled(state);
00122 deleteAction->setEnabled(state);
00123 }
00124
00125 void CostTypeChild::reassessValueBased(QString position, int type, QString pal, QString replacementvalue, QString salvagevalue, QString usefuleconomiclife)
00126 {
00127 if(!table->reassessValueBased(position, type, pal, replacementvalue, salvagevalue, usefuleconomiclife))
00128 {
00129 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00130 }
00131 }
00132
00133 void CostTypeChild::reassessIndexBased(QString position, int type, QString pal, QString decliningbalance, QString usefuleconomiclife, QString purchasePrice, QString purchaseIndex, QString currentIndex)
00134 {
00135 if(!table->reassessIndexBased(position, type, pal, decliningbalance, usefuleconomiclife, purchasePrice, purchaseIndex, currentIndex))
00136 {
00137 qDebug()<<"index: " << position << "\n" << type << "\n" << pal << "\n" << decliningbalance << "\n" << usefuleconomiclife << "\n" << purchasePrice << "\n" << purchaseIndex << "\n" << currentIndex;
00138 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00139 }
00140 }
00141
00142 void CostTypeChild::delimitAmount(QString position, int type, QString incomestatement, QString amounttodelimit)
00143 {
00144 if(!table->delimitAmount(position, type, incomestatement, amounttodelimit))
00145 {
00146 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00147 }
00148 }
00149
00150 void CostTypeChild::acceptCosts(QString position, int type, QString incomestatement)
00151 {
00152 if(!table->acceptCosts(position, type, incomestatement))
00153 {
00154 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00155 }
00156 }
00157
00158 void CostTypeChild::normalize(QString position, int type, QString averagecosts, QString actualcosts)
00159 {
00160 if(!table->normalize(position, type, averagecosts, actualcosts))
00161 {
00162 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00163 }
00164 }
00165
00166 void CostTypeChild::wages(QString position, int type, QString wages, QString specialpayment, QString legaltaxes, QString paymentbyresult, QString directcostpart, QString nonwagelaborcosts)
00167 {
00168 if(!table->wages(position, type, wages, specialpayment, legaltaxes, paymentbyresult, directcostpart, nonwagelaborcosts))
00169 {
00170 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00171 }
00172 }
00173
00174 void CostTypeChild::incidentialInterest(QString position, int type, QString incomestatement)
00175 {
00176 if(!table->incidentialInterest(position, type, incomestatement))
00177 {
00178 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00179 }
00180 }
00181
00182 void CostTypeChild::interestOnOwnBoundCapital(QString position, int type, QString incomeStatement, QString interestOnBorrowedCapital, QString ownCapital, QString interestRate)
00183 {
00184 if(!table->interestOnOwnBoundCapital(position, type, incomeStatement, interestOnBorrowedCapital, ownCapital, interestRate))
00185 {
00186 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00187 }
00188 }
00189
00190 void CostTypeChild::interestOnOperatingAssets(QString position, int ty, QString incomeStatement, QString interestRateOwnBoundCapital, QString operatingAssets)
00191 {
00192 if(!table->interestOnOperatingAssets(position, ty, incomeStatement, interestRateOwnBoundCapital, operatingAssets))
00193 {
00194 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00195 }
00196 }
00197
00198 void CostTypeChild::completeCosts(QString position, int type, QString salarywithouttaxes, QString monthsforcalculation, QString riskpremium)
00199 {
00200 if(!table->completeCostsEmployersSalary(position, type, salarywithouttaxes, monthsforcalculation, riskpremium))
00201 {
00202 QMessageBox::warning(this, tr("Fehler"), tr("Bitte korrigieren Sie Ihre Eingaben!"));
00203 }
00204 }
00205
00206 void CostTypeChild::setRevenues(double e)
00207 {
00208 table->revenues = e;
00209 table->refreshSums();
00210 }
00211
00212 void CostTypeChild::removeEntry()
00213 {
00214 QTableView *temp = static_cast<QTableView*>(tableView);
00215 QItemSelectionModel *selectionModel = temp->selectionModel();
00216 QItemSelection selection = ((CostTypeFilterModel*)(temp->model()))->mapSelectionToSource(selectionModel->selection());
00217
00218 table->removeRows(selection.indexes().value(0).row(), 1, QModelIndex());
00219 table->refreshSums();
00220 }
00221
00222 void CostTypeChild::editEntry()
00223 {
00224
00225 QTableView *temp = static_cast<QTableView*>(tableView);
00226 QItemSelectionModel *selectionModel = temp->selectionModel();
00227 QItemSelection selection = ((CostTypeFilterModel*)(temp->model()))->mapSelectionToSource(selectionModel->selection());
00228
00229 QModelIndexList indexes = selection.indexes();
00230
00231 QList<int> rows;
00232 for(int row = 0; row < indexes.count(); row++)
00233 {
00234 QModelIndex i = indexes.value(row);
00235 int row = i.row();
00236 if(!rows.contains(row))
00237 {
00238 rows << row;
00239 }
00240 }
00241
00242 QModelIndexList cleanedUpIndexes;
00243 for(int i = 0; i < rows.count(); i++)
00244 {
00245 QModelIndex in = table->index(rows.value(i), 0, QModelIndex());
00246 cleanedUpIndexes << in;
00247 }
00248
00249 emit setMdiAreaEnabled(false);
00250 emit editInformationAvailable(table, cleanedUpIndexes);
00251 }