wip: chore

This commit is contained in:
2023-09-06 00:31:20 +08:00
parent fcc0d40d9a
commit 1955a7963a
8 changed files with 135 additions and 20 deletions

View File

@ -16,12 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>tab.selectChart</string>
</property>

View File

@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'tabInputScore.ui'
##
## Created by: Qt User Interface Compiler version 6.5.0
## Created by: Qt User Interface Compiler version 6.5.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
@ -31,11 +31,6 @@ class Ui_TabInputScore(object):
self.verticalLayout.setObjectName(u"verticalLayout")
self.groupBox = QGroupBox(TabInputScore)
self.groupBox.setObjectName(u"groupBox")
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth())
self.groupBox.setSizePolicy(sizePolicy)
self.verticalLayout_2 = QVBoxLayout(self.groupBox)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)

View File

@ -0,0 +1,126 @@
# Adapted from https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html
from PySide6.QtCore import QPoint, QRect, QSize, Qt
from PySide6.QtWidgets import QLayout, QLayoutItem, QSizePolicy, QStyle, QWidget
class FlowLayout(QLayout):
def __init__(self, parent=None, margin=0, hSpacing=0, vSpacing=0):
super().__init__(parent)
self.hSpace = hSpacing
self.vSpace = vSpacing
self.setContentsMargins(margin, margin, margin, margin)
self.itemList: list[QLayoutItem] = []
def __del__(self):
item = self.takeAt(0)
while item:
del item
item = self.takeAt(0)
def addItem(self, item: QLayoutItem):
self.itemList.append(item)
def horizontalSpacing(self):
return (
self.hSpace
if self.hSpace >= 0
else self.smartSpacing(QStyle.PixelMetric.PM_LayoutHorizontalSpacing)
)
def verticalSpacing(self):
return (
self.vSpace
if self.vSpace >= 0
else self.smartSpacing(QStyle.PixelMetric.PM_LayoutVerticalSpacing)
)
def count(self):
return len(self.itemList)
def itemAt(self, index: int):
return self.itemList[index] if 0 <= index < len(self.itemList) else None
def takeAt(self, index):
return self.itemList.pop(index) if 0 <= index < len(self.itemList) else None
# Qt::Orientations FlowLayout::expandingDirections() const
# {
# return { };
# }
def expandingDirections(self):
return Qt.Orientations(0)
def hasHeightForWidth(self):
return True
def heightForWidth(self, width: int):
return self.doLayout(QRect(0, 0, width, 0), True)
def setGeometry(self, rect: QRect):
super().setGeometry(rect)
self.doLayout(rect, False)
def sizeHint(self):
return self.minimumSize()
def minimumSize(self):
size = QSize()
for item in self.itemList:
size = size.expandedTo(item.minimumSize())
margins = self.contentsMargins()
size += QSize(
margins.left() + margins.right(), margins.top() + margins.bottom()
)
return size
def doLayout(self, rect: QRect, testOnly: bool):
margins = self.contentsMargins()
left = margins.left()
top = margins.top()
right = margins.right()
bottom = margins.bottom()
effectiveRect = rect.adjusted(+left, +top, -right, -bottom)
x = effectiveRect.x()
y = effectiveRect.y()
lineHeight = 0
for item in self.itemList:
widget = item.widget()
spaceX = self.horizontalSpacing()
if spaceX == -1:
spaceX = widget.style().layoutSpacing(
QSizePolicy.ControlType.PushButton,
QSizePolicy.ControlType.PushButton,
)
spaceY = self.verticalSpacing()
if spaceY == -1:
spaceY = widget.style().layoutSpacing(
QSizePolicy.ControlType.PushButton,
QSizePolicy.ControlType.PushButton,
)
nextX = x + item.sizeHint().width() + spaceX
if nextX - spaceX > effectiveRect.right() and lineHeight > 0:
x = effectiveRect.x()
y = y + lineHeight + spaceY
nextX = x + item.sizeHint().width() + spaceX
lineHeight = 0
if not testOnly:
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
x = nextX
lineHeight = max(lineHeight, item.sizeHint().height())
return y + lineHeight - rect.y() + bottom
def smartSpacing(self, pm: QStyle.PixelMetric):
parent = self.parent()
if not parent:
return -1
elif parent.isWidgetType():
parent: QWidget
return parent.style().pixelMetric(pm, None, parent)
else:
parent: QLayout
return parent.spacing()

View File

@ -39,7 +39,7 @@ class DbB30TableModel(DbTableModel):
ptts = [r.potential for r in results]
for scoreId, ptt in zip(songIds, ptts):
score = self._db.get_score_by_id(scoreId)
score = self._db.get_score(scoreId)
chart = self._db.get_chart(score.song_id, score.rating_class)
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())

View File

@ -46,7 +46,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
def updateResultLabel(self):
chart = self.value()
if isinstance(chart, Chart):
pack = self.db.get_pack_by_id(chart.set)
pack = self.db.get_pack(chart.set)
texts = [
[
pack.name,

View File

@ -112,7 +112,7 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
isAppendPack = re.search(r"_append_.*$", pack.id)
if isAppendPack:
basePackId = re.sub(r"_append_.*$", "", pack.id)
basePackName = self.db.get_pack_by_id(basePackId).name
basePackName = self.db.get_pack(basePackId).name
packName = f"{basePackName} - {pack.name}"
else:
packName = pack.name

View File

@ -77,8 +77,8 @@ class TabTools_InfoLookup(Ui_TabTools_InfoLookup, QWidget):
self.resetPackLabels()
return
pack = self.db.get_pack_by_id(packId)
packLocalized = self.db.get_pack_localized_by_id(packId)
pack = self.db.get_pack(packId)
packLocalized = self.db.get_pack_localized(packId)
name = self.getLocalizedItem(pack, packLocalized, "name")
description = self.getLocalizedItem(pack, packLocalized, "description")
@ -98,8 +98,8 @@ class TabTools_InfoLookup(Ui_TabTools_InfoLookup, QWidget):
self.resetSongLabels()
return
song = self.db.get_song_by_id(songId)
songLocalized = self.db.get_song_localized_by_id(songId)
song = self.db.get_song(songId)
songLocalized = self.db.get_song_localized(songId)
title = self.getLocalizedItem(song, songLocalized, "title")
bgSideTexts = []