Get next chunk of information @output: - QString - next chunk of information. If there is no more information to return, function will return empty string
| 47 | // - QString - next chunk of information. If there is no more information to |
| 48 | // return, function will return empty string |
| 49 | QString ContentIterator::getNext() |
| 50 | { |
| 51 | // Check if we have already get to the end of the content |
| 52 | if (atEnd) { return QString(); } |
| 53 | |
| 54 | QString content; |
| 55 | int rowsNumber = 0; |
| 56 | |
| 57 | // Initially m_dataRow have negative value. Negative value indicates that |
| 58 | // client have called this function first time. In this case at the |
| 59 | // beginning of the chunk we should place header information. And then |
| 60 | // set m_dataRow to the index of the first row in main data container. |
| 61 | if (m_dataRow < 0) |
| 62 | { |
| 63 | if (false == m_header.isEmpty()) |
| 64 | { |
| 65 | content.append(composeRow(m_header)); |
| 66 | ++rowsNumber; |
| 67 | } |
| 68 | |
| 69 | m_dataRow = 0; |
| 70 | } |
| 71 | |
| 72 | // Check if m_dataRow is less than number of rows in m_data. If this is |
| 73 | // true, add information from the m_data to the chunk. Otherwise, this means |
| 74 | // that we already have passed all information from the m_data. |
| 75 | if (m_dataRow < m_data.rowCount()) |
| 76 | { |
| 77 | int endRow = |
| 78 | qMin(m_dataRow + m_chunkSize - rowsNumber, m_data.rowCount()); |
| 79 | for (int i = m_dataRow; i < endRow; ++i, ++m_dataRow, ++rowsNumber) |
| 80 | { |
| 81 | content.append(composeRow(m_data.rowValues(i))); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // If we still have place in chunk, try to add footer information to it. |
| 86 | if (rowsNumber < m_chunkSize) |
| 87 | { |
| 88 | if (false == m_footer.isEmpty()) |
| 89 | { |
| 90 | content.append(composeRow(m_footer)); |
| 91 | ++rowsNumber; |
| 92 | } |
| 93 | |
| 94 | // At this point chunk contains the last row - footer. That |
| 95 | // means that we get to the end of content. |
| 96 | atEnd = true; |
| 97 | } |
| 98 | |
| 99 | return content; |
| 100 | } |
| 101 | |
| 102 | // Compose row string from values |
| 103 | // @input: |