mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
[DeckList] refactor: pass DeckList by const ref (#6437)
* [DeckList] refactor: pass DeckList by const ref * Change getDeckList to return a const ref
This commit is contained in:
parent
73a90bdf38
commit
a0f977e80c
12 changed files with 70 additions and 75 deletions
|
|
@ -527,9 +527,9 @@ DeckLoader *DeckEditorDeckDockWidget::getDeckLoader()
|
|||
return deckLoader;
|
||||
}
|
||||
|
||||
DeckList *DeckEditorDeckDockWidget::getDeckList()
|
||||
const DeckList &DeckEditorDeckDockWidget::getDeckList() const
|
||||
{
|
||||
return deckModel->getDeckList();
|
||||
return *deckModel->getDeckList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public slots:
|
|||
void syncDisplayWidgetsToModel();
|
||||
void sortDeckModelToDeckView();
|
||||
DeckLoader *getDeckLoader();
|
||||
DeckList *getDeckList();
|
||||
const DeckList &getDeckList() const;
|
||||
void actIncrement();
|
||||
bool swapCard(const QModelIndex &idx);
|
||||
void actDecrementCard(const ExactCard &card, QString zoneName);
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ DlgEditDeckInClipboard::DlgEditDeckInClipboard(const DeckList &_deckList, bool _
|
|||
* @param addComments Whether to add annotations
|
||||
* @return A QString
|
||||
*/
|
||||
static QString deckListToString(const DeckList *deckList, bool addComments)
|
||||
static QString deckListToString(const DeckList &deckList, bool addComments)
|
||||
{
|
||||
QString buffer;
|
||||
QTextStream stream(&buffer);
|
||||
|
|
@ -160,7 +160,7 @@ static QString deckListToString(const DeckList *deckList, bool addComments)
|
|||
|
||||
void DlgEditDeckInClipboard::actRefresh()
|
||||
{
|
||||
setText(deckListToString(&deckList, annotated));
|
||||
setText(deckListToString(deckList, annotated));
|
||||
}
|
||||
|
||||
void DlgEditDeckInClipboard::actOK()
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ void AbstractTabDeckEditor::onDeckModified()
|
|||
*/
|
||||
void AbstractTabDeckEditor::onDeckHistorySaveRequested(const QString &modificationReason)
|
||||
{
|
||||
historyManager->save(deckDockWidget->getDeckList()->createMemento(modificationReason));
|
||||
historyManager->save(deckDockWidget->getDeckList().createMemento(modificationReason));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -231,7 +231,7 @@ void AbstractTabDeckEditor::openDeck(const LoadedDeck &deck)
|
|||
void AbstractTabDeckEditor::setDeck(const LoadedDeck &_deck)
|
||||
{
|
||||
deckDockWidget->setDeck(_deck);
|
||||
CardPictureLoader::cacheCardPixmaps(CardDatabaseManager::query()->getCards(getDeckList()->getCardRefList()));
|
||||
CardPictureLoader::cacheCardPixmaps(CardDatabaseManager::query()->getCards(getDeckList().getCardRefList()));
|
||||
setModified(false);
|
||||
|
||||
aDeckDockVisible->setChecked(true);
|
||||
|
|
@ -245,7 +245,7 @@ DeckLoader *AbstractTabDeckEditor::getDeckLoader() const
|
|||
}
|
||||
|
||||
/** @brief Returns the currently loaded deck list. */
|
||||
DeckList *AbstractTabDeckEditor::getDeckList() const
|
||||
const DeckList &AbstractTabDeckEditor::getDeckList() const
|
||||
{
|
||||
return deckDockWidget->getDeckList();
|
||||
}
|
||||
|
|
@ -446,7 +446,7 @@ bool AbstractTabDeckEditor::actSaveDeckAs()
|
|||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setDefaultSuffix("cod");
|
||||
dialog.setNameFilters(DeckLoader::FILE_NAME_FILTERS);
|
||||
dialog.selectFile(getDeckList()->getName().trimmed());
|
||||
dialog.selectFile(getDeckList().getName().trimmed());
|
||||
|
||||
if (!dialog.exec())
|
||||
return false;
|
||||
|
|
@ -591,26 +591,21 @@ void AbstractTabDeckEditor::actLoadDeckFromWebsite()
|
|||
*/
|
||||
void AbstractTabDeckEditor::exportToDecklistWebsite(DeckLoader::DecklistWebsite website)
|
||||
{
|
||||
if (DeckList *deckList = getDeckList()) {
|
||||
QString decklistUrlString = DeckLoader::exportDeckToDecklist(deckList, website);
|
||||
// Check to make sure the string isn't empty.
|
||||
if (decklistUrlString.isEmpty()) {
|
||||
// Show an error if the deck is empty, and return.
|
||||
QMessageBox::critical(this, tr("Error"), tr("There are no cards in your deck to be exported"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Encode the string recieved from the model to make sure all characters are encoded.
|
||||
// first we put it into a qurl object
|
||||
QUrl decklistUrl = QUrl(decklistUrlString);
|
||||
// we get the correctly encoded url.
|
||||
decklistUrlString = decklistUrl.toEncoded();
|
||||
// We open the url in the user's default browser
|
||||
QDesktopServices::openUrl(decklistUrlString);
|
||||
} else {
|
||||
// if there's no deck loader object, return an error
|
||||
QMessageBox::critical(this, tr("Error"), tr("No deck was selected to be exported."));
|
||||
QString decklistUrlString = DeckLoader::exportDeckToDecklist(getDeckList(), website);
|
||||
// Check to make sure the string isn't empty.
|
||||
if (decklistUrlString.isEmpty()) {
|
||||
// Show an error if the deck is empty, and return.
|
||||
QMessageBox::critical(this, tr("Error"), tr("There are no cards in your deck to be exported"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Encode the string recieved from the model to make sure all characters are encoded.
|
||||
// first we put it into a qurl object
|
||||
QUrl decklistUrl = QUrl(decklistUrlString);
|
||||
// we get the correctly encoded url.
|
||||
decklistUrlString = decklistUrl.toEncoded();
|
||||
// We open the url in the user's default browser
|
||||
QDesktopServices::openUrl(decklistUrlString);
|
||||
}
|
||||
|
||||
/** @brief Exports deck to www.decklist.org. */
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public:
|
|||
DeckLoader *getDeckLoader() const;
|
||||
|
||||
/** @brief Returns the currently active deck list. */
|
||||
DeckList *getDeckList() const;
|
||||
const DeckList &getDeckList() const;
|
||||
|
||||
/** @brief Sets the modified state of the tab.
|
||||
* @param _windowModified Whether the tab is modified.
|
||||
|
|
|
|||
|
|
@ -334,13 +334,13 @@ QMenu *DeckPreviewWidget::createRightClickMenu()
|
|||
auto saveToClipboardMenu = menu->addMenu(tr("Save Deck to Clipboard"));
|
||||
|
||||
connect(saveToClipboardMenu->addAction(tr("Annotated")), &QAction::triggered, this,
|
||||
[this] { DeckLoader::saveToClipboard(&deckLoader->getDeck().deckList, true, true); });
|
||||
[this] { DeckLoader::saveToClipboard(deckLoader->getDeck().deckList, true, true); });
|
||||
connect(saveToClipboardMenu->addAction(tr("Annotated (No set info)")), &QAction::triggered, this,
|
||||
[this] { DeckLoader::saveToClipboard(&deckLoader->getDeck().deckList, true, false); });
|
||||
[this] { DeckLoader::saveToClipboard(deckLoader->getDeck().deckList, true, false); });
|
||||
connect(saveToClipboardMenu->addAction(tr("Not Annotated")), &QAction::triggered, this,
|
||||
[this] { DeckLoader::saveToClipboard(&deckLoader->getDeck().deckList, false, true); });
|
||||
[this] { DeckLoader::saveToClipboard(deckLoader->getDeck().deckList, false, true); });
|
||||
connect(saveToClipboardMenu->addAction(tr("Not Annotated (No set info)")), &QAction::triggered, this,
|
||||
[this] { DeckLoader::saveToClipboard(&deckLoader->getDeck().deckList, false, false); });
|
||||
[this] { DeckLoader::saveToClipboard(deckLoader->getDeck().deckList, false, false); });
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue