Migrated old visualization of the bidding round statuses with donut charts from the legacy BeetRound project.
This commit is contained in:
110
UIs/BeetRoundWidgets/widgets/biddingroundstatuswidget.cpp
Normal file
110
UIs/BeetRoundWidgets/widgets/biddingroundstatuswidget.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include "biddingroundstatuswidget.h"
|
||||
|
||||
#include <QChartView>
|
||||
#include <QLabel>
|
||||
#include <QPieSeries>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
BiddingRoundStatusWidget::BiddingRoundStatusWidget(const QString& title,
|
||||
const int placedBiddings,
|
||||
const int expectedBiddings,
|
||||
const int financialNeed,
|
||||
const int currentSum,
|
||||
const qreal currentAverage,
|
||||
QWidget* parent)
|
||||
: QWidget{parent}
|
||||
, m_title(title)
|
||||
, m_financialNeed(financialNeed)
|
||||
, m_currentSum(currentSum) {
|
||||
m_moneyDonutSeries = new QPieSeries();
|
||||
m_moneyDonutSeries->setHoleSize(0.35);
|
||||
const QString sumText = QString("Summe: %1 €").arg(currentSum);
|
||||
m_sumSlice = m_moneyDonutSeries->append(sumText, currentSum);
|
||||
m_sumSlice->setLabelVisible();
|
||||
|
||||
const int currentGap = m_financialNeed - currentSum;
|
||||
const QString gapText = QString("offen: %1 €").arg(currentGap);
|
||||
m_gapSlice = m_moneyDonutSeries->append(gapText, currentGap);
|
||||
m_gapSlice->setLabelVisible();
|
||||
|
||||
m_chartView = new QChartView();
|
||||
m_chartView->setMinimumWidth(100);
|
||||
// m_chartView->setMaximumWidth(500);
|
||||
m_chartView->setRenderHint(QPainter::Antialiasing);
|
||||
m_chartView->chart()->setTitle(m_title);
|
||||
m_chartView->chart()->addSeries(m_moneyDonutSeries);
|
||||
m_chartView->chart()->legend()->setAlignment(Qt::AlignBottom);
|
||||
m_chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean);
|
||||
m_chartView->chart()->legend()->setFont(QFont("Arial", 8));
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->addWidget(m_chartView, 5);
|
||||
QBoxLayout* progressLayout = createProgressLayout(placedBiddings, expectedBiddings);
|
||||
layout->addLayout(progressLayout);
|
||||
|
||||
/// bidding average
|
||||
QHBoxLayout* averageLayout = new QHBoxLayout();
|
||||
m_biddingAverageDescription = new QLabel("Durchschnittsgebot: ");
|
||||
const QString currencyString = createCurrencyString(currentAverage);
|
||||
m_biddingAverageValue = new QLabel(currencyString);
|
||||
averageLayout->addWidget(m_biddingAverageDescription);
|
||||
averageLayout->addWidget(m_biddingAverageValue);
|
||||
layout->addLayout(averageLayout);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::onExpectedBiddingsChanged(const int nExpected) {
|
||||
m_biddingRoundProgress->setExpectedBiddings(nExpected);
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::onNPlacedBiddingsChanged(const int nPlaced) {
|
||||
m_biddingRoundProgress->setCurrentBiddings(nPlaced);
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::onBiddingSumChanged(const int sum) {
|
||||
m_currentSum = sum;
|
||||
updateDonutChart();
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::onBiddingAverageChanged(const qreal average) {
|
||||
if (m_biddingAverageValue) {
|
||||
m_biddingAverageValue->setText(createCurrencyString(average));
|
||||
}
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::onFinancialNeedChanged(const int financialNeed) {
|
||||
m_financialNeed = financialNeed;
|
||||
updateDonutChart();
|
||||
}
|
||||
|
||||
QBoxLayout* BiddingRoundStatusWidget::createProgressLayout(const int nPlaced, const int nExpected) {
|
||||
QVBoxLayout* progressLayout = new QVBoxLayout();
|
||||
|
||||
m_biddingRoundProgress = new BiddingRoundProgressLayout(nPlaced, nExpected);
|
||||
progressLayout->addLayout(m_biddingRoundProgress);
|
||||
|
||||
return progressLayout;
|
||||
}
|
||||
|
||||
void BiddingRoundStatusWidget::updateDonutChart() {
|
||||
int currentGap;
|
||||
if (m_currentSum < m_financialNeed) {
|
||||
currentGap = m_financialNeed - m_currentSum;
|
||||
} else {
|
||||
currentGap = 0;
|
||||
}
|
||||
const QString sumText = QString("Summe: %1 €").arg(m_currentSum);
|
||||
m_sumSlice->setValue(m_currentSum);
|
||||
m_sumSlice->setLabel(sumText);
|
||||
|
||||
const QString gapText = QString("offen: %1 €").arg(currentGap);
|
||||
m_gapSlice->setValue(currentGap);
|
||||
m_gapSlice->setLabel(gapText);
|
||||
const bool gapLabelVisible = currentGap != 0;
|
||||
m_gapSlice->setLabelVisible(gapLabelVisible);
|
||||
}
|
||||
|
||||
QString BiddingRoundStatusWidget::createCurrencyString(const qreal value) const {
|
||||
return QString::number(value) + " €";
|
||||
}
|
||||
Reference in New Issue
Block a user