本文整理汇总了C++中QTextDocument::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::clear方法的具体用法?C++ QTextDocument::clear怎么用?C++ QTextDocument::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewScriptFile
/*!
* Creates a new empty script.
*
* Before creates the new scripts, it verifies if the current script can be closed.
*/
void CodeEditorWidget::NewScriptFile()
{
if( !OkToContinue() ) return;
QTextDocument* document = codeEditor->document();
document->clear();
m_currentScritFileName = "";
emit FileOpened( QString( "" ) );
document->setModified( false );
}
示例2: refresh
void TextEmojiWrapper::refresh()
{
if(!p->document)
return;
if(!p->emojis)
return;
QTextDocument *document = p->document->textDocument();
document->clear();
QTextCursor cursor(document);
cursor.setPosition(0);
QString &text = p->text;
const QHash<QString,QString> &emojis = p->emojis->emojis();
for( int i=0; i<text.size(); i++ )
{
QString image;
for( int j=1; j<5; j++ )
{
QString emoji = text.mid(i,j);
if( !emojis.contains(emoji) )
continue;
image = emojis.value(emoji);
i += emoji.size()-1;
break;
}
if(image.isEmpty())
{
cursor.insertText(QString(text[i]));
}
else
{
QTextImageFormat format;
format.setName(AsemanDevices::localFilesPrePath()+image);
format.setHeight(18);
format.setWidth(18);
cursor.insertImage(format);
}
}
}
示例3: StartDocument
/*!
* Sets the code editor's contents to \a fileName contents and sets the currents file to \a fileName.
*/
void CodeEditorWidget::StartDocument( QString fileName )
{
QFile scriptFile( fileName );
if( !scriptFile.open( QIODevice::ReadOnly) )
{
QMessageBox::warning( this, tr( "Tonatiuh warning" ),
tr( "Cannot open file %1." )
.arg( fileName ) );
return;
}
QTextStream in( &scriptFile );
QTextDocument* document = codeEditor->document();
document->clear();
document->setPlainText( in.readAll() );
scriptFile.close();
m_currentScritFileName = fileName;
emit FileOpened( fileName );
document->setModified( false );
}
示例4: testUnapplyStyle
void TestStyles::testUnapplyStyle()
{
// Used to test OverlineColor style
QColor testOverlineColor(255, 128, 64);
KoCharacterStyle::LineWeight testOverlineWeight = KoCharacterStyle::ThickLineWeight;
qreal testOverlineWidth = 1.5;
// in this test we should avoid testing any of the hardcodedDefaultProperties; see KoCharacterStyle for details!
KoParagraphStyle headers;
headers.setOverlineColor(testOverlineColor);
headers.setOverlineMode(KoCharacterStyle::ContinuousLineMode);
headers.setOverlineStyle(KoCharacterStyle::DottedLine);
headers.setOverlineType(KoCharacterStyle::DoubleLine);
headers.setOverlineWidth(testOverlineWeight, testOverlineWidth);
headers.setFontWeight(QFont::Bold);
headers.setAlignment(Qt::AlignCenter);
KoParagraphStyle head1;
head1.setParentStyle(&headers);
head1.setLeftMargin(QTextLength(QTextLength::FixedLength, 40));
QTextDocument doc;
doc.setPlainText("abc");
QTextBlock block = doc.begin();
head1.applyStyle(block);
QTextCursor cursor(block);
QTextBlockFormat bf = cursor.blockFormat();
KoParagraphStyle bfStyle (bf, cursor.charFormat());
QCOMPARE(bf.alignment(), Qt::AlignCenter);
QCOMPARE(bfStyle.leftMargin(), 40.);
QTextCharFormat cf = cursor.charFormat();
QCOMPARE(cf.colorProperty(KoCharacterStyle::OverlineColor), testOverlineColor);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineMode), (int) KoCharacterStyle::ContinuousLineMode);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineStyle), (int) KoCharacterStyle::DottedLine);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineType), (int) KoCharacterStyle::DoubleLine);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineWeight), (int) testOverlineWeight);
QCOMPARE(cf.doubleProperty(KoCharacterStyle::OverlineWidth), testOverlineWidth);
head1.unapplyStyle(block);
bf = cursor.blockFormat();
QCOMPARE(bf.hasProperty(QTextFormat::BlockAlignment), false);
QCOMPARE(bf.hasProperty(QTextFormat::BlockLeftMargin), false);
cf = cursor.charFormat();
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false);
doc.clear();
block = doc.begin();
head1.applyStyle(block);
bf = cursor.blockFormat();
KoParagraphStyle bfStyle2 (bf, cursor.charFormat());
QCOMPARE(bf.alignment(), Qt::AlignCenter);
QCOMPARE(bfStyle2.leftMargin(), 40.);
cf = cursor.charFormat();
//QCOMPARE(cf.fontOverline(), true);
QCOMPARE(cf.colorProperty(KoCharacterStyle::OverlineColor), testOverlineColor);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineMode), (int) KoCharacterStyle::ContinuousLineMode);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineStyle), (int) KoCharacterStyle::DottedLine);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineType), (int) KoCharacterStyle::DoubleLine);
QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineWeight), (int) testOverlineWeight);
QCOMPARE(cf.doubleProperty(KoCharacterStyle::OverlineWidth), testOverlineWidth);
head1.unapplyStyle(block);
bf = cursor.blockFormat();
QCOMPARE(bf.hasProperty(QTextFormat::BlockAlignment), false);
QCOMPARE(bf.hasProperty(QTextFormat::BlockLeftMargin), false);
cf = cursor.charFormat();
//QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false);
doc.setHtml("bla bla<i>italic</i>enzo");
block = doc.begin();
head1.applyStyle(block);
bf = cursor.blockFormat();
KoParagraphStyle bfStyle3(bf, cursor.charFormat());
QCOMPARE(bf.alignment(), Qt::AlignCenter);
QCOMPARE(bfStyle3.leftMargin(), 40.);
cf = cursor.charFormat();
//QCOMPARE(cf.fontOverline(), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), true);
QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), true);
cursor.setPosition(7);
cursor.setPosition(12, QTextCursor::KeepAnchor);
QTextCharFormat italic;
italic.setFontItalic(true);
cursor.mergeCharFormat(italic);
cursor.setPosition(8);
cf = cursor.charFormat();
QCOMPARE(cf.fontItalic(), true);
cursor.setPosition(0);
//.........这里部分代码省略.........
示例5: read
void QGithubMarkdown::read(const QByteArray &markdown, QTextDocument *target)
{
doc = target;
doc->clear();
cursor = QTextCursor(doc);
cursor.beginEditBlock();
const QList<Token> tokens = tokenize(clean(QString::fromUtf8(markdown)));
const QList<Paragraph> paragraphs = paragraphize(tokens);
const auto paralists = listize(paragraphs);
//std::for_each(paragraphs.begin(), paragraphs.end(), [](const Paragraph &item){qDebug() << item;});
bool firstBlock = true;
for (const auto paralist : paralists)
{
auto insertTokens = [&](const QList<Token> &tokens, const QTextCharFormat &format, const bool isCode)
{
QTextCharFormat fmt(format);
QTextCharFormat codeFmt(format);
codeFmt.setFontFamily("Monospace");
QListIterator<Token> iterator(tokens);
while (iterator.hasNext())
{
const Token token = iterator.next();
if (isCode)
{
cursor.insertText(token.source);
}
else
{
if (token.type == Token::Bold)
{
if (fmt.fontWeight() == QFont::Bold)
{
fmt.setFontWeight(QFont::Normal);
}
else
{
fmt.setFontWeight(QFont::Bold);
}
}
else if (token.type == Token::Italic)
{
fmt.setFontItalic(!fmt.fontItalic());
}
else if (token.type == Token::InlineCodeDelimiter)
{
while (iterator.hasNext())
{
const Token next = iterator.next();
if (next.type == Token::InlineCodeDelimiter)
{
break;
}
else
{
cursor.insertText(token.source, codeFmt);
}
}
}
else if (token.type == Token::Character)
{
cursor.insertText(token.content.toChar(), fmt);
}
else
{
cursor.insertText(token.source, fmt);
}
}
}
};
if (paralist.second.indent == -1)
{
const Paragraph paragraph = paralist.first;
QTextCharFormat charFmt;
QTextBlockFormat blockFmt;
blockFmt.setBottomMargin(5.0f);
if (Paragraph::FirstHeading <= paragraph.type && paragraph.type <= Paragraph::LastHeading)
{
charFmt.setFontPointSize(sizeMap[paragraph.type]);
}
else if (paragraph.type == Paragraph::Quote)
{
blockFmt.setIndent(1);
}
else if (paragraph.type == Paragraph::Code)
{
blockFmt.setNonBreakableLines(true);
charFmt.setFontFamily("Monospace");
}
if (!firstBlock)
{
cursor.insertBlock();
}
else
{
firstBlock = false;
}
cursor.setBlockFormat(blockFmt);
cursor.block().setUserState(paragraph.type);
//.........这里部分代码省略.........
示例6: on_actionBuild_triggered
void InsitucCADMainWindow::on_actionBuild_triggered()
{
if (!program_) {
std::cerr << "Empty AST." << std::endl;
QMessageBox::critical(this, "Failure!", "AST is empty.");
return;
}
if (!assembler_.clear()) {
std::cerr << "Can't clear the assembler istance" << std::endl;
QMessageBox::critical(this, "Failure!", "Can't clear the assembler istance");
return;
}
{
int size = treeModelTranfsormations->wrts.size();
for (int i = 0; i < size; ++i) {
QPair< QString, QString > const & globalVariable = treeModelTranfsormations->wrts.at(i);
Q_ASSERT(!globalVariable.first.isEmpty());
meta::symbol_type const name_{{globalVariable.first.toStdString()}, {}, {}};
auto const print_err = [&]
{
std::string const s = oss_.str();
std::cerr << s << std::endl;
QMessageBox::critical(this, "Failure!", QString::fromStdString(s));
oss_.clear();
oss_.str("");
};
if (assembler_.is_global_variable(name_)) {
oss_ << "Global variable with name \"" << name_ << "\" at line " << i << " is already defined";
return print_err();
}
if (assembler_.is_reserved_symbol(name_)) {
oss_ << "Name \"" << name_ << "\" at line " << i << " intended for global variable is reserved symbol";
return print_err();
}
if (assembler_.is_dummy_placeholder(name_)) {
oss_ << "Name \"" << name_ << "\" at line " << i << " intended for global variable is dummy placeholder";
return print_err();
}
if (assembler_.is_function(name_)) {
oss_ << "Name \"" << name_ << "\" at line " << i << " intended for global variable already used as function name";
return print_err();
}
if (globalVariable.second.isEmpty()) {
assembler_.add_global_variable(name_);
std::cout << "Added variable \"" << name_ << "\" without initial value" << std::endl;
} else {
string_type const value_string_ = globalVariable.second.toStdString();
auto value_ = parser::parse_real_number(std::cbegin(value_string_), std::cend(value_string_));
if (!value_) {
oss_ << "String \"" << value_string_ << "\" at line " << i << " is not valid global variable value representation";
return print_err();
}
assembler_.add_global_variable(name_, value_.value());
std::cout << "Variable \"" << name_ << "\" with initial value " << value_.value() << " have been added" << std::endl;
}
}
}
if (!compiler_(*program_)) {
std::cerr << "Can't compile AST:" << std::endl
<< "//< begin" << std::endl
<< *program_ << std::endl
<< "//< end" << std::endl;
QMessageBox::critical(this, "Failure!", "Can't compile AST.");
return;
}
{
oss_ << assembler_;
QTextDocument * document = ui->textEditAssembly->document();
document->clear();
QTextCursor cursor = setTextTermFormatting(document, QString::fromStdString(oss_.str()));
cursor.movePosition(QTextCursor::Start);
ui->textEditAssembly->setTextCursor(cursor);
oss_.clear();
oss_.str("");
}
tableModelGlobalVariablesValues->populateWithData(treeModelTranfsormations->wrts);
QMessageBox::information(this, "Success!", "AST successfully compiled.");
}
示例7: palette
XmlConsole::XmlConsole(Client* client, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::XmlConsole),
m_client(client), m_filter(0x1f)
{
m_ui->setupUi(this);
m_client->addXmlStreamHandler(this);
QPalette pal = palette();
pal.setColor(QPalette::Base, Qt::black);
pal.setColor(QPalette::Text, Qt::white);
m_ui->xmlBrowser->viewport()->setPalette(pal);
QTextDocument *doc = m_ui->xmlBrowser->document();
doc->setDocumentLayout(new QPlainTextDocumentLayout(doc));
doc->clear();
QTextFrameFormat format = doc->rootFrame()->frameFormat();
format.setBackground(QColor(Qt::black));
format.setMargin(0);
doc->rootFrame()->setFrameFormat(format);
QMenu *menu = new QMenu(m_ui->filterButton);
menu->setSeparatorsCollapsible(false);
menu->addSeparator()->setText(tr("Filter"));
QActionGroup *group = new QActionGroup(menu);
QAction *disabled = group->addAction(menu->addAction(tr("Disabled")));
disabled->setCheckable(true);
disabled->setData(Disabled);
QAction *jid = group->addAction(menu->addAction(tr("By JID")));
jid->setCheckable(true);
jid->setData(ByJid);
QAction *xmlns = group->addAction(menu->addAction(tr("By namespace uri")));
xmlns->setCheckable(true);
xmlns->setData(ByXmlns);
QAction *attrb = group->addAction(menu->addAction(tr("By all attributes")));
attrb->setCheckable(true);
attrb->setData(ByAllAttributes);
disabled->setChecked(true);
connect(group, SIGNAL(triggered(QAction*)), this, SLOT(onActionGroupTriggered(QAction*)));
menu->addSeparator()->setText(tr("Visible stanzas"));
group = new QActionGroup(menu);
group->setExclusive(false);
QAction *iq = group->addAction(menu->addAction(tr("Information query")));
iq->setCheckable(true);
iq->setData(XmlNode::Iq);
iq->setChecked(true);
QAction *message = group->addAction(menu->addAction(tr("Message")));
message->setCheckable(true);
message->setData(XmlNode::Message);
message->setChecked(true);
QAction *presence = group->addAction(menu->addAction(tr("Presence")));
presence->setCheckable(true);
presence->setData(XmlNode::Presence);
presence->setChecked(true);
QAction *custom = group->addAction(menu->addAction(tr("Custom")));
custom->setCheckable(true);
custom->setData(XmlNode::Custom);
custom->setChecked(true);
connect(group, SIGNAL(triggered(QAction*)), this, SLOT(onActionGroupTriggered(QAction*)));
m_ui->filterButton->setMenu(menu);
m_stackBracketsColor = QColor(0x666666);
m_stackIncoming.bodyColor = QColor(0xbb66bb);
m_stackIncoming.tagColor = QColor(0x006666);
m_stackIncoming.attributeColor = QColor(0x009933);
m_stackIncoming.paramColor = QColor(0xcc0000);
m_stackOutgoing.bodyColor = QColor(0x999999);
m_stackOutgoing.tagColor = QColor(0x22aa22);
m_stackOutgoing.attributeColor = QColor(0xffff33);
m_stackOutgoing.paramColor = QColor(0xdd8811);
QAction *action = new QAction(tr("Close"),this);
action->setSoftKeyRole(QAction::NegativeSoftKey);
connect(action, SIGNAL(triggered()), SLOT(close()));
addAction(action);
}
示例8: on_dateTreeWidget_currentItemChanged
void HistoryWindow::on_dateTreeWidget_currentItemChanged(QTreeWidgetItem *dayItem, QTreeWidgetItem *)
{
QTreeWidgetItem *monthItem = dayItem ? dayItem->parent() : nullptr;
if (!dayItem || !monthItem)
return;
if (dayItem->data(0, Qt::UserRole).type() != QVariant::Date)
return;
if (monthItem->data(0, Qt::UserRole).type() != QVariant::Date)
return;
auto contactIndex = ui.fromComboBox->currentIndex();
auto contactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
auto date = dayItem->data(0, Qt::UserRole).toDate();
QDateTime from(date, QTime(0, 0));
QDateTime to(date, QTime(23, 59, 59, 999));
int count = std::numeric_limits<int>::max();
history()->read(contactInfo, from, to, count).connect(this, [this, contactInfo, date] (const MessageList &messages) {
int contactIndex = ui.fromComboBox->currentIndex();
auto currentContactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
if (!(currentContactInfo == contactInfo))
return;
QTextDocument *doc = ui.historyLog->document();
doc->setParent(0);
ui.historyLog->setDocument(0);
doc->clear();
QTextCursor cursor = QTextCursor(doc);
QTextCharFormat defaultFont = cursor.charFormat();
QTextCharFormat serviceFont = cursor.charFormat();
serviceFont.setForeground(Qt::darkGreen);
serviceFont.setFontWeight(QFont::Bold);
QTextCharFormat incomingFont = cursor.charFormat();
incomingFont.setForeground(Qt::red);
incomingFont.setFontWeight(QFont::Bold);
QTextCharFormat outgoingFont = cursor.charFormat();
outgoingFont.setForeground(Qt::blue);
outgoingFont.setFontWeight(QFont::Bold);
const QString serviceMessageTitle = tr("Service message");
const QString resultString = QStringLiteral("<span style='background: #ffff00'>\\1</span>");
cursor.beginEditBlock();
Account *account = findAccount(contactInfo);
ChatUnit *unit = findContact(contactInfo);
QString accountNickname = account ? account->name() : contactInfo.account;
QString fromNickname = unit ? unit->title() : contactInfo.contact;
int in_count = 0;
int out_count = 0;
for (const Message &message : messages) {
bool service = message.property("service", false);
QDateTime time = message.time();
bool incoming = message.isIncoming();
QString historyMessage = message.html();
QString sender = message.property("senderName", incoming ? fromNickname : accountNickname);
incoming ? in_count++ : out_count++;
if (service) {
cursor.setCharFormat(serviceFont);
cursor.insertText(serviceMessageTitle);
} else {
cursor.setCharFormat(incoming ? incomingFont : outgoingFont);
cursor.insertText(sender);
}
cursor.insertText(QStringLiteral(" (")
% time.toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"))
% QStringLiteral(")"));
cursor.setCharFormat(defaultFont);
cursor.insertText(QStringLiteral("\n"));
if (m_search_word.isEmpty()) {
cursor.insertHtml(historyMessage);
cursor.insertText(QStringLiteral("\n"));
} else {
cursor.insertHtml(historyMessage.replace(m_search, resultString));
cursor.insertText(QStringLiteral("\n"));
}
}
cursor.endEditBlock();
doc->setParent(ui.historyLog);
ui.historyLog->setDocument(doc);
if (m_search_word.isEmpty())
ui.historyLog->moveCursor(QTextCursor::End);
else
ui.historyLog->find(m_search_word);
ui.historyLog->verticalScrollBar()->setValue(ui.historyLog->verticalScrollBar()->maximum());
ui.label_in->setText(tr("In: %L1").arg(in_count));
ui.label_out->setText(tr("Out: %L1").arg(out_count));
ui.label_all->setText(tr("All: %L1").arg(in_count + out_count));
});
}
示例9: clear
void QTextDocumentProto::clear()
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
item->clear();
}