Connect wild mon chart to editor

This commit is contained in:
GriffinR 2024-08-26 23:53:08 -04:00
parent dba3e524b3
commit d8d196b79d
9 changed files with 139 additions and 97 deletions

View file

@ -26,6 +26,7 @@
#include "movablerect.h" #include "movablerect.h"
#include "cursortilerect.h" #include "cursortilerect.h"
#include "mapruler.h" #include "mapruler.h"
#include "encountertablemodel.h"
class DraggablePixmapItem; class DraggablePixmapItem;
class MetatilesPixmapItem; class MetatilesPixmapItem;
@ -84,7 +85,7 @@ public:
void removeSelectedConnection(); void removeSelectedConnection();
void addNewWildMonGroup(QWidget *window); void addNewWildMonGroup(QWidget *window);
void deleteWildMonGroup(); void deleteWildMonGroup();
QTableView* getCurrentWildMonTable(); EncounterTableModel* getCurrentWildMonTable();
void updateDiveMap(QString mapName); void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName); void updateEmergeMap(QString mapName);
void setSelectedConnection(MapConnection *connection); void setSelectedConnection(MapConnection *connection);
@ -224,7 +225,9 @@ private slots:
signals: signals:
void objectsChanged(); void objectsChanged();
void openConnectedMap(MapConnection*); void openConnectedMap(MapConnection*);
void wildMonDataChanged(); void wildMonTableOpened(EncounterTableModel*);
void wildMonTableClosed();
void wildMonTableEdited();
void warpEventDoubleClicked(QString, int, Event::Group); void warpEventDoubleClicked(QString, int, Event::Group);
void currentMetatilesSelectionChanged(); void currentMetatilesSelectionChanged();
void mapRulerStatusChanged(const QString &); void mapRulerStatusChanged(const QString &);

View file

@ -183,7 +183,6 @@ private slots:
void onOpenConnectedMap(MapConnection*); void onOpenConnectedMap(MapConnection*);
void onMapNeedsRedrawing(); void onMapNeedsRedrawing();
void onTilesetsSaved(QString, QString); void onTilesetsSaved(QString, QString);
void onWildMonDataChanged();
void openNewMapPopupWindow(); void openNewMapPopupWindow();
void onNewMapCreated(); void onNewMapCreated();
void onMapCacheCleared(); void onMapCacheCleared();

View file

@ -21,7 +21,8 @@ public:
public slots: public slots:
void setTable(const EncounterTableModel *table); void setTable(const EncounterTableModel *table);
void createCharts(); void clearTable();
void refresh();
private: private:
Ui::WildMonChart *ui; Ui::WildMonChart *ui;
@ -56,15 +57,17 @@ private:
void clearTableData(); void clearTableData();
void readTable(); void readTable();
void createSpeciesDistributionChart(); QChart* createSpeciesDistributionChart();
void createLevelDistributionChart(); QChart* createLevelDistributionChart();
QBarSet* createLevelDistributionBarSet(const QString &, const QString &, bool); QBarSet* createLevelDistributionBarSet(const QString &, const QString &, bool);
void refreshSpeciesDistributionChart();
void refreshLevelDistributionChart();
void saveSpeciesColors(const QList<QBarSet*> &); void saveSpeciesColors(const QList<QBarSet*> &);
void applySpeciesColors(const QList<QBarSet*> &); void applySpeciesColors(const QList<QBarSet*> &);
QChart::ChartTheme currentTheme() const; QChart::ChartTheme currentTheme() const;
void updateTheme(); void updateTheme();
void stopChartAnimation(); void stopChartAnimation(QChart*);
void showHelpDialog(); void showHelpDialog();
}; };

View file

