From a80c756dcbd1d1ace9172cc699b55bfa017d0ee1 Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Tue, 17 Mar 2020 01:41:41 +0100 Subject: [PATCH] update deprecated methods in qt5.14 and protobuf 3.4 (#3906) --- cockatrice/src/carddatabase.cpp | 4 +-- cockatrice/src/dlg_create_token.cpp | 16 +++++++++--- cockatrice/src/dlg_tip_of_the_day.cpp | 18 ++++++------- cockatrice/src/remoteclient.cpp | 9 ++++--- cockatrice/src/stackzone.cpp | 16 +++++++----- cockatrice/src/tab_supervisor.cpp | 2 +- cockatrice/src/tablezone.cpp | 26 ++++++++++++------- common/decklist.cpp | 2 +- servatrice/src/isl_interface.cpp | 4 +++ .../src/servatrice_database_interface.cpp | 6 ++++- servatrice/src/serversocketinterface.cpp | 8 ++++++ 11 files changed, 74 insertions(+), 37 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 569edd46..2417a15e 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -573,7 +573,7 @@ QStringList CardDatabase::getAllMainCardTypes() const while (cardIterator.hasNext()) { types.insert(cardIterator.next().value()->getMainCardType()); } - return types.toList(); + return types.values(); } void CardDatabase::checkUnknownSets() @@ -699,4 +699,4 @@ const QString CardInfo::getPowTough() const void CardInfo::setPowTough(const QString &value) { setProperty(Mtg::PowTough, value); -} \ No newline at end of file +} diff --git a/cockatrice/src/dlg_create_token.cpp b/cockatrice/src/dlg_create_token.cpp index e0a3d4dc..6b2a3eab 100644 --- a/cockatrice/src/dlg_create_token.cpp +++ b/cockatrice/src/dlg_create_token.cpp @@ -103,7 +103,11 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa chooseTokenFromDeckRadioButton->setDisabled(true); // No tokens in deck = no need for option } else { chooseTokenFromDeckRadioButton->setChecked(true); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + cardDatabaseDisplayModel->setCardNameSet(QSet(predefinedTokens.begin(), predefinedTokens.end())); +#else cardDatabaseDisplayModel->setCardNameSet(QSet::fromList(predefinedTokens)); +#endif } QVBoxLayout *tokenChooseLayout = new QVBoxLayout; @@ -182,14 +186,20 @@ void DlgCreateToken::updateSearch(const QString &search) void DlgCreateToken::actChooseTokenFromAll(bool checked) { - if (checked) + if (checked) { cardDatabaseDisplayModel->setCardNameSet(QSet()); + } } void DlgCreateToken::actChooseTokenFromDeck(bool checked) { - if (checked) + if (checked) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + cardDatabaseDisplayModel->setCardNameSet(QSet(predefinedTokens.begin(), predefinedTokens.end())); +#else cardDatabaseDisplayModel->setCardNameSet(QSet::fromList(predefinedTokens)); +#endif + } } void DlgCreateToken::actOk() @@ -227,4 +237,4 @@ QString DlgCreateToken::getAnnotation() const bool DlgCreateToken::getDestroy() const { return destroyCheckBox->isChecked(); -} \ No newline at end of file +} diff --git a/cockatrice/src/dlg_tip_of_the_day.cpp b/cockatrice/src/dlg_tip_of_the_day.cpp index 37d6465f..c26af60b 100644 --- a/cockatrice/src/dlg_tip_of_the_day.cpp +++ b/cockatrice/src/dlg_tip_of_the_day.cpp @@ -41,17 +41,15 @@ DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent) tipNumber = new QLabel(); tipNumber->setAlignment(Qt::AlignCenter); - if (settingsCache->getSeenTips().size() != tipDatabase->rowCount()) { - newTipsAvailable = true; - QList rangeToMaxTips; - for (int i = 0; i < tipDatabase->rowCount(); i++) { - rangeToMaxTips.append(i); + QList seenTips = settingsCache->getSeenTips(); + newTipsAvailable = false; + currentTip = 0; + for (int i = 0; i < tipDatabase->rowCount(); i++) { + if (!seenTips.contains(i)) { + newTipsAvailable = true; + currentTip = i; + break; } - QSet unseenTips = rangeToMaxTips.toSet() - settingsCache->getSeenTips().toSet(); - currentTip = *std::min_element(unseenTips.begin(), unseenTips.end()); - } else { - newTipsAvailable = false; - currentTip = 0; } connect(this, SIGNAL(newTipRequested(int)), this, SLOT(updateTip(int))); diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index 06e4664c..b49228a9 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -334,8 +334,11 @@ void RemoteClient::websocketMessageReceived(const QByteArray &message) void RemoteClient::sendCommandContainer(const CommandContainer &cont) { - - auto size = static_cast(cont.ByteSize()); +#if GOOGLE_PROTOBUF_VERSION > 3001000 + unsigned int size = cont.ByteSizeLong(); +#else + unsigned int size = cont.ByteSize(); +#endif #ifdef QT_DEBUG qDebug() << "OUT" << size << QString::fromStdString(cont.ShortDebugString()); #endif @@ -639,4 +642,4 @@ void RemoteClient::submitForgotPasswordChallengeResponse(const Response &respons emit sigForgotPasswordError(); doDisconnectFromServer(); -} \ No newline at end of file +} diff --git a/cockatrice/src/stackzone.cpp b/cockatrice/src/stackzone.cpp index a22ab174..f518d075 100644 --- a/cockatrice/src/stackzone.cpp +++ b/cockatrice/src/stackzone.cpp @@ -73,7 +73,7 @@ void StackZone::handleDropEvent(const QList &dragItems, void StackZone::reorganizeCards() { if (!cards.isEmpty()) { - QList arrowsToUpdate; + QSet arrowsToUpdate; const int cardCount = cards.size(); qreal totalWidth = boundingRect().width(); @@ -95,12 +95,16 @@ void StackZone::reorganizeCards() c->setPos(x, ((qreal)i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2); c->setRealZValue(i); - arrowsToUpdate.append(c->getArrowsFrom()); - arrowsToUpdate.append(c->getArrowsTo()); + for (ArrowItem *item : c->getArrowsFrom()) { + arrowsToUpdate.insert(item); + } + for (ArrowItem *item : c->getArrowsTo()) { + arrowsToUpdate.insert(item); + } + } + for (ArrowItem *item : arrowsToUpdate) { + item->updatePath(); } - QSetIterator arrowIterator(QSet::fromList(arrowsToUpdate)); - while (arrowIterator.hasNext()) - arrowIterator.next()->updatePath(); } update(); } diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index bbc9450c..446170c5 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -344,7 +344,7 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex) (QTabBar::ButtonPosition)tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tabBar()); CloseButton *closeButton = new CloseButton; connect(closeButton, SIGNAL(clicked()), this, SLOT(closeButtonPressed())); - closeButton->setProperty("tab", qVariantFromValue((QObject *)tab)); + closeButton->setProperty("tab", QVariant::fromValue((QObject *)tab)); tabBar()->setTabButton(tabIndex, closeSide, closeButton); } diff --git a/cockatrice/src/tablezone.cpp b/cockatrice/src/tablezone.cpp index 9247ba2f..483863fa 100644 --- a/cockatrice/src/tablezone.cpp +++ b/cockatrice/src/tablezone.cpp @@ -153,7 +153,7 @@ void TableZone::handleDropEventByGrid(const QList &dragItems, void TableZone::reorganizeCards() { - QList arrowsToUpdate; + QSet arrowsToUpdate; // Calculate card stack widths so mapping functions work properly computeCardStackWidths(); @@ -185,18 +185,24 @@ void TableZone::reorganizeCards() qreal childY = y + 5; attachedCard->setPos(childX, childY); attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100); - - arrowsToUpdate.append(attachedCard->getArrowsFrom()); - arrowsToUpdate.append(attachedCard->getArrowsTo()); + for (ArrowItem *item : attachedCard->getArrowsFrom()) { + arrowsToUpdate.insert(item); + } + for (ArrowItem *item : attachedCard->getArrowsTo()) { + arrowsToUpdate.insert(item); + } } - arrowsToUpdate.append(cards[i]->getArrowsFrom()); - arrowsToUpdate.append(cards[i]->getArrowsTo()); + for (ArrowItem *item : cards[i]->getArrowsFrom()) { + arrowsToUpdate.insert(item); + } + for (ArrowItem *item : cards[i]->getArrowsTo()) { + arrowsToUpdate.insert(item); + } + } + for (ArrowItem *item : arrowsToUpdate) { + item->updatePath(); } - - QSetIterator arrowIterator(QSet::fromList(arrowsToUpdate)); - while (arrowIterator.hasNext()) - arrowIterator.next()->updatePath(); resizeToContents(); update(); diff --git a/common/decklist.cpp b/common/decklist.cpp index 2dc0489e..e750c641 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -704,7 +704,7 @@ QStringList DeckList::getCardList() const { QSet result; getCardListHelper(root, result); - return result.toList(); + return result.values(); } int DeckList::getSideboardSize() const diff --git a/servatrice/src/isl_interface.cpp b/servatrice/src/isl_interface.cpp index d2ce7f05..646248b0 100644 --- a/servatrice/src/isl_interface.cpp +++ b/servatrice/src/isl_interface.cpp @@ -261,7 +261,11 @@ void IslInterface::catchSocketError(QAbstractSocket::SocketError socketError) void IslInterface::transmitMessage(const IslMessage &item) { QByteArray buf; +#if GOOGLE_PROTOBUF_VERSION > 3001000 + unsigned int size = item.ByteSizeLong(); +#else unsigned int size = item.ByteSize(); +#endif buf.resize(size + 4); item.SerializeToArray(buf.data() + 4, size); buf.data()[3] = (unsigned char)size; diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 927db7c9..955dfb01 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -804,7 +804,11 @@ void Servatrice_DatabaseInterface::storeGameInformation(const QString &roomName, QVariantList replayIds, replayGameIds, replayDurations, replayBlobs; for (int i = 0; i < replayList.size(); ++i) { QByteArray blob; +#if GOOGLE_PROTOBUF_VERSION > 3001000 + const unsigned int size = replayList[i]->ByteSizeLong(); +#else const unsigned int size = replayList[i]->ByteSize(); +#endif blob.resize(size); replayList[i]->SerializeToArray(blob.data(), size); @@ -1376,4 +1380,4 @@ void Servatrice_DatabaseInterface::addAuditRecord(const QString &user, query->bindValue(":details", details); execSqlQuery(query); -} \ No newline at end of file +} diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 62104633..02e1d6ef 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -1553,7 +1553,11 @@ void TcpServerSocketInterface::flushOutputQueue() locker.unlock(); QByteArray buf; +#if GOOGLE_PROTOBUF_VERSION > 3001000 + unsigned int size = item.ByteSizeLong(); +#else unsigned int size = item.ByteSize(); +#endif buf.resize(size + 4); item.SerializeToArray(buf.data() + 4, size); buf.data()[3] = (unsigned char)size; @@ -1747,7 +1751,11 @@ void WebsocketServerSocketInterface::flushOutputQueue() locker.unlock(); QByteArray buf; +#if GOOGLE_PROTOBUF_VERSION > 3001000 + unsigned int size = item.ByteSizeLong(); +#else unsigned int size = item.ByteSize(); +#endif buf.resize(size); item.SerializeToArray(buf.data(), size); // In case socket->write() calls catchSocketError(), the mutex must not be locked during this call.