First work on grid

This commit is contained in:
Grégory Soutadé 2011-10-20 11:11:59 +02:00
parent ea054b48ad
commit 5bea328b8d
12 changed files with 1928 additions and 19 deletions

View File

@ -26,7 +26,8 @@ MOCS_OBJS=$(MOC_HEADERS:.hpp=.moc)
all: mojito kc
clean:
find src -type f -name '*.[o~]' -exec rm -f \{\} \;
find src -type f -name '*.o' -exec rm -f \{\} \;
find src -type f -name '*~' -exec rm -f \{\} \;
find src -type f -name '*.moc' -exec rm -f \{\} \;
find src -type f -name '*.objs' -exec rm -f \{\} \;
rm -f kc

View File

@ -32,7 +32,7 @@
#define APP_VERSION "0.3"
#define ESCAPE_CHARS(s) s.replace("\"", "\\\"");
#define ESCAPE_CHARS(s) s = s.replace("\"", "\\\"");
/*{ \
if (s.Find(wxT("\\\"")) == wxNOT_FOUND) \
s.Replace(wxT("\""), wxT("\\\""), true); \
@ -40,7 +40,7 @@
s.Replace(wxT("\'"), wxT("\\\'"), true); \
}
*/
#define UNESCAPE_CHARS(s) s.replace("\\\"", "\"");
#define UNESCAPE_CHARS(s) s = s.replace("\\\"", "\"");
/*{ \
s.Replace(wxT("\\\""), wxT("\""), true); \
s.Replace(wxT("\\\'"), wxT("\'"), true); \

View File

@ -87,18 +87,12 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0);
_dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole);
}
// _dataset = new CategorySimpleDataset(_categories, nbCategories);
// _dataset->AddSerie(_("Serie 1"), _categoriesValues, nbCategories);
// _dataset->SetRenderer(new CategoryRenderer(*colorScheme));
// _pie->SetDataset(_dataset);
// _pie->SetColorScheme(colorScheme);
_pie->setModel(_dataset);
_pie->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// _pie->SetLegend(new Legend(wxBOTTOM, wxCENTER));
// _grid = new GridAccount(_kiss, this, OPS_GRID_ID, true, true, true);
_grid = new GridAccount(_kiss, this, true, true, true);
_grid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_accountsGrid = new QTableWidget(this);
_accountsGrid->setColumnCount(NUMBER_COLS_ACCOUNTS);
@ -112,7 +106,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_FINAL, new QTableWidgetItem(_("Final value")));
_accountsGrid->resizeColumnsToContents();
_accountsGrid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
_accountsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
for(i=0; i<NUMBER_COLS_ACCOUNTS; i++)
{
@ -124,7 +118,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_statsGrid = new QTableWidget(this);
_statsGrid->verticalHeader()->setHidden(true);
_statsGrid->horizontalHeader()->setHidden(true);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// chart = new wxChartPanel(this);
// chart->SetChart(new Chart(_pie, _("Cost repartition")));
@ -171,7 +165,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
hbox2->addWidget(_accountsGrid, 2);
hbox2->addWidget(_calendar);
vbox2->addLayout(hbox2);
// vbox2->Add(_grid, 0, wxGROW|wxALL, 2);
vbox2->addWidget(_grid, 1);
hbox->addLayout(vbox2);
vbox->addWidget(_statsGrid);
vbox->addWidget(_pie);
@ -309,7 +303,6 @@ void AccountPanel::ChangeUser()
curNode = new QTreeWidgetItem(QStringList(QString::number(it->first)));
_tree->addTopLevelItem(curNode);
}
layout();
if (curYear != -1)
{
_tree->setCurrentItem(curNode);
@ -320,8 +313,8 @@ void AccountPanel::ChangeUser()
{
curNode = new QTreeWidgetItem(QStringList(QString::number(curDate.year())));
_tree->addTopLevelItem(curNode);
layout();
}
layout();
}
void AccountPanel::LoadYear(int year, bool showMonth)
@ -416,7 +409,7 @@ void AccountPanel::ShowMonth(int month, int year)
// Operations are ordered
_curOperations = &((*user->_operations[year])[month]);
// _grid->LoadOperations(_curOperations, _curMonth, _curYear);
_grid->LoadOperations(_curOperations, _curMonth, _curYear);
InitAccountsGrid(user, month, year);

View File

@ -37,7 +37,7 @@
#include "view.hpp"
#include <model/model.hpp>
// #include "grid/GridAccount.hpp"
#include "grid/GridAccount.hpp"
// #include "grid/CalendarEditor.hpp"
// #include <wx/category/categorysimpledataset.h>
@ -79,7 +79,7 @@ private slots:
private:
QTreeWidget *_tree;
QCalendarWidget* _calendar;
// GridAccount* _grid;
GridAccount* _grid;
QTableWidget* _accountsGrid, *_statsGrid;
PieView* _pie;
double *_categoriesValues;

View 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);
}

View 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

View 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);
}

View 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

View 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()));
}

View 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

File diff suppressed because it is too large Load Diff

View 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