本文整理汇总了C++中QTextTableCell::firstCursorPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextTableCell::firstCursorPosition方法的具体用法?C++ QTextTableCell::firstCursorPosition怎么用?C++ QTextTableCell::firstCursorPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextTableCell
的用法示例。
在下文中一共展示了QTextTableCell::firstCursorPosition方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillCategoryTableLine
void PrintDialog::fillCategoryTableLine( QTextTable * table, const unsigned int & row,
const QString & position, const QString & lastname,
const QString & firstname, const QString & time)
{
int realRow = row + 1;
table->insertRows ( realRow, 1 );
QTextCharFormat cellFormat;
cellFormat.setFontPointSize(10.0);
if(row%2)
cellFormat.setBackground(QBrush(QColor(240,240,240)));
QTextTableCell cell = table->cellAt(realRow, 0);
QTextCursor cursor = cell.firstCursorPosition();
cell.setFormat(cellFormat);
cursor.insertText(position);
cell = table->cellAt(realRow, 1);
cursor = cell.firstCursorPosition();
cell.setFormat(cellFormat);
cursor.insertText(lastname);
cell = table->cellAt(realRow, 2);
cursor = cell.firstCursorPosition();
cell.setFormat(cellFormat);
cursor.insertText(firstname);
cell = table->cellAt(realRow, 3);
cursor = cell.firstCursorPosition();
cell.setFormat(cellFormat);
cursor.insertText(time);
}
示例2: printDeckListNode
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);
}
示例3: cursor
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());
}
示例4:
void
ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp)
{
QTextCharFormat timeFormat;
timeFormat.setForeground(Qt::gray);
timeFormat.setFontUnderline(true);
timeFormat.setUnderlineColor(Qt::gray);
QTextTableCell timeCell = table->cellAt(0, 1);
timeCell.setFormat(timeFormat);
timeCell.firstCursorPosition().insertText(formatTime(timestamp));
}
示例5: sl_InsertColumnAction_Triggered
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());
}
示例6: sl_CreateTableAction_Triggered
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());
}
示例7: insertTable
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);
}
示例8: cursor
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"));
}
示例9: initTest
void TestTableLayout::initTest(int rows, int columns,
KoTableStyle *tableStyle,
const QList<KoTableColumnStyle *> &columnStyles,
const QList<KoTableRowStyle *> &rowStyles,
const QMap<QPair<int, int>, KoTableCellStyle *> &cellStyles,
const QMap<QPair<int, int>, QString> &cellTexts)
{
// Mock shape of size 200x1000 pt.
m_shape = new MockTextShape();
Q_ASSERT(m_shape);
m_shape->setSize(QSizeF(200, 1000));
// Document layout.
m_layout = m_shape->layout;
Q_ASSERT(m_layout);
// Document.
m_doc = m_layout->document();
Q_ASSERT(m_doc);
m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false));
// Layout state (layout helper).
m_textLayout = new Layout(m_layout);
Q_ASSERT(m_textLayout);
m_layout->setLayout(m_textLayout);
// Style manager.
m_styleManager = new KoStyleManager();
Q_ASSERT(m_styleManager);
KoTextDocument(m_doc).setStyleManager(m_styleManager);
// Table style.
m_defaultTableStyle = new KoTableStyle();
Q_ASSERT(m_defaultTableStyle);
m_defaultTableStyle->setMargin(0.0);
m_defaultTableStyle->setWidth(QTextLength(QTextLength::FixedLength, 200));
QTextTableFormat tableFormat;
if (tableStyle) {
tableStyle->applyStyle(tableFormat);
} else {
m_defaultTableStyle->applyStyle(tableFormat);
}
// Table.
QTextCursor cursor(m_doc);
m_table = cursor.insertTable(rows, columns, tableFormat);
Q_ASSERT(m_table);
// Column and row style manager.
m_tableColumnAndRowStyleManager = KoTableColumnAndRowStyleManager::getManager(m_table);
// Column styles.
m_defaultColumnStyle.setRelativeColumnWidth(50.0);
for (int col = 0; col < columns; ++col) {
if (columnStyles.value(col)) {
m_tableColumnAndRowStyleManager.setColumnStyle(col, *(columnStyles.at(col)));
} else {
m_tableColumnAndRowStyleManager.setColumnStyle(col, m_defaultColumnStyle);
}
}
// Row styles.
for (int row = 0; row < rows; ++row) {
if (rowStyles.value(row)) {
m_tableColumnAndRowStyleManager.setRowStyle(row, *(rowStyles.at(row)));
} else {
m_tableColumnAndRowStyleManager.setRowStyle(row, m_defaultRowStyle);
}
}
// Cell styles and texts.
m_defaultCellStyle = new KoTableCellStyle();
Q_ASSERT(m_defaultCellStyle);
for (int row = 0; row < m_table->rows(); ++row) {
for (int col = 0; col < m_table->columns(); ++col) {
// Style.
QTextTableCell cell = m_table->cellAt(row, col);
QTextTableCellFormat cellFormat = cell.format().toTableCellFormat();
if (cellStyles.contains(qMakePair(row, col))) {
cellStyles.value(qMakePair(row, col))->applyStyle(cellFormat);
cell.setFormat(cellFormat.toCharFormat());
} else {
m_defaultCellStyle->applyStyle(cellFormat);
}
cell.setFormat(cellFormat.toCharFormat());
// Text.
if (cellTexts.contains(qMakePair(row, col))) {
cell.firstCursorPosition().insertText(cellTexts.value(qMakePair(row, col)));
}
}
}
KoParagraphStyle style;
style.setStyleId(101); // needed to do manually since we don't use the stylemanager
QTextBlock b2 = m_doc->begin();
while (b2.isValid()) {
style.applyStyle(b2);
b2 = b2.next();
}
}
示例10: fillTable
///////////////////////////////////////////////////////////////////////////////////
//fin modele-----------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////
void ProduceDoc::fillTable(QList<QVector<QString> > & tableau,
QTextTableFormat & tableFormatOrganized,
QTextCursor * cursorForFillFunction,
QString & thisMonth,
QStringList & listSums,
int choice,
const QString & totalMovementString){
QList<QVector<QString> > tableauInFonction;
tableauInFonction = tableau;
int nbreLignesTableau = tableauInFonction.size();
int nbreColonnesTableau = TABLE_NAME_OF_ACTS;
int sizeOfTable = nbreLignesTableau*nbreColonnesTableau;
QTextTableFormat tableFormat = tableFormatOrganized;
QTextCursor *cursortrieinfunction = cursorForFillFunction;
QString thisMonthfonction = thisMonth;
QString type = "";
QStringList totalSumsList = listSums;
QString total;
/*for (int i = 0; i < totalSumsList.size(); i += 1)
{
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << " totalSumsList =" << totalSumsList[i] ;
}*/
if(choice == RECEIPTS_TYPE){
type = tr("Receipts");
total = totalSumsList[SUMS_SUM];
}
if(choice == MOVEMENTS_TYPE){
type = tr("Movements");
total = totalMovementString;
}
QTextBlockFormat centerHead ;
//centrer .setBackground(Qt::yellow) ;
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << " thisMonthfonction =" << thisMonthfonction ;
QString heads = tr("Month of ")+thisMonthfonction+" = "+type;
if (thisMonthfonction == tr("complete year"))
{
heads = tr("Total of ")+thisMonthfonction+" = "+type;
}
centerHead .setAlignment(Qt::AlignCenter) ;
cursortrieinfunction -> insertBlock(centerHead);
cursortrieinfunction -> insertHtml("<font size = 6 color = #3300FF><bold><br/>"
"<br/>"+heads+"<bold>"
"</font><br/><br/>");
QTextTableFormat tableFormatDone;
myFormat(tableFormatDone,m_tablesRecapParameters);
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << " thread 10 " ;
if(sizeOfTable!= 0){
if((thisMonthfonction != tr("complete year")) ){
QTextTable * table = cursortrieinfunction->insertTable(nbreLignesTableau,
nbreColonnesTableau,
tableFormat);
for(int i=0 ; i< nbreLignesTableau ; i++){
QVector<QString> vectorString;
vectorString = tableauInFonction[i];
/*if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << "vectorString size ="
<< QString::number(vectorString.size());*/
QStringList list; // liste des données de la ligne
/*if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << "nbreColonnesTableau = "
<< QString::number(nbreColonnesTableau) ;*/
for (int a = 0 ;a < nbreColonnesTableau ; a++){
QString str = vectorString[a];
list << str;
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << " str =" << str ;
}
double s = list[2].toDouble();
if(s > 0){
for(int j= 0 ; j < nbreColonnesTableau ; j++){
QTextTableCell cell = table->cellAt(i,j);
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor . insertText(list[j]);
}
}
}
QTextBlockFormat centrer ;
//centrer .setBackground(Qt::yellow) ;
centrer .setAlignment(Qt::AlignCenter) ;
cursortrieinfunction -> insertBlock(centrer);
cursortrieinfunction -> insertText("\n\n");
//----------------insertion fin de table-------------------------------------------
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << "total =" << total ;
table -> insertRows(table->rows(),1);
table -> mergeCells(table->rows()-1,0,1,2);//-1 car part de zero
QTextTableCell cell = table->cellAt(table->rows()-1,0);
QTextCursor cellCursor = cell.firstCursorPosition();
QString totalMonth = QString("<html><font size = 4 color = #FF0000><bold>%1 %2 <bold></font></html>")
.arg(tr("Total of "),thisMonthfonction);
//.........这里部分代码省略.........
示例11:
QTextTable * PrintDialog::insertCategoryTable(QTextCursor & cursor, const QString & categoryName)
{
QTextBlockFormat blockCategoryTitleFormat;
blockCategoryTitleFormat.setAlignment(Qt::AlignCenter);
blockCategoryTitleFormat.setTopMargin(40.0);
blockCategoryTitleFormat.setBottomMargin(30.0);
QTextCharFormat categoryTitleFormat;
categoryTitleFormat.setFontCapitalization(QFont::AllUppercase);
categoryTitleFormat.setFontWeight(25);
categoryTitleFormat.setFontPointSize(14.0);
QString category = "Category \"";
category += categoryName;
category += "\"";
cursor.insertBlock(blockCategoryTitleFormat);
cursor.insertText(category,categoryTitleFormat);
cursor.insertBlock(QTextBlockFormat()); // to break the previous block format
QTextTable * table = cursor.insertTable(1, 4);
if(!table)
return NULL;
QTextTableFormat categoryTableFormat;
categoryTableFormat.setAlignment(Qt::AlignHCenter);
categoryTableFormat.setHeaderRowCount(1); // header line
categoryTableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid);
categoryTableFormat.setBorder(1.0);
categoryTableFormat.setCellPadding(10);
categoryTableFormat.setCellSpacing(0);
table->setFormat(categoryTableFormat);
// header :
// header cell format :
QTextCharFormat headerCellFormat;
headerCellFormat.setFontWeight(50);
headerCellFormat.setFontPointSize(12.0);
headerCellFormat.setBackground(QBrush(QColor(60,60,60)));
headerCellFormat.setForeground(QBrush(QColor(255,255,255)));
QTextTableCell cell = table->cellAt(0,0);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Position"));
cell = table->cellAt(0,1);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("LastName"));
cell = table->cellAt(0,2);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Firstname"));
cell = table->cellAt(0,3);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Time"));
return table;
}
示例12: insertCalendar
//! [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()));
}
示例13: createPage
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)
//.........这里部分代码省略.........
示例14: mergeCells
/*!
\since 4.1
Merges the cell at the specified \a row and \a column with the adjacent cells
into one cell. The new cell will span \a numRows rows and \a numCols columns.
If \a numRows or \a numCols is less than the current number of rows or columns
the cell spans then this method does nothing.
\sa splitCell()
*/
void QTextTable::mergeCells(int row, int column, int numRows, int numCols)
{
Q_D(QTextTable);
if (d->dirty)
d->update();
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *fc = p->formatCollection();
const QTextTableCell cell = cellAt(row, column);
if (!cell.isValid() || row != cell.row() || column != cell.column())
return;
QTextCharFormat fmt = cell.format();
const int rowSpan = fmt.tableCellRowSpan();
const int colSpan = fmt.tableCellColumnSpan();
numRows = qMin(numRows, rows() - cell.row());
numCols = qMin(numCols, columns() - cell.column());
// nothing to merge?
if (numRows < rowSpan || numCols < colSpan)
return;
// check the edges of the merge rect to make sure no cell spans the edge
for (int r = row; r < row + numRows; ++r) {
if (cellAt(r, column) == cellAt(r, column - 1))
return;
if (cellAt(r, column + numCols) == cellAt(r, column + numCols - 1))
return;
}
for (int c = column; c < column + numCols; ++c) {
if (cellAt(row, c) == cellAt(row - 1, c))
return;
if (cellAt(row + numRows, c) == cellAt(row + numRows - 1, c))
return;
}
p->beginEditBlock();
const int origCellPosition = cell.firstPosition() - 1;
const int cellFragment = d->grid[row * d->nCols + column];
// find the position at which to insert the contents of the merged cells
QFragmentFindHelper helper(origCellPosition, p->fragmentMap());
QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end());
Q_ASSERT(*it == cellFragment);
const int insertCellIndex = it - d->cells.begin();
int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end);
uint insertPos = p->fragmentMap().position(insertFragment);
d->blockFragmentUpdates = true;
bool rowHasText = cell.firstCursorPosition().block().length();
bool needsParagraph = rowHasText && colSpan == numCols;
// find all cells that will be erased by the merge
for (int r = row; r < row + numRows; ++r) {
int firstColumn = r < row + rowSpan ? column + colSpan : column;
// don't recompute the cell index for the first row
int firstCellIndex = r == row ? insertCellIndex + 1 : -1;
int cellIndex = firstCellIndex;
for (int c = firstColumn; c < column + numCols; ++c) {
const int fragment = d->grid[r * d->nCols + c];
// already handled?
if (fragment == cellFragment)
continue;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment);
uint pos = it.position();
if (firstCellIndex == -1) {
QFragmentFindHelper helper(pos, p->fragmentMap());
QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end());
Q_ASSERT(*it == fragment);
firstCellIndex = cellIndex = it - d->cells.begin();
}
++cellIndex;
QTextCharFormat fmt = fc->charFormat(it->format);
//.........这里部分代码省略.........