00001 #ifndef COSTCENTREMODEL_H
00002 #define COSTCENTREMODEL_H
00003
00004 #include <QAbstractTableModel>
00005 #include <QDomElement>
00006 #include <QStringList>
00007 #include "abstractmodel.h"
00008 class CostTypeModel;
00009 class CostCentreColumns;
00010 class CostCentreRows;
00011 class CostCentre;
00012
00013 class CostCentreModel : public QAbstractTableModel, public AbstractModel
00014 {
00015 Q_OBJECT
00016
00017 public:
00018 CostCentreModel(uint fileid, uint type, QString documentname, QObject *parent = 0);
00019
00020 virtual QDomElement documentNode();
00021 virtual bool loadDocument(const QDomElement file);
00022
00023 int rowCount(const QModelIndex &parent) const;
00024 int columnCount(const QModelIndex &parent) const;
00025
00026 void setCostTypeModel(CostTypeModel *model);
00027 CostTypeModel *costTypeModel;
00028
00029 QStringList data(const int row) const;
00030 QVariant data(const QModelIndex &index, int role) const;
00031 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00032
00033 Qt::ItemFlags flags(const QModelIndex &index) const;
00034 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00035
00036 void addPosition(QStringList columns, bool overwriteRowId = false);
00037 bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
00038 bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());
00039
00040 bool addCostCentre(QString columnname, int type, QString base = "");
00041 bool insertColumns(int position, int columns, const QModelIndex &index = QModelIndex());
00042 bool removeColumns(int position, int columns, const QModelIndex &index = QModelIndex());
00043
00044 bool containsCostCentre(QString name, int type);
00045 bool containsColumn(QString name);
00046 bool containsPosition(QStringList row);
00047
00048
00049 int columnIdIndex(QString columnName);
00050
00051 QList<QStringList> entries();
00052
00053 QStringList headers();
00054
00055 int costCentreCount();
00056 double sums(int sumType);
00057 double sums(int sumType, int column);
00058
00059 bool isCostCentreColumn(int column);
00060
00061 int costTypeFileIdentification() { return costTypeFileId; }
00062
00063 void setBase(QString columnName, QString base);
00064 void setBase(int column, QString base);
00065
00066 public slots:
00067 void refreshSums();
00068
00069 private slots:
00070 void costTypeRowEdited(int rowid);
00071 void costTypeRowRemoved(int rowid);
00072
00073 private:
00074 CostCentreColumns *columns;
00075 CostCentreRows *rows;
00076 CostCentre *costcentre;
00077
00078 QList<QStringList> p_entries;
00079 QStringList p_headers;
00080
00081 void addColumn(int position, QString columnName);
00082 void addPosition(int position, QStringList columns, bool overwriteRowId = false);
00083
00084 bool searchModel(QString entry);
00085 int rowIdIndex(QString row);
00086
00087 int costTypeFileId;
00088 int lastid;
00089
00090 signals:
00091 void rowChangedWarning(int rowid);
00092 void rowRemovedWarning(int rowid);
00093 };
00094
00095 #endif