First work on grid
This commit is contained in:
50
src/view/grid/ChoiceDelegate.cpp
Normal file
50
src/view/grid/ChoiceDelegate.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "ChoiceDelegate.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
QWidget * ChoiceDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
QComboBox* combo = new QComboBox(parent);
|
||||
|
||||
for(int i=0; i<_nbValues; i++)
|
||||
combo->addItem(_values[i]);
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
void ChoiceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *combo = qobject_cast<QComboBox *>(editor);
|
||||
model->setData(index, qVariantFromValue(combo->currentText()));
|
||||
}
|
||||
|
||||
void ChoiceDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QComboBox* combo = qobject_cast<QComboBox *>(editor);
|
||||
int i = combo->findText(qVariantValue<QString>(index.data()));
|
||||
|
||||
if (i != -1) combo->setCurrentIndex(i);
|
||||
}
|
||||
43
src/view/grid/ChoiceDelegate.hpp
Normal file
43
src/view/grid/ChoiceDelegate.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHOICEDELEGATE_H
|
||||
#define CHOICEDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QString>
|
||||
|
||||
class ChoiceDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ChoiceDelegate(QWidget *parent = 0, QString* values=0, int nbValues=0) : QItemDelegate(parent), _values(values), _nbValues(nbValues) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
QString* _values;
|
||||
int _nbValues;
|
||||
};
|
||||
|
||||
#endif
|
||||
54
src/view/grid/DateDelegate.cpp
Normal file
54
src/view/grid/DateDelegate.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "DateDelegate.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
QWidget * DateDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
QComboBox* combo = new QComboBox(parent);
|
||||
QDate date(_year, _month, _day);
|
||||
QString s;
|
||||
|
||||
for(int i=0; i<date.daysInMonth(); i++)
|
||||
combo->addItem(s.sprintf("%d", i+1));
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *combo = qobject_cast<QComboBox *>(editor);
|
||||
QString s ;
|
||||
|
||||
s = s.sprintf("%02d/%02d/%04d", combo->currentIndex()+1, _month+1, _year);
|
||||
|
||||
model->setData(index, qVariantFromValue(s));
|
||||
}
|
||||
|
||||
void DateDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QComboBox* combo = qobject_cast<QComboBox *>(editor);
|
||||
combo->setCurrentIndex(qVariantValue<QString>(index.data()).left(2).toInt()-1);
|
||||
}
|
||||
42
src/view/grid/DateDelegate.hpp
Normal file
42
src/view/grid/DateDelegate.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DATEDELEGATE_H
|
||||
#define DATEDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QString>
|
||||
|
||||
class DateDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
DateDelegate(QWidget *parent = 0, int month=0, int year=0) : QItemDelegate(parent), _day(1), _month(month), _year(year) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
int _day, _month, _year;
|
||||
};
|
||||
|
||||
#endif
|
||||
43
src/view/grid/FloatDelegate.cpp
Normal file
43
src/view/grid/FloatDelegate.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "FloatDelegate.hpp"
|
||||
|
||||
QWidget * FloatDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
return new QLineEdit(parent);
|
||||
}
|
||||
|
||||
void FloatDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *line = qobject_cast<QLineEdit *>(editor);
|
||||
QString s ;
|
||||
double value = line->text().toDouble();
|
||||
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", value)));
|
||||
}
|
||||
|
||||
void FloatDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit* line = qobject_cast<QLineEdit *>(editor);
|
||||
line->setText(qVariantValue<QString>(index.data()));
|
||||
}
|
||||
39
src/view/grid/FloatDelegate.hpp
Normal file
39
src/view/grid/FloatDelegate.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FLOATDELEGATE_H
|
||||
#define FLOATDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QString>
|
||||
|
||||
class FloatDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
FloatDelegate(QWidget *parent = 0) : QItemDelegate(parent) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
1540
src/view/grid/GridAccount.cpp
Normal file
1540
src/view/grid/GridAccount.cpp
Normal file
File diff suppressed because it is too large
Load Diff
104
src/view/grid/GridAccount.hpp
Normal file
104
src/view/grid/GridAccount.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRIDACCOUNT_H
|
||||
#define GRIDACCOUNT_H
|
||||
|
||||
// #include <wx/wx.h>
|
||||
// #include <wx/grid.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <view/AccountPanel.hpp>
|
||||
#include <model/model.hpp>
|
||||
#include <controller/KissCount.hpp>
|
||||
// #include "wxGridCellFastBoolEditor.hpp"
|
||||
// #include "wxGridCellTreeButtonRenderer.hpp"
|
||||
// #include "wxGridCellTreeButtonEditor.hpp"
|
||||
// #include "wxGridCellBitmapRenderer.hpp"
|
||||
// #include "wxGridCellFormulaEditor.hpp"
|
||||
// #include "wxGridCellTabStringRenderer.hpp"
|
||||
|
||||
#include <QTableWidget>
|
||||
|
||||
class KissCount;
|
||||
|
||||
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
|
||||
|
||||
typedef void (*updateOperationFunc)(Operation* op, void** params);
|
||||
|
||||
class GridAccount : public QTableWidget
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
class OperationNotFound {};
|
||||
|
||||
GridAccount(KissCount* kiss, QWidget *parent,
|
||||
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
|
||||
~GridAccount();
|
||||
|
||||
// wxPen GetColGridLinePen (int col);
|
||||
// wxPen GetRowGridLinePen (int row);
|
||||
|
||||
virtual void ClearGrid();
|
||||
void LoadOperations(std::vector<Operation>* operations, int month, int year);
|
||||
void InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year) ;
|
||||
void InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year) ;
|
||||
|
||||
void GetSelectedOperations(std::vector<int>* rows);
|
||||
|
||||
void MassUpdate(std::vector<int>& rows, updateOperationFunc func, void** params);
|
||||
|
||||
void Group();
|
||||
void UnGroup();
|
||||
|
||||
int _fixCosts;
|
||||
int _week1, _week2, _week3, _week4;
|
||||
std::vector<Operation> _displayedOperations;
|
||||
|
||||
private slots:
|
||||
void OnOperationModified();
|
||||
|
||||
private:
|
||||
QWidget* _parent;
|
||||
KissCount* _kiss;
|
||||
bool _displayLines;
|
||||
bool _canAddOperation, _setWeek;
|
||||
bool _databaseSynchronization;
|
||||
QString* _categories, *_accounts;
|
||||
std::vector<Operation>* _operations;
|
||||
bool _loadOperations;
|
||||
int _curMonth, _curYear;
|
||||
|
||||
void SetWeek(int week, int line);
|
||||
void ResetWeeks();
|
||||
void ComputeWeeks();
|
||||
|
||||
void InsertIntoGrid(Operation& op);
|
||||
void DeleteOperation(const Operation& op);
|
||||
void UpdateMeta(Operation& op);
|
||||
int RemoveMeta(Operation op, int line, bool removeRoot, bool deleteOp);
|
||||
void CheckMeta(Operation& op, int line, bool check);
|
||||
|
||||
Operation& GetOperation(int id) throw(OperationNotFound);
|
||||
void UpdateOperation(Operation& op);
|
||||
int GetDisplayedRow(int id);
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user