The calculation of how many harvest shares are expected in total.
This commit is contained in:
@ -16,14 +16,23 @@ SummaryWidget::SummaryWidget(std::shared_ptr<ModelSummary> modelSummary, QWidget
|
|||||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
/// monthly need
|
/// monthly need
|
||||||
QHBoxLayout* footerLayout = new QHBoxLayout();
|
QHBoxLayout* footerLayout = new QHBoxLayout();
|
||||||
|
|
||||||
|
QLabel* nTotalSharesLabel = new QLabel("Erwartete Ernteanteile:");
|
||||||
|
const qreal expectedShares = m_modelSummary->nTotalExpectedShares();
|
||||||
|
m_nTotalExpectedShares = new QLabel(QString::number(expectedShares));
|
||||||
|
|
||||||
QLabel* financialNeedLabel = new QLabel("monatlicher Finanzbedarf:");
|
QLabel* financialNeedLabel = new QLabel("monatlicher Finanzbedarf:");
|
||||||
m_financialNeedBox = new QSpinBox();
|
m_financialNeedBox = new QSpinBox();
|
||||||
m_financialNeedBox->setMaximum(50000);
|
m_financialNeedBox->setMaximum(50000);
|
||||||
m_financialNeedBox->setValue(m_financialNeed);
|
m_financialNeedBox->setValue(m_financialNeed);
|
||||||
|
|
||||||
connect(m_financialNeedBox, &QSpinBox::valueChanged, this,
|
connect(m_financialNeedBox, &QSpinBox::valueChanged, this,
|
||||||
&SummaryWidget::onFinancialNeedChanged);
|
&SummaryWidget::onFinancialNeedChanged);
|
||||||
|
|
||||||
|
footerLayout->addWidget(nTotalSharesLabel);
|
||||||
|
footerLayout->addWidget(m_nTotalExpectedShares);
|
||||||
|
footerLayout->addStretch(1);
|
||||||
footerLayout->addWidget(financialNeedLabel);
|
footerLayout->addWidget(financialNeedLabel);
|
||||||
footerLayout->addWidget(m_financialNeedBox);
|
footerLayout->addWidget(m_financialNeedBox);
|
||||||
footerLayout->addStretch(1);
|
footerLayout->addStretch(1);
|
||||||
@ -50,6 +59,11 @@ void SummaryWidget::onNExpectedBiddingChanged(int newNExpected) {
|
|||||||
m_biddingStatus3->onExpectedBiddingsChanged(newNExpected);
|
m_biddingStatus3->onExpectedBiddingsChanged(newNExpected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SummaryWidget::onNTotalExpectedSharesChanged(qreal newNExpected) {
|
||||||
|
const QString expectedSharesString = QString::number(newNExpected);
|
||||||
|
m_nTotalExpectedShares->setText(expectedSharesString);
|
||||||
|
}
|
||||||
|
|
||||||
void SummaryWidget::onNPlacedBiddingsChanged(const int roundNumber) {
|
void SummaryWidget::onNPlacedBiddingsChanged(const int roundNumber) {
|
||||||
switch (roundNumber) {
|
switch (roundNumber) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -140,6 +154,9 @@ void SummaryWidget::setupConnections() {
|
|||||||
// "bindProperty(&bindable, &signal, &getter, widget)"
|
// "bindProperty(&bindable, &signal, &getter, widget)"
|
||||||
QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged,
|
QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged,
|
||||||
[&]() { onNExpectedBiddingChanged(m_modelSummary->nExpectedBiddings()); });
|
[&]() { onNExpectedBiddingChanged(m_modelSummary->nExpectedBiddings()); });
|
||||||
|
QObject::connect(m_modelSummary.get(), &ModelSummary::nTotalExpectedSharesChanged, this, [&]() {
|
||||||
|
onNTotalExpectedSharesChanged(m_modelSummary->nTotalExpectedShares());
|
||||||
|
});
|
||||||
QObject::connect(m_modelSummary.get(), &ModelSummary::nPlacedBiddingsChanged, this,
|
QObject::connect(m_modelSummary.get(), &ModelSummary::nPlacedBiddingsChanged, this,
|
||||||
&SummaryWidget::onNPlacedBiddingsChanged);
|
&SummaryWidget::onNPlacedBiddingsChanged);
|
||||||
QObject::connect(m_modelSummary.get(), &ModelSummary::biddingSumChanged, this,
|
QObject::connect(m_modelSummary.get(), &ModelSummary::biddingSumChanged, this,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ class SummaryWidget : public QWidget {
|
|||||||
private slots:
|
private slots:
|
||||||
void onFinancialNeedChanged(int newFinancialNeed);
|
void onFinancialNeedChanged(int newFinancialNeed);
|
||||||
void onNExpectedBiddingChanged(int newNExpected);
|
void onNExpectedBiddingChanged(int newNExpected);
|
||||||
|
void onNTotalExpectedSharesChanged(qreal newNExpected);
|
||||||
|
|
||||||
void onNPlacedBiddingsChanged(const int roundNumber);
|
void onNPlacedBiddingsChanged(const int roundNumber);
|
||||||
void onBiddingSumChanged(const int roundNumber);
|
void onBiddingSumChanged(const int roundNumber);
|
||||||
@ -31,8 +32,9 @@ class SummaryWidget : public QWidget {
|
|||||||
std::unique_ptr<BiddingRoundStatusWidget> m_biddingStatus3;
|
std::unique_ptr<BiddingRoundStatusWidget> m_biddingStatus3;
|
||||||
|
|
||||||
// TODO read from settings (maybe via model/core; maybe set in constructor)
|
// TODO read from settings (maybe via model/core; maybe set in constructor)
|
||||||
const int m_financialNeed = 13942;
|
const int m_financialNeed = 13942;
|
||||||
QSpinBox* m_financialNeedBox = nullptr;
|
QSpinBox* m_financialNeedBox = nullptr;
|
||||||
|
QLabel* m_nTotalExpectedShares = nullptr;
|
||||||
|
|
||||||
QLabel* m_rowCountValueLabel;
|
QLabel* m_rowCountValueLabel;
|
||||||
QLabel* m_nExpectedBiddingsValueLabel;
|
QLabel* m_nExpectedBiddingsValueLabel;
|
||||||
|
|||||||
@ -10,6 +10,8 @@ ModelSummary::ModelSummary(std::shared_ptr<TableModel> model, QObject* parent)
|
|||||||
// TODO ? use existing model signals (dataChanged(role),...) instead of special signals
|
// TODO ? use existing model signals (dataChanged(role),...) instead of special signals
|
||||||
connect(m_model.get(), &TableModel::nExpectedBiddingsChanged, this,
|
connect(m_model.get(), &TableModel::nExpectedBiddingsChanged, this,
|
||||||
&ModelSummary::nExpectedBiddingsChanged);
|
&ModelSummary::nExpectedBiddingsChanged);
|
||||||
|
connect(m_model.get(), &TableModel::nTotalExpectedSharesChanged, this,
|
||||||
|
&ModelSummary::nTotalExpectedSharesChanged);
|
||||||
connect(m_model.get(), &TableModel::nPlacedBiddingsChanged, this,
|
connect(m_model.get(), &TableModel::nPlacedBiddingsChanged, this,
|
||||||
&ModelSummary::nPlacedBiddingsChanged);
|
&ModelSummary::nPlacedBiddingsChanged);
|
||||||
connect(m_model.get(), &TableModel::biddingSumChanged, this, &ModelSummary::biddingSumChanged);
|
connect(m_model.get(), &TableModel::biddingSumChanged, this, &ModelSummary::biddingSumChanged);
|
||||||
@ -29,6 +31,8 @@ QBindable<int> ModelSummary::bindableRowCount() {
|
|||||||
return &m_rowCount;
|
return &m_rowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal ModelSummary::nTotalExpectedShares() const { return m_model->nTotalExpectedShares(); }
|
||||||
|
|
||||||
int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); }
|
int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); }
|
||||||
|
|
||||||
int ModelSummary::nPlacedBiddings1() const { return m_model->nPlacedBiddings1(); }
|
int ModelSummary::nPlacedBiddings1() const { return m_model->nPlacedBiddings1(); }
|
||||||
|
|||||||
@ -19,6 +19,8 @@ class ModelSummary : public QObject {
|
|||||||
|
|
||||||
int rowCount() const;
|
int rowCount() const;
|
||||||
QBindable<int> bindableRowCount();
|
QBindable<int> bindableRowCount();
|
||||||
|
|
||||||
|
qreal nTotalExpectedShares() const;
|
||||||
int nExpectedBiddings() const;
|
int nExpectedBiddings() const;
|
||||||
int nPlacedBiddings1() const;
|
int nPlacedBiddings1() const;
|
||||||
int nPlacedBiddings2() const;
|
int nPlacedBiddings2() const;
|
||||||
@ -36,6 +38,7 @@ class ModelSummary : public QObject {
|
|||||||
void rowCountChanged();
|
void rowCountChanged();
|
||||||
|
|
||||||
void nExpectedBiddingsChanged();
|
void nExpectedBiddingsChanged();
|
||||||
|
void nTotalExpectedSharesChanged();
|
||||||
void nPlacedBiddingsChanged(const int roundNumber);
|
void nPlacedBiddingsChanged(const int roundNumber);
|
||||||
void biddingSumChanged(const int roundNumber);
|
void biddingSumChanged(const int roundNumber);
|
||||||
void biddingAverageChanged(const int roundNumber);
|
void biddingAverageChanged(const int roundNumber);
|
||||||
|
|||||||
@ -340,6 +340,30 @@ void TableModel::insertItems(int startPosition,
|
|||||||
m_undoStack->push(insertCommand);
|
m_undoStack->push(insertCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal TableModel::nTotalExpectedShares() const {
|
||||||
|
qreal result = 0;
|
||||||
|
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||||
|
/// if BiddingTypeRole is not empty
|
||||||
|
const QString biddingType = (*i)->data(BiddingTypeRole).toString();
|
||||||
|
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||||
|
if (biddingType.isEmpty() || shareAmount == 0.0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/// add amount
|
||||||
|
const QString shareType = (*i)->data(ShareTypeRole).toString();
|
||||||
|
if (shareType == "bezahlt") {
|
||||||
|
result += shareAmount;
|
||||||
|
} else if (shareType == "teils/teils") {
|
||||||
|
result += shareAmount / 2;
|
||||||
|
} else {
|
||||||
|
qInfo() << "Share type not 'bezahlt' nor 'teils/teils'. Will be ignored..";
|
||||||
|
qDebug() << "Share type:" << shareType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qInfo() << "Biddings expected for " << result << "shares!";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int TableModel::nExpectedBiddings() const {
|
int TableModel::nExpectedBiddings() const {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||||
@ -397,6 +421,7 @@ void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int las
|
|||||||
}
|
}
|
||||||
emit rowCountChanged();
|
emit rowCountChanged();
|
||||||
emit nExpectedBiddingsChanged();
|
emit nExpectedBiddingsChanged();
|
||||||
|
emit nTotalExpectedSharesChanged();
|
||||||
|
|
||||||
emit nPlacedBiddingsChanged(1);
|
emit nPlacedBiddingsChanged(1);
|
||||||
emit nPlacedBiddingsChanged(2);
|
emit nPlacedBiddingsChanged(2);
|
||||||
@ -449,6 +474,7 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
|||||||
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole) ||
|
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole) ||
|
||||||
roles.contains(ShareTypeRole)) {
|
roles.contains(ShareTypeRole)) {
|
||||||
emit nExpectedBiddingsChanged();
|
emit nExpectedBiddingsChanged();
|
||||||
|
emit nTotalExpectedSharesChanged();
|
||||||
}
|
}
|
||||||
if (roles.contains(ShareAmountRole) || roles.contains(ShareTypeRole)) {
|
if (roles.contains(ShareAmountRole) || roles.contains(ShareTypeRole)) {
|
||||||
emit nPlacedBiddingsChanged(1);
|
emit nPlacedBiddingsChanged(1);
|
||||||
|
|||||||
@ -63,6 +63,7 @@ class TableModel : public QAbstractTableModel {
|
|||||||
const QModelIndex& parentIndex = QModelIndex());
|
const QModelIndex& parentIndex = QModelIndex());
|
||||||
|
|
||||||
/// property functions
|
/// property functions
|
||||||
|
qreal nTotalExpectedShares() const;
|
||||||
int nExpectedBiddings() const;
|
int nExpectedBiddings() const;
|
||||||
int nPlacedBiddings1() const;
|
int nPlacedBiddings1() const;
|
||||||
int nPlacedBiddings2() const;
|
int nPlacedBiddings2() const;
|
||||||
@ -80,6 +81,7 @@ class TableModel : public QAbstractTableModel {
|
|||||||
void rowCountChanged();
|
void rowCountChanged();
|
||||||
|
|
||||||
void nExpectedBiddingsChanged();
|
void nExpectedBiddingsChanged();
|
||||||
|
void nTotalExpectedSharesChanged();
|
||||||
void nPlacedBiddingsChanged(const int roundNumber);
|
void nPlacedBiddingsChanged(const int roundNumber);
|
||||||
void biddingSumChanged(const int roundNumber);
|
void biddingSumChanged(const int roundNumber);
|
||||||
void biddingAverageChanged(const int roundNumber);
|
void biddingAverageChanged(const int roundNumber);
|
||||||
|
|||||||
@ -86,6 +86,13 @@ TEST_F(ModelTest, ExpectedPlacedBiddings) {
|
|||||||
ASSERT_EQ(expected, expectedPlacedBiddings);
|
ASSERT_EQ(expected, expectedPlacedBiddings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ModelTest, ExpectedTotalShareAmount) {
|
||||||
|
const int expected = 0;
|
||||||
|
const auto nTotalExpectedShares = model->nTotalExpectedShares();
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, nTotalExpectedShares);
|
||||||
|
}
|
||||||
|
|
||||||
/// model with data
|
/// model with data
|
||||||
|
|
||||||
TEST_F(ModelTestWithData, TestRowCount) {
|
TEST_F(ModelTestWithData, TestRowCount) {
|
||||||
@ -115,3 +122,10 @@ TEST_F(ModelTestWithData, PlacedBiddings1) {
|
|||||||
|
|
||||||
ASSERT_EQ(expected, actual);
|
ASSERT_EQ(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ModelTestWithData, NTotalExpectedShares) {
|
||||||
|
const qreal expected = 3;
|
||||||
|
const auto actual = model->nTotalExpectedShares();
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, actual);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user