Modify operations in FormulaDelegate

Add "+" button in GridAccount
This commit is contained in:
Grégory Soutadé 2011-10-22 09:57:20 +02:00
parent aa47adb791
commit 2243f0a1cf
3 changed files with 17 additions and 17 deletions

View File

@ -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<FormulaDelegate*>(this)->newFormula(value); // hum hum...
FormulaDelegate* _this = const_cast<FormulaDelegate*>(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<QLineEdit *>(editor);
QString s = qVariantValue<QString>(index.data());
if (_formula.startsWith("="))
line->setText(_formula);
if ((*_operations)[index.row()].formula.length())
line->setText((*_operations)[index.row()].formula);
else
line->setText(s);
}

View File

@ -22,13 +22,14 @@
#include <QItemDelegate>
#include <QString>
#include <model/model.hpp>
class FormulaDelegate : public QItemDelegate
{
Q_OBJECT;
public:
FormulaDelegate(QWidget *parent = 0) : QItemDelegate(parent) {}
FormulaDelegate(QWidget *parent = 0, std::vector<Operation>* 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<Operation>* _operations;
};
#endif

View File

@ -225,7 +225,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* 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());