mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 09:33:57 -07:00
[VDE] Accurately represent card amounts.
Took 40 minutes Took 3 seconds Took 3 minutes Took 2 minutes
This commit is contained in:
parent
999733fc0f
commit
ed5dbb77b5
4 changed files with 75 additions and 21 deletions
|
|
@ -37,6 +37,7 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
||||||
&CardGroupDisplayWidget::onSelectionChanged);
|
&CardGroupDisplayWidget::onSelectionChanged);
|
||||||
}
|
}
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
||||||
|
connect(deckListModel, &QAbstractItemModel::dataChanged, this, &CardGroupDisplayWidget::onDataChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just here so it can get overwritten in subclasses.
|
// Just here so it can get overwritten in subclasses.
|
||||||
|
|
@ -81,12 +82,15 @@ void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected,
|
||||||
|
|
||||||
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
if (it != indexToWidgetMap.end()) {
|
if (it != indexToWidgetMap.end()) {
|
||||||
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(it.value())) {
|
// Highlight all copies of this card
|
||||||
|
for (auto widget : it.value()) {
|
||||||
|
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(widget)) {
|
||||||
displayWidget->setHighlighted(true);
|
displayWidget->setHighlighted(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &range : deselected) {
|
for (auto &range : deselected) {
|
||||||
for (int row = range.top(); row <= range.bottom(); ++row) {
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
|
@ -96,12 +100,15 @@ void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected,
|
||||||
|
|
||||||
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
if (it != indexToWidgetMap.end()) {
|
if (it != indexToWidgetMap.end()) {
|
||||||
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(it.value())) {
|
// Un-highlight all copies of this card
|
||||||
|
for (auto widget : it.value()) {
|
||||||
|
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(widget)) {
|
||||||
displayWidget->setHighlighted(false);
|
displayWidget->setHighlighted(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
@ -110,9 +117,6 @@ void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected,
|
||||||
|
|
||||||
QWidget *CardGroupDisplayWidget::constructWidgetForIndex(QPersistentModelIndex index)
|
QWidget *CardGroupDisplayWidget::constructWidgetForIndex(QPersistentModelIndex index)
|
||||||
{
|
{
|
||||||
if (indexToWidgetMap.contains(index)) {
|
|
||||||
return indexToWidgetMap[index];
|
|
||||||
}
|
|
||||||
auto cardName = index.sibling(index.row(), DeckListModelColumns::CARD_NAME).data(Qt::EditRole).toString();
|
auto cardName = index.sibling(index.row(), DeckListModelColumns::CARD_NAME).data(Qt::EditRole).toString();
|
||||||
auto cardProviderId =
|
auto cardProviderId =
|
||||||
index.sibling(index.row(), DeckListModelColumns::CARD_PROVIDER_ID).data(Qt::EditRole).toString();
|
index.sibling(index.row(), DeckListModelColumns::CARD_PROVIDER_ID).data(Qt::EditRole).toString();
|
||||||
|
|
@ -125,7 +129,12 @@ QWidget *CardGroupDisplayWidget::constructWidgetForIndex(QPersistentModelIndex i
|
||||||
connect(widget, &CardInfoPictureWithTextOverlayWidget::hoveredOnCard, this, &CardGroupDisplayWidget::onHover);
|
connect(widget, &CardInfoPictureWithTextOverlayWidget::hoveredOnCard, this, &CardGroupDisplayWidget::onHover);
|
||||||
connect(cardSizeWidget->getSlider(), &QSlider::valueChanged, widget, &CardInfoPictureWidget::setScaleFactor);
|
connect(cardSizeWidget->getSlider(), &QSlider::valueChanged, widget, &CardInfoPictureWidget::setScaleFactor);
|
||||||
|
|
||||||
indexToWidgetMap.insert(index, widget);
|
// Add to the list of widgets for this index
|
||||||
|
if (!indexToWidgetMap.contains(index)) {
|
||||||
|
indexToWidgetMap.insert(index, QList<QWidget *>());
|
||||||
|
}
|
||||||
|
indexToWidgetMap[index].append(widget);
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,18 +161,26 @@ void CardGroupDisplayWidget::updateCardDisplays()
|
||||||
// 4. persist the source index
|
// 4. persist the source index
|
||||||
QPersistentModelIndex persistent(sourceIndex);
|
QPersistentModelIndex persistent(sourceIndex);
|
||||||
|
|
||||||
|
// Get the card amount
|
||||||
|
int cardAmount =
|
||||||
|
sourceIndex.sibling(sourceIndex.row(), DeckListModelColumns::CARD_AMOUNT).data(Qt::EditRole).toInt();
|
||||||
|
|
||||||
|
// Create multiple widgets for the card count
|
||||||
|
for (int copy = 0; copy < cardAmount; ++copy) {
|
||||||
addToLayout(constructWidgetForIndex(persistent));
|
addToLayout(constructWidgetForIndex(persistent));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
||||||
{
|
{
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
auto displayWidget = indexToWidgetMap.value(idx);
|
for (auto displayWidget : indexToWidgetMap.value(idx)) {
|
||||||
removeFromLayout(displayWidget);
|
removeFromLayout(displayWidget);
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
delete displayWidget;
|
delete displayWidget;
|
||||||
}
|
}
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
@ -184,30 +201,59 @@ void CardGroupDisplayWidget::onCardAddition(const QModelIndex &parent, int first
|
||||||
// Persist the index
|
// Persist the index
|
||||||
QPersistentModelIndex persistent(child);
|
QPersistentModelIndex persistent(child);
|
||||||
|
|
||||||
|
// Get the card amount for the newly added card
|
||||||
|
int cardAmount = child.sibling(child.row(), DeckListModelColumns::CARD_AMOUNT).data(Qt::EditRole).toInt();
|
||||||
|
|
||||||
|
// Insert multiple copies
|
||||||
|
for (int copy = 0; copy < cardAmount; ++copy) {
|
||||||
insertIntoLayout(constructWidgetForIndex(persistent), row);
|
insertIntoLayout(constructWidgetForIndex(persistent), row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onCardRemoval(const QModelIndex &parent, int first, int last)
|
void CardGroupDisplayWidget::onCardRemoval(const QModelIndex &parent, int first, int last)
|
||||||
{
|
{
|
||||||
Q_UNUSED(first);
|
Q_UNUSED(first);
|
||||||
Q_UNUSED(last);
|
Q_UNUSED(last);
|
||||||
|
|
||||||
if (parent == trackedIndex) {
|
if (parent == trackedIndex) {
|
||||||
|
QList<QPersistentModelIndex> keysToRemove;
|
||||||
|
|
||||||
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
||||||
if (!idx.isValid()) {
|
if (!idx.isValid()) {
|
||||||
removeFromLayout(indexToWidgetMap.value(idx));
|
keysToRemove.append(idx);
|
||||||
indexToWidgetMap.value(idx)->deleteLater();
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const QPersistentModelIndex &idx : keysToRemove) {
|
||||||
|
for (auto widget : indexToWidgetMap.value(idx)) {
|
||||||
|
removeFromLayout(widget);
|
||||||
|
widget->deleteLater();
|
||||||
|
}
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
}
|
||||||
|
|
||||||
if (!trackedIndex.isValid()) {
|
if (!trackedIndex.isValid()) {
|
||||||
emit cleanupRequested(this);
|
emit cleanupRequested(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::onDataChanged(const QModelIndex &topLeft,
|
||||||
|
const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles)
|
||||||
|
{
|
||||||
|
Q_UNUSED(roles);
|
||||||
|
if (topLeft.parent() != trackedIndex && bottomRight.parent() != trackedIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When card amounts change, rebuild the display
|
||||||
|
clearAllDisplayWidgets();
|
||||||
|
updateCardDisplays();
|
||||||
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSortCriteria)
|
void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSortCriteria)
|
||||||
{
|
{
|
||||||
activeSortCriteria = std::move(_activeSortCriteria);
|
activeSortCriteria = std::move(_activeSortCriteria);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public:
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
QItemSelectionModel *selectionModel;
|
QItemSelectionModel *selectionModel;
|
||||||
QPersistentModelIndex trackedIndex;
|
QPersistentModelIndex trackedIndex;
|
||||||
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
|
QMap<QPersistentModelIndex, QList<QWidget *>> indexToWidgetMap;
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
QString cardGroupCategory;
|
QString cardGroupCategory;
|
||||||
QString activeGroupCriteria;
|
QString activeGroupCriteria;
|
||||||
|
|
@ -53,6 +53,7 @@ public slots:
|
||||||
virtual void updateCardDisplays();
|
virtual void updateCardDisplays();
|
||||||
virtual void onCardAddition(const QModelIndex &parent, int first, int last);
|
virtual void onCardAddition(const QModelIndex &parent, int first, int last);
|
||||||
virtual void onCardRemoval(const QModelIndex &parent, int first, int last);
|
virtual void onCardRemoval(const QModelIndex &parent, int first, int last);
|
||||||
|
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||||
void onActiveSortCriteriaChanged(QStringList activeSortCriteria);
|
void onActiveSortCriteriaChanged(QStringList activeSortCriteria);
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,17 @@ FlatCardGroupDisplayWidget::FlatCardGroupDisplayWidget(QWidget *parent,
|
||||||
|
|
||||||
layout->addWidget(flowWidget);
|
layout->addWidget(flowWidget);
|
||||||
|
|
||||||
|
// Clear all existing widgets
|
||||||
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
||||||
FlatCardGroupDisplayWidget::removeFromLayout(indexToWidgetMap.value(idx));
|
for (auto widget : indexToWidgetMap.value(idx)) {
|
||||||
indexToWidgetMap.value(idx)->deleteLater();
|
FlatCardGroupDisplayWidget::removeFromLayout(widget);
|
||||||
|
widget->deleteLater();
|
||||||
|
}
|
||||||
indexToWidgetMap.remove(idx);
|
indexToWidgetMap.remove(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatCardGroupDisplayWidget::updateCardDisplays();
|
FlatCardGroupDisplayWidget::updateCardDisplays();
|
||||||
|
|
||||||
disconnect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::onCardAddition);
|
disconnect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::onCardAddition);
|
||||||
disconnect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
disconnect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,12 @@ OverlappedCardGroupDisplayWidget::OverlappedCardGroupDisplayWidget(QWidget *pare
|
||||||
|
|
||||||
layout->addWidget(overlapWidget);
|
layout->addWidget(overlapWidget);
|
||||||
|
|
||||||
|
// Clear all existing widgets
|
||||||
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
||||||
OverlappedCardGroupDisplayWidget::removeFromLayout(indexToWidgetMap.value(idx));
|
for (auto widget : indexToWidgetMap.value(idx)) {
|
||||||
indexToWidgetMap.value(idx)->deleteLater();
|
OverlappedCardGroupDisplayWidget::removeFromLayout(widget);
|
||||||
|
widget->deleteLater();
|
||||||
|
}
|
||||||
indexToWidgetMap.remove(idx);
|
indexToWidgetMap.remove(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue