mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
impr: update when database changed, instead of showEvent
This commit is contained in:
@ -4,10 +4,10 @@ from arcaea_offline.database import Database
|
||||
from arcaea_offline.models import Chart
|
||||
from arcaea_offline.utils.rating import rating_class_to_text
|
||||
from PySide6.QtCore import Signal, Slot
|
||||
from PySide6.QtGui import QShowEvent
|
||||
from PySide6.QtWidgets import QWidget
|
||||
|
||||
from ui.designer.components.chartSelector_ui import Ui_ChartSelector
|
||||
from ui.extends.shared.database import databaseUpdateSignals
|
||||
from ui.extends.shared.language import LanguageChangeEventFilter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -30,6 +30,12 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
self.songIdSelector.valueChanged.connect(self.valueChanged)
|
||||
self.ratingClassSelector.valueChanged.connect(self.valueChanged)
|
||||
|
||||
# handle `songIdSelector.updateDatabase` by this component
|
||||
databaseUpdateSignals.songDataUpdated.disconnect(
|
||||
self.songIdSelector.updateDatabase
|
||||
)
|
||||
databaseUpdateSignals.songDataUpdated.connect(self.updateDatabase)
|
||||
|
||||
def value(self):
|
||||
songId = self.songIdSelector.songId()
|
||||
ratingClass = self.ratingClassSelector.value()
|
||||
@ -38,13 +44,15 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
return self.db.get_chart(songId, ratingClass)
|
||||
return None
|
||||
|
||||
def showEvent(self, event: QShowEvent):
|
||||
def updateDatabase(self):
|
||||
# remember selection and restore later
|
||||
ratingClass = self.ratingClassSelector.value()
|
||||
|
||||
# wait `songIdSelector` finish
|
||||
self.songIdSelector.updateDatabase()
|
||||
|
||||
if ratingClass is not None:
|
||||
self.ratingClassSelector.select(ratingClass)
|
||||
return super().showEvent(event)
|
||||
|
||||
@Slot()
|
||||
def updateResultLabel(self):
|
||||
|
@ -5,11 +5,11 @@ from typing import Literal
|
||||
from arcaea_offline.database import Database
|
||||
from arcaea_offline.models import Chart
|
||||
from PySide6.QtCore import QModelIndex, Qt, Signal, Slot
|
||||
from PySide6.QtGui import QShowEvent
|
||||
from PySide6.QtWidgets import QCompleter, QWidget
|
||||
|
||||
from ui.designer.components.songIdSelector_ui import Ui_SongIdSelector
|
||||
from ui.extends.components.songIdSelector import SearchCompleterModel
|
||||
from ui.extends.shared.database import databaseUpdateSignals
|
||||
from ui.extends.shared.delegates.descriptionDelegate import DescriptionDelegate
|
||||
from ui.extends.shared.language import LanguageChangeEventFilter
|
||||
|
||||
@ -40,6 +40,8 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
||||
lambda: self.quickSwitchSelection("next", "package")
|
||||
)
|
||||
|
||||
databaseUpdateSignals.songDataUpdated.connect(self.updateDatabase)
|
||||
|
||||
self.fillPackComboBox()
|
||||
self.packComboBox.setCurrentIndex(-1)
|
||||
self.songIdComboBox.setCurrentIndex(-1)
|
||||
@ -93,8 +95,7 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
||||
self.packComboBox.setCurrentIndex(-1)
|
||||
self.songIdComboBox.setCurrentIndex(-1)
|
||||
|
||||
def showEvent(self, event: QShowEvent):
|
||||
# update database results when widget visible
|
||||
def updateDatabase(self):
|
||||
self.searchCompleterModel.updateSearcherSongs()
|
||||
|
||||
# remember selection and restore later
|
||||
@ -107,7 +108,6 @@ class SongIdSelector(Ui_SongIdSelector, QWidget):
|
||||
self.selectPack(pack)
|
||||
if songId:
|
||||
self.selectSongId(songId)
|
||||
return super().showEvent(event)
|
||||
|
||||
def fillPackComboBox(self):
|
||||
self.packComboBox.clear()
|
||||
|
Reference in New Issue
Block a user