本文整理汇总了C++中qtextblock::iterator::atEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::atEnd方法的具体用法?C++ iterator::atEnd怎么用?C++ iterator::atEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtextblock::iterator
的用法示例。
在下文中一共展示了iterator::atEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replaceImageUrl
void TextDocument::replaceImageUrl(const QUrl &oldName, const QString &newName) {
QList <QPair<int, int> > fragments;
QTextBlock block = begin();
while(block.isValid()) {
QTextBlock::iterator iterator;
for(iterator = block.begin(); !(iterator.atEnd()); ++iterator) {
QTextFragment fragment = iterator.fragment();
if(fragment.isValid() && fragment.charFormat().isImageFormat()) {
QTextImageFormat format = fragment.charFormat().toImageFormat();
if (QUrl::fromEncoded(format.name().toUtf8()) != oldName) {continue;}
fragments.append(QPair<int, int>(fragment.position(), fragment.length()));
}
}
block = block.next();
}
QTextCursor cursor(this);
cursor.beginEditBlock();
QPair<int, int> pair;
foreach (pair, fragments) {
cursor.setPosition(pair.first);
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, pair.second);
QTextImageFormat format = cursor.charFormat().toImageFormat();
format.setName(newName);
cursor.mergeCharFormat(format);
}
示例2: isClickOnContact
bool ContactListEdit::isClickOnContact()
{
_right_click += QPoint(2, 0);
int current_position = this->document()->documentLayout()->hitTest( _right_click, Qt::ExactHit );
if(current_position > -1)
{
QTextBlock current_block = document()->begin();
while(current_block.isValid())
{
for(QTextBlock::iterator it = current_block.begin(); !(it.atEnd()); ++it)
{
QTextFragment current_fragment = it.fragment();
if(current_fragment.isValid())
if(current_fragment.contains(current_position))
{
QTextFormat current_format = current_fragment.charFormat();
if(current_format.isImageFormat())
{
_image_format = current_format.toImageFormat();
return true;
}
}
}
current_block = current_block.next();
}
}
return false;
}
示例3: readFragment
void XmlWriter::readFragment(const QTextBlock ¤tBlock,
QDomElement blockElement,
QDomDocument *document)
{
//! [3] //! [4]
QTextBlock::iterator it;
for (it = currentBlock.begin(); !(it.atEnd()); ++it) {
QTextFragment currentFragment = it.fragment();
if (currentFragment.isValid())
//! [3] //! [5]
processFragment(currentFragment);
//! [4] //! [5]
if (currentFragment.isValid()) {
QDomElement fragmentElement = document->createElement("fragment");
blockElement.appendChild(fragmentElement);
fragmentElement.setAttribute("length", currentFragment.length());
QDomText fragmentText = document->createTextNode(currentFragment.text());
fragmentElement.appendChild(fragmentText);
}
//! [6] //! [7]
}
//! [7] //! [6]
}
示例4: writeAutomaticStyles
void OdtWriter::writeAutomaticStyles(const QTextDocument* document)
{
m_xml.writeStartElement(QString::fromLatin1("office:automatic-styles"));
QVector<QTextFormat> formats = document->allFormats();
// Find all used styles
QVector<int> text_styles;
QVector<int> paragraph_styles;
int index = 0;
for (QTextBlock block = document->begin(); block.isValid(); block = block.next()) {
index = block.blockFormatIndex();
if (!paragraph_styles.contains(index)) {
int heading = block.blockFormat().property(QTextFormat::UserProperty).toInt();
if (!heading) {
paragraph_styles.append(index);
} else {
m_styles.insert(index, QString("Heading-%1").arg(heading));
}
}
for (QTextBlock::iterator iter = block.begin(); !(iter.atEnd()); ++iter) {
index = iter.fragment().charFormatIndex();
if (!text_styles.contains(index) && formats.at(index).propertyCount()) {
text_styles.append(index);
}
}
}
// Write text styles
int text_style = 1;
for (int i = 0; i < text_styles.size(); ++i) {
int index = text_styles.at(i);
const QTextFormat& format = formats.at(index);
QString name = QString::fromLatin1("T") + QString::number(text_style);
if (writeTextStyle(format.toCharFormat(), name)) {
m_styles.insert(index, name);
++text_style;
}
}
// Write paragraph styles
int paragraph_style = 1;
for (int i = 0; i < paragraph_styles.size(); ++i) {
int index = paragraph_styles.at(i);
const QTextFormat& format = formats.at(index);
QString name = QString::fromLatin1("P") + QString::number(paragraph_style);
if (writeParagraphStyle(format.toBlockFormat(), name)) {
m_styles.insert(index, name);
++paragraph_style;
} else {
m_styles.insert(index, "Normal");
}
}
m_xml.writeEndElement();
}
示例5: processUpdates
void ChangeFollower::processUpdates(const QList<int> &changedStyles)
{
KoStyleManager *sm = m_styleManager.data();
if (!sm) {
// since the stylemanager would be the one calling this method, I doubt this
// will ever happen. But better safe than sorry..
deleteLater();
return;
}
// optimization strategy; store the formatid of the formats we checked into
// a qset for 'hits' and 'ignores' and avoid the copying of the format
// (fragment.charFormat() / block.blockFormat()) when the formatId is
// already checked previosly
QTextCursor cursor(m_document);
QTextBlock block = cursor.block();
while (block.isValid()) {
QTextBlockFormat bf = block.blockFormat();
int id = bf.intProperty(KoParagraphStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
cursor.setPosition(block.position());
KoParagraphStyle *style = sm->paragraphStyle(id);
Q_ASSERT(style);
style->applyStyle(bf);
cursor.setBlockFormat(bf);
}
QTextCharFormat cf = block.charFormat();
id = cf.intProperty(KoCharacterStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
KoCharacterStyle *style = sm->characterStyle(id);
Q_ASSERT(style);
style->applyStyle(block);
}
QTextBlock::iterator iter = block.begin();
while (! iter.atEnd()) {
QTextFragment fragment = iter.fragment();
cf = fragment.charFormat();
id = cf.intProperty(KoCharacterStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
// create selection
cursor.setPosition(fragment.position());
cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
KoCharacterStyle *style = sm->characterStyle(id);
Q_ASSERT(style);
style->applyStyle(cf);
cursor.mergeCharFormat(cf);
}
iter++;
}
block = block.next();
}
}
示例6: selectAndMarkAnchor
void MoveViewController::selectAndMarkAnchor(const QString& link)
{
QTextBlock block = this->document->begin();
while(block != this->document->end())
{
QTextBlock::iterator it;
for(it = block.begin(); !it.atEnd(); ++it)
{
QTextFragment fragment = it.fragment();
if(!fragment.isValid())
{
continue;
}
QTextCharFormat format = fragment.charFormat();
if(format.isAnchor() && format.anchorHref() == link)
{
QTextCursor cursor = this->textCursor();
cursor.setPosition(fragment.position());
int len = 0;
bool finished = false;
// we want to mark (highlight) everything from the
// start of the anchor until the end of the move
// the end of the move is indicated by an empty space
// (there is always an empty space after a move)
while(!finished && !it.atEnd()) {
if(it.fragment().text().startsWith(" ") || len >= 6) {
finished = true;
} else {
len+= it.fragment().text().length();
it++;
}
}
cursor.setPosition(fragment.position() + len, QTextCursor::KeepAnchor);
setTextCursor(cursor);
ensureCursorVisible();
return;
}
}
block = block.next();
}
}
示例7: getFragmentUnderMouse
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
{
QTextCursor cursor(cursorForPosition(pos));
QTextBlock block(cursor.block());
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
QTextFragment frag = it.fragment();
if (frag.contains(cursor.position()))
return frag;
}
return QTextFragment();
}
示例8: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextEdit *editor = new QTextEdit;
QTextDocument *document = new QTextDocument(editor);
QTextCursor cursor(document);
QTextImageFormat imageFormat;
imageFormat.setName(":/images/advert.png");
cursor.insertImage(imageFormat);
QTextBlock block = cursor.block();
QTextFragment fragment;
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
fragment = it.fragment();
if (fragment.contains(cursor.position()))
break;
}
//! [0]
if (fragment.isValid()) {
QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();
if (newImageFormat.isValid()) {
newImageFormat.setName(":/images/newimage.png");
QTextCursor helper = cursor;
helper.setPosition(fragment.position());
helper.setPosition(fragment.position() + fragment.length(),
QTextCursor::KeepAnchor);
helper.setCharFormat(newImageFormat);
//! [0] //! [1]
}
//! [1] //! [2]
}
//! [2]
cursor.insertBlock();
cursor.insertText("Code less. Create more.");
editor->setDocument(document);
editor->setWindowTitle(tr("Text Document Image Format"));
editor->resize(320, 480);
editor->show();
return app.exec();
}
示例9: fileNameFromDiffSpecification
QString MercurialEditor::fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const
{
const QString filechangeId(QLatin1String("+++ b/"));
QTextBlock::iterator iterator;
for (iterator = diffFileSpec.begin(); !(iterator.atEnd()); iterator++) {
QTextFragment fragment = iterator.fragment();
if(fragment.isValid()) {
if (fragment.text().startsWith(filechangeId)) {
const QString filename = fragment.text().remove(0, filechangeId.size());
return findDiffFile(filename, MercurialPlugin::instance()->versionControl());
}
}
}
return QString();
}
示例10: setHtml
/*!
Replaces the entire contents of the document
with the given HTML-formatted text in the \a text string
*/
void RichString::setHtml(const QString &text)
{
QTextDocument doc;
doc.setHtml(text);
QTextBlock block = doc.firstBlock();
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
QTextFragment textFragment = it.fragment();
if (textFragment.isValid()) {
Format fmt;
fmt.setFont(textFragment.charFormat().font());
fmt.setFontColor(textFragment.charFormat().foreground().color());
addFragment(textFragment.text(), fmt);
}
}
}
示例11: getListOfImageNames
QStringList ContactListEdit::getListOfImageNames() const
{
QStringList image_names;
QTextBlock block = document()->begin();
while (block.isValid())
{
for (QTextBlock::iterator i = block.begin(); !i.atEnd(); ++i)
{
QTextCharFormat format = i.fragment().charFormat();
bool isImage = format.isImageFormat();
if (isImage)
image_names << format.toImageFormat().name();
}
block = block.next();
}
return image_names;
}
示例12: textFragmentAt
QTextDocumentFragment SimpleMessageStyle::textFragmentAt(QWidget *AWidget, const QPoint &APosition) const
{
StyleViewer *view = qobject_cast<StyleViewer *>(AWidget);
if (view)
{
QTextCursor cursor = view->cursorForPosition(APosition);
for (QTextBlock::iterator it = cursor.block().begin(); !it.atEnd(); ++it)
{
if (it.fragment().contains(cursor.position()))
{
cursor.setPosition(it.fragment().position());
cursor.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor,it.fragment().length());
return cursor.selection();
}
}
}
return QTextDocumentFragment();
}
示例13: validateClickPosition
bool ContactListEdit::validateClickPosition(const QPoint& position, bool* isExistingContact,
bts::addressbook::wallet_contact* foundContact) const
{
assert(isExistingContact != nullptr);
assert(foundContact != nullptr);
*isExistingContact = false;
QPoint shiftedPos(position);
shiftedPos += QPoint(2, 0);
int current_position = document()->documentLayout()->hitTest(shiftedPos, Qt::ExactHit);
if(current_position > -1)
{
QTextBlock current_block = document()->begin();
while(current_block.isValid())
{
for(QTextBlock::iterator it = current_block.begin(); !(it.atEnd()); ++it)
{
QTextFragment current_fragment = it.fragment();
if(current_fragment.isValid() && current_fragment.contains(current_position))
{
QTextFormat current_format = current_fragment.charFormat();
if(current_format.isImageFormat())
{
QTextImageFormat imageFormat = current_format.toImageFormat();
IMailProcessor::TRecipientPublicKey pk;
decodePublicKey(imageFormat, &pk);
*isExistingContact = Utils::matchContact(pk, foundContact);
return true;
}
}
}
current_block = current_block.next();
}
}
return false;
}
示例14: processBlockContent
QString TextDocumentSerializer::processBlockContent(QTextBlock block)
{
QTextBlock::iterator it = block.begin();
QString text;
while(!it.atEnd()){
QTextFragment currentFragment = it.fragment();
if (currentFragment.isValid())
text += processFragment(currentFragment);
++it;
}
if(block.textList())
return QString("<li>%1</li>").arg(text);
else
return QString("%1<br>").arg(text);
}
示例15: parse
FormattedMessage FormattedMessage::parse(const QTextDocument *document)
{
FormattedMessage result;
QString text;
QTextBlock block = document->firstBlock();
bool firstParagraph = true;
while (block.isValid())
{
bool firstFragment = true;
for (QTextBlock::iterator it = block.begin(); !it.atEnd(); ++it)
{
QTextFragment fragment = it.fragment();
if (!fragment.isValid())
continue;
if (!firstParagraph && firstFragment)
text = '\n' + fragment.text();
else
text = fragment.text();
QTextCharFormat format = fragment.charFormat();
parseImages(result, text,
format.font().bold(),
format.font().italic(),
format.font().underline(),
format.foreground().color());
firstFragment = false;
}
if (firstFragment)
parseImages(result, "\n", false, false, false, QColor());
block = block.next();
firstParagraph = false;
}
return result;
}