* Puts the items of a QStringList into an HTML block or a sequence of blocks. */
| 49 | * Puts the items of a QStringList into an HTML block or a sequence of blocks. |
| 50 | */ |
| 51 | QString formatBlock(const QStringList& items) |
| 52 | { |
| 53 | #if defined(Q_OS_ANDROID) // or any other small-screen device |
| 54 | QString block = QLatin1String("<p>") |
| 55 | + items.join(QString::fromLatin1(", ")) |
| 56 | + QLatin1String("</p>"); |
| 57 | #else |
| 58 | QString block; |
| 59 | block.reserve(100 + 30 * items.size()); |
| 60 | block.append(QLatin1String("<table><tr><td>")); |
| 61 | constexpr int columns = 3; |
| 62 | const int rows = (int)ceil((double)items.size() / columns); |
| 63 | for (int i = 0, row = 1; i < items.size(); ++i) |
| 64 | { |
| 65 | block.append(items[i]); |
| 66 | if (rows != row) |
| 67 | { |
| 68 | block.append(QString::fromLatin1("<br/>")); |
| 69 | ++row; |
| 70 | } |
| 71 | else if (i < items.size()) |
| 72 | { |
| 73 | block.append(QString::fromLatin1("</td><td> </td><td>")); |
| 74 | row = 1; |
| 75 | } |
| 76 | } |
| 77 | block.append(QString::fromLatin1("</td></tr></table>")); |
| 78 | #endif |
| 79 | return block; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | } // namespace |
no test coverage detected