@ -7,7 +7,6 @@
#include "mapsceneeventfilter.h" #include "mapsceneeventfilter.h"
#include "metatile.h" #include "metatile.h"
#include "montabwidget.h" #include "montabwidget.h"
#include "encountertablemodel.h"
#include "editcommands.h" #include "editcommands.h"
#include "config.h" #include "config.h"
#include "scripting.h" #include "scripting.h"
@ -43,6 +42,11 @@ Editor::Editor(Ui::MainWindow* ui)
selectNewEvents = false; selectNewEvents = false;
} }
}); });
// Send signals used for updating the wild pokemon summary chart
connect(ui->stackedWidget_WildMons, &QStackedWidget::currentChanged, [this] {
emit wildMonTableOpened(getCurrentWildMonTable());
});
} }
Editor::~Editor() Editor::~Editor()
@ -79,9 +83,7 @@ void Editor::saveUiFields() {
} }
void Editor::setProject(Project * project) { void Editor::setProject(Project * project) {
if (this->project) { closeProject();
closeProject();
}
this->project = project; this->project = project;
MapConnection::project = project; MapConnection::project = project;
} }
@ -194,6 +196,7 @@ void Editor::setEditingConnections() {
void Editor::clearWildMonTables() { void Editor::clearWildMonTables() {
QStackedWidget *stack = ui->stackedWidget_WildMons; QStackedWidget *stack = ui->stackedWidget_WildMons;
const QSignalBlocker blocker(stack);
// delete widgets from previous map data if they exist // delete widgets from previous map data if they exist
while (stack->count()) { while (stack->count()) {
@ -203,6 +206,7 @@ void Editor::clearWildMonTables() {
} }
ui->comboBox_EncounterGroupLabel->clear(); ui->comboBox_EncounterGroupLabel->clear();
emit wildMonTableClosed();
} }
void Editor::displayWildMonTables() { void Editor::displayWildMonTables() {
@ -243,8 +247,12 @@ void Editor::displayWildMonTables() {
} }
tabIndex++; tabIndex++;
} }
connect(tabWidget, &MonTabWidget::currentChanged, [this] {
emit wildMonTableOpened(getCurrentWildMonTable());
});
} }
stack->setCurrentIndex(0); stack->setCurrentIndex(0);
emit wildMonTableOpened(getCurrentWildMonTable());
} }
void Editor::addNewWildMonGroup(QWidget *window) { void Editor::addNewWildMonGroup(QWidget *window) {
@ -359,7 +367,7 @@ void Editor::addNewWildMonGroup(QWidget *window) {
tabIndex++; tabIndex++;
} }
saveEncounterTabData(); saveEncounterTabData();
emit wildMonDataChanged(); emit wildMonTableEdited();
} }
} }
@ -397,7 +405,8 @@ void Editor::deleteWildMonGroup() {
project->encounterGroupLabels.remove(i); project->encounterGroupLabels.remove(i);
displayWildMonTables(); displayWildMonTables();
emit wildMonDataChanged(); saveEncounterTabData();
emit wildMonTableEdited();
} }
} }
@ -650,7 +659,8 @@ void Editor::configureEncounterJSON(QWidget *window) {
// Re-draw the tab accordingly. // Re-draw the tab accordingly.
displayWildMonTables(); displayWildMonTables();
emit wildMonDataChanged(); saveEncounterTabData();
emit wildMonTableEdited();
} }
} }
@ -684,10 +694,14 @@ void Editor::saveEncounterTabData() {
} }
} }
QTableView* Editor::getCurrentWildMonTable() { EncounterTableModel* Editor::getCurrentWildMonTable() {
QStackedWidget *stack = ui->stackedWidget_WildMons; auto tabWidget = static_cast<MonTabWidget*>(ui->stackedWidget_WildMons->currentWidget());
auto tabWidget = static_cast<MonTabWidget *>(stack->widget(stack->currentIndex())); if (!tabWidget) return nullptr;
return tabWidget->tableAt(tabWidget->currentIndex());
auto tableView = tabWidget->tableAt(tabWidget->currentIndex());
if (!tableView) return nullptr;
return static_cast<EncounterTableModel*>(tableView->model());
} }
void Editor::updateEncounterFields(EncounterFields newFields) { void Editor::updateEncounterFields(EncounterFields newFields) {

View file

@ -239,10 +239,8 @@ void MainWindow::initExtraSignals() {
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged); connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
// Change pages on wild encounter groups // Change pages on wild encounter groups
QStackedWidget *stack = ui->stackedWidget_WildMons; connect(ui->comboBox_EncounterGroupLabel, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index){
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; ui->stackedWidget_WildMons->setCurrentIndex(index);
connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
stack->setCurrentIndex(index);
}); });
// Convert the layout of the map tools' frame into an adjustable FlowLayout // Convert the layout of the map tools' frame into an adjustable FlowLayout
@ -309,7 +307,7 @@ void MainWindow::initEditor() {
connect(this->editor, &Editor::openConnectedMap, this, &MainWindow::onOpenConnectedMap); connect(this->editor, &Editor::openConnectedMap, this, &MainWindow::onOpenConnectedMap);
connect(this->editor, &Editor::warpEventDoubleClicked, this, &MainWindow::openWarpMap); connect(this->editor, &Editor::warpEventDoubleClicked, this, &MainWindow::openWarpMap);
connect(this->editor, &Editor::currentMetatilesSelectionChanged, this, &MainWindow::currentMetatilesSelectionChanged); connect(this->editor, &Editor::currentMetatilesSelectionChanged, this, &MainWindow::currentMetatilesSelectionChanged);
connect(this->editor, &Editor::wildMonDataChanged, this, &MainWindow::onWildMonDataChanged); connect(this->editor, &Editor::wildMonTableEdited, [this] { this->markMapEdited(); });
connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged); connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged);
connect(this->editor, &Editor::tilesetUpdated, this, &Scripting::cb_TilesetUpdated); connect(this->editor, &Editor::tilesetUpdated, this, &Scripting::cb_TilesetUpdated);
connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, &Editor::openMapScripts); connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, &Editor::openMapScripts);
@ -2560,11 +2558,6 @@ void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryT
redrawMapScene(); redrawMapScene();
} }
void MainWindow::onWildMonDataChanged() {
editor->saveEncounterTabData();
markMapEdited();
}
void MainWindow::onMapRulerStatusChanged(const QString &status) { void MainWindow::onMapRulerStatusChanged(const QString &status) {
if (status.isEmpty()) { if (status.isEmpty()) {
label_MapRulerStatus->hide(); label_MapRulerStatus->hide();
@ -2659,12 +2652,10 @@ void MainWindow::on_pushButton_DeleteWildMonGroup_clicked() {
void MainWindow::on_pushButton_SummaryChart_clicked() { void MainWindow::on_pushButton_SummaryChart_clicked() {
if (!this->wildMonChart) { if (!this->wildMonChart) {
// TODO: Move to editor, connect to signals for when the table data changes this->wildMonChart = new WildMonChart(this, this->editor->getCurrentWildMonTable());
QTableView *table = this->editor->getCurrentWildMonTable(); connect(this->editor, &Editor::wildMonTableOpened, this->wildMonChart, &WildMonChart::setTable);
EncounterTableModel *data = table ? static_cast<EncounterTableModel *>(table->model()) : nullptr; connect(this->editor, &Editor::wildMonTableClosed, this->wildMonChart, &WildMonChart::clearTable);
this->wildMonChart = new WildMonChart(this, data); connect(this->editor, &Editor::wildMonTableEdited, this->wildMonChart, &WildMonChart::refresh);
} else {
this->wildMonChart->createCharts();
} }
openSubWindow(this->wildMonChart); openSubWindow(this->wildMonChart);
} }

View file

@ -79,8 +79,11 @@ QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt
editor->setMaximum(this->project->miscConstants.value("max_level_define").toInt()); editor->setMaximum(this->project->miscConstants.value("max_level_define").toInt());
} }
else if (col == EncounterTableModel::ColumnType::EncounterRate) { else if (col == EncounterTableModel::ColumnType::EncounterRate) {
// The games multiply the encounter rate value provided here by 16, so the input limit is the max/16.
// TODO: Read MAX_ENCOUNTER_RATE?
static const int maxEncounterRate = 2880;
editor->setMinimum(0); editor->setMinimum(0);
editor->setMaximum(180); editor->setMaximum(maxEncounterRate / 16);
} }
return editor; return editor;

View file

@ -142,45 +142,57 @@ QVariant EncounterTableModel::headerData(int section, Qt::Orientation orientatio
} }
bool EncounterTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { bool EncounterTableModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (role == Qt::EditRole) { if (role != Qt::EditRole)
if (!checkIndex(index)) return false;
return false; if (!checkIndex(index))
return false;
int row = index.row(); int row = index.row();
int col = index.column(); int col = index.column();
switch (col) { switch (col) {
case ColumnType::Species: case ColumnType::Species: {
this->monInfo.wildPokemon[row].species = value.toString(); QString species = value.toString();
break; if (this->monInfo.wildPokemon[row].species != species) {
this->monInfo.wildPokemon[row].species = species;
case ColumnType::MinLevel: { emit edited();
int minLevel = value.toInt();
this->monInfo.wildPokemon[row].minLevel = minLevel;
if (minLevel > this->monInfo.wildPokemon[row].maxLevel)
this->monInfo.wildPokemon[row].maxLevel = minLevel;
break;
} }
break;
case ColumnType::MaxLevel: {
int maxLevel = value.toInt();
this->monInfo.wildPokemon[row].maxLevel = maxLevel;
if (maxLevel < this->monInfo.wildPokemon[row].minLevel)
this->monInfo.wildPokemon[row].minLevel = maxLevel;
break;
}
case ColumnType::EncounterRate:
this->monInfo.encounterRate = value.toInt();
break;
default:
return false;
}
emit edited();
return true;
} }
return false;
case ColumnType::MinLevel: {
int minLevel = value.toInt();
if (this->monInfo.wildPokemon[row].minLevel != minLevel) {
this->monInfo.wildPokemon[row].minLevel = minLevel;
this->monInfo.wildPokemon[row].maxLevel = qMax(minLevel, this->monInfo.wildPokemon[row].maxLevel);
emit edited();
}
break;
}
case ColumnType::MaxLevel: {
int maxLevel = value.toInt();
if (this->monInfo.wildPokemon[row].maxLevel != maxLevel) {
this->monInfo.wildPokemon[row].maxLevel = maxLevel;
this->monInfo.wildPokemon[row].minLevel = qMin(maxLevel, this->monInfo.wildPokemon[row].minLevel);
emit edited();
}
break;
}
case ColumnType::EncounterRate: {
int encounterRate = value.toInt();
if (this->monInfo.encounterRate != encounterRate) {
this->monInfo.encounterRate = encounterRate;
emit edited();
}
break;
}
default:
return false;
}
return true;
} }
Qt::ItemFlags EncounterTableModel::flags(const QModelIndex &index) const { Qt::ItemFlags EncounterTableModel::flags(const QModelIndex &index) const {

View file

@ -68,7 +68,7 @@ void MonTabWidget::paste(int index) {
WildMonInfo newInfo = getDefaultMonInfo(this->editor->project->wildMonFields.at(index)); WildMonInfo newInfo = getDefaultMonInfo(this->editor->project->wildMonFields.at(index));
combineEncounters(newInfo, encounterClipboard); combineEncounters(newInfo, encounterClipboard);
populateTab(index, newInfo); populateTab(index, newInfo);
emit editor->wildMonDataChanged(); emit editor->wildMonTableEdited();
} }
void MonTabWidget::actionCopyTab(int index) { void MonTabWidget::actionCopyTab(int index) {
@ -88,21 +88,19 @@ void MonTabWidget::actionCopyTab(int index) {
} }
void MonTabWidget::actionAddDeleteTab(int index) { void MonTabWidget::actionAddDeleteTab(int index) {
clearTableAt(index);
if (activeTabs[index]) { if (activeTabs[index]) {
// delete tab // delete tab
clearTableAt(index);
deactivateTab(index); deactivateTab(index);
editor->saveEncounterTabData(); editor->saveEncounterTabData();
emit editor->wildMonDataChanged();
} }
else { else {
// add tab // add tab
clearTableAt(index);
populateTab(index, getDefaultMonInfo(editor->project->wildMonFields.at(index))); populateTab(index, getDefaultMonInfo(editor->project->wildMonFields.at(index)));
editor->saveEncounterTabData(); editor->saveEncounterTabData();
setCurrentIndex(index); setCurrentIndex(index);
emit editor->wildMonDataChanged();
} }
emit editor->wildMonTableEdited();
} }
void MonTabWidget::clearTableAt(int tabIndex) { void MonTabWidget::clearTableAt(int tabIndex) {
@ -130,6 +128,7 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo) {
EncounterTableModel *model = new EncounterTableModel(monInfo, editor->project->wildMonFields, tabIndex, this); EncounterTableModel *model = new EncounterTableModel(monInfo, editor->project->wildMonFields, tabIndex, this);
connect(model, &EncounterTableModel::edited, editor, &Editor::saveEncounterTabData); connect(model, &EncounterTableModel::edited, editor, &Editor::saveEncounterTabData);
connect(model, &EncounterTableModel::edited, editor, &Editor::wildMonTableEdited);
speciesTable->setModel(model); speciesTable->setModel(model);
speciesTable->setItemDelegateForColumn(EncounterTableModel::ColumnType::Species, new SpeciesComboDelegate(editor->project, this)); speciesTable->setItemDelegateForColumn(EncounterTableModel::ColumnType::Species, new SpeciesComboDelegate(editor->project, this));
@ -158,6 +157,8 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo) {
} }
QTableView *MonTabWidget::tableAt(int tabIndex) { QTableView *MonTabWidget::tableAt(int tabIndex) {
if (tabIndex < 0)
return nullptr;
return static_cast<QTableView *>(this->widget(tabIndex)); return static_cast<QTableView *>(this->widget(tabIndex));
} }

View file

@ -30,9 +30,9 @@ WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) :
connect(ui->button_Help, &QAbstractButton::clicked, this, &WildMonChart::showHelpDialog); connect(ui->button_Help, &QAbstractButton::clicked, this, &WildMonChart::showHelpDialog);
// Changing these settings changes which level distribution chart is shown // Changing these settings changes which level distribution chart is shown
connect(ui->groupBox_Species, &QGroupBox::clicked, this, &WildMonChart::createLevelDistributionChart); connect(ui->groupBox_Species, &QGroupBox::clicked, this, &WildMonChart::refreshLevelDistributionChart);
connect(ui->comboBox_Species, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart); connect(ui->comboBox_Species, &QComboBox::currentTextChanged, this, &WildMonChart::refreshLevelDistributionChart);
connect(ui->comboBox_Group, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart); connect(ui->comboBox_Group, &QComboBox::currentTextChanged, this, &WildMonChart::refreshLevelDistributionChart);
// Set up Theme combo box // Set up Theme combo box
for (auto i : themes) for (auto i : themes)
@ -59,9 +59,14 @@ WildMonChart::~WildMonChart() {
}; };
void WildMonChart::setTable(const EncounterTableModel *table) { void WildMonChart::setTable(const EncounterTableModel *table) {
if (this->table == table)
return;
this->table = table; this->table = table;
readTable(); refresh();
createCharts(); }
void WildMonChart::clearTable() {
setTable(nullptr);
} }
void WildMonChart::clearTableData() { void WildMonChart::clearTableData() {
@ -78,6 +83,7 @@ void WildMonChart::clearTableData() {
const QSignalBlocker blocker2(ui->comboBox_Group); const QSignalBlocker blocker2(ui->comboBox_Group);
ui->comboBox_Species->clear(); ui->comboBox_Species->clear();
ui->comboBox_Group->clear(); ui->comboBox_Group->clear();
ui->comboBox_Group->setEnabled(false);
} }
// Extract all the data from the table that we need for the charts // Extract all the data from the table that we need for the charts
@ -151,15 +157,28 @@ void WildMonChart::readTable() {
ui->comboBox_Group->setEnabled(usesGroupLabels()); ui->comboBox_Group->setEnabled(usesGroupLabels());
} }
void WildMonChart::createCharts() { void WildMonChart::refresh() {
createSpeciesDistributionChart(); readTable();
createLevelDistributionChart(); refreshSpeciesDistributionChart();
refreshLevelDistributionChart();
// Turn off the animation once it's played, otherwise it replays any time the window changes size. // 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 // TODO: Store timer, disable if closing or creating new chart
//QTimer::singleShot(chart->animationDuration() + 500, this, &WildMonChart::stopChartAnimation); //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());
}
void WildMonChart::refreshLevelDistributionChart() {
if (ui->chartView_LevelDistribution->chart())
ui->chartView_LevelDistribution->chart()->deleteLater();
ui->chartView_LevelDistribution->setChart(createLevelDistributionChart());
}
QStringList WildMonChart::getSpeciesNamesAlphabetical() const { QStringList WildMonChart::getSpeciesNamesAlphabetical() const {
return this->speciesToGroupedData.keys(); return this->speciesToGroupedData.keys();
} }
@ -190,7 +209,7 @@ bool WildMonChart::usesGroupLabels() const {
return this->groupNames.length() > 1; return this->groupNames.length() > 1;
} }
void WildMonChart::createSpeciesDistributionChart() { QChart* WildMonChart::createSpeciesDistributionChart() {
QList<QBarSet*> barSets; QList<QBarSet*> barSets;
for (const auto species : getSpeciesNamesAlphabetical()) { for (const auto species : getSpeciesNamesAlphabetical()) {
// Add encounter chance data // Add encounter chance data
@ -249,9 +268,7 @@ void WildMonChart::createSpeciesDistributionChart() {
series->attachAxis(axisY); series->attachAxis(axisY);
} }
if (ui->chartView_SpeciesDistribution->chart()) return chart;
ui->chartView_SpeciesDistribution->chart()->deleteLater();
ui->chartView_SpeciesDistribution->setChart(chart);
} }
QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, const QString &groupName, bool individual) { QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, const QString &groupName, bool individual) {
@ -281,14 +298,14 @@ QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, con
const QSignalBlocker blocker2(ui->comboBox_Species); const QSignalBlocker blocker2(ui->comboBox_Species);
ui->groupBox_Species->setChecked(true); ui->groupBox_Species->setChecked(true);
ui->comboBox_Species->setCurrentText(species); ui->comboBox_Species->setCurrentText(species);
createLevelDistributionChart(); refreshLevelDistributionChart();
}); });
} }
return set; return set;
} }
void WildMonChart::createLevelDistributionChart() { QChart* WildMonChart::createLevelDistributionChart() {
const QString groupName = ui->comboBox_Group->currentText(); const QString groupName = ui->comboBox_Group->currentText();
LevelRange levelRange; LevelRange levelRange;
@ -344,9 +361,7 @@ void WildMonChart::createLevelDistributionChart() {
}; };
axisY->setMax(roundUp(qCeil(axisY->max()), 5)); axisY->setMax(roundUp(qCeil(axisY->max()), 5));
if (ui->chartView_LevelDistribution->chart()) return chart;
ui->chartView_LevelDistribution->chart()->deleteLater();
ui->chartView_LevelDistribution->setChart(chart);
} }
QChart::ChartTheme WildMonChart::currentTheme() const { QChart::ChartTheme WildMonChart::currentTheme() const {
@ -365,7 +380,6 @@ void WildMonChart::updateTheme() {
QChart *chart = ui->chartView_SpeciesDistribution->chart(); QChart *chart = ui->chartView_SpeciesDistribution->chart();
if (!chart) if (!chart)
return; return;
this->speciesToColor.clear();
chart->setTheme(theme); chart->setTheme(theme);
saveSpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0))->barSets()); saveSpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0))->barSets());
@ -377,6 +391,7 @@ void WildMonChart::updateTheme() {
} }
void WildMonChart::saveSpeciesColors(const QList<QBarSet*> &barSets) { void WildMonChart::saveSpeciesColors(const QList<QBarSet*> &barSets) {
this->speciesToColor.clear();
for (auto set : barSets) for (auto set : barSets)
this->speciesToColor.insert(set->label(), set->color()); this->speciesToColor.insert(set->label(), set->color());
} }
@ -386,9 +401,10 @@ void WildMonChart::applySpeciesColors(const QList<QBarSet*> &barSets) {
set->setColor(this->speciesToColor.value(set->label())); set->setColor(this->speciesToColor.value(set->label()));
} }
void WildMonChart::stopChartAnimation() { void WildMonChart::stopChartAnimation(QChart *chart) {
if (ui->chartView_SpeciesDistribution->chart()) if (!chart)
ui->chartView_SpeciesDistribution->chart()->setAnimationOptions(QChart::NoAnimation); return;
chart->setAnimationOptions(QChart::NoAnimation);
} }
void WildMonChart::showHelpDialog() { void WildMonChart::showHelpDialog() {