diff --git a/include/ui/wildmonchart.h b/include/ui/wildmonchart.h index 07ea7b7b..a7c56a47 100644 --- a/include/ui/wildmonchart.h +++ b/include/ui/wildmonchart.h @@ -67,7 +67,7 @@ private: void applySpeciesColors(const QList &); QChart::ChartTheme currentTheme() const; void updateTheme(); - void stopChartAnimation(QChart*); + void limitChartAnimation(QChart*); void showHelpDialog(); }; diff --git a/src/ui/wildmonchart.cpp b/src/ui/wildmonchart.cpp index dfdda38d..011dc326 100644 --- a/src/ui/wildmonchart.cpp +++ b/src/ui/wildmonchart.cpp @@ -2,10 +2,6 @@ #include "ui_wildmonchart.h" #include "config.h" -#include "log.h" - -// TODO: Draw species icons below legend icons? - static const QString baseWindowTitle = QString("Wild Pokémon Summary Charts"); static const QList> themes = { @@ -48,8 +44,7 @@ WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) : porymapConfig.wildMonChartTheme = ui->comboBox_Theme->currentText(); } - // TODO: Re-enable once finished - //restoreGeometry(porymapConfig.wildMonChartGeometry); + restoreGeometry(porymapConfig.wildMonChartGeometry); setTable(table); }; @@ -158,25 +153,36 @@ void WildMonChart::readTable() { } void WildMonChart::refresh() { + const QSignalBlocker blocker1(ui->comboBox_Species); + const QSignalBlocker blocker2(ui->comboBox_Group); + const QString oldSpecies = ui->comboBox_Species->currentText(); + const QString oldGroup = ui->comboBox_Group->currentText(); + readTable(); + + // If the old UI settings are still valid we should restore them + int index = ui->comboBox_Species->findText(oldSpecies); + if (index >= 0) ui->comboBox_Species->setCurrentIndex(index); + + index = ui->comboBox_Group->findText(oldGroup); + if (index >= 0) ui->comboBox_Group->setCurrentIndex(index); + refreshSpeciesDistributionChart(); refreshLevelDistributionChart(); - - // Turn off the animation once it's played, otherwise it replays any time the window changes size. - // TODO: Store timer, disable if closing or creating new chart - //QTimer::singleShot(chart->animationDuration() + 500, this, &WildMonChart::stopChartAnimation); } void WildMonChart::refreshSpeciesDistributionChart() { if (ui->chartView_SpeciesDistribution->chart()) ui->chartView_SpeciesDistribution->chart()->deleteLater(); ui->chartView_SpeciesDistribution->setChart(createSpeciesDistributionChart()); + limitChartAnimation(ui->chartView_SpeciesDistribution->chart()); } void WildMonChart::refreshLevelDistributionChart() { if (ui->chartView_LevelDistribution->chart()) ui->chartView_LevelDistribution->chart()->deleteLater(); ui->chartView_LevelDistribution->setChart(createLevelDistributionChart()); + limitChartAnimation(ui->chartView_LevelDistribution->chart()); } QStringList WildMonChart::getSpeciesNamesAlphabetical() const { @@ -401,18 +407,36 @@ void WildMonChart::applySpeciesColors(const QList &barSets) { set->setColor(this->speciesToColor.value(set->label())); } -void WildMonChart::stopChartAnimation(QChart *chart) { - if (!chart) - return; - chart->setAnimationOptions(QChart::NoAnimation); +// Turn off the animation once it's played, otherwise it replays any time the window changes size. +void WildMonChart::limitChartAnimation(QChart *chart) { + // Chart may be destroyed before the animation finishes + QPointer safeChart = chart; + + // QChart has no signal for when the animation is finished, so we use a timer to stop the animation. + // It is technically possible to get the chart to freeze mid-animation by resizing the window after + // the timer starts but before it finishes, but 1. animations are short so this is difficult to do, + // and 2. the issue resolves if the window is resized afterwards, so it's probably fine. + QTimer::singleShot(chart->animationDuration() + 500, [safeChart] { + if (safeChart) safeChart->setAnimationOptions(QChart::NoAnimation); + }); } void WildMonChart::showHelpDialog() { static const QString text = "This window provides some visualizations of the data in your current Wild Pokémon tab"; - static const QString informative = "The Species Distribution tab shows the cumulative encounter chance for each species " - "in the table. In other words, it answers the question \"For a given encounter of this type, " - "what is the likelihood that the pokémon encountered will be of that species?\"

" - "The Level Distribution tab..."; // TODO + static const QString informative = + "The Species Distribution tab shows the cumulative encounter chance for each species " + "in the table. In other words, it answers the question \"What is the likelihood of encountering " + "each species in a single encounter?\"" + "

" + "The Level Distribution tab shows the chance of encountering each species at a particular level. " + "In the top left under Group you can select which encounter group to show data for. " + "In the top right under Species you can select which species to show data for. " + "

" + "Individual Mode on the Level Distribution tab toggles whether data is shown for all species in the table. " + "The percentages will update to reflect whether you're showing all species or just that individual species. " + "In other words, while Individual Mode is checked the chart is answering the question \"If a species x " + "is encountered, what is the likelihood that it will be level y\", and while Individual Mode is not checked, " + "it answers the question \"For a single encounter, what is the likelihood of encountering a species x at level y.\""; QMessageBox msgBox(QMessageBox::Information, "porymap", text, QMessageBox::Close, this); msgBox.setTextFormat(Qt::RichText); msgBox.setInformativeText(informative);