Save summary chart settings in config

This commit is contained in:
GriffinR 2024-08-23 16:00:42 -04:00
parent 6f74909a3c
commit 2ec9012c07
4 changed files with 45 additions and 3 deletions

View file

@ -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<QUrl, QDateTime> rateLimitTimes;
QByteArray wildMonChartGeometry;
protected:
virtual QString getConfigFilepath() override;

View file

@ -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();

View file

@ -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<QString, QString> 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<QString, QString> 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));

View file

@ -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);
}