TableCell PageItem_Table::cellAt(const QPointF& point) const { QPointF gridPoint = getTransform().inverted().map(point) - gridOffset(); if (!QRectF(0, 0, tableWidth(), tableHeight()).contains(gridPoint)) return TableCell(); // Outside table grid. return cellAt( qUpperBound(m_rowPositions, gridPoint.y()) - m_rowPositions.begin() - 1, qUpperBound(m_columnPositions, gridPoint.x()) - m_columnPositions.begin() - 1); }
void PageItem_Table::insertRows(int index, int numRows) { ASSERT_VALID(); if (index < 0 || index > rows() || numRows < 1) return; double rowHeight = m_rowHeights.at(qMax(index - 1, 0)); double rowPosition = index == 0 ? 0.0 : m_rowPositions.at(index - 1) + rowHeight; for (int row = index; row < index + numRows; ++row) { // Insert row height and position. m_rowHeights.insert(row, rowHeight); m_rowPositions.insert(row, rowPosition); rowPosition += rowHeight; // Insert a row of cells. QList<TableCell> cellRow; for (int col = 0; col < columns(); ++col) cellRow.append(TableCell(row, col, this)); m_cellRows.insert(row, cellRow); } // Adjust following rows. double insertedHeight = rowHeight * numRows; for (int nextRow = index + numRows; nextRow < rows() + numRows; ++nextRow) { // Adjust position of following row. m_rowPositions[nextRow] += insertedHeight; // "Move" cells in following row down. foreach (TableCell cell, m_cellRows[nextRow]) cell.moveDown(numRows); } // Update row spans. updateSpans(index, numRows, RowsInserted); // Increase number of rows. m_rows += numRows; // Update cells. TODO: Not for entire table. updateCells(); emit changed(); ASSERT_VALID(); }
void PageItem_Table::insertColumns(int index, int numColumns) { ASSERT_VALID(); if (index < 0 || index > columns() || numColumns < 1) return; double columnWidth = m_columnWidths.at(qMax(index - 1, 0)); double columnPosition = index == 0 ? 0.0 : m_columnPositions.at(index - 1) + columnWidth; for (int col = index; col < index + numColumns; ++col) { // Insert column width and position. m_columnWidths.insert(col, columnWidth); m_columnPositions.insert(col, columnPosition); columnPosition += columnWidth; // Insert a column of cells. for (int row = 0; row < rows(); ++row) m_cellRows[row].insert(col, TableCell(row, col, this)); } // Adjust following columns. double insertedWidth = columnWidth * numColumns; for (int nextColumn = index + numColumns; nextColumn < columns() + numColumns; ++nextColumn) { // Adjust position of following column. m_columnPositions[nextColumn] += insertedWidth; // "Move" cells in following column right. foreach (QList<TableCell> cellRow, m_cellRows) cellRow[nextColumn].moveRight(numColumns); } // Update column spans. updateSpans(index, numColumns, ColumnsInserted); // Increase number of columns. m_columns += numColumns; // Update cells. TODO: Not for entire table. updateCells(); emit changed(); ASSERT_VALID(); }
void PageItem_Table::initialize(int numRows, int numColumns) { Q_ASSERT(m_Doc); Q_ASSERT(numRows > 0); Q_ASSERT(numColumns > 0); // Internal style is in document-wide style context. m_style.setContext(&m_Doc->tableStyles()); // Reserve space in lists. m_cellRows.reserve(numRows); m_rowHeights.reserve(numRows); m_rowPositions.reserve(numRows); m_columnWidths.reserve(numColumns); m_columnPositions.reserve(numColumns); // Initialize rows of cells. QList<TableCell> initialRow; initialRow.append(TableCell(0, 0, this)); m_cellRows.append(initialRow); // Initialize row/column geometries. m_rowPositions.insert(0, 0.0); m_rowHeights.insert(0, 10.0); m_columnPositions.insert(0, 0.0); m_columnWidths.insert(0, 10.0); // Initialize row/column counts. m_rows = 1; m_columns = 1; // Insert any remaining rows and/or columns. insertRows(0, numRows - 1); insertColumns(0, numColumns - 1); // Listen to changes in the document-wide cell/table style contexts. m_Doc->tableStyles().connect(this, SLOT(handleStyleChanged())); m_Doc->cellStyles().connect(this, SLOT(handleStyleChanged())); m_activeCell = cellAt(0, 0); m_activeRow = 0; m_activeColumn = 0; }
TableCell PageItem_Table::cellAt(int row, int column) const { if (!validCell(row, column)) return TableCell(); TableCell cell = m_cellRows[row][column]; QList<CellArea>::const_iterator areaIt; for (areaIt = m_cellAreas.begin(); areaIt != m_cellAreas.end(); ++areaIt) { CellArea area = (*areaIt); if (area.contains(row, column)) { // Cell was contained in merged area, so use spanning cell. cell = m_cellRows[area.row()][area.column()]; break; } } return cell; }
void htmlrenderer::TableRow::start_cell(size_t span) { inside = true; if (span < 1) span = 1; cells.push_back(TableCell(span)); }