From 2ec9012c07a6c6ede53f9e694eda96b8de43bf0c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 23 Aug 2024 16:00:42 -0400 Subject: [PATCH] Save summary chart settings in config --- include/config.h | 3 +++ include/ui/wildmonchart.h | 2 ++ src/config.cpp | 6 ++++++ src/ui/wildmonchart.cpp | 37 ++++++++++++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/config.h b/include/config.h index bf80ecb1..0e5e0acb 100644 --- a/include/config.h +++ b/include/config.h @@ -72,6 +72,7 @@ public: this->monitorFiles = true; this->tilesetCheckerboardFill = true; this->theme = "default"; + this->wildMonChartTheme = ""; this->textEditorOpenFolder = ""; this->textEditorGotoLine = ""; this->paletteEditorBitDepth = 24; @@ -117,6 +118,7 @@ public: bool monitorFiles; bool tilesetCheckerboardFill; QString theme; + QString wildMonChartTheme; QString textEditorOpenFolder; QString textEditorGotoLine; int paletteEditorBitDepth; @@ -126,6 +128,7 @@ public: QDateTime lastUpdateCheckTime; QVersionNumber lastUpdateCheckVersion; QMap rateLimitTimes; + QByteArray wildMonChartGeometry; protected: virtual QString getConfigFilepath() override; diff --git a/include/ui/wildmonchart.h b/include/ui/wildmonchart.h index 4de8d159..58371219 100644 --- a/include/ui/wildmonchart.h +++ b/include/ui/wildmonchart.h @@ -17,6 +17,8 @@ public: explicit WildMonChart(QWidget *parent, const EncounterTableModel *table); ~WildMonChart(); + virtual void closeEvent(QCloseEvent *event) override; + public slots: void setTable(const EncounterTableModel *table); void createCharts(); diff --git a/src/config.cpp b/src/config.cpp index fae8bac7..8335126f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -354,6 +354,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->customScriptsEditorGeometry = bytesFromString(value); } else if (key == "custom_scripts_editor_state") { this->customScriptsEditorState = bytesFromString(value); + } else if (key == "wild_mon_chart_geometry") { + this->wildMonChartGeometry = bytesFromString(value); } else if (key == "metatiles_zoom") { this->metatilesZoom = getConfigInteger(key, value, 10, 100, 30); } else if (key == "collision_zoom") { @@ -380,6 +382,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->tilesetCheckerboardFill = getConfigBool(key, value); } else if (key == "theme") { this->theme = value; + } else if (key == "wild_mon_chart_theme") { + this->wildMonChartTheme = value; } else if (key == "text_editor_open_directory") { this->textEditorOpenFolder = value; } else if (key == "text_editor_goto_line") { @@ -439,6 +443,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("project_settings_editor_state", stringFromByteArray(this->projectSettingsEditorState)); map.insert("custom_scripts_editor_geometry", stringFromByteArray(this->customScriptsEditorGeometry)); map.insert("custom_scripts_editor_state", stringFromByteArray(this->customScriptsEditorState)); + map.insert("wild_mon_chart_geometry", stringFromByteArray(this->wildMonChartGeometry)); map.insert("collision_opacity", QString::number(this->collisionOpacity)); map.insert("collision_zoom", QString::number(this->collisionZoom)); map.insert("metatiles_zoom", QString::number(this->metatilesZoom)); @@ -453,6 +458,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("monitor_files", this->monitorFiles ? "1" : "0"); map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0"); map.insert("theme", this->theme); + map.insert("wild_mon_chart_theme", this->wildMonChartTheme); map.insert("text_editor_open_directory", this->textEditorOpenFolder); map.insert("text_editor_goto_line", this->textEditorGotoLine); map.insert("palette_editor_bit_depth", QString::number(this->paletteEditorBitDepth)); diff --git a/src/ui/wildmonchart.cpp b/src/ui/wildmonchart.cpp index f2fd0afb..9c1a17d5 100644 --- a/src/ui/wildmonchart.cpp +++ b/src/ui/wildmonchart.cpp @@ -5,7 +5,6 @@ #include "log.h" // TODO: Draw species icons below legend icons? -// TODO: Save window size, theme selection in config // TODO: Help button that explains the charts static const QString baseWindowTitle = QString("Wild Pokémon Summary Charts"); @@ -39,6 +38,18 @@ WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) : ui->comboBox_Theme->addItem(i.first, i.second); connect(ui->comboBox_Theme, &QComboBox::currentTextChanged, this, &WildMonChart::updateTheme); + // User's theme choice is saved in the config + int configThemeIndex = ui->comboBox_Theme->findText(porymapConfig.wildMonChartTheme); + if (configThemeIndex >= 0) { + const QSignalBlocker blocker(ui->comboBox_Theme); + ui->comboBox_Theme->setCurrentIndex(configThemeIndex); + } else { + porymapConfig.wildMonChartTheme = ui->comboBox_Theme->currentText(); + } + + // TODO: Re-enable once finished + //restoreGeometry(porymapConfig.wildMonChartGeometry); + setTable(table); }; @@ -238,7 +249,8 @@ void WildMonChart::createSpeciesDistributionChart() { applySpeciesColors(series); - // TODO: Delete old chart + if (ui->chartView_SpeciesDistribution->chart()) + ui->chartView_SpeciesDistribution->chart()->deleteLater(); ui->chartView_SpeciesDistribution->setChart(chart); } @@ -265,6 +277,17 @@ QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, con QToolTip::showText(QCursor::pos(), text); }); + // Clicking on a bar set in the stacked chart opens its individual chart + if (!individual) { + connect(set, &QBarSet::clicked, [this, species](int) { + const QSignalBlocker blocker1(ui->groupBox_Species); + const QSignalBlocker blocker2(ui->comboBox_Species); + ui->groupBox_Species->setChecked(true); + ui->comboBox_Species->setCurrentText(species); + createLevelDistributionChart(); + }); + } + return set; } @@ -336,7 +359,9 @@ void WildMonChart::createLevelDistributionChart() { applySpeciesColors(series); } - // TODO: Cache old chart + // TODO: Cache old charts? + if (ui->chartView_LevelDistribution->chart()) + ui->chartView_LevelDistribution->chart()->deleteLater(); ui->chartView_LevelDistribution->setChart(chart); } @@ -346,6 +371,7 @@ QChart::ChartTheme WildMonChart::currentTheme() const { void WildMonChart::updateTheme() { auto theme = currentTheme(); + porymapConfig.wildMonChartTheme = ui->comboBox_Theme->currentText(); // In order to keep the color of each species in the legend consistent across // charts we save species->color mappings. The legend colors are overwritten @@ -381,3 +407,8 @@ void WildMonChart::stopChartAnimation() { if (ui->chartView_SpeciesDistribution->chart()) ui->chartView_SpeciesDistribution->chart()->setAnimationOptions(QChart::NoAnimation); } + +void WildMonChart::closeEvent(QCloseEvent *event) { + porymapConfig.wildMonChartGeometry = saveGeometry(); + QWidget::closeEvent(event); +}