void readBoolEntry(const QDomElement &e, const QString &name, bool *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; *v = (tagContent(tag) == "true") ? true: false; }
void readNumEntry(const QDomElement &e, const QString &name, int *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; *v = tagContent(tag).toInt(); }
void readBoolEntry(const QDomElement &e, const QString &name, bool *v) { bool found = FALSE; QDomElement tag = findSubTag(e, name, &found); if(!found) return; *v = (tagContent(tag) == "true") ? TRUE: FALSE; }
void readNumEntry(const QDomElement &e, const QString &name, int *v) { bool found = FALSE; QDomElement tag = findSubTag(e, name, &found); if(!found) return; *v = tagContent(tag).toInt(); }
void readColorEntry(const QDomElement &e, const QString &name, QColor *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; QColor c; c.setNamedColor(tagContent(tag)); if(c.isValid()) *v = c; }
void readColorEntry(const QDomElement &e, const QString &name, QColor *v) { bool found = FALSE; QDomElement tag = findSubTag(e, name, &found); if(!found) return; QColor c; c.setNamedColor(tagContent(tag)); if(c.isValid()) *v = c; }
void readSizeEntry(const QDomElement &e, const QString &name, QSize *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; QStringList list = tagContent(tag).split(','); if(list.count() != 2) return; QSize s; s.setWidth(list[0].toInt()); s.setHeight(list[1].toInt()); *v = s; }
void readSizeEntry(const QDomElement &e, const QString &name, QSize *v) { bool found = FALSE; QDomElement tag = findSubTag(e, name, &found); if(!found) return; QStringList list = tagContent(tag).split(','); if(list.count() != 2) return; QSize s; s.setWidth(list[0].toInt()); s.setHeight(list[1].toInt()); *v = s; }
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 xmlToStringList(const QDomElement &e, const QString &name, QStringList *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; QStringList list; for(QDomNode n = tag.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement i = n.toElement(); if(i.isNull()) continue; if(i.tagName() == "item") list += tagContent(i); } *v = list; }
void readRectEntry(const QDomElement &e, const QString &name, QRect *v) { QDomElement tag = e.firstChildElement(name); if(tag.isNull()) return; QStringList list = tagContent(tag).split(','); if(list.count() != 4) return; QRect r; r.setX(list[0].toInt()); r.setY(list[1].toInt()); r.setWidth(list[2].toInt()); r.setHeight(list[3].toInt()); *v = r; }
void xmlToStringList(const QDomElement &e, const QString &name, QStringList *v) { bool found = false; QDomElement tag = findSubTag(e, name, &found); if(!found) return; QStringList list; for(QDomNode n = tag.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement i = n.toElement(); if(i.isNull()) continue; if(i.tagName() == "item") list += tagContent(i); } *v = list; }
void readRectEntry(const QDomElement &e, const QString &name, QRect *v) { bool found = FALSE; QDomElement tag = findSubTag(e, name, &found); if(!found) return; QStringList list = tagContent(tag).split(','); if(list.count() != 4) return; QRect r; r.setX(list[0].toInt()); r.setY(list[1].toInt()); r.setWidth(list[2].toInt()); r.setHeight(list[3].toInt()); *v = r; }
static JingleRtpReason elementToReason(const QDomElement &e) { if(e.tagName() != "reason") return JingleRtpReason(); QDomElement condElement = firstChildElement(e); if(condElement.isNull()) return JingleRtpReason(); int x = elementNameToCondition(condElement.tagName()); if(x == -1) return JingleRtpReason(); JingleRtpReason out; out.condition = (JingleRtpReason::Condition)x; QDomElement text = e.firstChildElement("text"); if(!text.isNull()) out.text = tagContent(text); return out; }
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::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--; } }