[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [skrooge] /: Bad display amount in split editor
From: Stephane Mankowski <stephane () mankowski ! fr>
Date: 2016-01-02 18:50:04
Message-ID: E1aFRFc-0004NP-Fa () scm ! kde ! org
[Download RAW message or body]
Git commit d6894bd080fb4ef97dbdd567819f8af38c3d6cf5 by Stephane Mankowski.
Committed on 02/01/2016 at 18:49.
Pushed by smankowski into branch 'master'.
Bad display amount in split editor
BUG:357414
M +1 -0 CHANGELOG
M +57 -33 plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
M +1 -0 plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
M +3 -3 plugins/skrooge/skrooge_operation/skgsplittabledelegate.cpp
http://commits.kde.org/skrooge/d6894bd080fb4ef97dbdd567819f8af38c3d6cf5
diff --git a/CHANGELOG b/CHANGELOG
index c3d204e..05aaa4e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
skrooge (2.3.0)
*Correction bug 357081: No option to disable tray icon
+ *Correction bug 357414: Bad display amount in split editor
*Correction: Avoid failure in kmy import when sub category already exists
*Correction: Better autoreconciliation (the autoreconciliation can be done even \
when operations are not well sorted)
*Correction: Migration to nullptr
diff --git a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp \
b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp index \
ae0482a..72dbc87 100644
--- a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
+++ b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
@@ -209,6 +209,7 @@ SKGOperationPluginWidget::SKGOperationPluginWidget(SKGDocumentBank* \
iDocument)
connect(getDocument(), &SKGDocument::tableModified, this, \
&SKGOperationPluginWidget::dataModified, Qt::QueuedConnection);
+ connect(ui.kUnitEdit, &SKGUnitComboBox::editTextChanged, this, \
&SKGOperationPluginWidget::refreshSubOperationAmount, \
Qt::QueuedConnection);
connect(ui.kUnitEdit, &SKGUnitComboBox::editTextChanged, this, \
&SKGOperationPluginWidget::onOperationCreatorModified, \
Qt::QueuedConnection);
connect(ui.kAmountEdit, &SKGCalculatorEdit::textChanged, this, \
&SKGOperationPluginWidget::onOperationCreatorModified, \
Qt::QueuedConnection);
connect(ui.kAmountSharesEdit, &SKGCalculatorEdit::textChanged, this, \
&SKGOperationPluginWidget::onOperationCreatorModified, Qt::QueuedConnection); @@ \
-777,7 +778,7 @@ SKGError SKGOperationPluginWidget::updateSelection(const \
SKGObjectBase::SKGListS QString comment = item->text();
item = ui.kSubOperationsTable->item(j, \
m_attributesForSplit.indexOf(QStringLiteral("f_value")));
- double val = SKGServices::stringToDouble(item->text());
+ double val = item->data(101).toDouble();
QString formula = item->toolTip();
item = ui.kSubOperationsTable->item(j, \
m_attributesForSplit.indexOf(QStringLiteral("t_refund"))); @@ -2192,7 +2193,7 @@ \
double SKGOperationPluginWidget::getRemainingQuantity() for (int i = 0; i < \
nbSubOperations ; ++i) {
QTableWidgetItem* quantityItem = ui.kSubOperationsTable->item(i, \
m_attributesForSplit.indexOf(QStringLiteral("f_value"))); if (quantityItem) {
- sumQuantities = sumQuantities + \
SKGServices::stringToDouble(quantityItem->text()); + sumQuantities = \
sumQuantities + quantityItem->data(101).toDouble(); }
}
@@ -2221,6 +2222,42 @@ void SKGOperationPluginWidget::onDateChanged(const QDate \
iDate)
ui.kSubOperationsTable->blockSignals(previous); // Reenable signals
}
+void SKGOperationPluginWidget::refreshSubOperationAmount()
+{
+ SKGTRACEINFUNC(10);
+ bool previous = ui.kSubOperationsTable->blockSignals(true); // Disable signals \
so that filling cell doesn't create new lines +
+ int nbSubOperations = ui.kSubOperationsTable->rowCount();
+
+ // Refresh computed amounts
+ auto unit = ui.kUnitEdit->getUnit().getUnitInfo();
+ unit.Value = 1.0;
+ for (int i = 0; i < nbSubOperations ; ++i) {
+ QTableWidgetItem* quantityItem = ui.kSubOperationsTable->item(i, \
m_attributesForSplit.indexOf(QStringLiteral("f_value"))); + if (quantityItem) \
{ + QString formula = quantityItem->toolTip();
+ if (formula.startsWith(QLatin1String("="))) {
+ formula = formula.right(formula.length() - 1);
+ formula.replace(',', '.'); // Replace comma by a point in case of \
typo + formula.remove(' ');
+ formula.replace(QStringLiteral("total"), \
SKGServices::doubleToString(ui.kAmountEdit->value())); +
+ QScriptEngine myEngine;
+ QScriptValue result = myEngine.evaluate(formula);
+ if (result.isNumber()) {
+ auto value = result.toNumber();
+ quantityItem->setText(getDocument()->formatMoney(value, unit, \
false)); + quantityItem->setData(101, value);
+ }
+ } else {
+ auto value = quantityItem->data(101).toDouble();
+ quantityItem->setText(getDocument()->formatMoney(value, unit, \
false)); + }
+ }
+ }
+ ui.kSubOperationsTable->blockSignals(previous); // Reenable signals
+}
+
void SKGOperationPluginWidget::onQuantityChanged()
{
SKGTRACEINFUNC(10);
@@ -2232,25 +2269,7 @@ void SKGOperationPluginWidget::onQuantityChanged()
m_tableDelegate->addParameterValue(QStringLiteral("total"), \
ui.kAmountEdit->value());
// Refresh computed amounts
- for (int i = 0; i < nbSubOperations ; ++i) {
- QTableWidgetItem* quantityItem = ui.kSubOperationsTable->item(i, \
m_attributesForSplit.indexOf(QStringLiteral("f_value")));
- if (quantityItem) {
- QString formula = quantityItem->toolTip();
- if (formula.startsWith(QLatin1String("="))) {
- formula = formula.right(formula.length() - 1);
- formula.replace(',', '.'); // Replace comma by a point in case \
of typo
- formula.remove(' ');
- formula.replace(QStringLiteral("total"), \
SKGServices::doubleToString(ui.kAmountEdit->value()));
-
- QScriptEngine myEngine;
- QScriptValue result = myEngine.evaluate(formula);
- if (result.isNumber()) {
- QString t = SKGServices::doubleToString(result.toNumber());
- quantityItem->setText(t);
- }
- }
- }
- }
+ refreshSubOperationAmount();
}
// This code put the remaining quantity on the all sub operations with the same \
ratios ^^^ @@ -2258,13 +2277,15 @@ void SKGOperationPluginWidget::onQuantityChanged()
QTableWidgetItem* remainingQuantityItem = \
ui.kSubOperationsTable->item(nbSubOperations - 1, \
m_attributesForSplit.indexOf(QStringLiteral("f_value"))); if (remainingQuantityItem) \
{ // 348490 vvv
- double remain = SKGServices::stringToDouble(remainingQuantityItem->text()) + \
getRemainingQuantity(); + double remain = \
remainingQuantityItem->data(101).toDouble() + getRemainingQuantity(); if \
(qAbs(remain) < 1e-10) { onRemoveSubOperation(nbSubOperations - 1);
} else {
- QString t = SKGServices::doubleToString(remain);
- remainingQuantityItem->setText(t);
- remainingQuantityItem->setToolTip(t);
+ auto unit = ui.kUnitEdit->getUnit().getUnitInfo();
+ unit.Value = 1.0;
+ remainingQuantityItem->setText(getDocument()->formatMoney(remain, unit, \
false)); + remainingQuantityItem->setData(101, remain);
+ remainingQuantityItem->setToolTip(SKGServices::doubleToString(remain));
}
// 348490 ^^^
}
@@ -2277,19 +2298,20 @@ void SKGOperationPluginWidget::onSubopCellChanged(int row, \
int column)
QTableWidgetItem* subop_cell = ui.kSubOperationsTable->item(row, column);
QBrush base_brush = ui.kSubOperationsTable->item(row, 0)->foreground();
- int nbSubOperations = ui.kSubOperationsTable->rowCount();
if (column == m_attributesForSplit.indexOf(QStringLiteral("f_value"))) {
// If the quantity in the last line is edited, we add a new
// line with the new remaining quantity
- addSubOperationLine(nbSubOperations, ui.kDateEdit->date(), \
QStringLiteral(""), QStringLiteral(""), QStringLiteral(""), 0, \
QStringLiteral(""));
- }
- if (column == m_attributesForSplit.indexOf(QStringLiteral("f_value"))) {
- if (subop_cell->text().toDouble() != 0) {
+ addSubOperationLine(ui.kSubOperationsTable->rowCount(), \
ui.kDateEdit->date(), QStringLiteral(""), + \
QStringLiteral(""), QStringLiteral(""), 0, QStringLiteral("")); +
+ if (subop_cell->data(101).toDouble() != 0) {
onQuantityChanged();
} else {
base_brush = \
KColorScheme(QPalette::Normal).foreground(KColorScheme::NegativeText); }
subop_cell->setForeground(base_brush);
+
+ refreshSubOperationAmount();
}
}
@@ -2550,10 +2572,12 @@ void SKGOperationPluginWidget::addSubOperationLine(int row, \
const QDate date, co
ui.kSubOperationsTable->setItem(row, \
m_attributesForSplit.indexOf(QStringLiteral("t_comment")), commentItem);
// Quantity
- QString t = SKGServices::doubleToString(quantity);
- auto quantityItem = new QTableWidgetItem(t);
+ auto unit = ui.kUnitEdit->getUnit().getUnitInfo();
+ unit.Value = 1.0;
+ auto quantityItem = new QTableWidgetItem(getDocument()->formatMoney(quantity, \
unit, false)); quantityItem->setTextAlignment(Qt::AlignVCenter | Qt::AlignRight);
- quantityItem->setToolTip(formula.isEmpty() ? t : formula);
+ quantityItem->setData(101, quantity);
+ quantityItem->setToolTip(formula.isEmpty() ? \
SKGServices::doubleToString(quantity) : formula);
ui.kSubOperationsTable->setItem(row, \
m_attributesForSplit.indexOf(QStringLiteral("f_value")), quantityItem);
// Refund
diff --git a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h \
b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h index f503d4e..92eee57 \
100644
--- a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
+++ b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
@@ -137,6 +137,7 @@ private Q_SLOTS:
void onAutoPoint();
void onAddFakeOperation();
void onFreeze();
+ void refreshSubOperationAmount();
void cleanEditor();
void displaySelectionAmount();
void displayReconciliationInfo();
diff --git a/plugins/skrooge/skrooge_operation/skgsplittabledelegate.cpp \
b/plugins/skrooge/skrooge_operation/skgsplittabledelegate.cpp index 80dc7bc..02a7c68 \
100644
--- a/plugins/skrooge/skrooge_operation/skgsplittabledelegate.cpp
+++ b/plugins/skrooge/skrooge_operation/skgsplittabledelegate.cpp
@@ -132,10 +132,10 @@ void SKGSplitTableDelegate::setModelData(QWidget* editor, \
QAbstractItemModel* mo if (calculator && model) {
QString f = calculator->formula();
QString t = SKGServices::doubleToString(calculator->value());
- if (f.isEmpty()) {
- f = t;
- }
+ bool previous = model->blockSignals(true);
model->setData(index, f, Qt::ToolTipRole);
+ model->setData(index, calculator->value(), 101);
+ model->blockSignals(previous);
model->setData(index, t, Qt::DisplayRole);
}
} else if (index.column() == m_listAttributes.indexOf(QStringLiteral("d_date"))) \
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic