diff --git a/ui/designer/tabs/tabTools/tabTools_ChartRecommend.ui b/ui/designer/tabs/tabTools/tabTools_ChartRecommend.ui index 4e5da0f..7ea7eba 100644 --- a/ui/designer/tabs/tabTools/tabTools_ChartRecommend.ui +++ b/ui/designer/tabs/tabTools/tabTools_ChartRecommend.ui @@ -6,113 +6,15 @@ 0 0 - 668 - 546 + 616 + 500 TabTools_ChartRecommend - - - - - constantRangeFromPlayRating - - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - 3 - - - 100.000000000000000 - - - 0.100000000000000 - - - - - - - - - AA - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - - - EX - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - - - EX+ - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - - - ... - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - ... - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - ... - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - + + chartsByConstant @@ -147,51 +49,197 @@ + + + 0 + 0 + + ... - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - refreshButton - - - - + 0 0 - + + + 150 + 0 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::NoSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + - + + + + constantRangeFromPlayRating + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + 3 + + + 100.000000000000000 + + + 0.100000000000000 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + EX+ + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + ... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + EX + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + ... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + AA + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + ... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + A + + + + + + + ... + + + + + + + B + + + + + + + ... + + + + + + + C + + + + + + + ... + + + + + + + + + chartsRecommendFromPlayRating @@ -246,45 +294,48 @@ + + + 0 + 0 + + ... - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - refreshButton - - - - + - + 0 0 - + + + 200 + 0 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + diff --git a/ui/designer/tabs/tabTools/tabTools_ChartRecommend_ui.py b/ui/designer/tabs/tabTools/tabTools_ChartRecommend_ui.py index 92fc2cc..16a5684 100644 --- a/ui/designer/tabs/tabTools/tabTools_ChartRecommend_ui.py +++ b/ui/designer/tabs/tabTools/tabTools_ChartRecommend_ui.py @@ -15,82 +15,19 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) -from PySide6.QtWidgets import (QApplication, QDoubleSpinBox, QGridLayout, QGroupBox, - QHBoxLayout, QLabel, QPushButton, QSizePolicy, - QSpacerItem, QVBoxLayout, QWidget) +from PySide6.QtWidgets import (QAbstractItemView, QApplication, QDoubleSpinBox, QFormLayout, + QGridLayout, QGroupBox, QHBoxLayout, QHeaderView, + QLabel, QListView, QSizePolicy, QTableView, + QVBoxLayout, QWidget) class Ui_TabTools_ChartRecommend(object): def setupUi(self, TabTools_ChartRecommend): if not TabTools_ChartRecommend.objectName(): TabTools_ChartRecommend.setObjectName(u"TabTools_ChartRecommend") - TabTools_ChartRecommend.resize(668, 546) + TabTools_ChartRecommend.resize(616, 500) TabTools_ChartRecommend.setWindowTitle(u"TabTools_ChartRecommend") - self.verticalLayout = QVBoxLayout(TabTools_ChartRecommend) - self.verticalLayout.setObjectName(u"verticalLayout") - self.groupBox = QGroupBox(TabTools_ChartRecommend) - self.groupBox.setObjectName(u"groupBox") - self.verticalLayout_2 = QVBoxLayout(self.groupBox) - self.verticalLayout_2.setObjectName(u"verticalLayout_2") - self.rangeFromPlayRating_playRatingSpinBox = QDoubleSpinBox(self.groupBox) - self.rangeFromPlayRating_playRatingSpinBox.setObjectName(u"rangeFromPlayRating_playRatingSpinBox") - self.rangeFromPlayRating_playRatingSpinBox.setMinimumSize(QSize(100, 0)) - self.rangeFromPlayRating_playRatingSpinBox.setMaximumSize(QSize(100, 16777215)) - self.rangeFromPlayRating_playRatingSpinBox.setDecimals(3) - self.rangeFromPlayRating_playRatingSpinBox.setMaximum(100.000000000000000) - self.rangeFromPlayRating_playRatingSpinBox.setSingleStep(0.100000000000000) - - self.verticalLayout_2.addWidget(self.rangeFromPlayRating_playRatingSpinBox) - - self.gridLayout_3 = QGridLayout() - self.gridLayout_3.setObjectName(u"gridLayout_3") - self.label_3 = QLabel(self.groupBox) - self.label_3.setObjectName(u"label_3") - self.label_3.setText(u"AA") - self.label_3.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) - - self.gridLayout_3.addWidget(self.label_3, 0, 2, 1, 1) - - self.label_2 = QLabel(self.groupBox) - self.label_2.setObjectName(u"label_2") - self.label_2.setText(u"EX") - self.label_2.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) - - self.gridLayout_3.addWidget(self.label_2, 0, 1, 1, 1) - - self.label = QLabel(self.groupBox) - self.label.setObjectName(u"label") - self.label.setText(u"EX+") - self.label.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) - - self.gridLayout_3.addWidget(self.label, 0, 0, 1, 1) - - self.rangeFromPlayRating_ExPlusLabel = QLabel(self.groupBox) - self.rangeFromPlayRating_ExPlusLabel.setObjectName(u"rangeFromPlayRating_ExPlusLabel") - self.rangeFromPlayRating_ExPlusLabel.setText(u"...") - self.rangeFromPlayRating_ExPlusLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) - - self.gridLayout_3.addWidget(self.rangeFromPlayRating_ExPlusLabel, 1, 0, 1, 1) - - self.rangeFromPlayRating_ExLabel = QLabel(self.groupBox) - self.rangeFromPlayRating_ExLabel.setObjectName(u"rangeFromPlayRating_ExLabel") - self.rangeFromPlayRating_ExLabel.setText(u"...") - self.rangeFromPlayRating_ExLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) - - self.gridLayout_3.addWidget(self.rangeFromPlayRating_ExLabel, 1, 1, 1, 1) - - self.rangeFromPlayRating_AaLabel = QLabel(self.groupBox) - self.rangeFromPlayRating_AaLabel.setObjectName(u"rangeFromPlayRating_AaLabel") - self.rangeFromPlayRating_AaLabel.setText(u"...") - self.rangeFromPlayRating_AaLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) - - self.gridLayout_3.addWidget(self.rangeFromPlayRating_AaLabel, 1, 2, 1, 1) - - - self.verticalLayout_2.addLayout(self.gridLayout_3) - - - self.verticalLayout.addWidget(self.groupBox) - + self.gridLayout = QGridLayout(TabTools_ChartRecommend) + self.gridLayout.setObjectName(u"gridLayout") self.groupBox_2 = QGroupBox(TabTools_ChartRecommend) self.groupBox_2.setObjectName(u"groupBox_2") self.verticalLayout_3 = QVBoxLayout(self.groupBox_2) @@ -109,37 +46,137 @@ class Ui_TabTools_ChartRecommend(object): self.chartsByConstant_numLabel = QLabel(self.groupBox_2) self.chartsByConstant_numLabel.setObjectName(u"chartsByConstant_numLabel") + sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.chartsByConstant_numLabel.sizePolicy().hasHeightForWidth()) + self.chartsByConstant_numLabel.setSizePolicy(sizePolicy) self.chartsByConstant_numLabel.setText(u"...") self.horizontalLayout_3.addWidget(self.chartsByConstant_numLabel) - self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) - - self.horizontalLayout_3.addItem(self.horizontalSpacer) - - self.chartsByConstant_refreshButton = QPushButton(self.groupBox_2) - self.chartsByConstant_refreshButton.setObjectName(u"chartsByConstant_refreshButton") - self.chartsByConstant_refreshButton.setEnabled(False) - - self.horizontalLayout_3.addWidget(self.chartsByConstant_refreshButton) - self.verticalLayout_3.addLayout(self.horizontalLayout_3) - self.widget = QWidget(self.groupBox_2) - self.widget.setObjectName(u"widget") - sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth()) - self.widget.setSizePolicy(sizePolicy) - self.chartsByConstant_gridLayout = QGridLayout(self.widget) - self.chartsByConstant_gridLayout.setObjectName(u"chartsByConstant_gridLayout") + self.chartsByConstant_modelView = QListView(self.groupBox_2) + self.chartsByConstant_modelView.setObjectName(u"chartsByConstant_modelView") + sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) + sizePolicy1.setHorizontalStretch(0) + sizePolicy1.setVerticalStretch(0) + sizePolicy1.setHeightForWidth(self.chartsByConstant_modelView.sizePolicy().hasHeightForWidth()) + self.chartsByConstant_modelView.setSizePolicy(sizePolicy1) + self.chartsByConstant_modelView.setMinimumSize(QSize(150, 0)) + self.chartsByConstant_modelView.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.chartsByConstant_modelView.setSelectionMode(QAbstractItemView.NoSelection) + self.chartsByConstant_modelView.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) + self.chartsByConstant_modelView.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) - self.verticalLayout_3.addWidget(self.widget) + self.verticalLayout_3.addWidget(self.chartsByConstant_modelView) - self.verticalLayout.addWidget(self.groupBox_2) + self.gridLayout.addWidget(self.groupBox_2, 0, 1, 1, 1) + + self.groupBox = QGroupBox(TabTools_ChartRecommend) + self.groupBox.setObjectName(u"groupBox") + self.verticalLayout_2 = QVBoxLayout(self.groupBox) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.rangeFromPlayRating_playRatingSpinBox = QDoubleSpinBox(self.groupBox) + self.rangeFromPlayRating_playRatingSpinBox.setObjectName(u"rangeFromPlayRating_playRatingSpinBox") + self.rangeFromPlayRating_playRatingSpinBox.setMinimumSize(QSize(100, 0)) + self.rangeFromPlayRating_playRatingSpinBox.setMaximumSize(QSize(100, 16777215)) + self.rangeFromPlayRating_playRatingSpinBox.setDecimals(3) + self.rangeFromPlayRating_playRatingSpinBox.setMaximum(100.000000000000000) + self.rangeFromPlayRating_playRatingSpinBox.setSingleStep(0.100000000000000) + + self.verticalLayout_2.addWidget(self.rangeFromPlayRating_playRatingSpinBox) + + self.formLayout = QFormLayout() + self.formLayout.setObjectName(u"formLayout") + self.formLayout.setLabelAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) + self.formLayout.setFormAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignVCenter) + self.label = QLabel(self.groupBox) + self.label.setObjectName(u"label") + self.label.setText(u"EX+") + self.label.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) + + self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label) + + self.rangeFromPlayRating_ExPlusLabel = QLabel(self.groupBox) + self.rangeFromPlayRating_ExPlusLabel.setObjectName(u"rangeFromPlayRating_ExPlusLabel") + self.rangeFromPlayRating_ExPlusLabel.setText(u"...") + self.rangeFromPlayRating_ExPlusLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) + + self.formLayout.setWidget(0, QFormLayout.FieldRole, self.rangeFromPlayRating_ExPlusLabel) + + self.label_2 = QLabel(self.groupBox) + self.label_2.setObjectName(u"label_2") + self.label_2.setText(u"EX") + self.label_2.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) + + self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_2) + + self.rangeFromPlayRating_ExLabel = QLabel(self.groupBox) + self.rangeFromPlayRating_ExLabel.setObjectName(u"rangeFromPlayRating_ExLabel") + self.rangeFromPlayRating_ExLabel.setText(u"...") + self.rangeFromPlayRating_ExLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) + + self.formLayout.setWidget(1, QFormLayout.FieldRole, self.rangeFromPlayRating_ExLabel) + + self.label_3 = QLabel(self.groupBox) + self.label_3.setObjectName(u"label_3") + self.label_3.setText(u"AA") + self.label_3.setAlignment(Qt.AlignBottom|Qt.AlignLeading|Qt.AlignLeft) + + self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_3) + + self.rangeFromPlayRating_AaLabel = QLabel(self.groupBox) + self.rangeFromPlayRating_AaLabel.setObjectName(u"rangeFromPlayRating_AaLabel") + self.rangeFromPlayRating_AaLabel.setText(u"...") + self.rangeFromPlayRating_AaLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) + + self.formLayout.setWidget(2, QFormLayout.FieldRole, self.rangeFromPlayRating_AaLabel) + + self.label_5 = QLabel(self.groupBox) + self.label_5.setObjectName(u"label_5") + self.label_5.setText(u"A") + + self.formLayout.setWidget(3, QFormLayout.LabelRole, self.label_5) + + self.rangeFromPlayRating_ALabel = QLabel(self.groupBox) + self.rangeFromPlayRating_ALabel.setObjectName(u"rangeFromPlayRating_ALabel") + self.rangeFromPlayRating_ALabel.setText(u"...") + + self.formLayout.setWidget(3, QFormLayout.FieldRole, self.rangeFromPlayRating_ALabel) + + self.label_8 = QLabel(self.groupBox) + self.label_8.setObjectName(u"label_8") + self.label_8.setText(u"B") + + self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_8) + + self.rangeFromPlayRating_BLabel = QLabel(self.groupBox) + self.rangeFromPlayRating_BLabel.setObjectName(u"rangeFromPlayRating_BLabel") + self.rangeFromPlayRating_BLabel.setText(u"...") + + self.formLayout.setWidget(4, QFormLayout.FieldRole, self.rangeFromPlayRating_BLabel) + + self.label_10 = QLabel(self.groupBox) + self.label_10.setObjectName(u"label_10") + self.label_10.setText(u"C") + + self.formLayout.setWidget(5, QFormLayout.LabelRole, self.label_10) + + self.rangeFromPlayRating_CLabel = QLabel(self.groupBox) + self.rangeFromPlayRating_CLabel.setObjectName(u"rangeFromPlayRating_CLabel") + self.rangeFromPlayRating_CLabel.setText(u"...") + + self.formLayout.setWidget(5, QFormLayout.FieldRole, self.rangeFromPlayRating_CLabel) + + + self.verticalLayout_2.addLayout(self.formLayout) + + + self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1) self.groupBox_3 = QGroupBox(TabTools_ChartRecommend) self.groupBox_3.setObjectName(u"groupBox_3") @@ -173,34 +210,33 @@ class Ui_TabTools_ChartRecommend(object): self.chartsRecommendFromPlayRating_numLabel = QLabel(self.groupBox_3) self.chartsRecommendFromPlayRating_numLabel.setObjectName(u"chartsRecommendFromPlayRating_numLabel") + sizePolicy.setHeightForWidth(self.chartsRecommendFromPlayRating_numLabel.sizePolicy().hasHeightForWidth()) + self.chartsRecommendFromPlayRating_numLabel.setSizePolicy(sizePolicy) self.chartsRecommendFromPlayRating_numLabel.setText(u"...") self.horizontalLayout_2.addWidget(self.chartsRecommendFromPlayRating_numLabel) - self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) - - self.horizontalLayout_2.addItem(self.horizontalSpacer_2) - - self.chartsRecommendFromPlayRating_refreshButton = QPushButton(self.groupBox_3) - self.chartsRecommendFromPlayRating_refreshButton.setObjectName(u"chartsRecommendFromPlayRating_refreshButton") - self.chartsRecommendFromPlayRating_refreshButton.setEnabled(False) - - self.horizontalLayout_2.addWidget(self.chartsRecommendFromPlayRating_refreshButton) - self.verticalLayout_4.addLayout(self.horizontalLayout_2) - self.widget_2 = QWidget(self.groupBox_3) - self.widget_2.setObjectName(u"widget_2") - sizePolicy.setHeightForWidth(self.widget_2.sizePolicy().hasHeightForWidth()) - self.widget_2.setSizePolicy(sizePolicy) - self.chartsRecommendFromPlayRating_gridLayout = QGridLayout(self.widget_2) - self.chartsRecommendFromPlayRating_gridLayout.setObjectName(u"chartsRecommendFromPlayRating_gridLayout") + self.chartsRecommendFromPlayRating_modelView = QTableView(self.groupBox_3) + self.chartsRecommendFromPlayRating_modelView.setObjectName(u"chartsRecommendFromPlayRating_modelView") + sizePolicy2 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + sizePolicy2.setHorizontalStretch(0) + sizePolicy2.setVerticalStretch(0) + sizePolicy2.setHeightForWidth(self.chartsRecommendFromPlayRating_modelView.sizePolicy().hasHeightForWidth()) + self.chartsRecommendFromPlayRating_modelView.setSizePolicy(sizePolicy2) + self.chartsRecommendFromPlayRating_modelView.setMinimumSize(QSize(200, 0)) + self.chartsRecommendFromPlayRating_modelView.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.chartsRecommendFromPlayRating_modelView.setSelectionMode(QAbstractItemView.SingleSelection) + self.chartsRecommendFromPlayRating_modelView.setSelectionBehavior(QAbstractItemView.SelectRows) + self.chartsRecommendFromPlayRating_modelView.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) + self.chartsRecommendFromPlayRating_modelView.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) - self.verticalLayout_4.addWidget(self.widget_2) + self.verticalLayout_4.addWidget(self.chartsRecommendFromPlayRating_modelView) - self.verticalLayout.addWidget(self.groupBox_3) + self.gridLayout.addWidget(self.groupBox_3, 1, 0, 1, 2) self.retranslateUi(TabTools_ChartRecommend) @@ -209,11 +245,9 @@ class Ui_TabTools_ChartRecommend(object): # setupUi def retranslateUi(self, TabTools_ChartRecommend): - self.groupBox.setTitle(QCoreApplication.translate("TabTools_ChartRecommend", u"constantRangeFromPlayRating", None)) self.groupBox_2.setTitle(QCoreApplication.translate("TabTools_ChartRecommend", u"chartsByConstant", None)) - self.chartsByConstant_refreshButton.setText(QCoreApplication.translate("TabTools_ChartRecommend", u"refreshButton", None)) + self.groupBox.setTitle(QCoreApplication.translate("TabTools_ChartRecommend", u"constantRangeFromPlayRating", None)) self.groupBox_3.setTitle(QCoreApplication.translate("TabTools_ChartRecommend", u"chartsRecommendFromPlayRating", None)) - self.chartsRecommendFromPlayRating_refreshButton.setText(QCoreApplication.translate("TabTools_ChartRecommend", u"refreshButton", None)) pass # retranslateUi diff --git a/ui/extends/shared/delegates/scoreDelegate.py b/ui/extends/shared/delegates/scoreDelegate.py index 56e7b65..61b2aa4 100644 --- a/ui/extends/shared/delegates/scoreDelegate.py +++ b/ui/extends/shared/delegates/scoreDelegate.py @@ -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): diff --git a/ui/extends/tabs/tabTools/tabTools_ChartRecommend.py b/ui/extends/tabs/tabTools/tabTools_ChartRecommend.py new file mode 100644 index 0000000..a716e42 --- /dev/null +++ b/ui/extends/tabs/tabTools/tabTools_ChartRecommend.py @@ -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) diff --git a/ui/implements/tabs/tabTools/tabTools_ChartRecommend.py b/ui/implements/tabs/tabTools/tabTools_ChartRecommend.py index a9a1b82..172cbfc 100644 --- a/ui/implements/tabs/tabTools/tabTools_ChartRecommend.py +++ b/ui/implements/tabs/tabTools/tabTools_ChartRecommend.py @@ -1,5 +1,4 @@ import logging -import random from arcaea_offline.calculate import calculate_constants_from_play_rating from arcaea_offline.database import Database @@ -7,11 +6,17 @@ from arcaea_offline.models import Chart, ScoreBest from arcaea_offline.utils.rating import rating_class_to_text from arcaea_offline.utils.score import score_to_grade_text from PySide6.QtCore import Slot -from PySide6.QtWidgets import QLabel, QWidget +from PySide6.QtWidgets import QWidget from ui.designer.tabs.tabTools.tabTools_ChartRecommend_ui import ( Ui_TabTools_ChartRecommend, ) +from ui.extends.tabs.tabTools.tabTools_ChartRecommend import ( + ChartsModel, + ChartsWithScoreBestModel, + CustomChartDelegate, + CustomScoreBestDelegate, +) logger = logging.getLogger(__name__) @@ -31,11 +36,25 @@ class TabTools_ChartRecommend(Ui_TabTools_ChartRecommend, QWidget): self.db = Database() - self.chartsByConstant = [] - self.chartsRecommendFromPlayRating = [] + self.chartsByConstantModel = ChartsModel(self) + self.chartsRecommendFromPlayRatingModel = ChartsWithScoreBestModel(self) self.numLabelFormatString = "{} charts" + self.chartDelegate = CustomChartDelegate(self) + self.scoreBestDelegate = CustomScoreBestDelegate(self) + self.chartsByConstant_modelView.setModel(self.chartsByConstantModel) + self.chartsByConstant_modelView.setItemDelegate(self.chartDelegate) + self.chartsRecommendFromPlayRating_modelView.setModel( + self.chartsRecommendFromPlayRatingModel + ) + self.chartsRecommendFromPlayRating_modelView.setItemDelegateForColumn( + 0, self.chartDelegate + ) + self.chartsRecommendFromPlayRating_modelView.setItemDelegateForColumn( + 1, self.scoreBestDelegate + ) + self.chartsRecommendFromPlayRating_playRatingSpinBox.valueChanged.connect( self.updateChartsRecommendFromPlayRating ) @@ -43,81 +62,61 @@ class TabTools_ChartRecommend(Ui_TabTools_ChartRecommend, QWidget): self.updateChartsRecommendFromPlayRating ) - self.chartsByConstant_refreshButton.clicked.connect(self.fillChartsByConstant) - self.chartsRecommendFromPlayRating_refreshButton.clicked.connect( - self.fillChartsRecommendFromPlayRating - ) - @Slot(float) def on_rangeFromPlayRating_playRatingSpinBox_valueChanged(self, value: float): try: - result = calculate_constants_from_play_rating(value) - exPlusLower, exPlusUpper = result.EXPlus - exLower, exUpper = result.EX - aaLower, aaUpper = result.AA - - self.rangeFromPlayRating_ExPlusLabel.setText( - f"{exPlusLower:.3f}~{exPlusUpper:.3f}" + constant = round( + value, self.rangeFromPlayRating_playRatingSpinBox.decimals() ) - self.rangeFromPlayRating_ExLabel.setText(f"{exLower:.3f}~{exUpper:.3f}") - self.rangeFromPlayRating_AaLabel.setText(f"{aaLower:.3f}~{aaUpper:.3f}") + result = calculate_constants_from_play_rating(constant) + labels = [ + self.rangeFromPlayRating_ExPlusLabel, + self.rangeFromPlayRating_ExLabel, + self.rangeFromPlayRating_AaLabel, + self.rangeFromPlayRating_ALabel, + self.rangeFromPlayRating_BLabel, + self.rangeFromPlayRating_CLabel, + ] + + for label, constantRange in zip( + labels, + [result.EXPlus, result.EX, result.AA, result.A, result.B, result.C], + ): + label.setText(f"{constantRange[0]:.3f}~{constantRange[1]:.3f}") except Exception: - logging.exception("cannot calculate constant from play rating") + logging.exception("Cannot calculate constant from play rating:") self.rangeFromPlayRating_ExPlusLabel.setText("...") self.rangeFromPlayRating_ExLabel.setText("...") self.rangeFromPlayRating_AaLabel.setText("...") - def fillChartsByConstant(self): - while item := self.chartsByConstant_gridLayout.takeAt(0): - item.widget().deleteLater() - - charts = random.sample( - self.chartsByConstant, k=min(len(self.chartsByConstant), 6) - ) - row = 0 - for i, chart in enumerate(charts): - if i % 3 == 0: - row += 1 - label = QLabel(self) - label.setText(chartToText(chart)) - self.chartsByConstant_gridLayout.addWidget(label, row, i % 3) - @Slot(float) def on_chartsByConstant_constantSpinBox_valueChanged(self, value: float): - self.chartsByConstant = self.db.get_charts_by_constant(int(value * 10)) - chartsNum = len(self.chartsByConstant) - self.chartsByConstant_refreshButton.setEnabled(chartsNum > 6) + constant = round(value, self.chartsByConstant_constantSpinBox.decimals()) + charts = self.db.get_charts_by_constant(int(constant * 10)) + chartsNum = len(charts) self.chartsByConstant_numLabel.setText( self.numLabelFormatString.format(chartsNum) ) - self.fillChartsByConstant() - - def fillChartsRecommendFromPlayRating(self): - while item := self.chartsRecommendFromPlayRating_gridLayout.takeAt(0): - item.widget().deleteLater() - - charts = random.sample( - self.chartsRecommendFromPlayRating, - k=min(len(self.chartsRecommendFromPlayRating), 6), - ) - row = 0 - for i, chart in enumerate(charts): - if i % 3 == 0: - row += 1 - scoreBest = self.db.get_score_best(chart.song_id, chart.rating_class) - label = QLabel(self) - label.setText(f"{chartToText(chart)}
-
{scoreBestToText(scoreBest)}") - self.chartsRecommendFromPlayRating_gridLayout.addWidget(label, row, i % 3) + self.chartsByConstantModel.setCharts(charts) def updateChartsRecommendFromPlayRating(self): playRating = self.chartsRecommendFromPlayRating_playRatingSpinBox.value() bounds = self.chartsRecommendFromPlayRating_boundsSpinBox.value() - self.chartsRecommendFromPlayRating = self.db.recommend_charts( - playRating, bounds + charts = self.db.recommend_charts( + round( + playRating, + self.chartsRecommendFromPlayRating_playRatingSpinBox.decimals(), + ), + round( + bounds, + self.chartsRecommendFromPlayRating_boundsSpinBox.decimals(), + ), ) - chartsNum = len(self.chartsRecommendFromPlayRating) - self.chartsRecommendFromPlayRating_refreshButton.setEnabled(chartsNum > 6) + chartsNum = len(charts) self.chartsRecommendFromPlayRating_numLabel.setText( self.numLabelFormatString.format(chartsNum) ) - self.fillChartsRecommendFromPlayRating() + scores = [self.db.get_score_best(c.song_id, c.rating_class) for c in charts] + self.chartsRecommendFromPlayRatingModel.setChartAndScore(charts, scores) + self.chartsRecommendFromPlayRating_modelView.resizeRowsToContents() + self.chartsRecommendFromPlayRating_modelView.resizeColumnsToContents()