Initial wild pokemon summary chart
This commit is contained in:
parent
baaf9c8c9d
commit
b1814e0e3f
10 changed files with 200 additions and 4 deletions
|
@ -3010,6 +3010,13 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_SummaryChart">
|
||||||
|
<property name="text">
|
||||||
|
<string>Summary Chart...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_ConfigureEncountersJSON">
|
<widget class="QPushButton" name="pushButton_ConfigureEncountersJSON">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
43
forms/wildmonchart.ui
Normal file
43
forms/wildmonchart.ui
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>WildMonChart</class>
|
||||||
|
<widget class="QWidget" name="WildMonChart">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Wild Pokémon Summary</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QChartView" name="chartView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QChartView</class>
|
||||||
|
<extends>QGraphicsView</extends>
|
||||||
|
<header>QtCharts</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -83,6 +83,7 @@ public:
|
||||||
void removeCurrentConnection();
|
void removeCurrentConnection();
|
||||||
void addNewWildMonGroup(QWidget *window);
|
void addNewWildMonGroup(QWidget *window);
|
||||||
void deleteWildMonGroup();
|
void deleteWildMonGroup();
|
||||||
|
QTableView* getCurrentWildMonTable();
|
||||||
void updateDiveMap(QString mapName);
|
void updateDiveMap(QString mapName);
|
||||||
void updateEmergeMap(QString mapName);
|
void updateEmergeMap(QString mapName);
|
||||||
void setSelectedConnectionFromMap(QString mapName);
|
void setSelectedConnectionFromMap(QString mapName);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "preferenceeditor.h"
|
#include "preferenceeditor.h"
|
||||||
#include "projectsettingseditor.h"
|
#include "projectsettingseditor.h"
|
||||||
#include "customscriptseditor.h"
|
#include "customscriptseditor.h"
|
||||||
|
#include "wildmonchart.h"
|
||||||
#include "updatepromoter.h"
|
#include "updatepromoter.h"
|
||||||
#include "aboutporymap.h"
|
#include "aboutporymap.h"
|
||||||
|
|
||||||
|
@ -285,6 +286,7 @@ private slots:
|
||||||
void on_horizontalSlider_CollisionZoom_valueChanged(int value);
|
void on_horizontalSlider_CollisionZoom_valueChanged(int value);
|
||||||
void on_pushButton_NewWildMonGroup_clicked();
|
void on_pushButton_NewWildMonGroup_clicked();
|
||||||
void on_pushButton_DeleteWildMonGroup_clicked();
|
void on_pushButton_DeleteWildMonGroup_clicked();
|
||||||
|
void on_pushButton_SummaryChart_clicked();
|
||||||
void on_pushButton_ConfigureEncountersJSON_clicked();
|
void on_pushButton_ConfigureEncountersJSON_clicked();
|
||||||
void on_pushButton_CreatePrefab_clicked();
|
void on_pushButton_CreatePrefab_clicked();
|
||||||
void on_spinBox_SelectedElevation_valueChanged(int elevation);
|
void on_spinBox_SelectedElevation_valueChanged(int elevation);
|
||||||
|
@ -314,6 +316,7 @@ private:
|
||||||
QPointer<UpdatePromoter> updatePromoter = nullptr;
|
QPointer<UpdatePromoter> updatePromoter = nullptr;
|
||||||
QPointer<NetworkAccessManager> networkAccessManager = nullptr;
|
QPointer<NetworkAccessManager> networkAccessManager = nullptr;
|
||||||
QPointer<AboutPorymap> aboutWindow = nullptr;
|
QPointer<AboutPorymap> aboutWindow = nullptr;
|
||||||
|
QPointer<WildMonChart> wildMonChart = nullptr;
|
||||||
FilterChildrenProxyModel *mapListProxyModel;
|
FilterChildrenProxyModel *mapListProxyModel;
|
||||||
QStandardItemModel *mapListModel;
|
QStandardItemModel *mapListModel;
|
||||||
QList<QStandardItem*> *mapGroupItemsList;
|
QList<QStandardItem*> *mapGroupItemsList;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
WildMonInfo encounterData();
|
WildMonInfo encounterData();
|
||||||
|
QList<double> percentages() const { return slotPercentages; }
|
||||||
void resize(int rows, int cols);
|
void resize(int rows, int cols);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
28
include/ui/wildmonchart.h
Normal file
28
include/ui/wildmonchart.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef WILDMONCHART_H
|
||||||
|
#define WILDMONCHART_H
|
||||||
|
|
||||||
|
#include "encountertablemodel.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class WildMonChart;
|
||||||
|
}
|
||||||
|
|
||||||
|
class WildMonChart : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WildMonChart(QWidget *parent, EncounterTableModel *data);
|
||||||
|
~WildMonChart();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setChartData(EncounterTableModel *data);
|
||||||
|
void updateChart();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::WildMonChart *ui;
|
||||||
|
EncounterTableModel *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WILDMONCHART_H
|
11
porymap.pro
11
porymap.pro
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui qml network
|
QT += core gui qml network charts
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ SOURCES += src/core/block.cpp \
|
||||||
src/settings.cpp \
|
src/settings.cpp \
|
||||||
src/log.cpp \
|
src/log.cpp \
|
||||||
src/ui/uintspinbox.cpp \
|
src/ui/uintspinbox.cpp \
|
||||||
src/ui/updatepromoter.cpp
|
src/ui/updatepromoter.cpp \
|
||||||
|
src/ui/wildmonchart.cpp
|
||||||
|
|
||||||
HEADERS += include/core/block.h \
|
HEADERS += include/core/block.h \
|
||||||
include/core/bitpacker.h \
|
include/core/bitpacker.h \
|
||||||
|
@ -202,7 +203,8 @@ HEADERS += include/core/block.h \
|
||||||
include/settings.h \
|
include/settings.h \
|
||||||
include/log.h \
|
include/log.h \
|
||||||
include/ui/uintspinbox.h \
|
include/ui/uintspinbox.h \
|
||||||
include/ui/updatepromoter.h
|
include/ui/updatepromoter.h \
|
||||||
|
include/ui/wildmonchart.h
|
||||||
|
|
||||||
FORMS += forms/mainwindow.ui \
|
FORMS += forms/mainwindow.ui \
|
||||||
forms/prefabcreationdialog.ui \
|
forms/prefabcreationdialog.ui \
|
||||||
|
@ -221,7 +223,8 @@ FORMS += forms/mainwindow.ui \
|
||||||
forms/projectsettingseditor.ui \
|
forms/projectsettingseditor.ui \
|
||||||
forms/customscriptseditor.ui \
|
forms/customscriptseditor.ui \
|
||||||
forms/customscriptslistitem.ui \
|
forms/customscriptslistitem.ui \
|
||||||
forms/updatepromoter.ui
|
forms/updatepromoter.ui \
|
||||||
|
forms/wildmonchart.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/images.qrc \
|
resources/images.qrc \
|
||||||
|
|
|
@ -698,6 +698,12 @@ void Editor::saveEncounterTabData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTableView* Editor::getCurrentWildMonTable() {
|
||||||
|
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||||
|
auto tabWidget = static_cast<MonTabWidget *>(stack->widget(stack->currentIndex()));
|
||||||
|
return tabWidget->tableAt(tabWidget->currentIndex());
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::updateEncounterFields(EncounterFields newFields) {
|
void Editor::updateEncounterFields(EncounterFields newFields) {
|
||||||
EncounterFields oldFields = project->wildMonFields;
|
EncounterFields oldFields = project->wildMonFields;
|
||||||
// Go through fields and determine whether we need to update a field.
|
// Go through fields and determine whether we need to update a field.
|
||||||
|
|
|
@ -2572,6 +2572,16 @@ void MainWindow::on_pushButton_DeleteWildMonGroup_clicked() {
|
||||||
editor->deleteWildMonGroup();
|
editor->deleteWildMonGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_SummaryChart_clicked() {
|
||||||
|
if (!this->wildMonChart) {
|
||||||
|
// TODO: Move to editor, connect to signals for when the table data changes
|
||||||
|
QTableView *table = this->editor->getCurrentWildMonTable();
|
||||||
|
EncounterTableModel *data = table ? static_cast<EncounterTableModel *>(table->model()) : nullptr;
|
||||||
|
this->wildMonChart = new WildMonChart(this, data);
|
||||||
|
}
|
||||||
|
openSubWindow(this->wildMonChart);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
|
void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
|
||||||
editor->configureEncounterJSON(this);
|
editor->configureEncounterJSON(this);
|
||||||
}
|
}
|
||||||
|
|
94
src/ui/wildmonchart.cpp
Normal file
94
src/ui/wildmonchart.cpp
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#include "wildmonchart.h"
|
||||||
|
#include "ui_wildmonchart.h"
|
||||||
|
|
||||||
|
#include <QtCharts>
|
||||||
|
|
||||||
|
WildMonChart::WildMonChart(QWidget *parent, EncounterTableModel *data) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::WildMonChart)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
setWindowFlags(Qt::Window);
|
||||||
|
|
||||||
|
ui->chartView->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
setChartData(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
WildMonChart::~WildMonChart() {
|
||||||
|
delete ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
void WildMonChart::setChartData(EncounterTableModel *data) {
|
||||||
|
this->data = data;
|
||||||
|
updateChart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WildMonChart::updateChart() {
|
||||||
|
// TODO: Handle empty chart
|
||||||
|
if (!this->data)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QList<double> inputValues = data->percentages();
|
||||||
|
const QVector<WildPokemon> inputPokemon = data->encounterData().wildPokemon;
|
||||||
|
|
||||||
|
QList<double> chartValues;
|
||||||
|
QList<WildPokemon> chartPokemon;
|
||||||
|
|
||||||
|
// Combine data for duplicate species entries
|
||||||
|
QList<QString> seenSpecies;
|
||||||
|
for (int i = 0; i < qMin(inputValues.length(), inputPokemon.length()); i++) {
|
||||||
|
const double percent = inputValues.at(i);
|
||||||
|
const WildPokemon pokemon = inputPokemon.at(i);
|
||||||
|
|
||||||
|
int existingIndex = seenSpecies.indexOf(pokemon.species);
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
// Duplicate species entry
|
||||||
|
chartValues[existingIndex] += percent;
|
||||||
|
if (pokemon.minLevel < chartPokemon.at(existingIndex).minLevel)
|
||||||
|
chartPokemon[existingIndex].minLevel = pokemon.minLevel;
|
||||||
|
if (pokemon.maxLevel > chartPokemon.at(existingIndex).maxLevel)
|
||||||
|
chartPokemon[existingIndex].maxLevel = pokemon.maxLevel;
|
||||||
|
} else {
|
||||||
|
// New species entry
|
||||||
|
chartValues.append(percent);
|
||||||
|
chartPokemon.append(pokemon);
|
||||||
|
seenSpecies.append(pokemon.species);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: If pokemon < values, fill remainder with an "empty" slice
|
||||||
|
|
||||||
|
// Populate chart
|
||||||
|
//const QString speciesPrefix = projectConfig.getIdentifier(ProjectIdentifier::regex_species); // TODO: Change regex to prefix
|
||||||
|
const QString speciesPrefix = "SPECIES_";
|
||||||
|
QPieSeries *series = new QPieSeries();
|
||||||
|
for (int i = 0; i < qMin(chartValues.length(), chartPokemon.length()); i++) {
|
||||||
|
const double percent = chartValues.at(i);
|
||||||
|
const WildPokemon pokemon = chartPokemon.at(i);
|
||||||
|
|
||||||
|
// Strip 'SPECIES_' prefix
|
||||||
|
QString name = pokemon.species;
|
||||||
|
if (name.startsWith(speciesPrefix))
|
||||||
|
name.remove(0, speciesPrefix.length());
|
||||||
|
|
||||||
|
QString label = QString("%1\nLv %2").arg(name).arg(pokemon.minLevel);
|
||||||
|
if (pokemon.minLevel != pokemon.maxLevel)
|
||||||
|
label.append(QString("-%1").arg(pokemon.maxLevel));
|
||||||
|
label.append(QString(" (%1%)").arg(percent * 100));
|
||||||
|
|
||||||
|
QPieSlice *slice = new QPieSlice(label, percent);
|
||||||
|
//slice->setLabelPosition(QPieSlice::LabelInsideNormal);
|
||||||
|
slice->setLabelVisible();
|
||||||
|
series->append(slice);
|
||||||
|
}
|
||||||
|
|
||||||
|
QChart *chart = new QChart();
|
||||||
|
chart->addSeries(series);
|
||||||
|
chart->legend()->hide();
|
||||||
|
|
||||||
|
ui->chartView->setChart(chart); // TODO: Leaking old chart
|
||||||
|
|
||||||
|
// TODO: Draw icons onto slices
|
||||||
|
}
|
Loading…
Reference in a new issue