void TableEditor::slotInsertCol() { int num = m_dataTable->numCols(); if (m_col >= 0) num = m_col; m_dataTable->insertColumns(num); m_dataTable->setColumnWidth(num, 150); if (m_createNodes) { TableNode tableNode; int i = 0; for (QValueList<QValueList<TableNode> >::Iterator it = m_tableTags->begin(); it != m_tableTags->end(); ++it) { tableNode.merged = false; tableNode.node = new Node(0L); newNum++; tableNode.node->tag = new Tag(); tableNode.node->tag->setDtd(m_dtd); if (m_tableTags == m_tableHeaderTags) { tableNode.node->tag->parse("<th>", m_write); } else { tableNode.node->tag->parse("<td>", m_write); } (*it).append(tableNode); setCellText(m_dataTable, i, num, ""); i++; } } m_colSpin->setValue(m_dataTable->numCols()); }
void TableEditor::slotMergeCells() { slotUnmergeCells(); //first unmerge all cells from the selection QTableSelection selection = m_dataTable->selection(m_dataTable->currentSelection()); int tRow, bRow, lCol, rCol; tRow = selection.topRow(); bRow = selection.bottomRow(); lCol = selection.leftCol(); rCol = selection.rightCol(); TableNode *mainTableNode = &((*m_tableTags)[tRow][lCol]); if (rCol - lCol > 0) mainTableNode->node->tag->editAttribute("colspan", QString("%1").arg(rCol - lCol + 1)); if (bRow - tRow > 0) mainTableNode->node->tag->editAttribute("rowspan", QString("%1").arg(bRow - tRow + 1)); for (int i = 0; i < bRow - tRow + 1; i++) for (int j = 0; j < rCol - lCol + 1; j++) { if (i != 0 || j != 0) { setCellText(m_dataTable, tRow + i, lCol + j, i18n("Merged with (%1, %2).").arg(tRow + 1).arg(lCol + 1)); m_dataTable->item(tRow + i, lCol + j)->setEnabled(false); TableNode *tableNode = &((*m_tableTags)[tRow + i][lCol + j]); Node::deleteNode(tableNode->node); tableNode->node = new Node(0L); newNum++; tableNode->node->tag = new Tag(*(mainTableNode->node->tag)); tableNode->merged = true; tableNode->mergedRow = tRow; tableNode->mergedCol = lCol; } } }
void ConvFitDataTablePresenter::updateTableEntry(std::size_t dataIndex, std::size_t spectrum, int row) { IndirectDataTablePresenter::updateTableEntry(dataIndex, spectrum, row); const auto &name = m_convFitModel->getResolution(dataIndex)->getName(); setCellText(QString::fromStdString(name), row, 1); }
void JumpFitDataTablePresenter::updateTableEntry(std::size_t dataIndex, std::size_t spectrum, int row) { IndirectDataTablePresenter::updateTableEntry(dataIndex, spectrum, row); const auto parameter = m_jumpFitModel->getFitParameterName(dataIndex, spectrum); setCellText(QString::fromStdString(parameter), row, 1); }
void ObjectTableWidget::clearCellText(unsigned row_idx, unsigned col_idx) { try { setCellText(QString(), row_idx, col_idx); } catch(Exception &e) { throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e); } }
void TableEditor::slotRemoveRow() { if (m_row == -1) m_row = m_dataTable->numRows() - 1; int i = 0; int j = 0; for (QValueList<QValueList<TableNode> >::Iterator it = m_tableTags->begin(); it != m_tableTags->end(); ++it) { j = 0; for (QValueList<TableNode>::Iterator it2 = (*it).begin(); it2 != (*it).end(); ++it2) { if ((*it2).merged && (*it2).mergedRow == m_row) { (*it2).merged = false; setCellText(m_dataTable, i, j, tagContent((*it2).node)); m_dataTable->item(i, j)->setEnabled(true); (*it2).node->tag->deleteAttribute("colspan"); (*it2).node->tag->deleteAttribute("rowspan"); } j++; } i++; } QValueList<TableNode*> updatedMainNodes; QValueList<QValueList<TableNode> >::Iterator it2 = m_tableTags->at(m_row); for (QValueList<TableNode>::Iterator it3 = (*it2).begin(); it3 != (*it2).end(); ++it3) { if ((*it3).merged) { TableNode *mainTableNode = &((*m_tableTags)[(*it3).mergedRow][(*it3).mergedCol]); if (mainTableNode->node && !updatedMainNodes.contains(mainTableNode)) { int rowspan = mainTableNode->node->tag->attributeValue("rowspan", true).toInt(); rowspan--; if (rowspan > 1) mainTableNode->node->tag->editAttribute("rowspan", QString("%1").arg(rowspan)); else mainTableNode->node->tag->deleteAttribute("rowspan"); updatedMainNodes.append(mainTableNode); } } Node::deleteNode((*it3).node); (*it3).node = 0L; newNum--; } m_tableTags->erase(it2); m_dataTable->removeRow(m_row); QValueList<TableNode>::Iterator it = m_tableRows->at(m_row); Node::deleteNode((*it).node); newNum--; m_tableRows->erase(it); m_rowSpin->setValue(m_dataTable->numRows()); }
void TableEditor::slotInsertRow() { int num = m_dataTable->numRows(); if (m_row >= 0) num = m_row; m_dataTable->insertRows(num); m_dataTable->setRowHeight(num, 50); if (m_createNodes) { TableNode tableNode; tableNode.merged = false; tableNode.node = new Node(0L); newNum++; tableNode.node->tag = new Tag(); tableNode.node->tag->setDtd(m_dtd); tableNode.node->tag->parse("<tr>", m_write); QValueList<TableNode>::Iterator rowIt = m_tableRows->at(num); if (rowIt != m_tableRows->end()) m_tableRows->insert(rowIt, tableNode); else m_tableRows->append(tableNode); QValueList<TableNode> tableRowTags; for (int i = 0; i < m_dataTable->numCols(); i++) { tableNode.merged = false; tableNode.node = new Node(0L); newNum++; tableNode.node->tag = new Tag(); tableNode.node->tag->setDtd(m_dtd); if (m_tableTags == m_tableHeaderTags) { tableNode.node->tag->parse("<th>", m_write); } else { tableNode.node->tag->parse("<td>", m_write); } tableRowTags.append(tableNode); setCellText(m_dataTable, num, i, ""); } QValueList<QValueList<TableNode> >::Iterator it = m_tableTags->at(num); if (it != m_tableTags->end()) m_tableTags->insert(it, tableRowTags); else m_tableTags->append(tableRowTags); } m_rowSpin->setValue(m_dataTable->numRows()); }
void KImportDialog::fillTable() { // kdDebug(5300) << "KImportDialog::fillTable()" << endl; int row, column; for(row = 0; row < mTable->numRows(); ++row) for(column = 0; column < mTable->numCols(); ++column) mTable->clearCell(row, column); for(row = 0; row < int(mData.count()); ++row) { QValueVector<QString> *rowVector = mData[ row ]; for(column = 0; column < int(rowVector->size()); ++column) { setCellText(row, column, rowVector->at(column)); } } }
bool TableEditor::setTableArea( int bLine, int bCol, int eLine, int eCol, Parser *docParser ) { const uint pInitialTableSize = 20; m_bLine = bLine; m_bCol = bCol; m_eLine = eLine; m_eCol = eCol; m_createNodes = false; //don't create the cell and row content when adding a new cell/row Node *node = docParser->nodeAt(bLine, bCol + 1); Node *lastNode = docParser->nodeAt(eLine, eCol); if (node) kdDebug(24000) << "node = " << node->tag->name << endl; if (lastNode) kdDebug(24000) << "lastnode = " << lastNode->tag->name << endl; if (!node || !lastNode) return false; m_write = node->tag->write(); m_dtd = node->tag->dtd(); if ( !QuantaCommon::closesTag(node->tag, lastNode->tag) ) { return false; } int nCol, nRow, maxCol; nCol = nRow = maxCol = 0; bool countRows = false; bool missingBody = false; m_rowSpin = 0L; m_colSpin = 0L; m_dataTable = 0L; QValueList<TableNode> tableRowTags; QValueVector< QValueVector<TableNode> > mergeMatrix; mergeMatrix.resize(pInitialTableSize); for (uint i = 0; i < pInitialTableSize; i++) mergeMatrix[i].resize(pInitialTableSize); TableNode tableNode; Node *n = node; while (n != lastNode->nextSibling()) { QString tagName = n->tag->name.lower(); if (tagName == "table") { if (m_table && m_dataTable && nRow > 0 && nCol > 0) //nested table! { int line, col; n->tag->beginPos(line, col); NestedTable table; table.row = nRow -1; table.col = nCol - 1; table.bLine = line; table.bCol = col; if (n->next && QuantaCommon::closesTag(n->tag, n->next->tag)) { n->next->tag->endPos(table.eLine, table.eCol); table.node = n; table.nestedData = m_write->text(table.bLine, table.bCol, table.eLine, table.eCol); m_nestedTables.append(table); m_dataTable->item(nRow -1, nCol -1)->setPixmap(QIconSet(UserIcon("quick_table")).pixmap()); m_dataTable->updateCell(nRow - 1, nCol - 1); } n = n->next; } else { m_table = new Tag(*(n->tag)); newNum++; } } else if (tagName == "thead") { headerCheckBox->setChecked(true); countRows = true; m_rowSpin = headerRowSpinBox; m_colSpin = headerColSpinBox; m_dataTable= headerTableData; m_tableTags = m_tableHeaderTags; m_tableRows = m_tableHeaderRows; if (m_thead) { //there was already a <thead> tag in the area nRow = m_dataTable->numRows(); } else { m_thead = new Tag(*(n->tag)); newNum++; } } else if (tagName == "/thead") { headerRowSpinBox->setValue(nRow); headerColSpinBox->setValue(maxCol); countRows = false; nCol = nRow = maxCol = 0; m_rowSpin = 0L; m_colSpin = 0L; m_dataTable = 0L; } else if (tagName == "tfoot") { footerCheckBox->setChecked(true); m_rowSpin = footerRowSpinBox; m_colSpin = footerColSpinBox; m_tableTags = m_tableFooterTags; m_tableRows = m_tableFooterRows; m_dataTable = footerTableData; countRows = true; if (m_tfoot) { //there was already a <tfoot> tag in the area nRow = m_dataTable->numRows(); } else { m_tfoot = new Tag(*(n->tag)); newNum++; } } else if (tagName == "/tfoot") { footerRowSpinBox->setValue(nRow); footerColSpinBox->setValue(maxCol); countRows = false; nCol = nRow = maxCol = 0; m_rowSpin = 0L; m_colSpin = 0L; m_dataTable = 0L; } else if (tagName == "tbody") { m_rowSpin = rowSpinBox; m_colSpin = colSpinBox; m_tableTags = m_tableDataTags; m_tableRows = m_tableDataRows; m_dataTable = tableData; countRows = true; m_tbody = new Tag(*(n->tag)); newNum++; } else if (tagName == "/tbody") { rowSpinBox->setValue(nRow); colSpinBox->setValue(maxCol); countRows = false; nCol = nRow = maxCol = 0; m_tableTags = 0L; m_tableRows = 0L; m_rowSpin = 0L; m_colSpin = 0L; m_dataTable = 0L; } else if (tagName == "tr") { if (!countRows) { missingBody = true; m_rowSpin = rowSpinBox; m_colSpin = colSpinBox; m_tableTags = m_tableDataTags; m_tableRows = m_tableDataRows; m_dataTable = tableData; countRows = true; m_tbody = new Tag(); newNum++; m_tbody->parse("<tbody>", m_write); } nRow++; if ((uint)nRow >= mergeMatrix.size()) { // Check if there are enough rows in mergeMatriz mergeMatrix.resize(2 * mergeMatrix.size()); for (uint i = mergeMatrix.size() / 2; i < mergeMatrix.size(); i++) mergeMatrix[i].resize(mergeMatrix[0].size()); } m_rowSpin->setValue(nRow); nCol = 0; tableNode.node = new Node(0L); tableNode.node->tag = new Tag(*(n->tag)); newNum++; tableNode.merged = false; m_tableRows->append(tableNode); } else if (tagName == "/tr") { if (countRows) { maxCol = (nCol > maxCol) ? nCol : maxCol; maxCol = (maxCol == 0) ? 1 : maxCol; for (int col = nCol; col < maxCol; col++) { if (mergeMatrix[nRow - 1][col].node != 0L) { if (m_colSpin->value() < col) m_colSpin->setValue(col); TableNode tableN = mergeMatrix[nRow - 1][col]; Node *n = tableN.node; setCellText(m_dataTable, nRow - 1, col, i18n("Merged with (%1, %2).").arg(tableN.mergedRow + 1).arg(tableN.mergedCol + 1)); m_dataTable->item(nRow-1, col)->setEnabled(false); tableNode.node = new Node(0L); tableNode.node->tag = new Tag(*(n->tag)); configureCell(nRow-1, col, tableNode.node); newNum++; tableNode.merged = true; tableNode.mergedRow = tableN.mergedRow; tableNode.mergedCol = tableN.mergedCol; tableRowTags.append(tableNode); if ((uint)nCol >= mergeMatrix[0].size()) // Check if there are enough cols for (uint i=0; i<mergeMatrix.size(); i++) mergeMatrix[i].resize(2 * mergeMatrix[i].size()); } else { tableNode.node = new Node(0L); newNum++; tableNode.node->tag = new Tag(); tableNode.node->tag->setDtd(m_dtd); tableNode.node->tag->parse("<td>", m_write); tableNode.merged = false; tableRowTags.append(tableNode); } } if (!tableRowTags.isEmpty()) m_tableTags->append(tableRowTags); tableRowTags.clear(); } } else if (tagName == "th" || tagName == "td") { if (countRows) { int col = nCol; while (mergeMatrix[nRow - 1][col].node != 0L) { if (m_colSpin->value() < col) m_colSpin->setValue(col); TableNode tableN = mergeMatrix[nRow - 1][col]; Node *n = tableN.node; setCellText(m_dataTable, nRow - 1, col, i18n("Merged with (%1, %2).").arg(tableN.mergedRow + 1).arg(tableN.mergedCol + 1)); m_dataTable->item(nRow-1, col)->setEnabled(false); tableNode.node = new Node(0L); tableNode.node->tag = new Tag(*(n->tag)); configureCell(nRow-1, col, tableNode.node); newNum++; tableNode.merged = true; tableNode.mergedRow = tableN.mergedRow; tableNode.mergedCol = tableN.mergedCol; tableRowTags.append(tableNode); col++; nCol++; if ((uint)nCol >= mergeMatrix[0].size()) // Check if there are enough cols for (uint i = 0; i < mergeMatrix.size(); i++) mergeMatrix[i].resize(2 * mergeMatrix[i].size()); } nCol++; if (m_rowSpin && m_colSpin && m_dataTable) { m_rowSpin->setValue(nRow); if (m_colSpin->value() < nCol) m_colSpin->setValue(nCol); setCellText(m_dataTable, nRow - 1, nCol - 1, tagContent(n)); tableNode.node = new Node(0L); tableNode.node->tag = new Tag(*(n->tag)); configureCell(nRow-1, col, tableNode.node); newNum++; tableNode.merged = false; tableRowTags.append(tableNode); } QString colspanValue = n->tag->attributeValue("colspan", true); int colValue = 1; int lastCol = nCol; if (!colspanValue.isEmpty()) { bool ok; colValue = colspanValue.toInt(&ok, 10); if (ok && colValue > 1) { nCol += (colValue - 1); if (m_colSpin->value() < nCol) m_colSpin->setValue(nCol); for (int i = 0; i < colValue - 1; i++) { setCellText(m_dataTable, nRow - 1, lastCol + i, i18n("Merged with (%1, %2).").arg(nRow).arg(lastCol)); m_dataTable->item(nRow-1, lastCol + i)->setEnabled(false); tableNode.node = new Node(0L); tableNode.node->tag = new Tag(*(n->tag)); configureCell(nRow-1, col, tableNode.node); newNum++; tableNode.merged = true; tableNode.mergedRow = nRow - 1; tableNode.mergedCol = lastCol - 1; tableRowTags.append(tableNode); } } else colValue = 1; } QString rowspanValue = n->tag->attributeValue("rowspan", true); if (!rowspanValue.isEmpty()) { bool ok; int rowValue = rowspanValue.toInt(&ok, 10); if (ok && rowValue > 1) { lastCol--; // Check if there are enough columns in mergeMatriz if ((uint)(lastCol + colValue) >= mergeMatrix[0].size()) for (uint i = 0; i < mergeMatrix.size(); i++) mergeMatrix[i].resize(2 * mergeMatrix[i].size()); // Check if there are enough rows in mergeMatriz if ((uint)(nRow + rowValue) >= mergeMatrix.size()) { mergeMatrix.resize(2 * mergeMatrix.size()); for (uint i = mergeMatrix.size() / 2; i < mergeMatrix.size(); i++) mergeMatrix[i].resize(mergeMatrix[0].size()); } for (int i = 0; i < rowValue - 1; i++) for (int j = 0; j < colValue; j++) { mergeMatrix[nRow + i][lastCol + j].mergedRow = nRow - 1; mergeMatrix[nRow + i][lastCol + j].mergedCol = lastCol; mergeMatrix[nRow + i][lastCol + j].node = n; } } } } } else if (tagName == "caption") { captionText->setText(tagContent(n)); } else if (tagName == "col" || tagName == "colgroup") { m_colTags.append(n->tag); } n = n->nextSibling(); } /* if (missingBody) { //Hm, why do we need it? I don't remember now. ;-) rowSpinBox->setValue(nRow); colSpinBox->setValue(maxCol); } */ //by default the current page is the data handling page m_tableTags = m_tableDataTags; m_tableRows = m_tableDataRows; m_dataTable = tableData; m_rowSpin = rowSpinBox; m_colSpin = colSpinBox; //create the thead, tbody, tfoot tags if they were not present in the parsed area if (!m_thead) { m_thead = new Tag(); newNum++; m_thead->parse("<thead>", m_write); } if (!m_tfoot) { m_tfoot = new Tag(); newNum++; m_tfoot->parse("<tfoot>", m_write); } m_createNodes = true; //enable cell/row creation configureTable(tableData); configureTable(headerTableData); configureTable(footerTableData); return true; }
void TableEditor::slotEditChildTable() { bool tempDocCreated = false; bool error = false; QValueList<NestedTable>::Iterator errorIt; Parser *localParser = 0L; Document *w = 0L; Node *savedBaseNode = 0L; NestedTable table; for (QValueList<NestedTable>::Iterator it = m_nestedTables.begin(); it != m_nestedTables.end(); ++it) { table = *it; if (table.row == m_row && table.col == m_col) { QString cellData = m_dataTable->text(table.row, table.col); int pos = cellData.find(table.nestedData); if (pos == -1) { KMessageBox::error(this, i18n("Cannot edit the child table; you probably modified the cell containing the table manually."), i18n("Cannot Read Table")); error = true; errorIt = it; break; } //create a new editor object and save the current state of the table there KTextEditor::Document *doc = KTextEditor::createDocument ("libkatepart", 0L, "KTextEditor::Document"); w = new Document(doc, 0L); QString tableData = readModifiedTable(); w->editIf->insertText(0, 0, tableData); localParser = new Parser(); savedBaseNode = baseNode; //we must save it as it's deleted in the localParser->parse(); baseNode = 0L; baseNode = localParser->parse(w); tempDocCreated = true; //try to find the child table position int pos2 = tableData.find(cellData); if (pos2 != -1) pos2 = tableData.find(table.nestedData, pos2); else { KMessageBox::error(this, i18n("Cannot edit the child table; you probably modified the cell containing the table manually."), i18n("Cannot Read Table")); error = true; errorIt = it; break; } tableData = tableData.left(pos2); table.bLine = tableData.contains('\n'); pos2 = tableData.findRev('\n'); if (pos2 != -1) { table.bCol = tableData.length() - pos2; } else { table.bCol = tableData.length(); } Node *childTableNode = localParser->nodeAt(table.bLine, table.bCol); if (!childTableNode->next || !QuantaCommon::closesTag(childTableNode->tag, childTableNode->next->tag)) { KMessageBox::error(this, i18n("Cannot find the closing tag of the child table; you have probably introduced unclosed tags in the table and have broken its consistency."), i18n("Cannot Read Table")); error = true; errorIt = it; break; } childTableNode->next->tag->endPos(table.eLine, table.eCol); TableEditor editor; editor.setCaption("Child Table Editor"); editor.setBaseURL(m_baseURL); editor.setTableArea(table.bLine, table.bCol, table.eLine, table.eCol, localParser); if (editor.exec()) { int length = table.nestedData.length(); (*it).nestedData = editor.readModifiedTable(); cellData.replace(pos, length, (*it).nestedData); setCellText(m_dataTable, table.row, table.col, cellData); } //cleanup on success Node::deleteNode(baseNode); baseNode = savedBaseNode; delete localParser; delete w; return; } } //cleanup on error if (error) { m_nestedTables.erase(errorIt); m_dataTable->item(table.row, table.col)->setPixmap(QPixmap()); m_dataTable->updateCell(table.row, table.col); if (tempDocCreated) { Node::deleteNode(baseNode); baseNode = savedBaseNode; delete localParser; delete w; } } }
void TableEditor::slotUnmergeCells() { int tRow, bRow, lCol, rCol; int selectionNum = m_dataTable->currentSelection(); if (selectionNum != -1) { QTableSelection selection = m_dataTable->selection(selectionNum); tRow = selection.topRow(); bRow = selection.bottomRow(); lCol = selection.leftCol(); rCol = selection.rightCol(); } else { tRow = m_row; bRow = m_row; lCol = m_col; rCol = m_col; } for (int row = tRow; row <= bRow; ++row) for (int col = lCol; col <= rCol; ++col) { TableNode tableNode = (*m_tableTags)[row][col]; if (!tableNode.merged) continue; TableNode newTableNode; int i = 0; int j = 0; for (QValueList<QValueList<TableNode> >::Iterator it = m_tableTags->begin(); it != m_tableTags->end(); ++it) { j = 0; QValueList<TableNode>::Iterator it2 = (*it).begin(); while (it2 != (*it).end()) { if ((*it2).merged && tableNode.mergedRow == (*it2).mergedRow && tableNode.mergedCol == (*it2).mergedCol) { Node::deleteNode((*it2).node); newNum--; it2 = (*it).erase(it2); newTableNode.merged = false; newTableNode.node = new Node(0L); newNum++; newTableNode.node->tag = new Tag(); newTableNode.node->tag->setDtd(m_dtd); if (m_tableTags == m_tableHeaderTags) { newTableNode.node->tag->parse("<th>", m_write); } else { newTableNode.node->tag->parse("<td>", m_write); } (*it).insert(it2, newTableNode); setCellText(m_dataTable, i, j, tagContent(newTableNode.node)); m_dataTable->item(i, j)->setEnabled(true); } else { ++it2; } j++; } i++; } newTableNode = (*m_tableTags)[tableNode.mergedRow][tableNode.mergedCol]; newTableNode.node->tag->deleteAttribute("colspan"); newTableNode.node->tag->deleteAttribute("rowspan"); //change the main node TableNode tmpNode = newTableNode; newTableNode.node = new Node(0L); newNum++; newTableNode.node->tag = new Tag(*(tmpNode.node->tag)); QValueList<QValueList<TableNode> >::Iterator iter1 = m_tableTags->at(tableNode.mergedRow); QValueList<TableNode>::Iterator iter2 = (*iter1).at(tableNode.mergedCol); iter2 = (*iter1).erase(iter2); (*iter1).insert(iter2, newTableNode); Node::deleteNode(tmpNode.node); newNum--; } }