std::string Table<T>::to_latex() const { Table<std::string> strTable(num_rows(), num_cols()); std::stringstream os; os << "\\begin{table}\n\\centering\n"; os << "\\begin{tabular}{"; for(size_t i=0; i < num_cols(); i++) os << get_col_sep(i) << get_col_alignment(i); os << get_col_sep(num_cols()); os << "}\n"; for(size_t i_row = 0; i_row < num_rows(); ++i_row) { if(get_row_sep(i_row) != ' ') os << "\\hline \n"; for(size_t i_col = 0; i_col < num_cols(); ++i_col) { if(i_col != 0) os << " & "; os << EntryToString(*this, i_row, i_col); } os << " \\\\\n"; } if(get_row_sep(num_rows()) != ' ') os << "\\hline \n"; os << "\\end{tabular}\n"; os << "\\end{table}\n"; return os.str(); }
void UINetworkManagerIndicator::updateAppearance() { /* First of all, we are hiding LED in case of 'idle' state: */ if (state() == UINetworkManagerIndicatorState_Idle && !isHidden()) hide(); /* Prepare description: */ QString strDecription; /* Check if there are any network-requests: */ if (!m_ids.isEmpty()) { /* Prepare table: */ QString strTable("<table>%1</table>"); QString strBodyItem("<tr><td>%1</td><td> </td><td>%2</td></tr>"); QString strParagraph("<p>%1</p>"); QString strBoldNobreak("<nobr><b>%1</b></nobr>"); QString strNobreak("<nobr>%1</nobr>"); QString strItalic("<i>%1</i>"); /* Prepare header: */ QString strHeader(strBoldNobreak.arg(tr("Current network operations:"))); /* Prepare table body: */ QString strBody; for (int i = 0; i < m_data.size(); ++i) { const UINetworkRequestData &data = m_data[i]; const QString &strDescription = data.description; QString strStatus(data.failed ? tr("failed", "network operation") : tr("(%1 of %2)") .arg(vboxGlobal().formatSize(data.bytesReceived)) .arg(vboxGlobal().formatSize(data.bytesTotal))); QString strBodyLine(strBodyItem.arg(strNobreak.arg(strDescription)).arg(strNobreak.arg(strStatus))); strBody += strBodyLine; } /* Compose description: */ strDecription = strParagraph.arg(strHeader + strTable.arg(strBody)) + strParagraph.arg(strNobreak.arg(strItalic.arg(tr("Double-click for more information.")))); } else strDecription = QString(); /* Set description: */ setToolTip(strDecription); /* Finally, we are showing LED in case of state is not 'idle': */ if (state() != UINetworkManagerIndicatorState_Idle && isHidden()) show(); }
std::ostream& Table<T>::stream(std::ostream& os) const { const Table<T> &table = *this; // we'll fill a fresh table with strings of the given table // At the same time we'll find the max-width of each column Table<std::string> strTable(num_rows(), num_cols()); std::vector<size_t> colSizes(num_cols(), 0); for(size_t i_row = 0; i_row < num_rows(); ++i_row){ for(size_t i_col = 0; i_col < num_cols(); ++i_col){ strTable(i_row, i_col) = EntryToString(table, i_row, i_col); colSizes[i_col] = std::max(colSizes[i_col], strTable(i_row, i_col).size()); } } size_t totalRowLength=0; for(size_t i_col = 0; i_col < num_cols(); ++i_col) { totalRowLength++; totalRowLength += colSizes[i_col] + 2; } totalRowLength++; // now print each row for(size_t i_row = 0; i_row < num_rows(); ++i_row) { if(get_row_sep(i_row) != 0x00 && get_row_sep(i_row) != ' ') os << repeat(get_row_sep(i_row), totalRowLength) << "\n"; for(size_t i_col = 0; i_col < num_cols(); ++i_col) { os << get_col_sep(i_col); size_t l = colSizes[i_col] + 1; size_t s = strTable(i_row, i_col).size(); os << " "; if(get_col_alignment(i_col) == 'r') os << std::setw(l) << std::right << strTable(i_row, i_col); else if(get_col_alignment(i_col) == 'l') os << std::setw(l) << std::left << strTable(i_row, i_col); else os << repeat(' ', (l-s)/2) << std::setw(l-(l-s)/2) << std::left << strTable(i_row, i_col); } os << get_col_sep(num_cols()) << std::endl; } if(get_row_sep(num_cols()) != 0x00 && get_row_sep(num_cols()) != ' ') os << repeat(get_row_sep(num_cols()), totalRowLength) << "\n"; return os; }