From 2243f0a1cfbdba102c1b1c78d2a053d5c39d20fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 22 Oct 2011 09:57:20 +0200 Subject: [PATCH] Modify operations in FormulaDelegate Add "+" button in GridAccount --- src/view/grid/FormulaDelegate.cpp | 14 +++++--------- src/view/grid/FormulaDelegate.hpp | 7 +++---- src/view/grid/GridAccount.cpp | 13 +++++++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/view/grid/FormulaDelegate.cpp b/src/view/grid/FormulaDelegate.cpp index 84ae1df..f1d0a91 100644 --- a/src/view/grid/FormulaDelegate.cpp +++ b/src/view/grid/FormulaDelegate.cpp @@ -30,11 +30,6 @@ QWidget * FormulaDelegate::createEditor (QWidget * parent, const QStyleOptionVie return new QLineEdit(parent); } -void FormulaDelegate::newFormula(QString f) -{ - _formula = f; -} - void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { @@ -65,8 +60,9 @@ void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, delete[] str2; return; } - - const_cast(this)->newFormula(value); // hum hum... + + FormulaDelegate* _this = const_cast(this); // hum hum ... + _this->_operations->at(index.row()).formula = value; delete[] str2; res = ParseExp::EvaluateExpr(&opt, true); model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res))); @@ -86,8 +82,8 @@ void FormulaDelegate::setEditorData(QWidget *editor, QLineEdit* line = qobject_cast(editor); QString s = qVariantValue(index.data()); - if (_formula.startsWith("=")) - line->setText(_formula); + if ((*_operations)[index.row()].formula.length()) + line->setText((*_operations)[index.row()].formula); else line->setText(s); } diff --git a/src/view/grid/FormulaDelegate.hpp b/src/view/grid/FormulaDelegate.hpp index 23834b7..e2a8539 100644 --- a/src/view/grid/FormulaDelegate.hpp +++ b/src/view/grid/FormulaDelegate.hpp @@ -22,13 +22,14 @@ #include #include +#include class FormulaDelegate : public QItemDelegate { Q_OBJECT; public: - FormulaDelegate(QWidget *parent = 0) : QItemDelegate(parent) {} + FormulaDelegate(QWidget *parent = 0, std::vector* operations=0) : QItemDelegate(parent), _operations(operations) {} QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; @@ -36,9 +37,7 @@ public: const QModelIndex &index) const; private: - void newFormula(QString f); - - QString _formula; + std::vector* _operations; }; #endif diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 2043263..a5c4a1b 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -225,7 +225,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, // setItemDelegateForColumn(DEBIT, floatEditor); // setItemDelegateForColumn(CREDIT, floatEditor); - FormulaDelegate* formulaEditor = new FormulaDelegate(this); + FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations); setItemDelegateForColumn(DEBIT, formulaEditor); setItemDelegateForColumn(CREDIT, formulaEditor); @@ -347,9 +347,6 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, _fixCosts++; } - //SetCellEditor(line, DEBIT, new wxGridCellFormulaEditor(op.formula)); - //SetCellEditor(line, CREDIT, new wxGridCellFormulaEditor(op.formula)); - if (op.id) { cat = user->GetCategory(op.category); @@ -360,7 +357,9 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, item = new QTableWidgetItem(); setItem(line, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", op.day+1, month+1, year))); if (op.amount < 0) + { setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", -op.amount))); + } else setItem(line, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", op.amount))); @@ -442,6 +441,12 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (op.id && op.meta) { + int height = rowHeight(TREE); + QPushButton* button = new QPushButton("+"); + //button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + //button->resize(button->minimumSize()); + button->setMaximumSize(QSize(height, height)); + setCellWidget(line, TREE, button); // SetCellRenderer(line, TREE, new wxGridCellTreeButtonRenderer()); // SetCellEditor(line, TREE, new wxGridCellTreeButtonEditor());