Add chart theme selector
This commit is contained in:
parent
8f6871dae0
commit
7c9fcb6616
3 changed files with 122 additions and 21 deletions
|
@ -6,26 +6,61 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>776</width>
|
<width>785</width>
|
||||||
<height>445</height>
|
<height>492</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Wild Pokémon Summary</string>
|
<string>Wild Pokémon Summary</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="leftMargin">
|
<item>
|
||||||
<number>4</number>
|
<widget class="QFrame" name="frame_TopBar">
|
||||||
</property>
|
<property name="frameShape">
|
||||||
<property name="topMargin">
|
<enum>QFrame::NoFrame</enum>
|
||||||
<number>4</number>
|
</property>
|
||||||
</property>
|
<property name="frameShadow">
|
||||||
<property name="rightMargin">
|
<enum>QFrame::Plain</enum>
|
||||||
<number>4</number>
|
</property>
|
||||||
</property>
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="bottomMargin">
|
<property name="leftMargin">
|
||||||
<number>4</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_Theme">
|
||||||
|
<property name="text">
|
||||||
|
<string>Theme</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_Theme"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
|
|
|
@ -41,11 +41,13 @@ private:
|
||||||
typedef QMap<QString, Summary> GroupedData;
|
typedef QMap<QString, Summary> GroupedData;
|
||||||
|
|
||||||
QMap<QString, GroupedData> speciesToGroupedData;
|
QMap<QString, GroupedData> speciesToGroupedData;
|
||||||
|
QMap<QString, QColor> speciesToColor;
|
||||||
|
|
||||||
|
|
||||||
QStringList getSpeciesNames() const;
|
QStringList getSpeciesNames() 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 &species, const QString &groupName) const;
|
LevelRange getLevelRange(const QString &, const QString &) const;
|
||||||
bool usesGroupLabels() const;
|
bool usesGroupLabels() const;
|
||||||
|
|
||||||
void clearTableData();
|
void clearTableData();
|
||||||
|
@ -54,6 +56,9 @@ private:
|
||||||
void createLevelDistributionChart();
|
void createLevelDistributionChart();
|
||||||
QBarSet* createLevelDistributionBarSet(const QString &, const QString &, bool, double *);
|
QBarSet* createLevelDistributionBarSet(const QString &, const QString &, bool, double *);
|
||||||
|
|
||||||
|
void applySpeciesColors(QAbstractBarSeries *);
|
||||||
|
QChart::ChartTheme currentTheme() const;
|
||||||
|
void updateTheme();
|
||||||
void stopChartAnimation();
|
void stopChartAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,22 @@
|
||||||
|
|
||||||
// TODO: Draw species icons below legend icons?
|
// TODO: Draw species icons below legend icons?
|
||||||
// TODO: NoScrollComboBoxes
|
// TODO: NoScrollComboBoxes
|
||||||
// TODO: Consistent species->color across charts
|
// 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");
|
static const QString baseWindowTitle = QString("Wild Pokémon Summary Charts");
|
||||||
|
|
||||||
|
static const QList<QPair<QString, QChart::ChartTheme>> themes = {
|
||||||
|
{"Light", QChart::ChartThemeLight},
|
||||||
|
{"Dark", QChart::ChartThemeDark},
|
||||||
|
{"Blue Cerulean", QChart::ChartThemeBlueCerulean},
|
||||||
|
{"Brown Sand", QChart::ChartThemeBrownSand},
|
||||||
|
{"Blue NCS", QChart::ChartThemeBlueNcs},
|
||||||
|
{"High Contrast", QChart::ChartThemeHighContrast},
|
||||||
|
{"Blue Icy", QChart::ChartThemeBlueIcy},
|
||||||
|
{"Qt", QChart::ChartThemeQt},
|
||||||
|
};
|
||||||
|
|
||||||
WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) :
|
WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::WildMonChart)
|
ui(new Ui::WildMonChart)
|
||||||
|
@ -23,6 +35,11 @@ WildMonChart::WildMonChart(QWidget *parent, const EncounterTableModel *table) :
|
||||||
connect(ui->comboBox_Species, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart);
|
connect(ui->comboBox_Species, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart);
|
||||||
connect(ui->comboBox_Group, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart);
|
connect(ui->comboBox_Group, &QComboBox::currentTextChanged, this, &WildMonChart::createLevelDistributionChart);
|
||||||
|
|
||||||
|
// Set up Theme combo box
|
||||||
|
for (auto i : themes)
|
||||||
|
ui->comboBox_Theme->addItem(i.first, i.second);
|
||||||
|
connect(ui->comboBox_Theme, &QComboBox::currentTextChanged, this, &WildMonChart::updateTheme);
|
||||||
|
|
||||||
setTable(table);
|
setTable(table);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,8 +56,9 @@ void WildMonChart::setTable(const EncounterTableModel *table) {
|
||||||
void WildMonChart::clearTableData() {
|
void WildMonChart::clearTableData() {
|
||||||
this->groupNames.clear();
|
this->groupNames.clear();
|
||||||
this->tableIndexToGroupName.clear();
|
this->tableIndexToGroupName.clear();
|
||||||
this->speciesToGroupedData.clear();
|
|
||||||
this->groupedLevelRanges.clear();
|
this->groupedLevelRanges.clear();
|
||||||
|
this->speciesToGroupedData.clear();
|
||||||
|
this->speciesToColor.clear();
|
||||||
setWindowTitle(baseWindowTitle);
|
setWindowTitle(baseWindowTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +190,8 @@ void WildMonChart::createSpeciesDistributionChart() {
|
||||||
|
|
||||||
// Show species name and % when hovering over a bar set. This covers some shortfalls in our ability to control the chart design
|
// Show species name and % when hovering over a bar set. This covers some shortfalls in our ability to control the chart design
|
||||||
// (i.e. bar segments may be too narrow to see the % label, or colors may be hard to match to the legend).
|
// (i.e. bar segments may be too narrow to see the % label, or colors may be hard to match to the legend).
|
||||||
connect(set, &QBarSet::hovered, [set, species] (bool on, int i) {
|
connect(set, &QBarSet::hovered, [set] (bool on, int i) {
|
||||||
QString text = on ? QString("%1 (%2%)").arg(species).arg(set->at(i)) : "";
|
QString text = on ? QString("%1 (%2%)").arg(set->label()).arg(set->at(i)) : "";
|
||||||
QToolTip::showText(QCursor::pos(), text);
|
QToolTip::showText(QCursor::pos(), text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -186,6 +204,7 @@ void WildMonChart::createSpeciesDistributionChart() {
|
||||||
// Set up chart
|
// Set up chart
|
||||||
auto chart = new QChart();
|
auto chart = new QChart();
|
||||||
chart->addSeries(series);
|
chart->addSeries(series);
|
||||||
|
chart->setTheme(currentTheme());
|
||||||
chart->setAnimationOptions(QChart::SeriesAnimations);
|
chart->setAnimationOptions(QChart::SeriesAnimations);
|
||||||
chart->legend()->setVisible(true);
|
chart->legend()->setVisible(true);
|
||||||
chart->legend()->setShowToolTips(true);
|
chart->legend()->setShowToolTips(true);
|
||||||
|
@ -206,6 +225,8 @@ void WildMonChart::createSpeciesDistributionChart() {
|
||||||
series->attachAxis(axisY);
|
series->attachAxis(axisY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applySpeciesColors(series);
|
||||||
|
|
||||||
// TODO: Delete old chart
|
// TODO: Delete old chart
|
||||||
ui->chartView_SpeciesDistribution->setChart(chart);
|
ui->chartView_SpeciesDistribution->setChart(chart);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +247,7 @@ QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, con
|
||||||
// Show data when hovering over a bar set. This covers some shortfalls in our ability to control the chart design.
|
// Show data when hovering over a bar set. This covers some shortfalls in our ability to control the chart design.
|
||||||
connect(set, &QBarSet::hovered, [=] (bool on, int i) {
|
connect(set, &QBarSet::hovered, [=] (bool on, int i) {
|
||||||
QString text = on ? QString("%1 Lv%2 (%3%)")
|
QString text = on ? QString("%1 Lv%2 (%3%)")
|
||||||
.arg(individual ? "" : species)
|
.arg(individual ? "" : set->label())
|
||||||
.arg(QString::number(i + levelRange.min))
|
.arg(QString::number(i + levelRange.min))
|
||||||
.arg(set->at(i))
|
.arg(set->at(i))
|
||||||
: "";
|
: "";
|
||||||
|
@ -259,6 +280,7 @@ void WildMonChart::createLevelDistributionChart() {
|
||||||
// Set up chart
|
// Set up chart
|
||||||
auto chart = new QChart();
|
auto chart = new QChart();
|
||||||
//chart->setTitle("");
|
//chart->setTitle("");
|
||||||
|
chart->setTheme(currentTheme());
|
||||||
chart->setAnimationOptions(QChart::SeriesAnimations);
|
chart->setAnimationOptions(QChart::SeriesAnimations);
|
||||||
chart->legend()->setVisible(true);
|
chart->legend()->setVisible(true);
|
||||||
chart->legend()->setShowToolTips(true);
|
chart->legend()->setShowToolTips(true);
|
||||||
|
@ -278,7 +300,7 @@ void WildMonChart::createLevelDistributionChart() {
|
||||||
return num + multiple - remainder;
|
return num + multiple - remainder;
|
||||||
};
|
};
|
||||||
QValueAxis *axisY = new QValueAxis();
|
QValueAxis *axisY = new QValueAxis();
|
||||||
axisY->setMax(roundUp(qCeil(maxPercent), 5));
|
axisY->setMax(roundUp(qCeil(maxPercent), 5)); // TODO: This isn't taking stacking into account
|
||||||
//axisY->setTickType(QValueAxis::TicksDynamic);
|
//axisY->setTickType(QValueAxis::TicksDynamic);
|
||||||
//axisY->setTickInterval(5);
|
//axisY->setTickInterval(5);
|
||||||
axisY->setLabelFormat("%u%%");
|
axisY->setLabelFormat("%u%%");
|
||||||
|
@ -292,6 +314,7 @@ void WildMonChart::createLevelDistributionChart() {
|
||||||
series->attachAxis(axisY);
|
series->attachAxis(axisY);
|
||||||
//series->setLabelsVisible();
|
//series->setLabelsVisible();
|
||||||
chart->addSeries(series);
|
chart->addSeries(series);
|
||||||
|
applySpeciesColors(series);
|
||||||
} else {
|
} else {
|
||||||
auto series = new QStackedBarSeries();
|
auto series = new QStackedBarSeries();
|
||||||
series->append(barSets);
|
series->append(barSets);
|
||||||
|
@ -299,12 +322,50 @@ void WildMonChart::createLevelDistributionChart() {
|
||||||
series->attachAxis(axisY);
|
series->attachAxis(axisY);
|
||||||
//series->setLabelsVisible();
|
//series->setLabelsVisible();
|
||||||
chart->addSeries(series);
|
chart->addSeries(series);
|
||||||
|
applySpeciesColors(series);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache old chart
|
// TODO: Cache old chart
|
||||||
ui->chartView_LevelDistribution->setChart(chart);
|
ui->chartView_LevelDistribution->setChart(chart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChart::ChartTheme WildMonChart::currentTheme() const {
|
||||||
|
return static_cast<QChart::ChartTheme>(ui->comboBox_Theme->currentData().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WildMonChart::updateTheme() {
|
||||||
|
auto theme = currentTheme();
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// when we change themes, so we need to recalculate them. We let the species
|
||||||
|
// distribution chart determine what those mapping are (it always includes every
|
||||||
|
// species in the table) and then we apply those mappings to subsequent charts.
|
||||||
|
QChart *chart = ui->chartView_SpeciesDistribution->chart();
|
||||||
|
if (!chart)
|
||||||
|
return;
|
||||||
|
this->speciesToColor.clear();
|
||||||
|
chart->setTheme(theme);
|
||||||
|
applySpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0)));
|
||||||
|
|
||||||
|
chart = ui->chartView_LevelDistribution->chart();
|
||||||
|
if (chart) {
|
||||||
|
chart->setTheme(theme);
|
||||||
|
applySpeciesColors(static_cast<QAbstractBarSeries*>(chart->series().at(0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WildMonChart::applySpeciesColors(QAbstractBarSeries *series) {
|
||||||
|
for (auto set : series->barSets()) {
|
||||||
|
const QString species = set->label();
|
||||||
|
if (speciesToColor.contains(species)) {
|
||||||
|
set->setColor(speciesToColor.value(species));
|
||||||
|
} else {
|
||||||
|
speciesToColor.insert(species, set->color());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WildMonChart::stopChartAnimation() {
|
void WildMonChart::stopChartAnimation() {
|
||||||
if (ui->chartView_SpeciesDistribution->chart())
|
if (ui->chartView_SpeciesDistribution->chart())
|
||||||
ui->chartView_SpeciesDistribution->chart()->setAnimationOptions(QChart::NoAnimation);
|
ui->chartView_SpeciesDistribution->chart()->setAnimationOptions(QChart::NoAnimation);
|
||||||
|
|
Loading…
Reference in a new issue