00001 #include <QMdiArea>
00002 #include <QMdiSubWindow>
00003 #include <QTableView>
00004 #include "costcentretab.h"
00005 #include "../Dialogs/addcostpositiondialog.h"
00006 #include "../Data/project.h"
00007 #include "../Data/datadefinitions.h"
00008 #include "../Data/settings.h"
00009 #include "../Childwindows/childwindow.h"
00010 #include "../Childwindows/costcentrechild.h"
00011 #include "../Models/costtypeselectionmodel.h"
00012
00013 CostCentreTab::CostCentreTab(Settings &set, QMdiArea *mdi, QWidget *parent) : QWidget(parent)
00014 {
00015 setupUi(this);
00016 settings = &set;
00017 mdiArea = mdi;
00018
00019 createActions();
00020 }
00021
00022 void CostCentreTab::createActions()
00023 {
00024 connect(buttonAddCostCentre, SIGNAL(clicked()), this, SLOT(addNewCostCentre()));
00025 connect(buttonChooseCostPosition, SIGNAL(clicked()), this, SLOT(openGetPositionDialog()));
00026 connect(buttonSetBase, SIGNAL(clicked()), this, SLOT(setBaseForCurrentCostCentre()));
00027 connect(comboBoxSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(setSelectionMode(int)));
00028 }
00029
00030 void CostCentreTab::setSelectionMode(int index)
00031 {
00032 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00033 {
00034 if(qobject_cast<ChildWindow*>(activeSubWindow->widget())->type() == WindowType::CostCentre)
00035 {
00036 CostCentreChild * child = (qobject_cast<CostCentreChild*>(activeSubWindow->widget()));
00037
00038 if(index == 0)
00039 {
00040 child->tableViewWidget()->setSelectionBehavior(QAbstractItemView::SelectColumns);
00041 }
00042 else
00043 {
00044 child->tableViewWidget()->setSelectionBehavior(QAbstractItemView::SelectRows);
00045 }
00046 }
00047 }
00048 }
00049
00050 void CostCentreTab::setBaseForCurrentCostCentre()
00051 {
00052 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00053 {
00054 if(qobject_cast<ChildWindow*>(activeSubWindow->widget())->type() == WindowType::CostCentre)
00055 {
00056 CostCentreChild * child = (qobject_cast<CostCentreChild*>(activeSubWindow->widget()));
00057 bool ok;
00058 textBaseValue->text().toDouble(&ok);
00059 if(!ok)
00060 {
00061 QMessageBox::warning(this, tr("Fehler"), tr("Ungültige Eingabe!"));
00062 }
00063 else
00064 {
00065 if(textBaseValue->text().toDouble()>0)
00066 {
00067 QTableView *temp = static_cast<QTableView*>(child->tableViewWidget());
00068 if(child->tableViewWidget()->selectionBehavior() == QAbstractItemView::SelectColumns)
00069 {
00070 QItemSelectionModel *selectionModel = temp->selectionModel();
00071 if(selectionModel)
00072 {
00073 QModelIndexList indexes = selectionModel->selectedColumns();
00074 if(indexes.size()>0)
00075 {
00076 int column = indexes.value(0).column();
00077
00078 if(column!=-1 && column>=2)
00079 {
00080 if(comboBoxBaseType->currentText()==tr("Stunden"))
00081 {
00082 child->setBase(column-2, textBaseValue->text() + "h");
00083 }
00084 else
00085 {
00086 child->setBase(column-2, textBaseValue->text());
00087 }
00088
00089 textBaseValue->setText("");
00090 }
00091 }
00092 }
00093 }
00094 else
00095 {
00096 QMessageBox::warning(this, tr("Fehler"), tr("Um die Basis einer Kostenstelle setzen zu können, müssen Sie ""Spalten"" als Auswahltyp festlegen, und anschließend die gewünschte Kostenstelle markieren!"));
00097 }
00098 }
00099 else
00100 {
00101 QMessageBox::warning(this, tr("Fehler"), tr("Die Basis muss positiv sein!"));
00102 }
00103 }
00104 }
00105 }
00106 }
00107
00108 void CostCentreTab::addNewCostCentre()
00109 {
00110 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00111 {
00112 if(qobject_cast<ChildWindow*>(activeSubWindow->widget())->type() == WindowType::CostCentre)
00113 {
00114 if(textCostCentreName->text()!="" && !textCostCentreName->text().contains(","))
00115 {
00116 if(radioPrimaryCostCentre->isChecked())
00117 {
00118 (qobject_cast<CostCentreChild*>(activeSubWindow->widget()))->addCostCentre(textCostCentreName->text(), CostCentre::PrimaryCostCentre);
00119 }
00120 else if(radioServiceCostCentre->isChecked())
00121 {
00122 (qobject_cast<CostCentreChild*>(activeSubWindow->widget()))->addCostCentre(textCostCentreName->text(), CostCentre::ServiceCostCentre);
00123 }
00124 else
00125 {
00126 QMessageBox::warning(NULL, tr("Fehler"), tr("Bitte wählen Sie aus, ob diese Stelle eine Haupt- oder eine Hilfskostenstelle ist"));
00127 }
00128 }
00129 else
00130 {
00131 QMessageBox::warning(NULL, tr("Fehler"), tr("Sie müssen einen Namen für die Kostenstelle eingeben! Dieser darf keine ',' enthalten!"));
00132 }
00133 }
00134 }
00135 }
00136
00137 void CostCentreTab::setModel(CostTypeModel *m)
00138 {
00139 model = m;
00140 }
00141
00142 void CostCentreTab::openGetPositionDialog()
00143 {
00144 CostCentreChild *child = NULL;
00145 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00146 {
00147 if(qobject_cast<ChildWindow*>(activeSubWindow->widget())->type() == WindowType::CostCentre)
00148 {
00149 child = (qobject_cast<CostCentreChild*>(activeSubWindow->widget()));
00150 }
00151 }
00152
00153 AddCostPositionDialog *choose = new AddCostPositionDialog(model, child->model(), this);
00154 choose->show();
00155 }