Fixes for some visuals in chart window
This commit is contained in:
parent
7c9fcb6616
commit
6f74909a3c
3 changed files with 44 additions and 19 deletions
|
@ -133,6 +133,12 @@
|
||||||
<property name="editable">
|
<property name="editable">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimumContentsLength">
|
||||||
|
<number>8</number>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -187,6 +193,12 @@
|
||||||
<property name="insertPolicy">
|
<property name="insertPolicy">
|
||||||
<enum>QComboBox::NoInsert</enum>
|
<enum>QComboBox::NoInsert</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimumContentsLength">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -26,6 +26,8 @@ private:
|
||||||
const EncounterTableModel *table;
|
const EncounterTableModel *table;
|
||||||
|
|
||||||
QStringList groupNames;
|
QStringList groupNames;
|
||||||
|
QStringList groupNamesReversed;
|
||||||
|
QStringList speciesInLegendOrder;
|
||||||
QMap<int, QString> tableIndexToGroupName;
|
QMap<int, QString> tableIndexToGroupName;
|
||||||
|
|
||||||
struct LevelRange {
|
struct LevelRange {
|
||||||
|
@ -44,7 +46,7 @@ private:
|
||||||
QMap<QString, QColor> speciesToColor;
|
QMap<QString, QColor> speciesToColor;
|
||||||
|
|
||||||
|
|
||||||
QStringList getSpeciesNames() const;
|
QStringList getSpeciesNamesAlphabetical() const;
|
||||||
double getSpeciesFrequency(const QString&, const QString&) const;
|
double getSpeciesFrequency(const QString&, const QString&) const;
|
||||||
QMap<int, double> getLevelFrequencies(const QString &, const QString &) const;
|
QMap<int, double> getLevelFrequencies(const QString &, const QString &) const;
|
||||||
LevelRange getLevelRange(const QString &, const QString &) const;
|
LevelRange getLevelRange(const QString &, const QString &) const;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
// TODO: Draw species icons below legend icons?
|
// TODO: Draw species icons below legend icons?
|
||||||
// TODO: NoScrollComboBoxes
|
|
||||||
// TODO: Save window size, theme selection in config
|
// TODO: Save window size, theme selection in config
|
||||||
// TODO: Help button that explains the charts
|
// TODO: Help button that explains the charts
|
||||||
|
|
||||||
|
@ -55,11 +54,18 @@ void WildMonChart::setTable(const EncounterTableModel *table) {
|
||||||
|
|
||||||
void WildMonChart::clearTableData() {
|
void WildMonChart::clearTableData() {
|
||||||
this->groupNames.clear();
|
this->groupNames.clear();
|
||||||
|
this->groupNamesReversed.clear();
|
||||||
|
this->speciesInLegendOrder.clear();
|
||||||
this->tableIndexToGroupName.clear();
|
this->tableIndexToGroupName.clear();
|
||||||
this->groupedLevelRanges.clear();
|
this->groupedLevelRanges.clear();
|
||||||
this->speciesToGroupedData.clear();
|
this->speciesToGroupedData.clear();
|
||||||
this->speciesToColor.clear();
|
this->speciesToColor.clear();
|
||||||
setWindowTitle(baseWindowTitle);
|
setWindowTitle(baseWindowTitle);
|
||||||
|
|
||||||
|
const QSignalBlocker blocker1(ui->comboBox_Species);
|
||||||
|
const QSignalBlocker blocker2(ui->comboBox_Group);
|
||||||
|
ui->comboBox_Species->clear();
|
||||||
|
ui->comboBox_Group->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -72,13 +78,18 @@ void WildMonChart::readTable() {
|
||||||
|
|
||||||
// Read data about encounter groups, e.g. for "fishing_mons" we want to know table indexes 2-4 belong to "good_rod"
|
// Read data about encounter groups, e.g. for "fishing_mons" we want to know table indexes 2-4 belong to "good_rod"
|
||||||
for (auto groupPair : this->table->encounterField().groups) {
|
for (auto groupPair : this->table->encounterField().groups) {
|
||||||
// Prepending names here instead of appending so that charts can match the order in the table visually.
|
// Frustratingly when adding categories to the charts they insert bottom-to-top, but the table and combo box
|
||||||
this->groupNames.prepend(groupPair.first);
|
// insert top-to-bottom. To keep the order visually the same across displays we keep separate ordered lists.
|
||||||
|
this->groupNames.append(groupPair.first);
|
||||||
|
this->groupNamesReversed.prepend(groupPair.first);
|
||||||
for (auto i : groupPair.second)
|
for (auto i : groupPair.second)
|
||||||
this->tableIndexToGroupName.insert(i, groupPair.first);
|
this->tableIndexToGroupName.insert(i, groupPair.first);
|
||||||
}
|
}
|
||||||
if (this->groupNames.isEmpty())
|
// Implicitly 1 unnamed group when none are listed
|
||||||
this->groupNames.append(QString()); // Implicitly 1 unnamed group when none are listed
|
if (this->groupNames.isEmpty()) {
|
||||||
|
this->groupNames.append(QString());
|
||||||
|
this->groupNamesReversed.append(QString());
|
||||||
|
}
|
||||||
|
|
||||||
// Read data from the table, combining data for duplicate entries
|
// Read data from the table, combining data for duplicate entries
|
||||||
const QList<double> tableFrequencies = this->table->percentages();
|
const QList<double> tableFrequencies = this->table->percentages();
|
||||||
|
@ -119,18 +130,13 @@ void WildMonChart::readTable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate combo boxes
|
// Populate combo boxes
|
||||||
// TODO: Limit width
|
|
||||||
const QSignalBlocker blocker1(ui->comboBox_Species);
|
const QSignalBlocker blocker1(ui->comboBox_Species);
|
||||||
const QSignalBlocker blocker2(ui->comboBox_Group);
|
const QSignalBlocker blocker2(ui->comboBox_Group);
|
||||||
ui->comboBox_Species->clear();
|
ui->comboBox_Species->clear();
|
||||||
ui->comboBox_Species->addItems(getSpeciesNames());
|
ui->comboBox_Species->addItems(getSpeciesNamesAlphabetical());
|
||||||
ui->comboBox_Group->clear();
|
ui->comboBox_Group->clear();
|
||||||
if (usesGroupLabels()) {
|
|
||||||
ui->comboBox_Group->addItems(this->groupNames);
|
ui->comboBox_Group->addItems(this->groupNames);
|
||||||
ui->comboBox_Group->setEnabled(true);
|
ui->comboBox_Group->setEnabled(usesGroupLabels());
|
||||||
} else {
|
|
||||||
ui->comboBox_Group->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WildMonChart::createCharts() {
|
void WildMonChart::createCharts() {
|
||||||
|
@ -142,7 +148,7 @@ void WildMonChart::createCharts() {
|
||||||
//QTimer::singleShot(chart->animationDuration() + 500, this, &WildMonChart::stopChartAnimation);
|
//QTimer::singleShot(chart->animationDuration() + 500, this, &WildMonChart::stopChartAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList WildMonChart::getSpeciesNames() const {
|
QStringList WildMonChart::getSpeciesNamesAlphabetical() const {
|
||||||
return this->speciesToGroupedData.keys();
|
return this->speciesToGroupedData.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,10 +180,10 @@ bool WildMonChart::usesGroupLabels() const {
|
||||||
|
|
||||||
void WildMonChart::createSpeciesDistributionChart() {
|
void WildMonChart::createSpeciesDistributionChart() {
|
||||||
QList<QBarSet*> barSets;
|
QList<QBarSet*> barSets;
|
||||||
for (const auto species : getSpeciesNames()) {
|
for (const auto species : getSpeciesNamesAlphabetical()) {
|
||||||
// Add encounter chance data
|
// Add encounter chance data
|
||||||
auto set = new QBarSet(species);
|
auto set = new QBarSet(species);
|
||||||
for (auto groupName : this->groupNames)
|
for (auto groupName : this->groupNamesReversed)
|
||||||
set->append(getSpeciesFrequency(species, groupName) * 100);
|
set->append(getSpeciesFrequency(species, groupName) * 100);
|
||||||
|
|
||||||
// We order the bar sets from lowest to highest total, left-to-right.
|
// We order the bar sets from lowest to highest total, left-to-right.
|
||||||
|
@ -196,6 +202,11 @@ void WildMonChart::createSpeciesDistributionChart() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preserve the order we set earlier so that the legend isn't shuffling around for the other all-species charts.
|
||||||
|
this->speciesInLegendOrder.clear();
|
||||||
|
for (auto set : barSets)
|
||||||
|
this->speciesInLegendOrder.append(set->label());
|
||||||
|
|
||||||
// Set up series
|
// Set up series
|
||||||
auto series = new QHorizontalPercentBarSeries();
|
auto series = new QHorizontalPercentBarSeries();
|
||||||
series->setLabelsVisible();
|
series->setLabelsVisible();
|
||||||
|
@ -220,7 +231,7 @@ void WildMonChart::createSpeciesDistributionChart() {
|
||||||
// Y-axis is the names of encounter groups (e.g. Old Rod, Good Rod...)
|
// Y-axis is the names of encounter groups (e.g. Old Rod, Good Rod...)
|
||||||
if (usesGroupLabels()) {
|
if (usesGroupLabels()) {
|
||||||
auto axisY = new QBarCategoryAxis();
|
auto axisY = new QBarCategoryAxis();
|
||||||
axisY->setCategories(this->groupNames);
|
axisY->setCategories(this->groupNamesReversed);
|
||||||
chart->addAxis(axisY, Qt::AlignLeft);
|
chart->addAxis(axisY, Qt::AlignLeft);
|
||||||
series->attachAxis(axisY);
|
series->attachAxis(axisY);
|
||||||
}
|
}
|
||||||
|
@ -272,7 +283,7 @@ void WildMonChart::createLevelDistributionChart() {
|
||||||
levelRange = getLevelRange(species, groupName);
|
levelRange = getLevelRange(species, groupName);
|
||||||
} else {
|
} else {
|
||||||
// Species box is inactive, we display data for all species in the table.
|
// Species box is inactive, we display data for all species in the table.
|
||||||
for (const auto species : getSpeciesNames())
|
for (const auto species : this->speciesInLegendOrder)
|
||||||
barSets.append(createLevelDistributionBarSet(species, groupName, false, &maxPercent));
|
barSets.append(createLevelDistributionBarSet(species, groupName, false, &maxPercent));
|
||||||
levelRange = this->groupedLevelRanges.value(groupName);
|
levelRange = this->groupedLevelRanges.value(groupName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue