Add combos button.

This commit is contained in:
Lukas Brübach 2025-04-16 23:26:12 +02:00
parent dab4037f98
commit 6abcb634ff
3 changed files with 41 additions and 1 deletions

View file

@ -2,8 +2,10 @@
#include "../../../../../../game/cards/card_database_manager.h"
#include "../../../../../ui/widgets/cards/card_info_picture_widget.h"
#include "../../tab_edhrec_main.h"
#include <QLabel>
#include <QPushButton>
EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCommanderDetailsDisplayWidget(
QWidget *parent,
@ -23,9 +25,30 @@ EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCom
salt = new QLabel(this);
salt->setAlignment(Qt::AlignCenter);
comboPushButton = new QPushButton(this);
layout->addWidget(commanderPicture);
layout->addWidget(label);
layout->addWidget(salt);
layout->addWidget(comboPushButton);
QWidget *currentParent = parentWidget();
TabEdhRecMain *parentTab = nullptr;
while (currentParent) {
if ((parentTab = qobject_cast<TabEdhRecMain *>(currentParent))) {
break;
}
currentParent = currentParent->parentWidget();
}
if (parentTab) {
connect(comboPushButton, &QPushButton::clicked, this,
&EdhrecCommanderResponseCommanderDetailsDisplayWidget::actRequestComboNavigation);
connect(this, &EdhrecCommanderResponseCommanderDetailsDisplayWidget::requestUrl, parentTab,
&TabEdhRecMain::actNavigatePage);
}
retranslateUi();
}
@ -33,4 +56,10 @@ void EdhrecCommanderResponseCommanderDetailsDisplayWidget::retranslateUi()
{
label->setText(commanderDetails.getLabel());
salt->setText(tr("Salt: ") + QString::number(commanderDetails.getSalt()));
comboPushButton->setText(tr("Combos"));
}
void EdhrecCommanderResponseCommanderDetailsDisplayWidget::actRequestComboNavigation()
{
emit requestUrl("/combos/" + commanderDetails.getSanitized());
}

View file

@ -5,6 +5,7 @@
#include "../../api_response/commander/edhrec_commander_api_response_commander_details.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
@ -17,9 +18,15 @@ public:
const EdhrecCommanderApiResponseCommanderDetails &_commanderDetails);
void retranslateUi();
public slots:
void actRequestComboNavigation();
signals:
void requestUrl(QString url);
private:
QLabel *label;
QLabel *salt;
QPushButton *comboPushButton;
QVBoxLayout *layout;
CardInfoPictureWidget *commanderPicture;
EdhrecCommanderApiResponseCommanderDetails commanderDetails;

View file

@ -161,7 +161,9 @@ void TabEdhRecMain::setCard(CardInfoPtr _cardToQuery, bool isCommander)
void TabEdhRecMain::actNavigatePage(QString url)
{
QNetworkRequest request{QUrl("https://json.edhrec.com/pages" + url + ".json")};
auto finalUrl = QUrl("https://json.edhrec.com/pages" + url + ".json");
qInfo() << "Requested:" << finalUrl;
QNetworkRequest request{finalUrl};
networkManager->get(request);
}
@ -222,6 +224,8 @@ void TabEdhRecMain::processApiJson(QNetworkReply *reply)
processTopTagsResponse(jsonObj);
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/top/year.json")) {
processTopCardsResponse(jsonObj);
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/combos/")) {
processCommanderResponse(jsonObj);
} else {
prettyPrintJson(jsonObj, 4);
}