mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 04:16:26 +00:00
impr: TabTools_ChartRecommend
ui
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from arcaea_offline.calculate import calculate_score_range
|
||||
from arcaea_offline.models import Chart, Score
|
||||
from arcaea_offline.models import Chart, Score, ScoreBest
|
||||
from arcaea_offline.utils.rating import rating_class_to_text
|
||||
from arcaea_offline.utils.score import (
|
||||
clear_type_to_text,
|
||||
@ -78,18 +78,21 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
createGradeGradientWrapper(QColor("#5d1d35"), QColor("#9f3c55")),
|
||||
]
|
||||
|
||||
def getScore(self, index: QModelIndex) -> Score | None:
|
||||
def getScore(self, index: QModelIndex) -> Score | ScoreBest | None:
|
||||
return None
|
||||
|
||||
def getChart(self, index: QModelIndex) -> Chart | None:
|
||||
return None
|
||||
|
||||
def isScoreInstance(self, index: QModelIndex) -> bool:
|
||||
return isinstance(self.getScore(index), (Score, ScoreBest))
|
||||
|
||||
def getScoreValidateOk(self, index: QModelIndex) -> bool | None:
|
||||
score = self.getScore(index)
|
||||
chart = self.getChart(index)
|
||||
|
||||
if (
|
||||
isinstance(score, Score)
|
||||
self.isScoreInstance(index)
|
||||
and isinstance(chart, Chart)
|
||||
and chart.notes is not None
|
||||
and score.pure is not None
|
||||
@ -104,11 +107,11 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
def getTextSegments(self, index, option):
|
||||
score = self.getScore(index)
|
||||
|
||||
if not isinstance(score, Score):
|
||||
if not self.isScoreInstance(index):
|
||||
return [
|
||||
[
|
||||
{
|
||||
self.TextRole: "Chart/Score Invalid",
|
||||
self.TextRole: "Score Invalid",
|
||||
self.ColorRole: QColor("#ff0000"),
|
||||
}
|
||||
]
|
||||
@ -199,7 +202,7 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
score = self.getScore(index)
|
||||
chart = self.getChart(index)
|
||||
if (
|
||||
isinstance(score, Score)
|
||||
self.isScoreInstance(index)
|
||||
and isinstance(chart, Chart)
|
||||
and self.paintWarningBackground(index)
|
||||
):
|
||||
@ -239,7 +242,7 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
else:
|
||||
editor.setWindowTitle("-")
|
||||
|
||||
if isinstance(score, Score):
|
||||
if self.isScoreInstance(index):
|
||||
editor.setText(score)
|
||||
|
||||
editor.setValidateBeforeAccept(False)
|
||||
@ -260,7 +263,7 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
chart = self.getChart(index)
|
||||
if isinstance(chart, Chart):
|
||||
editor.setChart(chart)
|
||||
if isinstance(score, Score):
|
||||
if self.isScoreInstance(index):
|
||||
editor.setValue(score)
|
||||
|
||||
def confirmSetModelData(self, editor: ScoreEditorDelegateWrapper):
|
||||
|
120
ui/extends/tabs/tabTools/tabTools_ChartRecommend.py
Normal file
120
ui/extends/tabs/tabTools/tabTools_ChartRecommend.py
Normal file
@ -0,0 +1,120 @@
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from arcaea_offline.database import Database
|
||||
from arcaea_offline.models import Chart, ScoreBest
|
||||
from arcaea_offline.utils.rating import rating_class_to_text
|
||||
from PySide6.QtCore import QAbstractListModel, QModelIndex, Qt
|
||||
from PySide6.QtGui import QStandardItem, QStandardItemModel
|
||||
|
||||
from ui.extends.shared.delegates.chartDelegate import ChartDelegate
|
||||
from ui.extends.shared.delegates.scoreDelegate import ScoreDelegate
|
||||
|
||||
|
||||
class ChartsModel(QAbstractListModel):
|
||||
ChartRole = Qt.ItemDataRole.UserRole
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.__data: list[dict[int, Any]] = []
|
||||
|
||||
def rowCount(self, *args) -> int:
|
||||
return len(self.__data)
|
||||
|
||||
def columnCount(self, *args) -> int:
|
||||
return 1
|
||||
|
||||
def headerData(self, *args):
|
||||
return None
|
||||
|
||||
def data(self, index: QModelIndex, role: int):
|
||||
if not self.checkIndex(index):
|
||||
return None
|
||||
|
||||
return self.__data[index.row()].get(role, None)
|
||||
|
||||
def clear(self):
|
||||
self.beginResetModel()
|
||||
self.beginRemoveRows(QModelIndex(), 0, self.rowCount())
|
||||
self.__data.clear()
|
||||
self.endRemoveRows()
|
||||
self.endResetModel()
|
||||
|
||||
def setCharts(self, charts: list[Chart]):
|
||||
self.clear()
|
||||
|
||||
db = Database()
|
||||
self.beginInsertRows(QModelIndex(), 0, len(charts))
|
||||
for chart in charts:
|
||||
pack = db.get_pack(chart.set)
|
||||
if re.search(r"_append_.*$", pack.id):
|
||||
basePackId = re.sub(r"_append_.*$", "", pack.id)
|
||||
basePackName = db.get_pack(basePackId).name
|
||||
packName = f"{basePackName} - {pack.name}"
|
||||
else:
|
||||
packName = pack.name
|
||||
|
||||
tooltip = (
|
||||
f"{chart.title}@{packName} [{rating_class_to_text(chart.rating_class)}]"
|
||||
)
|
||||
self.__data.append(
|
||||
{
|
||||
Qt.ItemDataRole.ToolTipRole: tooltip,
|
||||
self.ChartRole: chart,
|
||||
}
|
||||
)
|
||||
self.endInsertRows()
|
||||
|
||||
|
||||
class CustomChartDelegate(ChartDelegate):
|
||||
def getChart(self, index: QModelIndex) -> Chart | None:
|
||||
return index.data(ChartsModel.ChartRole)
|
||||
|
||||
|
||||
class ChartsWithScoreBestModel(QStandardItemModel):
|
||||
ChartRole = Qt.ItemDataRole.UserRole
|
||||
ScoreBestRole = Qt.ItemDataRole.UserRole + 10
|
||||
|
||||
def columnCount(self, *args) -> int:
|
||||
return 3
|
||||
|
||||
def headerData(self, *args):
|
||||
return None
|
||||
|
||||
def setChartAndScore(self, charts: list[Chart], scoreBests: list[ScoreBest]):
|
||||
self.clear()
|
||||
|
||||
db = Database()
|
||||
self.beginInsertRows(QModelIndex(), 0, len(charts))
|
||||
for chart, scoreBest in zip(charts, scoreBests):
|
||||
pack = db.get_pack(chart.set)
|
||||
if re.search(r"_append_.*$", pack.id):
|
||||
basePackId = re.sub(r"_append_.*$", "", pack.id)
|
||||
basePackName = db.get_pack(basePackId).name
|
||||
packName = f"{basePackName} - {pack.name}"
|
||||
else:
|
||||
packName = pack.name
|
||||
|
||||
tooltip = (
|
||||
f"{chart.title}@{packName} [{rating_class_to_text(chart.rating_class)}]\n"
|
||||
f"{scoreBest.score} > {scoreBest.potential}"
|
||||
)
|
||||
|
||||
chartItem = QStandardItem()
|
||||
chartItem.setData(tooltip, Qt.ItemDataRole.ToolTipRole)
|
||||
chartItem.setData(chart, self.ChartRole)
|
||||
|
||||
scoreBestItem = QStandardItem()
|
||||
scoreBestItem.setData(tooltip, Qt.ItemDataRole.ToolTipRole)
|
||||
scoreBestItem.setData(scoreBest, self.ScoreBestRole)
|
||||
|
||||
potentialTextItem = QStandardItem()
|
||||
potentialTextItem.setText(f"{scoreBest.potential}")
|
||||
|
||||
self.appendRow([chartItem, scoreBestItem, potentialTextItem])
|
||||
|
||||
|
||||
class CustomScoreBestDelegate(ScoreDelegate):
|
||||
def getScore(self, index: QModelIndex):
|
||||
return index.data(ChartsWithScoreBestModel.ScoreBestRole)
|
Reference in New Issue
Block a user