From b89535f7ff0cc071e695b441dfd14dc244f0fb03 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Mon, 26 Jan 2015 22:19:00 +0100 Subject: [PATCH] Refactored code --- cockatrice/src/zoneviewzone.cpp | 52 +++++++++++++++------------------ cockatrice/src/zoneviewzone.h | 4 --- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 24cca716..7c543326 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -106,9 +106,30 @@ void ZoneViewZone::reorganizeCards() int typeColumn = 0; int longestRow = 0; - if (pileView && sortByType) // we need sort by type enabled for the feature to work - setPileViewPositions(cardCount, cardsToDisplay, typeColumn, longestRow); - else { + if (pileView && sortByType) { // we need sort by type enabled for the feature to work + int typeRow = 0; + QString lastCardType; + for (int i = 0; i < cardCount; i++) { + CardItem *c = cardsToDisplay.at(i); + QString cardType = c->getInfo()->getMainCardType(); + + if (i){ // if not the first card + if (cardType == lastCardType) + typeRow++; // add below current card + else { // if no match then move card to next column + typeColumn++; + longestRow = qMax(typeRow, longestRow); + typeRow = 0; + } + } + + lastCardType = cardType; + qreal x = typeColumn * CARD_WIDTH; + qreal y = typeRow * CARD_HEIGHT / 3; + c->setPos(x + 5, y + 5); + c->setRealZValue(i); + } + } else { for (int i = 0; i < cardCount; i++) { CardItem *c = cardsToDisplay.at(i); qreal x = (i / rows) * CARD_WIDTH; @@ -128,31 +149,6 @@ void ZoneViewZone::reorganizeCards() emit optimumRectChanged(); } -void ZoneViewZone::setPileViewPositions(int cardCount, CardList &cardsToDisplay, int &typeColumn, int &longestRow){ - int typeRow = 0; - bool cardTypeMatch = true; - for (int i = 0; i < cardCount; i++) { - CardItem *c = cardsToDisplay.at(i); - QString cardType = c->getInfo()->getMainCardType(); - - if (i){ - // if not the first card. Last card and this card have a matching main type? - cardTypeMatch = cardType.compare(cardsToDisplay.at(i-1)->getInfo()->getMainCardType()) == 0 ? true : false; - if (!cardTypeMatch) { // if no match then move card to next column - typeColumn++; - longestRow = qMax(typeRow, longestRow); - typeRow = 0; - } else // add below current card - typeRow++; - } - - qreal x = typeColumn * CARD_WIDTH; - qreal y = typeRow * CARD_HEIGHT / 3; - c->setPos(x + 5, y + 5); - c->setRealZValue(i); - } -} - void ZoneViewZone::setSortByName(int _sortByName) { sortByName = _sortByName; diff --git a/cockatrice/src/zoneviewzone.h b/cockatrice/src/zoneviewzone.h index eff1ecfe..4c071589 100644 --- a/cockatrice/src/zoneviewzone.h +++ b/cockatrice/src/zoneviewzone.h @@ -26,10 +26,6 @@ public: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void reorganizeCards(); - - void setPileViewPositions(int cardCount, CardList &cardsToDisplay, int &typeColumn, int &longestRow); - - void initializeCards(const QList &cardList = QList()); void removeCard(int position); int getNumberCards() const { return numberCards; }