void ChatDialog::appendChatMessage(const QString& nick, const QString& text, time_t timestamp) { QTextCharFormat nickFormat; nickFormat.setForeground(Qt::darkGreen); nickFormat.setFontWeight(QFont::Bold); nickFormat.setFontUnderline(true); nickFormat.setUnderlineColor(Qt::gray); // Print who & when QTextCursor cursor(ui->textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTableFormat tableFormat; tableFormat.setBorder(0); QTextTable *table = cursor.insertTable(1, 2, tableFormat); QString from = QString("%1 ").arg(nick); QTextTableCell fromCell = table->cellAt(0, 0); fromCell.setFormat(nickFormat); fromCell.firstCursorPosition().insertText(from); printTimeInCell(table, timestamp); // Print what QTextCursor nextCursor(ui->textEdit->textCursor()); nextCursor.movePosition(QTextCursor::End); table = nextCursor.insertTable(1, 1, tableFormat); table->cellAt(0, 0).firstCursorPosition().insertText(text); // Popup notification showMessage(from, text); QScrollBar *bar = ui->textEdit->verticalScrollBar(); bar->setValue(bar->maximum()); }
static PyObject *meth_QTextTable_removeColumns(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { int a0; int a1; QTextTable *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Bii", &sipSelf, sipType_QTextTable, &sipCpp, &a0, &a1)) { Py_BEGIN_ALLOW_THREADS sipCpp->removeColumns(a0,a1); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QTextTable, sipName_removeColumns, doc_QTextTable_removeColumns); return NULL; }
static PyObject *meth_QTextTable_splitCell(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { int a0; int a1; int a2; int a3; QTextTable *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Biiii", &sipSelf, sipType_QTextTable, &sipCpp, &a0, &a1, &a2, &a3)) { Py_BEGIN_ALLOW_THREADS sipCpp->splitCell(a0,a1,a2,a3); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QTextTable, sipName_splitCell, doc_QTextTable_splitCell); return NULL; }
void ChatWindow::writeMessage(MessType type, QString mess ) { if( mess.isEmpty() ){ return; } QTextCursor cursor( m_chatEdit->textCursor() ); cursor.movePosition(QTextCursor::End); QTextTable* table = cursor.insertTable(1, 2, *m_tableFormat ); QTextCharFormat charFormat; switch( type ){ case MyMess : charFormat.setForeground(Qt::blue); table->cellAt(0,0).firstCursorPosition().insertText("<" + m_myName + "> ", charFormat); table->cellAt(0,1).firstCursorPosition().insertText(mess); break; case ConMess : charFormat.setForeground(Qt::darkGreen); table->cellAt(0,0).firstCursorPosition().insertText("<" + m_conName + "> ", charFormat); table->cellAt(0,1).firstCursorPosition().insertText(mess); break; case StatusMess : charFormat.setForeground(Qt::darkRed); cursor.insertText(" *** " + mess + " *** ", charFormat); break; default : kWarning() << "Wrong MessType"; break; } QScrollBar *bar = m_chatEdit->verticalScrollBar(); bar->setValue(bar->maximum()); }
void TextDocumentModel::fillFrameIterator(const QTextFrame::iterator &it, QStandardItem *parent) { if (QTextFrame *frame = it.currentFrame()) { const QRectF b = m_document->documentLayout()->frameBoundingRect(frame); QTextTable *table = qobject_cast<QTextTable *>(frame); auto item = new QStandardItem; if (table) { item->setText(tr("Table")); appendRow(parent, item, table->format(), b); fillTable(table, item); } else { item->setText(tr("Frame")); appendRow(parent, item, frame->frameFormat(), b); fillFrame(frame, item); } } const QTextBlock block = it.currentBlock(); if (block.isValid()) { auto item = new QStandardItem; item->setText(tr("Block: %1").arg(block.text())); const QRectF b = m_document->documentLayout()->blockBoundingRect(block); appendRow(parent, item, block.blockFormat(), b); fillBlock(block, item); } }
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node) { static const int totalColumns = 3; if (node->height() == 1) { QTextBlockFormat blockFormat; QTextCharFormat charFormat; charFormat.setFontPointSize(11); charFormat.setFontWeight(QFont::Bold); cursor->insertBlock(blockFormat, charFormat); cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QTextTableFormat tableFormat; tableFormat.setCellPadding(0); tableFormat.setCellSpacing(0); tableFormat.setBorder(0); QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat); for (int i = 0; i < node->size(); i++) { AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i)); QTextCharFormat cellCharFormat; cellCharFormat.setFontPointSize(9); QTextTableCell cell = table->cellAt(i, 0); cell.setFormat(cellCharFormat); QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(QString("%1 ").arg(card->getNumber())); cell = table->cellAt(i, 1); cell.setFormat(cellCharFormat); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(card->getName()); } } else if (node->height() == 2) { QTextBlockFormat blockFormat; QTextCharFormat charFormat; charFormat.setFontPointSize(14); charFormat.setFontWeight(QFont::Bold); cursor->insertBlock(blockFormat, charFormat); cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QTextTableFormat tableFormat; tableFormat.setCellPadding(10); tableFormat.setCellSpacing(0); tableFormat.setBorder(0); QVector<QTextLength> constraints; for (int i = 0; i < totalColumns; i++) constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns); tableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat); for (int i = 0; i < node->size(); i++) { QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition(); printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i))); } } cursor->movePosition(QTextCursor::End); }
void TextEditWidget::sl_MergeCellsAction_Triggered() { QTextTable* table = textField->textCursor().currentTable(); if (!table) { WARNING("Wrong button state"); return; } table->mergeCells(textField->textCursor()); }
void TextEditWidget::sl_RemoveColumnAction_Triggered() { QTextTable* table = textField->textCursor().currentTable(); if (!table) { WARNING("Wrong button state"); return; } int columnNumber = table->cellAt(textField->textCursor()).column(); table->removeColumns(columnNumber, 1); }
void MyChat::appendMessage(const QString from, const QString message) { QTextCursor cursor(textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTable *table = cursor.insertTable(1, 2, tableFormat); table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + ">: "); table->cellAt(0, 1).firstCursorPosition().insertText(message); QScrollBar *bar = textEdit->verticalScrollBar(); bar->setValue(bar->maximum()); }
void Dialog_report::buat_table() { int i; QTextCursor cursor( ui->edit->textCursor()); cursor.movePosition(QTextCursor::Start); ui->edit->setText("Ini report"); /* QTextTableFormat format; format.setHeight( 600 ); format.setWidth( 800 ); format.setCellPadding( 1 ); format.setCellSpacing( 1 ); format.setHeaderRowCount( 2 ); QTextTable *table = cursor.insertTable(10, 5, format); */ QTextTable *table = cursor.insertTable(10, 5 ); QTextBlockFormat centerAlignment; centerAlignment.setAlignment(Qt::AlignHCenter); centerAlignment.setLineHeight( 30, QTextBlockFormat::FixedHeight); centerAlignment.setLeftMargin( 10 ); centerAlignment.setRightMargin( 10 ); QTextCursor cursor2; cursor2 = table->cellAt(0, 0).firstCursorPosition(); cursor2.insertText(QString::fromUtf8("No")); cursor2.setBlockFormat(centerAlignment); for (i=1; i<9; i++) { cursor2 = table->cellAt(i, 0).firstCursorPosition(); cursor2.setBlockFormat(centerAlignment); cursor2.insertText(QString::number(i+1) + "Sil"); } /* int i, y; for (i=0; i<4; i++) { for (y=0;y<5; y++) QTextTable *table = cursor.insertTable( y, i ); //QTextTable *table = cursor.insertTable( y, i, tableFormat); }*/ //QTextTable *tbl; //tbl = new QTextTable( ui->edit ); }
void TextEditWidget::sl_InsertColumnAction_Triggered() { QTextTable* table = textField->textCursor().currentTable(); if (!table) { WARNING("Wrong button state"); return; } QTextTableCell currentCell = table->cellAt(textField->textCursor()); table->insertColumns(currentCell.column() + 1, 1); QTextTableCell cell = table->cellAt(0, currentCell.column() + 1); textField->setTextCursor(cell.firstCursorPosition()); }
void testFindingTables() { // How to find all the tables in a QTextDocument? QTextDocument textDoc; QTextCursor c( &textDoc ); QTextTable* firstTable = c.insertTable( 2, 2 ); QTextTableCell bottomRight = firstTable->cellAt( 1, 1 ); QTextTable* secondTable = bottomRight.firstCursorPosition().insertTable( 3, 3 ); // a nested table c.movePosition( QTextCursor::End ); QTextTable* thirdTable = c.insertTable( 1, 1 ); thirdTable->firstCursorPosition().insertText( "in table" ); c.insertText( "Foo" ); QList<QTextTable *> origTables; origTables << firstTable << secondTable << thirdTable; // A generic and slow solution is // curs.currentTable() && !tablesFound.contains(curs.currentTable()) // for each cursor position. Surely there's better. // We could jump to currentFrame().lastCursorPosition() but then it would skip // nested tables. QTextDocument* clonedDoc = textDoc.clone(); QSet<QTextTable *> tablesFound; { QTextCursor curs(clonedDoc); while (!curs.atEnd()) { QTextTable* currentTable = curs.currentTable(); if ( currentTable && !tablesFound.contains(currentTable) ) { tablesFound.insert( currentTable ); } curs.movePosition( QTextCursor::NextCharacter ); } QCOMPARE( tablesFound.size(), 3 ); } // Let's do something else then, let's find them by cursor position QList<QTextTable *> tablesByPos; { // first test const int firstPos = firstTable->firstCursorPosition().position(); QTextCursor curs( clonedDoc ); curs.setPosition( firstPos ); QVERIFY( curs.currentTable() ); // generic loop. works this approach is in TextDocument::breakTables now. Q_FOREACH( QTextTable* origTable, origTables ) { QTextCursor curs( clonedDoc ); curs.setPosition( origTable->firstCursorPosition().position() ); tablesByPos.append( curs.currentTable() ); } QCOMPARE( tablesByPos.size(), 3 ); QCOMPARE( tablesByPos.toSet(), tablesFound ); }
void ChatDialog::appendMessage(const QString &from, const QString &message) { if (from.isEmpty() || message.isEmpty()) return; QTextCursor cursor(textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTable *table = cursor.insertTable(1, 2, tableFormat); table->cellAt(0, 0).firstCursorPosition().insertText("<" + from + "> "); table->cellAt(0, 1).firstCursorPosition().insertText(message); QScrollBar *bar = textEdit->verticalScrollBar(); bar->setValue(bar->maximum()); }
// Добавление строк в таблицу void TableFormatter::onTableAddRowClicked(void) { QTextCursor cursor(textArea->textCursor()); QTextTable *table = cursor.currentTable(); if(table) { QTextTableCell cell=table->cellAt(cursor); // Выясняется текущая ячейка int cellRowCursor=cell.row(); // Текущий номер строки (счет с нуля) bool ok=false; int addNum=QInputDialog::getInt(editor, tr("Append rows to table"),tr("Append rows:"), 1, 1, 100, 1, &ok); if(ok && addNum > 0) table->insertRows(cellRowCursor + 1,addNum); } }
void DashboardWindow::printTreeWidget(QPrinter *printer) { //build a table QTextDocument doc; QTextCursor cursor(&doc); QTextTable *table = cursor.insertTable(1, ui.treeWidget->columnCount()); //header for (int colNum = 0; colNum < ui.treeWidget->columnCount(); ++colNum) { table->cellAt(0, colNum).firstCursorPosition().insertText(ui.treeWidget->headerItem()->text(colNum)); } //table content treeWidgetToTextTable(ui.treeWidget->invisibleRootItem(), table, 1); doc.print(printer); }
void QQuickTextNodeEngine::addFrameDecorations(QTextDocument *document, QTextFrame *frame) { QTextDocumentLayout *documentLayout = qobject_cast<QTextDocumentLayout *>(document->documentLayout()); QTextFrameFormat frameFormat = frame->format().toFrameFormat(); QTextTable *table = qobject_cast<QTextTable *>(frame); QRectF boundingRect = table == 0 ? documentLayout->frameBoundingRect(frame) : documentLayout->tableBoundingRect(table); QBrush bg = frame->frameFormat().background(); if (bg.style() != Qt::NoBrush) m_backgrounds.append(qMakePair(boundingRect, bg.color())); if (!frameFormat.hasProperty(QTextFormat::FrameBorder)) return; qreal borderWidth = frameFormat.border(); if (qFuzzyIsNull(borderWidth)) return; QBrush borderBrush = frameFormat.borderBrush(); QTextFrameFormat::BorderStyle borderStyle = frameFormat.borderStyle(); if (borderStyle == QTextFrameFormat::BorderStyle_None) return; addBorder(boundingRect.adjusted(frameFormat.leftMargin(), frameFormat.topMargin(), -frameFormat.rightMargin(), -frameFormat.bottomMargin()), borderWidth, borderStyle, borderBrush); if (table != 0) { int rows = table->rows(); int columns = table->columns(); for (int row=0; row<rows; ++row) { for (int column=0; column<columns; ++column) { QTextTableCell cell = table->cellAt(row, column); QRectF cellRect = documentLayout->tableCellBoundingRect(table, cell); addBorder(cellRect.adjusted(-borderWidth, -borderWidth, 0, 0), borderWidth, borderStyle, borderBrush); } } } }
QTextTable *QTextTablePrivate::createTable(QTextDocumentPrivate *pieceTable, int pos, int rows, int cols, const QTextTableFormat &tableFormat) { QTextTableFormat fmt = tableFormat; fmt.setColumns(cols); QTextTable *table = qobject_cast<QTextTable *>(pieceTable->createObject(fmt)); Q_ASSERT(table); pieceTable->beginEditBlock(); // qDebug("---> createTable: rows=%d, cols=%d at %d", rows, cols, pos); // add block after table QTextCharFormat charFmt; charFmt.setObjectIndex(table->objectIndex()); charFmt.setObjectType(QTextFormat::TableCellObject); int charIdx = pieceTable->formatCollection()->indexForFormat(charFmt); int cellIdx = pieceTable->formatCollection()->indexForFormat(QTextBlockFormat()); QTextTablePrivate *d = table->d_func(); d->blockFragmentUpdates = true; d->fragment_start = pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx); d->cells.append(d->fragment_start); ++pos; for (int i = 1; i < rows*cols; ++i) { d->cells.append(pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx)); // qDebug(" addCell at %d", pos); ++pos; } d->fragment_end = pieceTable->insertBlock(QTextEndOfFrame, pos, cellIdx, charIdx); // qDebug(" addEOR at %d", pos); ++pos; d->blockFragmentUpdates = false; d->dirty = true; pieceTable->endEditBlock(); return table; }
void TestChangeTrackedDelete::insertSampleTable(QTextDocument *document) { QTextCursor cursor(document); cursor.insertText("This is a paragraph of text before a table."); QTextTable *table = cursor.insertTable(3,3); table->cellAt(0,0).firstCursorPosition().insertText("first"); table->cellAt(0,1).firstCursorPosition().insertText("second"); table->cellAt(0,2).firstCursorPosition().insertText("third"); table->cellAt(1,0).firstCursorPosition().insertText("fourth"); table->cellAt(1,1).firstCursorPosition().insertText("fifth"); table->cellAt(1,2).firstCursorPosition().insertText("sixth"); table->cellAt(2,0).firstCursorPosition().insertText("seventh"); table->cellAt(2,1).firstCursorPosition().insertText("eigth"); table->cellAt(2,2).firstCursorPosition().insertText("ninth"); }
void ChatDialog::appendControlMessage(const QString& nick, const QString& action, time_t timestamp) { QTextCharFormat nickFormat; nickFormat.setForeground(Qt::gray); nickFormat.setFontWeight(QFont::Bold); nickFormat.setFontUnderline(true); nickFormat.setUnderlineColor(Qt::gray); QTextCursor cursor(ui->textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTableFormat tableFormat; tableFormat.setBorder(0); QTextTable *table = cursor.insertTable(1, 2, tableFormat); QString controlMsg = QString("%1 %2 ").arg(nick).arg(action); QTextTableCell fromCell = table->cellAt(0, 0); fromCell.setFormat(nickFormat); fromCell.firstCursorPosition().insertText(controlMsg); printTimeInCell(table, timestamp); }
void TextEditWidget::sl_CreateTableAction_Triggered() { QTextTable* table = textField->textCursor().currentTable(); if (table) { return; } textField->textCursor().beginEditBlock(); table = textField->textCursor().insertTable(2, 2); QTextTableFormat format = table->format(); format.setCellSpacing(0); format.setCellPadding(3); format.setBorderStyle(QTextFrameFormat::BorderStyle_Solid); QTextLength tableWidth(QTextLength::PercentageLength, 50); format.setWidth(tableWidth); table->setFormat(format); textField->textCursor().endEditBlock(); QTextTableCell cell = table->cellAt(0, 0); textField->setTextCursor(cell.firstCursorPosition()); }
QObject* TextCursor::insertTable(int rows, int columns) { QTextTableFormat format; //format.setColumns(columns); //format.setHeaderRowCount(1); format.setBackground(QColor("#e0e0e0")); //format.setCellPadding(1); format.setCellSpacing(1); //testcase QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 16); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); format.setColumnWidthConstraints(constraints); QTextTable* table = m_cursor.insertTable(rows, columns, format); //QTextTable* t = m_cursor.insertTable(rows, columns); QTextTableCell cell = table->cellAt(0, 0); cell.firstCursorPosition().insertText(tr("aaa") /*, QTextCharFormat::charFormat*/); table->cellAt(0, 1).firstCursorPosition().insertText(tr("bbb")); return new TextTable(this, table); }
int main(int argc, char * argv[]) { int rows = 6; int columns = 2; QApplication app(argc, argv); QTextEdit *textEdit = new QTextEdit; QTextCursor cursor(textEdit->textCursor()); cursor.movePosition(QTextCursor::Start); QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignHCenter); tableFormat.setCellPadding(2); tableFormat.setCellSpacing(2); QTextTable *table = cursor.insertTable(rows, columns); table->setFormat(tableFormat); QTextCharFormat boldFormat; boldFormat.setFontWeight(QFont::Bold); QTextBlockFormat centerFormat; centerFormat.setAlignment(Qt::AlignHCenter); cursor.mergeBlockFormat(centerFormat); cursor = table->cellAt(0, 0).firstCursorPosition(); cursor.insertText(("Details"), boldFormat); cursor = table->cellAt(1, 0).firstCursorPosition(); cursor.insertText("Alan"); cursor = table->cellAt(1, 1).firstCursorPosition(); cursor.insertText("5, Pickety Street"); //! [0] table->mergeCells(0, 0, 1, 2); //! [0] //! [1] table->splitCell(0, 0, 1, 1); //! [1] textEdit->show(); return app.exec(); }
void ChatAreaWidget::insertMessage(ChatAction *msgAction) { if (msgAction == nullptr) return; checkSlider(); QTextTable *chatTextTable = getMsgTable(); QTextCursor cur = chatTextTable->cellAt(0, 2).firstCursorPosition(); cur.clearSelection(); cur.setKeepPositionOnInsert(true); chatTextTable->cellAt(0, 0).firstCursorPosition().setBlockFormat(nameFormat); chatTextTable->cellAt(0, 0).firstCursorPosition().insertHtml(msgAction->getName()); chatTextTable->cellAt(0, 2).firstCursorPosition().insertHtml(msgAction->getMessage()); chatTextTable->cellAt(0, 4).firstCursorPosition().setBlockFormat(dateFormat); chatTextTable->cellAt(0, 4).firstCursorPosition().insertHtml(msgAction->getDate()); msgAction->setup(cur, this); messages.append(msgAction); }
void MainWindow::showTable() { QTextCursor cursor = editor->textCursor(); QTextTable *table = cursor.currentTable(); if (!table) return; QTableWidget *tableWidget = new QTableWidget(table->rows(), table->columns()); //! [9] for (int row = 0; row < table->rows(); ++row) { for (int column = 0; column < table->columns(); ++column) { QTextTableCell tableCell = table->cellAt(row, column); //! [9] QTextFrame::iterator it; QString text; for (it = tableCell.begin(); !(it.atEnd()); ++it) { QTextBlock childBlock = it.currentBlock(); if (childBlock.isValid()) text += childBlock.text(); } QTableWidgetItem *newItem = new QTableWidgetItem(text); tableWidget->setItem(row, column, newItem); /* //! [10] processTableCell(tableCell); //! [10] */ //! [11] } //! [11] //! [12] } //! [12] tableWidget->setWindowTitle(tr("Table Contents")); tableWidget->show(); }
void PrintView::createPage() const { QTextCursor cursor(ui->textEdit->textCursor()); QTextCharFormat format(cursor.charFormat()); format.setFontFamily("Times"); QTextCharFormat boldFormat = format; boldFormat.setFontWeight(QFont::Bold); unsigned int numOfTasks = numOfOpenTasks(); if(!numOfTasks) { cursor.insertText(tr("There are currently no open tasks."), format); return; } else { cursor.insertText(tr("Open tasks as of %1\n\n").arg(QDateTime::currentDateTime().toString()), format); } // sort tasks ascending according to their due dates QVector<Task*> allTasksCp = *allTasks; qSort(allTasksCp.begin(), allTasksCp.end(), TaskLessThan); QTextTableFormat tableFormat; tableFormat.setCellPadding(10.); tableFormat.setCellSpacing(0.); tableFormat.setHeaderRowCount(1); int rows = numOfTasks + 1/*allTasks.size()+1*/, columns = 6; QTextTable *table = cursor.insertTable(rows, columns, tableFormat); QTextTableCell cell; QTextCursor cellCursor; for (int column=0; column<columns; ++column) { cell = table->cellAt(0, column); cellCursor = cell.firstCursorPosition(); switch(column) { case 0: cellCursor.insertText(tr("Due date"), boldFormat); break; case 1: cellCursor.insertText(tr("Title"), boldFormat); break; case 2: cellCursor.insertText(tr("Description"), boldFormat); break; case 3: cellCursor.insertText(tr("Category"), boldFormat); break; case 4: cellCursor.insertText(tr("Location"), boldFormat); break; case 5: cellCursor.insertText(tr("Done"), boldFormat); break; } } int actualRow = 0; // as radio buttons they are exclusive, therefore we don't need a flag for the third 'all' option bool showWeek = ui->radioButton_week->isChecked(); bool showMonth = ui->radioButton_month->isChecked(); for (int row=0; row<allTasksCp.size(); ++row) { if(allTasksCp.at(row)->done()) { continue; } if(showWeek) { if(allTasksCp.at(row)->dueDate()>QDateTime::currentDateTime().addDays(7)) { continue; } } else if(showMonth) { if(allTasksCp.at(row)->dueDate()>QDateTime::currentDateTime().addDays(30)) { continue; } } for (int column=0; column<columns; ++column) { cell = table->cellAt(actualRow+1, column); cellCursor = cell.firstCursorPosition(); switch(column) { case 0: cellCursor.insertText(allTasksCp.at(row)->dueDate().toString(), format); break; case 1: cellCursor.insertText(allTasksCp.at(row)->title(), format); break; case 2: cellCursor.insertText(allTasksCp.at(row)->description(), format); break; case 3: cellCursor.insertText(allTasksCp.at(row)->category(), format); break; case 4: cellCursor.insertText(allTasksCp.at(row)->location(), format); break; } } ++actualRow; } }
//! [5] void MainWindow::insertCalendar() { editor->clear(); QTextCursor cursor = editor->textCursor(); cursor.beginEditBlock(); QDate date(selectedDate.year(), selectedDate.month(), 1); //! [5] //! [6] QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignHCenter); tableFormat.setBackground(QColor("#e0e0e0")); tableFormat.setCellPadding(2); tableFormat.setCellSpacing(4); //! [6] //! [7] QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14); tableFormat.setColumnWidthConstraints(constraints); //! [7] //! [8] QTextTable *table = cursor.insertTable(1, 7, tableFormat); //! [8] //! [9] QTextFrame *frame = cursor.currentFrame(); QTextFrameFormat frameFormat = frame->frameFormat(); frameFormat.setBorder(1); frame->setFrameFormat(frameFormat); //! [9] //! [10] QTextCharFormat format = cursor.charFormat(); format.setFontPointSize(fontSize); QTextCharFormat boldFormat = format; boldFormat.setFontWeight(QFont::Bold); QTextCharFormat highlightedFormat = boldFormat; highlightedFormat.setBackground(Qt::yellow); //! [10] //! [11] for (int weekDay = 1; weekDay <= 7; ++weekDay) { QTextTableCell cell = table->cellAt(0, weekDay-1); //! [11] //! [12] QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)), boldFormat); } //! [12] //! [13] table->insertRows(table->rows(), 1); //! [13] while (date.month() == selectedDate.month()) { int weekDay = date.dayOfWeek(); QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1); QTextCursor cellCursor = cell.firstCursorPosition(); if (date == QDate::currentDate()) cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat); else cellCursor.insertText(QString("%1").arg(date.day()), format); date = date.addDays(1); if (weekDay == 7 && date.month() == selectedDate.month()) table->insertRows(table->rows(), 1); } cursor.endEditBlock(); //! [14] setWindowTitle(tr("Calendar for %1 %2" ).arg(QDate::longMonthName(selectedDate.month()) ).arg(selectedDate.year())); }
void KoTextLoader::loadBody(const KoXmlElement &bodyElem, QTextCursor &cursor) { const QTextBlockFormat defaultBlockFormat = cursor.blockFormat(); const QTextCharFormat defaultCharFormat = cursor.charFormat(); const QTextDocument *document = cursor.block().document(); d->styleManager = KoTextDocument(document).styleManager(); Q_ASSERT(d->styleManager); d->changeTracker = KoTextDocument(document).changeTracker(); // if (!d->changeTracker) // d->changeTracker = dynamic_cast<KoChangeTracker *>(d->context.dataCenterMap().value("ChangeTracker")); // Q_ASSERT(d->changeTracker); kDebug(32500) << "text-style:" << KoTextDebug::textAttributes( cursor.blockCharFormat() ); #if 0 if ((document->isEmpty()) && (d->styleManager)) { QTextBlock block = cursor.block(); d->styleManager->defaultParagraphStyle()->applyStyle(block); } #endif startBody(KoXml::childNodesCount(bodyElem)); KoXmlElement tag; bool usedParagraph = false; // set to true if we found a tag that used the paragraph, indicating that the next round needs to start a new one. forEachElement(tag, bodyElem) { if (! tag.isNull()) { const QString localName = tag.localName(); if (tag.namespaceURI() == KoXmlNS::text) { if (usedParagraph) cursor.insertBlock(defaultBlockFormat, defaultCharFormat); usedParagraph = true; if (d->changeTracker && localName == "tracked-changes") { d->changeTracker->loadOdfChanges(tag); usedParagraph = false; } else if (d->changeTracker && localName == "change-start") { loadChangedRegion(tag, cursor); usedParagraph = false; } else if (d->changeTracker && localName == "change-end") { d->currentChangeId = 0; usedParagraph = false; } else if (localName == "p") { // text paragraph loadParagraph(tag, cursor); } else if (localName == "h") { // heading loadHeading(tag, cursor); } else if (localName == "unordered-list" || localName == "ordered-list" // OOo-1.1 || localName == "list" || localName == "numbered-paragraph") { // OASIS loadList(tag, cursor); } else if (localName == "section") { // Temporary support (###TODO) loadSection(tag, cursor); } else { KoVariable *var = KoVariableRegistry::instance()->createFromOdf(tag, d->context); if (var) { KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*>(cursor.block().document()->documentLayout()); if (layout) { KoInlineTextObjectManager *textObjectManager = layout->inlineTextObjectManager(); if (textObjectManager) { KoVariableManager *varManager = textObjectManager->variableManager(); if (varManager) { textObjectManager->insertInlineObject(cursor, var); } } } } else { usedParagraph = false; kWarning(32500) << "unhandled text:" << localName; } } } else if (tag.namespaceURI() == KoXmlNS::draw) { loadShape(tag, cursor); } else if (tag.namespaceURI() == KoXmlNS::table) { if (localName == "table") { loadTable(tag, cursor); } else { kWarning(32500) << "unhandled table:" << localName; } #if 0 // TODO commented out for now if (localName == "table") { cursor.insertText("\n"); cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1); QTextTable *tbl = cursor.insertTable(1, 1); int rows = 0; int columns = 0; kDebug(32500) << "Table inserted"; KoXmlElement tblTag; forEachElement(tblTag, tag) { if (! tblTag.isNull()) { const QString tblLocalName = tblTag.localName(); if (tblTag.namespaceURI() == KoXmlNS::table) { if (tblLocalName == "table-column") { // Do some parsing with the column, see §8.2.1, ODF 1.1 spec int repeatColumn = tblTag.attributeNS(KoXmlNS::table, "number-columns-repeated", "1").toInt(); columns = columns + repeatColumn; if (rows > 0) tbl->resize(rows, columns); else tbl->resize(1, columns); } else if (tblLocalName == "table-row") { // Lot of work to do here... rows++; if (columns > 0) tbl->resize(rows, columns); else tbl->resize(rows, 1); // Added a row int currentCell = 0; KoXmlElement rowTag; forEachElement(rowTag, tblTag) { if (!rowTag.isNull()) { const QString rowLocalName = rowTag.localName(); if (rowTag.namespaceURI() == KoXmlNS::table) { if (rowLocalName == "table-cell") { // Ok, it's a cell... const int currentRow = tbl->rows() - 1; QTextTableCell cell = tbl->cellAt(currentRow, currentCell); if (cell.isValid()) { cursor = cell.firstCursorPosition(); loadBody(context, rowTag, cursor); } else kDebug(32500) << "Invalid table-cell row=" << currentRow << " column=" << currentCell; currentCell++; } } } } } } } } cursor = tbl->lastCursorPosition(); cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1); } else { kWarning(32500) << "KoTextLoader::loadBody unhandled table::" << localName; } #endif }
void TestChangeTrackedDelete::testTableDelete() { TextTool *textTool = new TextTool(new MockCanvas); KoTextEditor *textEditor = textTool->textEditor(); QVERIFY(textEditor); QTextDocument *document = textEditor->document(); KTextDocumentLayout *layout = qobject_cast<KTextDocumentLayout*>(document->documentLayout()); QTextCursor *cursor = textEditor->cursor(); insertSampleTable(document); cursor->setPosition(13); cursor->setPosition(102, QTextCursor::KeepAnchor); ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool); textEditor->addCommand(delCommand); QCOMPARE(document->characterAt(13).unicode(), (ushort)(QChar::ObjectReplacementCharacter)); // This is wierd. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ?????? for (int i=0; i<document->characterCount(); i++) { cursor->setPosition(i); } cursor->setPosition(14); KDeleteChangeMarker *testMarker = dynamic_cast<KDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(*cursor)); QTextDocumentFragment deleteData = KTextDocument(document).changeTracker()->elementById(testMarker->changeId())->deleteData(); QTextDocument deleteDocument; QTextCursor deleteCursor(&deleteDocument); deleteCursor.insertFragment(deleteData); bool tableFound = false; for (int i=0; i < deleteDocument.characterCount(); i++) { deleteCursor.setPosition(i); if (deleteCursor.currentTable()) { tableFound = true; break; } } QVERIFY(tableFound == true); QTextTable *table = deleteCursor.currentTable(); QVERIFY(table->rows() == 3); QVERIFY(table->columns() == 3); tableFound = false; for (int i=0; i < document->characterCount(); i++) { deleteCursor.setPosition(i); if (deleteCursor.currentTable()) { tableFound = true; break; } } QVERIFY(tableFound == false); delCommand->undo(); tableFound = false; for (int i=0; i < document->characterCount(); i++) { deleteCursor.setPosition(i); if (deleteCursor.currentTable()) { tableFound = true; break; } } QVERIFY(tableFound == true); delete textTool; }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); QAction *saveAction = fileMenu->addAction(tr("&Save...")); saveAction->setShortcut(tr("Ctrl+S")); QAction *quitAction = fileMenu->addAction(tr("E&xit")); quitAction->setShortcut(tr("Ctrl+Q")); QMenu *showMenu = new QMenu(tr("&Show")); QAction *showTableAction = showMenu->addAction(tr("&Table")); menuBar()->addMenu(fileMenu); menuBar()->addMenu(showMenu); editor = new QTextEdit(); //! [0] //! [1] QTextCursor cursor(editor->textCursor()); //! [0] cursor.movePosition(QTextCursor::Start); //! [1] int rows = 11; int columns = 4; //! [2] QTextTableFormat tableFormat; tableFormat.setBackground(QColor("#e0e0e0")); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 16); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); tableFormat.setColumnWidthConstraints(constraints); //! [3] QTextTable *table = cursor.insertTable(rows, columns, tableFormat); //! [2] //! [3] int column; int row; QTextTableCell cell; QTextCursor cellCursor; QTextCharFormat charFormat; charFormat.setForeground(Qt::black); //! [4] cell = table->cellAt(0, 0); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("Week"), charFormat); //! [4] //! [5] for (column = 1; column < columns; ++column) { cell = table->cellAt(0, column); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("Team %1").arg(column), charFormat); } for (row = 1; row < rows; ++row) { cell = table->cellAt(row, 0); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("%1").arg(row), charFormat); for (column = 1; column < columns; ++column) { if ((row-1) % 3 == column-1) { //! [5] //! [6] cell = table->cellAt(row, column); QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("On duty"), charFormat); } //! [6] //! [7] } //! [7] //! [8] } //! [8] connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); connect(showTableAction, SIGNAL(triggered()), this, SLOT(showTable())); setCentralWidget(editor); setWindowTitle(tr("Text Document Tables")); }
void KDReports::AutoTableElement::build( ReportBuilder& builder ) const { if( !d->m_tableModel ) { return; } QTextDocument& textDoc = builder.currentDocument(); QTextCursor& textDocCursor = builder.cursor(); textDocCursor.beginEditBlock(); QTextTableFormat tableFormat; const int headerRowCount = d->m_horizontalHeaderVisible ? 1 : 0; const int headerColumnCount = d->m_verticalHeaderVisible ? 1 : 0; tableFormat.setHeaderRowCount( headerRowCount ); tableFormat.setProperty( KDReports::HeaderColumnsProperty, headerColumnCount ); tableFormat.setAlignment( textDocCursor.blockFormat().alignment() ); fillTableFormat( tableFormat, textDocCursor ); while (d->m_tableModel->canFetchMore(QModelIndex())) d->m_tableModel->fetchMore(QModelIndex()); const int rows = d->m_tableModel->rowCount(); const int columns = d->m_tableModel->columnCount(); QTextTable* textTable = textDocCursor.insertTable( rows + headerRowCount, columns + headerColumnCount, tableFormat ); QTextCharFormat tableHeaderFormat; tableHeaderFormat.setBackground( d->m_headerBackground ); //qDebug( "rows = %d, columns = %d", textTable->rows(), textTable->columns() ); if( d->m_horizontalHeaderVisible ) { for( int column = 0; column < columns; column++ ) { QTextTableCell cell = textTable->cellAt( 0, column + headerColumnCount ); Q_ASSERT( cell.isValid() ); cell.setFormat( tableHeaderFormat ); d->fillCellFromHeaderData( column, Qt::Horizontal, cell, textDoc, textTable, builder ); } } if( d->m_verticalHeaderVisible ) { for( int row = 0; row < rows; row++ ) { QTextTableCell cell = textTable->cellAt( row + headerRowCount, 0 ); Q_ASSERT( cell.isValid() ); cell.setFormat( tableHeaderFormat ); d->fillCellFromHeaderData( row, Qt::Vertical, cell, textDoc, textTable, builder ); } } QVector<QBitArray> coveredCells; coveredCells.resize(rows); for( int row = 0; row < rows; row++ ) coveredCells[row].resize(columns); // The normal data for( int row = 0; row < rows; row++ ) { for( int column = 0; column < columns; column++ ) { if (coveredCells[row].testBit(column)) continue; QTextTableCell cell = textTable->cellAt( row + headerRowCount, column + headerColumnCount ); Q_ASSERT( cell.isValid() ); const QSize span = d->fillTableCell( row, column, cell, textDoc, textTable, builder ); if (span.isValid()) { for (int r = row; r < row + span.height() && r < rows; ++r) { for (int c = column; c < column + span.width() && c < columns; ++c) { coveredCells[r].setBit(c); } } } } } textDocCursor.movePosition( QTextCursor::End ); textDocCursor.endEditBlock(); builder.currentDocumentData().registerAutoTable( textTable, this ); }