Modify operations in FormulaDelegate
Add "+" button in GridAccount
This commit is contained in:
parent
aa47adb791
commit
2243f0a1cf
|
@ -30,11 +30,6 @@ QWidget * FormulaDelegate::createEditor (QWidget * parent, const QStyleOptionVie
|
||||||
return new QLineEdit(parent);
|
return new QLineEdit(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormulaDelegate::newFormula(QString f)
|
|
||||||
{
|
|
||||||
_formula = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
@ -66,7 +61,8 @@ void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
return;
|
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;
|
delete[] str2;
|
||||||
res = ParseExp::EvaluateExpr(&opt, true);
|
res = ParseExp::EvaluateExpr(&opt, true);
|
||||||
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res)));
|
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res)));
|
||||||
|
@ -86,8 +82,8 @@ void FormulaDelegate::setEditorData(QWidget *editor,
|
||||||
QLineEdit* line = qobject_cast<QLineEdit *>(editor);
|
QLineEdit* line = qobject_cast<QLineEdit *>(editor);
|
||||||
QString s = qVariantValue<QString>(index.data());
|
QString s = qVariantValue<QString>(index.data());
|
||||||
|
|
||||||
if (_formula.startsWith("="))
|
if ((*_operations)[index.row()].formula.length())
|
||||||
line->setText(_formula);
|
line->setText((*_operations)[index.row()].formula);
|
||||||
else
|
else
|
||||||
line->setText(s);
|
line->setText(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,14 @@
|
||||||
|
|
||||||
#include <QItemDelegate>
|
#include <QItemDelegate>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <model/model.hpp>
|
||||||
|
|
||||||
class FormulaDelegate : public QItemDelegate
|
class FormulaDelegate : public QItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
|
||||||
public:
|
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;
|
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||||
|
@ -36,9 +37,7 @@ public:
|
||||||
const QModelIndex &index) const;
|
const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void newFormula(QString f);
|
std::vector<Operation>* _operations;
|
||||||
|
|
||||||
QString _formula;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -225,7 +225,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
|
||||||
// setItemDelegateForColumn(DEBIT, floatEditor);
|
// setItemDelegateForColumn(DEBIT, floatEditor);
|
||||||
// setItemDelegateForColumn(CREDIT, floatEditor);
|
// setItemDelegateForColumn(CREDIT, floatEditor);
|
||||||
|
|
||||||
FormulaDelegate* formulaEditor = new FormulaDelegate(this);
|
FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations);
|
||||||
setItemDelegateForColumn(DEBIT, formulaEditor);
|
setItemDelegateForColumn(DEBIT, formulaEditor);
|
||||||
setItemDelegateForColumn(CREDIT, formulaEditor);
|
setItemDelegateForColumn(CREDIT, formulaEditor);
|
||||||
|
|
||||||
|
@ -347,9 +347,6 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||||
_fixCosts++;
|
_fixCosts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetCellEditor(line, DEBIT, new wxGridCellFormulaEditor(op.formula));
|
|
||||||
//SetCellEditor(line, CREDIT, new wxGridCellFormulaEditor(op.formula));
|
|
||||||
|
|
||||||
if (op.id)
|
if (op.id)
|
||||||
{
|
{
|
||||||
cat = user->GetCategory(op.category);
|
cat = user->GetCategory(op.category);
|
||||||
|
@ -360,7 +357,9 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||||
item = new QTableWidgetItem();
|
item = new QTableWidgetItem();
|
||||||
setItem(line, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", op.day+1, month+1, year)));
|
setItem(line, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", op.day+1, month+1, year)));
|
||||||
if (op.amount < 0)
|
if (op.amount < 0)
|
||||||
|
{
|
||||||
setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", -op.amount)));
|
setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", -op.amount)));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
setItem(line, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", op.amount)));
|
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)
|
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());
|
// SetCellRenderer(line, TREE, new wxGridCellTreeButtonRenderer());
|
||||||
// SetCellEditor(line, TREE, new wxGridCellTreeButtonEditor());
|
// SetCellEditor(line, TREE, new wxGridCellTreeButtonEditor());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user