QString AbstractTextFormatter::formatTable( const QAbstractItemModel *model, int firstRow, int lastRow, const QModelIndex &parent, int role) const { QString s; QStringList headers; if (_columnHeadersEnabled) fetchHeaderList(&headers, model, parent, role); s.append(formatTableHeader(headers)); if (model) { if (firstRow < 0) firstRow = 0; if (lastRow == -1 || lastRow >= model->rowCount(parent)) lastRow = model->rowCount(parent)-1; if (_rowHeadersEnabled) { for (int row = firstRow; row <= lastRow; ++row) s.append(formatRowInternal(model, row, parent, role, QString::number(row))); } else { for (int row = firstRow; row <= lastRow; ++row) s.append(formatRow(model, row, parent, role)); } } s.append(formatTableFooter(headers)); return s; }
void addRows( QTableWidget *table, const ptrdiff_t newRowsNumber, const ptrdiff_t mode ) { ptrdiff_t n = 0; if ( mode == ADDROWS_ABOVE ) { if ( table->currentRow() > -1 ) { n = table->currentRow(); } } else if ( mode == ADDROWS_BELOW ) { if ( table->currentRow() > -1 ) { n = table->currentRow() + 1; } } else if ( mode == ADDROWS_BOTTOM ) { n = table->rowCount(); } for ( ptrdiff_t i=0; i<newRowsNumber; i++ ) { table->insertRow(n); formatRow(table, n); } }
QString AbstractTextFormatter::formatTable( const SharedUiItemList<> &list, int role) const { QString s; const SharedUiItem first = list.isEmpty() ? SharedUiItem() : list.first(); QStringList headers; if (_columnHeadersEnabled) fetchHeaderList(&headers, first); s.append(formatTableHeader(headers)); if (_rowHeadersEnabled) { int row = 0; for (const SharedUiItem &item : list) { ++row; s.append(formatRowInternal(item, role, QString::number(row))); } } else { for (const SharedUiItem &item : list) s.append(formatRow(item, role)); } s.append(formatTableFooter(headers)); return s; }
bool CSVFormatter::writeToStream(const CSVMap* map, Stream* stream, UChar32 sepchar, unsigned int varformat) { if (map!=NULL && stream!=NULL) { UnicodeString temp; bool first=false; int lastrow=0; CSVRowMap::const_iterator iter; for (iter=map->begin(); iter!=map->end(); ++iter) { if (!first) { lastrow=iter->first; first=true; } /*for (; lastrow!=iter->first; ++lastrow) { stream->writeChar('\n'); }*/ if (iter->second) { // check if record is NULL formatRow(*iter->second, temp, sepchar, varformat); stream->writeLine(temp); } } return true; } return false; }