| 96 | } |
| 97 | |
| 98 | void LogModel::setMaxLines(int maxLines) |
| 99 | { |
| 100 | // no-op |
| 101 | if(maxLines == m_maxLines) |
| 102 | { |
| 103 | return; |
| 104 | } |
| 105 | // if it all still fits in the buffer, just resize it |
| 106 | if(m_firstLine + m_numLines < m_maxLines) |
| 107 | { |
| 108 | m_maxLines = maxLines; |
| 109 | m_content.resize(maxLines); |
| 110 | return; |
| 111 | } |
| 112 | // otherwise, we need to reorganize the data because it crosses the wrap boundary |
| 113 | QVector<entry> newContent; |
| 114 | newContent.resize(maxLines); |
| 115 | if(m_numLines <= maxLines) |
| 116 | { |
| 117 | // if it all fits in the new buffer, just copy it over |
| 118 | for(int i = 0; i < m_numLines; i++) |
| 119 | { |
| 120 | newContent[i] = m_content[(m_firstLine + i) % m_maxLines]; |
| 121 | } |
| 122 | m_content.swap(newContent); |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | // if it doesn't fit, part of the data needs to be thrown away (the oldest log messages) |
| 127 | int lead = m_numLines - maxLines; |
| 128 | beginRemoveRows(QModelIndex(), 0, lead - 1); |
| 129 | for(int i = 0; i < maxLines; i++) |
| 130 | { |
| 131 | newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines]; |
| 132 | } |
| 133 | m_numLines = m_maxLines; |
| 134 | m_content.swap(newContent); |
| 135 | endRemoveRows(); |
| 136 | } |
| 137 | m_firstLine = 0; |
| 138 | m_maxLines = maxLines; |
| 139 | } |
| 140 | |
| 141 | int LogModel::getMaxLines() |
| 142 | { |
no test coverage detected