Commit 247f710c authored by Shlomi Fish's avatar Shlomi Fish

Extract a cardsListToLine function.

This is Refactoring / code cleanup.

See:

* https://refactoring.com/catalog/extractMethod.html

* https://en.wikipedia.org/wiki/Code_refactoring
parent 64882cd6
...@@ -135,12 +135,7 @@ QString Freecell::solverFormat() const ...@@ -135,12 +135,7 @@ QString Freecell::solverFormat() const
} }
for (int i = 0; i < 8 ; i++) for (int i = 0; i < 8 ; i++)
{ cardsListToLine(output, store[i]->cards());
QList<KCard*> cards = store[i]->cards();
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
output += cardToRankSuitString(*it) + ' ';
output += '\n';
}
return output; return output;
} }
......
...@@ -181,20 +181,7 @@ QString Golf::solverFormat() const ...@@ -181,20 +181,7 @@ QString Golf::solverFormat() const
} }
output += "\n"; output += "\n";
for (int i = 0; i < 7 ; i++) for (int i = 0; i < 7 ; i++)
{ cardsListToLine(output, stack[i]->cards());
QList<KCard*> cards = stack[i]->cards();
bool first = true;
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
{
if (!first)
{
output += ' ';
}
first = false;
output += cardToRankSuitString(*it);
}
output += '\n';
}
return output; return output;
} }
......
...@@ -186,3 +186,18 @@ QString cardToRankSuitString(const KCard *const card) ...@@ -186,3 +186,18 @@ QString cardToRankSuitString(const KCard *const card)
{ {
return rankToString(card->rank()) + suitToString(card->suit()); return rankToString(card->rank()) + suitToString(card->suit());
} }
void cardsListToLine(QString & output, const QList<KCard*> cards)
{
bool first = true;
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
{
if (!first)
{
output += ' ';
}
first = false;
output += cardToRankSuitString(*it);
}
output += '\n';
}
...@@ -35,5 +35,6 @@ bool checkAddAlternateColorDescendingFromKing( const QList<KCard*> & oldCards, c ...@@ -35,5 +35,6 @@ bool checkAddAlternateColorDescendingFromKing( const QList<KCard*> & oldCards, c
extern QString suitToString(int s); extern QString suitToString(int s);
extern QString rankToString(int r); extern QString rankToString(int r);
extern QString cardToRankSuitString(const KCard*); extern QString cardToRankSuitString(const KCard*);
extern void cardsListToLine(QString & output, const QList<KCard*> cards);
#endif #endif
...@@ -168,10 +168,7 @@ QString Simon::solverFormat() const ...@@ -168,10 +168,7 @@ QString Simon::solverFormat() const
for (int i = 0; i < 10 ; i++) for (int i = 0; i < 10 ; i++)
{ {
QList<KCard*> cards = store[i]->cards(); cardsListToLine(output, store[i]->cards());
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
output += cardToRankSuitString(*it) + ' ';
output += '\n';
} }
return output; return output;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment