00001 #ifndef ADDCOSTPOSITIONMODEL_H 00002 #define ADDCOSTPOSITIONMODEL_H 00003 00004 #include <QAbstractTableModel> 00005 #include <QStringList> 00006 #include <QColor> 00007 #include "../Data/datadefinitions.h" 00008 #include "costtypemodel.h" 00009 #include "costcentremodel.h" 00010 00011 class AddCostPositionModel : public QAbstractTableModel 00012 { 00013 Q_OBJECT 00014 public: 00015 AddCostPositionModel(CostTypeModel *model, CostCentreModel *costcentre, int rowid, double sum, QObject *parent = 0); 00016 00017 int rowCount(const QModelIndex &parent) const; 00018 int columnCount(const QModelIndex &parent) const; 00019 QVariant data(const QModelIndex &index, int role) const; 00020 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 00021 Qt::ItemFlags flags(const QModelIndex &index) const; 00022 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 00023 bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); 00024 bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); 00025 00026 QStringList currentRow() const; 00027 00028 double calculateCostCentreSum(int column); 00029 bool isCorrectSpreaded(); 00030 QString costTypesRow(); 00031 QString costSpreadingRow(); 00032 void clear(); 00033 00034 private: 00035 void setHeaders(); 00036 void setDefaultFields(); 00037 void setCostCentres(); 00038 00039 bool checkPercentageOfRow(QVariantList row); 00040 bool checkWorkTimeOfRow(QVariantList row); 00041 bool checkValuesOfRow(QVariantList row); 00042 00043 double calculatedRowValuePercentage(QVariantList row); 00044 double calculatedRowValueHours(QVariantList row); 00045 double calculatedRowValueBased(QVariantList row); 00046 00047 double workTimePerCostCentre(QVariantList row, int columnWanted); 00048 00049 QList<QVariantList> p_entries; 00050 QList<QString> p_headers; 00051 QList<QString> p_vert_headers; 00052 00053 CostTypeModel *costtypemodel; 00054 CostCentreModel *costcentremodel; 00055 int currentSelectedRowId; 00056 00057 double p_completeSum; 00058 double p_currentSum; 00059 00060 public slots: 00061 void refreshSums(const QModelIndex left, const QModelIndex right); 00062 00063 signals: 00064 void currentSumChanged(double); 00065 void updateView(); 00066 }; 00067 00068 #endif