const unsigned short Board::getNeighbors(unsigned short row, unsigned short column) const { unsigned short count = 0; for(short rowPos = validRow(row-1); rowPos <= validRow(row+1); rowPos++){ for(short columnPos = validColumn(column-1); columnPos <= validColumn(column+1); columnPos++){ count += isAlive(rowPos, columnPos) && !(rowPos == row && columnPos == column)? 1 : 0; } } return count; };
double PageItem_Table::columnPosition(int column) const { if (!validColumn(column)) return 0.0; return m_columnPositions.at(column); }
double PageItem_Table::columnWidth(int column) const { if (!validColumn(column)) return 0.0; return m_columnWidths.at(column); }
void PageItem_Table::removeColumns(int index, int numColumns) { ASSERT_VALID(); if (!validColumn(index) || numColumns < 1 || numColumns >= columns() || index + numColumns > columns()) return; // Remove column widths, column positions and columns of cells. double removedWidth = 0.0; for (int i = 0; i < numColumns; ++i) { // Remove columns widths and positions. removedWidth += m_columnWidths.takeAt(index); m_columnPositions.removeAt(index); // Remove and invalidate cells. QMutableListIterator<QList<TableCell> > rowIt(m_cellRows); while (rowIt.hasNext()) rowIt.next().takeAt(index).setValid(false); } // Adjust following columns. for (int nextColumn = index; nextColumn < columns() - numColumns; ++nextColumn) { // Adjust position of following column. m_columnPositions[nextColumn] -= removedWidth; // "Move" cells in following column left. foreach (QList<TableCell> cellRow, m_cellRows) cellRow[nextColumn].moveLeft(numColumns); } // Update column spans. updateSpans(index, numColumns, ColumnsRemoved); // Decrease number of columns. m_columns -= numColumns; // Update cells. TODO: Not for entire table. updateCells(); // Remove any invalid cells from selection. QMutableSetIterator<TableCell> cellIt(m_selection); while (cellIt.hasNext()) if (!cellIt.next().isValid()) cellIt.remove(); // Move to cell to the right. moveTo(cellAt(m_activeRow, qMin(m_activeColumn + 1, columns() - 1))); emit changed(); ASSERT_VALID(); }
const T& DenseMatrix<T>::getElement(size_t row, size_t col) const { if(!validRow(row)) { throw typename Matrix<T>::RowRangeError(row); } if(!validColumn(col)) { throw typename Matrix<T>::ColumnRangeError(col); } return a(row, col); }
MyVector<T> DenseMatrix<T>::getColumnAsVector(size_t column) const { if(!validColumn(column)) { throw typename Matrix<T>::ColumnRangeError(column); } MyVector<T> vec(numRows); for(size_t i = 0; i < numRows; ++i) { vec[i] = a(i, column); } return vec; }
void PageItem_Table::resizeColumn(int column, double width, ResizeStrategy strategy) { ASSERT_VALID(); if (!validColumn(column)) return; if (strategy == MoveFollowing) resizeColumnMoveFollowing(column, width); else if (strategy == ResizeFollowing) resizeColumnResizeFollowing(column, width); else qWarning("Unknown resize strategy!"); // Update cells. TODO: Not for entire table. updateCells(); emit changed(); ASSERT_VALID(); }