mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
parent
bac6beeb50
commit
122926c6cd
4 changed files with 64 additions and 33 deletions
|
|
@ -52,11 +52,6 @@ DeckEditorDeckDockWidget::DeckEditorDeckDockWidget(AbstractTabDeckEditor *parent
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::createDeckDock()
|
void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
{
|
{
|
||||||
historyManager = new DeckListHistoryManager();
|
|
||||||
|
|
||||||
connect(deckEditor, &AbstractTabDeckEditor::cardAboutToBeAdded, this,
|
|
||||||
&DeckEditorDeckDockWidget::onCardAboutToBeAdded);
|
|
||||||
|
|
||||||
deckModel = new DeckListModel(this);
|
deckModel = new DeckListModel(this);
|
||||||
deckModel->setObjectName("deckModel");
|
deckModel->setObjectName("deckModel");
|
||||||
connect(deckModel, &DeckListModel::deckHashChanged, this, &DeckEditorDeckDockWidget::updateHash);
|
connect(deckModel, &DeckListModel::deckHashChanged, this, &DeckEditorDeckDockWidget::updateHash);
|
||||||
|
|
@ -66,7 +61,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
proxy = new DeckListStyleProxy(this);
|
proxy = new DeckListStyleProxy(this);
|
||||||
proxy->setSourceModel(deckModel);
|
proxy->setSourceModel(deckModel);
|
||||||
|
|
||||||
historyManagerWidget = new DeckListHistoryManagerWidget(deckModel, proxy, historyManager, this);
|
historyManagerWidget = new DeckListHistoryManagerWidget(deckModel, proxy, deckEditor->getHistoryManager(), this);
|
||||||
connect(historyManagerWidget, &DeckListHistoryManagerWidget::requestDisplayWidgetSync, this,
|
connect(historyManagerWidget, &DeckListHistoryManagerWidget::requestDisplayWidgetSync, this,
|
||||||
&DeckEditorDeckDockWidget::syncDisplayWidgetsToModel);
|
&DeckEditorDeckDockWidget::syncDisplayWidgetsToModel);
|
||||||
|
|
||||||
|
|
@ -300,8 +295,8 @@ void DeckEditorDeckDockWidget::updateCard(const QModelIndex /*¤t*/, const
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::updateName(const QString &name)
|
void DeckEditorDeckDockWidget::updateName(const QString &name)
|
||||||
{
|
{
|
||||||
historyManager->save(deckLoader->getDeckList()->createMemento(
|
emit requestDeckHistorySave(
|
||||||
QString(tr("Rename deck to \"%1\" from \"%2\"")).arg(name).arg(deckLoader->getDeckList()->getName())));
|
QString(tr("Rename deck to \"%1\" from \"%2\"")).arg(name).arg(deckLoader->getDeckList()->getName()));
|
||||||
deckModel->getDeckList()->setName(name);
|
deckModel->getDeckList()->setName(name);
|
||||||
deckEditor->setModified(name.isEmpty());
|
deckEditor->setModified(name.isEmpty());
|
||||||
emit nameChanged();
|
emit nameChanged();
|
||||||
|
|
@ -310,10 +305,9 @@ void DeckEditorDeckDockWidget::updateName(const QString &name)
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::updateComments()
|
void DeckEditorDeckDockWidget::updateComments()
|
||||||
{
|
{
|
||||||
historyManager->save(
|
emit requestDeckHistorySave(tr("Updated comments (was %1 chars, now %2 chars)")
|
||||||
deckLoader->getDeckList()->createMemento(QString(tr("Updated comments (was %1 chars, now %2 chars)"))
|
.arg(deckLoader->getDeckList()->getComments().size())
|
||||||
.arg(deckLoader->getDeckList()->getComments().size())
|
.arg(commentsEdit->toPlainText().size()));
|
||||||
.arg(commentsEdit->toPlainText().size())));
|
|
||||||
|
|
||||||
deckModel->getDeckList()->setComments(commentsEdit->toPlainText());
|
deckModel->getDeckList()->setComments(commentsEdit->toPlainText());
|
||||||
deckEditor->setModified(commentsEdit->toPlainText().isEmpty());
|
deckEditor->setModified(commentsEdit->toPlainText().isEmpty());
|
||||||
|
|
@ -370,7 +364,7 @@ void DeckEditorDeckDockWidget::updateBannerCardComboBox()
|
||||||
// Handle results
|
// Handle results
|
||||||
if (restoreIndex != -1) {
|
if (restoreIndex != -1) {
|
||||||
bannerCardComboBox->setCurrentIndex(restoreIndex);
|
bannerCardComboBox->setCurrentIndex(restoreIndex);
|
||||||
setBannerCard(restoreIndex);
|
syncDeckListBannerCardWithComboBox();
|
||||||
} else {
|
} else {
|
||||||
// Add a placeholder "-" and set it as the current selection
|
// Add a placeholder "-" and set it as the current selection
|
||||||
bannerCardComboBox->insertItem(0, "-");
|
bannerCardComboBox->insertItem(0, "-");
|
||||||
|
|
@ -383,13 +377,18 @@ void DeckEditorDeckDockWidget::updateBannerCardComboBox()
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */)
|
void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */)
|
||||||
{
|
{
|
||||||
historyManager->save(deckLoader->getDeckList()->createMemento(tr("Banner card changed")));
|
emit requestDeckHistorySave(tr("Banner card changed"));
|
||||||
auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
syncDeckListBannerCardWithComboBox();
|
||||||
deckModel->getDeckList()->setBannerCard({name, id});
|
|
||||||
deckEditor->setModified(true);
|
deckEditor->setModified(true);
|
||||||
emit deckModified();
|
emit deckModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckEditorDeckDockWidget::syncDeckListBannerCardWithComboBox()
|
||||||
|
{
|
||||||
|
auto [name, id] = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
||||||
|
deckModel->getDeckList()->setBannerCard({name, id});
|
||||||
|
}
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::updateShowBannerCardComboBox(const bool visible)
|
void DeckEditorDeckDockWidget::updateShowBannerCardComboBox(const bool visible)
|
||||||
{
|
{
|
||||||
bannerCardLabel->setHidden(!visible);
|
bannerCardLabel->setHidden(!visible);
|
||||||
|
|
@ -427,7 +426,7 @@ void DeckEditorDeckDockWidget::setDeck(DeckLoader *_deck)
|
||||||
connect(deckLoader, &DeckLoader::deckLoaded, deckModel, &DeckListModel::rebuildTree);
|
connect(deckLoader, &DeckLoader::deckLoaded, deckModel, &DeckListModel::rebuildTree);
|
||||||
connect(deckLoader->getDeckList(), &DeckList::deckHashChanged, deckModel, &DeckListModel::deckHashChanged);
|
connect(deckLoader->getDeckList(), &DeckList::deckHashChanged, deckModel, &DeckListModel::deckHashChanged);
|
||||||
|
|
||||||
historyManager->clear();
|
emit requestDeckHistoryClear();
|
||||||
historyManagerWidget->setDeckListModel(deckModel);
|
historyManagerWidget->setDeckListModel(deckModel);
|
||||||
|
|
||||||
syncDisplayWidgetsToModel();
|
syncDisplayWidgetsToModel();
|
||||||
|
|
@ -521,14 +520,6 @@ QModelIndexList DeckEditorDeckDockWidget::getSelectedCardNodes() const
|
||||||
return selectedRows;
|
return selectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::onCardAboutToBeAdded(const ExactCard &addedCard, const QString &zoneName)
|
|
||||||
{
|
|
||||||
historyManager->save(deckLoader->getDeckList()->createMemento(
|
|
||||||
QString(tr("Added (%1): %2 (%3) %4"))
|
|
||||||
.arg(zoneName, addedCard.getName(), addedCard.getPrinting().getSet()->getCorrectedShortName(),
|
|
||||||
addedCard.getPrinting().getProperty("num"))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::actIncrement()
|
void DeckEditorDeckDockWidget::actIncrement()
|
||||||
{
|
{
|
||||||
auto selectedRows = getSelectedCardNodes();
|
auto selectedRows = getSelectedCardNodes();
|
||||||
|
|
@ -649,8 +640,7 @@ void DeckEditorDeckDockWidget::actRemoveCard()
|
||||||
QModelIndex sourceIndex = proxy->mapToSource(index);
|
QModelIndex sourceIndex = proxy->mapToSource(index);
|
||||||
QString cardName = sourceIndex.sibling(sourceIndex.row(), 1).data().toString();
|
QString cardName = sourceIndex.sibling(sourceIndex.row(), 1).data().toString();
|
||||||
|
|
||||||
historyManager->save(
|
emit requestDeckHistorySave(QString(tr("Removed \"%1\" (all copies)")).arg(cardName));
|
||||||
deckLoader->getDeckList()->createMemento(QString(tr("Removed \"%1\" (all copies)")).arg(cardName)));
|
|
||||||
|
|
||||||
deckModel->removeRow(sourceIndex.row(), sourceIndex.parent());
|
deckModel->removeRow(sourceIndex.row(), sourceIndex.parent());
|
||||||
isModified = true;
|
isModified = true;
|
||||||
|
|
@ -685,7 +675,7 @@ void DeckEditorDeckDockWidget::offsetCountAtIndex(const QModelIndex &idx, int of
|
||||||
.arg(cardName)
|
.arg(cardName)
|
||||||
.arg(deckModel->data(sourceIndex.sibling(sourceIndex.row(), 4), Qt::DisplayRole).toString());
|
.arg(deckModel->data(sourceIndex.sibling(sourceIndex.row(), 4), Qt::DisplayRole).toString());
|
||||||
|
|
||||||
historyManager->save(deckLoader->getDeckList()->createMemento(reason));
|
emit requestDeckHistorySave(reason);
|
||||||
|
|
||||||
if (new_count <= 0) {
|
if (new_count <= 0) {
|
||||||
deckModel->removeRow(sourceIndex.row(), sourceIndex.parent());
|
deckModel->removeRow(sourceIndex.row(), sourceIndex.parent());
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include "../visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h"
|
#include "../visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h"
|
||||||
#include "deck_list_history_manager_widget.h"
|
#include "deck_list_history_manager_widget.h"
|
||||||
#include "deck_list_style_proxy.h"
|
#include "deck_list_style_proxy.h"
|
||||||
#include "libcockatrice/deck_list/deck_list_history_manager.h"
|
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
|
@ -70,7 +69,6 @@ public slots:
|
||||||
void actDecrementSelection();
|
void actDecrementSelection();
|
||||||
void actSwapCard();
|
void actSwapCard();
|
||||||
void actRemoveCard();
|
void actRemoveCard();
|
||||||
void onCardAboutToBeAdded(const ExactCard &card, const QString &zoneName);
|
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -79,11 +77,12 @@ signals:
|
||||||
void hashChanged();
|
void hashChanged();
|
||||||
void deckChanged();
|
void deckChanged();
|
||||||
void deckModified();
|
void deckModified();
|
||||||
|
void requestDeckHistorySave(const QString &modificationReason);
|
||||||
|
void requestDeckHistoryClear();
|
||||||
void cardChanged(const ExactCard &_card);
|
void cardChanged(const ExactCard &_card);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AbstractTabDeckEditor *deckEditor;
|
AbstractTabDeckEditor *deckEditor;
|
||||||
DeckListHistoryManager *historyManager;
|
|
||||||
DeckListHistoryManagerWidget *historyManagerWidget;
|
DeckListHistoryManagerWidget *historyManagerWidget;
|
||||||
KeySignals deckViewKeySignals;
|
KeySignals deckViewKeySignals;
|
||||||
QLabel *nameLabel;
|
QLabel *nameLabel;
|
||||||
|
|
@ -113,6 +112,7 @@ private slots:
|
||||||
void updateName(const QString &name);
|
void updateName(const QString &name);
|
||||||
void updateComments();
|
void updateComments();
|
||||||
void setBannerCard(int);
|
void setBannerCard(int);
|
||||||
|
void syncDeckListBannerCardWithComboBox();
|
||||||
void updateHash();
|
void updateHash();
|
||||||
void refreshShortcuts();
|
void refreshShortcuts();
|
||||||
void updateShowBannerCardComboBox(bool visible);
|
void updateShowBannerCardComboBox(bool visible);
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ AbstractTabDeckEditor::AbstractTabDeckEditor(TabSupervisor *_tabSupervisor) : Ta
|
||||||
{
|
{
|
||||||
setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
|
setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
|
||||||
|
|
||||||
|
historyManager = new DeckListHistoryManager(this);
|
||||||
|
|
||||||
databaseDisplayDockWidget = new DeckEditorDatabaseDisplayWidget(this);
|
databaseDisplayDockWidget = new DeckEditorDatabaseDisplayWidget(this);
|
||||||
deckDockWidget = new DeckEditorDeckDockWidget(this);
|
deckDockWidget = new DeckEditorDeckDockWidget(this);
|
||||||
cardInfoDockWidget = new DeckEditorCardInfoDockWidget(this);
|
cardInfoDockWidget = new DeckEditorCardInfoDockWidget(this);
|
||||||
|
|
@ -70,6 +72,10 @@ AbstractTabDeckEditor::AbstractTabDeckEditor(TabSupervisor *_tabSupervisor) : Ta
|
||||||
// Connect deck signals to this tab
|
// Connect deck signals to this tab
|
||||||
connect(deckDockWidget, &DeckEditorDeckDockWidget::deckChanged, this, &AbstractTabDeckEditor::onDeckChanged);
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::deckChanged, this, &AbstractTabDeckEditor::onDeckChanged);
|
||||||
connect(deckDockWidget, &DeckEditorDeckDockWidget::deckModified, this, &AbstractTabDeckEditor::onDeckModified);
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::deckModified, this, &AbstractTabDeckEditor::onDeckModified);
|
||||||
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::requestDeckHistorySave, this,
|
||||||
|
&AbstractTabDeckEditor::onDeckHistorySaveRequested);
|
||||||
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::requestDeckHistoryClear, this,
|
||||||
|
&AbstractTabDeckEditor::onDeckHistoryClearRequested);
|
||||||
connect(deckDockWidget, &DeckEditorDeckDockWidget::cardChanged, this, &AbstractTabDeckEditor::updateCard);
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::cardChanged, this, &AbstractTabDeckEditor::updateCard);
|
||||||
connect(this, &AbstractTabDeckEditor::decrementCard, deckDockWidget, &DeckEditorDeckDockWidget::actDecrementCard);
|
connect(this, &AbstractTabDeckEditor::decrementCard, deckDockWidget, &DeckEditorDeckDockWidget::actDecrementCard);
|
||||||
|
|
||||||
|
|
@ -107,6 +113,7 @@ void AbstractTabDeckEditor::updateCard(const ExactCard &card)
|
||||||
/** @brief Placeholder: called when the deck changes. */
|
/** @brief Placeholder: called when the deck changes. */
|
||||||
void AbstractTabDeckEditor::onDeckChanged()
|
void AbstractTabDeckEditor::onDeckChanged()
|
||||||
{
|
{
|
||||||
|
historyManager->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -118,6 +125,22 @@ void AbstractTabDeckEditor::onDeckModified()
|
||||||
deckMenu->setSaveStatus(!isBlankNewDeck());
|
deckMenu->setSaveStatus(!isBlankNewDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Marks the tab as modified and updates the save menu status.
|
||||||
|
*/
|
||||||
|
void AbstractTabDeckEditor::onDeckHistorySaveRequested(const QString &modificationReason)
|
||||||
|
{
|
||||||
|
historyManager->save(deckDockWidget->getDeckList()->createMemento(modificationReason));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Marks the tab as modified and updates the save menu status.
|
||||||
|
*/
|
||||||
|
void AbstractTabDeckEditor::onDeckHistoryClearRequested()
|
||||||
|
{
|
||||||
|
historyManager->clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper for adding a card to a deck zone.
|
* @brief Helper for adding a card to a deck zone.
|
||||||
* @param card Card to add.
|
* @param card Card to add.
|
||||||
|
|
@ -131,7 +154,9 @@ void AbstractTabDeckEditor::addCardHelper(const ExactCard &card, QString zoneNam
|
||||||
if (card.getInfo().getIsToken())
|
if (card.getInfo().getIsToken())
|
||||||
zoneName = DECK_ZONE_TOKENS;
|
zoneName = DECK_ZONE_TOKENS;
|
||||||
|
|
||||||
emit cardAboutToBeAdded(card, zoneName);
|
onDeckHistorySaveRequested(QString(tr("Added (%1): %2 (%3) %4"))
|
||||||
|
.arg(zoneName, card.getName(), card.getPrinting().getSet()->getCorrectedShortName(),
|
||||||
|
card.getPrinting().getProperty("num")));
|
||||||
|
|
||||||
QModelIndex newCardIndex = deckDockWidget->deckModel->addCard(card, zoneName);
|
QModelIndex newCardIndex = deckDockWidget->deckModel->addCard(card, zoneName);
|
||||||
deckDockWidget->deckView->clearSelection();
|
deckDockWidget->deckView->clearSelection();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
#include "../interface/widgets/visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h"
|
#include "../interface/widgets/visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h"
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
|
#include <libcockatrice/deck_list/deck_list_history_manager.h>
|
||||||
|
|
||||||
class CardDatabaseModel;
|
class CardDatabaseModel;
|
||||||
class CardDatabaseDisplayModel;
|
class CardDatabaseDisplayModel;
|
||||||
|
|
||||||
|
|
@ -132,6 +134,13 @@ public:
|
||||||
return deckDockWidget;
|
return deckDockWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeckListHistoryManager *getHistoryManager() const
|
||||||
|
{
|
||||||
|
return historyManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckListHistoryManager *historyManager;
|
||||||
|
|
||||||
// UI Elements
|
// UI Elements
|
||||||
DeckEditorMenu *deckMenu; ///< Menu for deck operations
|
DeckEditorMenu *deckMenu; ///< Menu for deck operations
|
||||||
DeckEditorDatabaseDisplayWidget *databaseDisplayDockWidget; ///< Database dock
|
DeckEditorDatabaseDisplayWidget *databaseDisplayDockWidget; ///< Database dock
|
||||||
|
|
@ -147,6 +156,14 @@ public slots:
|
||||||
/** @brief Called when the deck is modified. */
|
/** @brief Called when the deck is modified. */
|
||||||
virtual void onDeckModified();
|
virtual void onDeckModified();
|
||||||
|
|
||||||
|
/** @brief Called when a widget is about to modify the state of the DeckList.
|
||||||
|
* @param modificationReason The reason for the state modification
|
||||||
|
*/
|
||||||
|
virtual void onDeckHistorySaveRequested(const QString &modificationReason);
|
||||||
|
|
||||||
|
/** @brief Called when a widget would like to clear the history. */
|
||||||
|
virtual void onDeckHistoryClearRequested();
|
||||||
|
|
||||||
/** @brief Updates the card info panel.
|
/** @brief Updates the card info panel.
|
||||||
* @param card The card to display.
|
* @param card The card to display.
|
||||||
*/
|
*/
|
||||||
|
|
@ -180,7 +197,6 @@ public slots:
|
||||||
virtual void dockTopLevelChanged(bool topLevel) = 0;
|
virtual void dockTopLevelChanged(bool topLevel) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cardAboutToBeAdded(const ExactCard &addedCard, const QString &zoneName);
|
|
||||||
/** @brief Emitted when a deck should be opened in a new editor tab. */
|
/** @brief Emitted when a deck should be opened in a new editor tab. */
|
||||||
void openDeckEditor(DeckLoader *deckLoader);
|
void openDeckEditor(DeckLoader *deckLoader);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue