本文整理汇总了C++中DocIterator类的典型用法代码示例。如果您正苦于以下问题:C++ DocIterator类的具体用法?C++ DocIterator怎么用?C++ DocIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addToToc
void InsetText::addToToc(DocIterator const & cdit, bool output_active,
UpdateType utype, TocBackend & backend) const
{
DocIterator dit = cdit;
dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
iterateForToc(dit, output_active, utype, backend);
}
示例2: isCurrentBuffer
bool SpellcheckerWidget::Private::atLastPos(DocIterator const & cursor) const
{
bool const valid_end = !end_.empty();
return cursor.depth() <= 1 && (
cursor.atEnd() ||
(valid_end && isCurrentBuffer(cursor) && cursor >= end_));
}
示例3: theFontMetrics
void RowPainter::paintMisspelledMark(Row::Element const & e) const
{
if (e.font.fontInfo().nospellcheck() == FONT_ON)
return;
// if changed the misspelled marker gets placed slightly lower than normal
// to avoid drawing at the same vertical offset
FontMetrics const & fm = theFontMetrics(e.font);
int const thickness = max(fm.lineWidth(), 2);
int const y = yo_ + pi_.base.solidLineOffset() + pi_.base.solidLineThickness()
+ (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
+ 1 + thickness / 2;
//FIXME: this could be computed only once, it is probably not costly.
// check for cursor position
// don't draw misspelled marker for words at cursor position
// we don't want to disturb the process of text editing
DocIterator const nw = pi_.base.bv->cursor().newWord();
pos_type cpos = -1;
if (!nw.empty() && par_.id() == nw.paragraph().id()) {
cpos = nw.pos();
if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
--cpos;
else if (cpos > 0 && par_.isWordSeparator(cpos))
--cpos;
}
pos_type pos = e.pos;
while (pos < e.pos + pos_type(e.str.length())) {
if (!par_.isMisspelled(pos)) {
++pos;
continue;
}
FontSpan const & range = par_.getSpellRange(pos);
// Skip element which are being edited
if (range.contains(cpos)) {
// the range includes the last element
pos = range.last + 1;
continue;
}
int x1 = fm.pos2x(e.str, range.first - e.pos,
e.isRTL(), e.extra);
int x2 = fm.pos2x(e.str, min(range.last - e.pos + 1,
pos_type(e.str.length())),
e.isRTL(), e.extra);
if (x1 > x2)
swap(x1, x2);
pi_.pain.line(int(x_ + x1), y, int(x_ + x2), y,
Color_error,
Painter::line_onoffdash, thickness);
pos = range.last + 1;
}
}
示例4: preparePreview
void InsetPreview::preparePreview(DocIterator const & pos) const
{
TexRow texrow;
odocstringstream str;
otexstream os(str, texrow);
OutputParams runparams(&pos.buffer()->params().encoding());
latex(os, runparams);
docstring const snippet = str.str();
preview_->addPreview(snippet, *pos.buffer());
}
示例5: setSelectionAndMargins
void Row::setSelectionAndMargins(DocIterator const & beg,
DocIterator const & end) const
{
setSelection(beg.pos(), end.pos());
if (selection()) {
end_margin_sel = isMarginSelected(false, beg, end);
begin_margin_sel = isMarginSelected(true, beg, end);
}
}
示例6: updateData
void MacroData::expand(vector<MathData> const & args, MathData & to) const
{
updateData();
// Hack. Any inset with a cell would do.
static InsetMathSqrt inset(0);
inset.setBuffer(const_cast<Buffer &>(*buffer_));
// FIXME UNICODE
asArray(display_.empty() ? definition_ : display_, inset.cell(0));
//lyxerr << "MathData::expand: args: " << args << endl;
//lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl;
for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) {
if (!it.nextInset())
continue;
if (it.nextInset()->lyxCode() != MATH_MACROARG_CODE)
continue;
//it.cell().erase(it.pos());
//it.cell().insert(it.pos(), it.nextInset()->asInsetMath()
size_t n = static_cast<MathMacroArgument*>(it.nextInset())->number();
if (n <= args.size()) {
it.cell().erase(it.pos());
it.cell().insert(it.pos(), args[n - 1]);
}
}
//lyxerr << "MathData::expand: res: " << inset.cell(0) << endl;
to = inset.cell(0);
}
示例7: addToToc
void InsetBranch::addToToc(DocIterator const & cpit) const
{
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
Toc & toc = buffer().tocBackend().toc("branch");
docstring str = params_.branch + ": ";
text().forToc(str, TOC_ENTRY_LENGTH);
toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
// Proceed with the rest of the inset.
InsetCollapsable::addToToc(cpit);
}
示例8: LYXERR
void GuiSpellchecker::check()
{
LYXERR(Debug::GUI, "Check the spelling of a word");
DocIterator from = bufferview()->cursor();
DocIterator to;
WordLangTuple word_lang;
docstring_list suggestions;
int progress;
try {
progress = buffer().spellCheck(from, to, word_lang, suggestions);
} catch (ExceptionMessage const & message) {
if (message.type_ == WarningException) {
Alert::warning(message.title_, message.details_);
close();
return;
}
throw message;
}
LYXERR(Debug::GUI, "Found word \"" << word_lang.word() << "\"");
d->count_ += progress;
d->progress_ += progress;
// end of document
if (from == doc_iterator_end(&buffer())) {
showSummary();
return;
}
if (!isVisible())
show();
d->word_ = word_lang;
int const progress_bar = d->total_
? int(100.0 * float(d->progress_)/d->total_) : 100;
LYXERR(Debug::GUI, "Updating spell progress.");
// set progress bar
d->ui.spellcheckPR->setValue(progress_bar);
// set suggestions
updateSuggestions(suggestions);
// set language
int const pos = d->ui.languageCO->findData(toqstr(word_lang.lang()->lang()));
if (pos != -1)
d->ui.languageCO->setCurrentIndex(pos);
// FIXME: if we used a lfun like in find/replace, dispatch would do
// that for us
int const size = to.pos() - from.pos();
BufferView * bv = const_cast<BufferView *>(bufferview());
bv->putSelectionAt(from, size, false);
}
示例9: iterateForToc
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) const
{
DocIterator dit = cdit;
Toc & toc = buffer().tocBackend().toc("tableofcontents");
BufferParams const & bufparams = buffer_->params();
int const min_toclevel = bufparams.documentClass().min_toclevel();
// we really should have done this before we got here, but it
// can't hurt too much to do it again
bool const doing_output = output_active && producesOutput();
// For each paragraph, traverse its insets and let them add
// their toc items
ParagraphList const & pars = paragraphs();
pit_type pend = paragraphs().size();
for (pit_type pit = 0; pit != pend; ++pit) {
Paragraph const & par = pars[pit];
dit.pit() = pit;
// if we find an optarg, we'll save it for use later.
InsetText const * arginset = 0;
InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
dit.pos() = it->pos;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
inset.addToToc(dit, doing_output);
if (inset.lyxCode() == ARG_CODE)
arginset = inset.asInsetText();
}
// now the toc entry for the paragraph
int const toclevel = text().getTocLevel(pit);
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
// insert this into the table of contents
docstring tocstring;
int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
if (arginset) {
tocstring = par.labelString();
if (!tocstring.empty())
tocstring += ' ';
arginset->text().forToc(tocstring, length);
} else
par.forToc(tocstring, length);
dit.pos() = 0;
toc.push_back(TocItem(dit, toclevel - min_toclevel,
tocstring, doing_output, tocstring));
}
// And now the list of changes.
par.addChangesToToc(dit, buffer(), doing_output);
}
}
示例10: addToToc
void InsetNote::addToToc(DocIterator const & cpit) const
{
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
Toc & toc = buffer().tocBackend().toc("note");
InsetLayout const & il = getLayout();
docstring str = translateIfPossible(il.labelstring()) + from_ascii(": ");
text().forToc(str, TOC_ENTRY_LENGTH);
toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
// Proceed with the rest of the inset.
InsetCollapsable::addToToc(cpit);
}
示例11: isMarginSelected
bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
DocIterator const & end) const
{
pos_type const sel_pos = left_margin ? sel_beg : sel_end;
pos_type const margin_pos = left_margin ? pos_ : end_;
// Is the chosen margin selected ?
if (sel_pos == margin_pos) {
if (beg.pos() == end.pos())
// This is a special case in which the space between after
// pos i-1 and before pos i is selected, i.e. the margins
// (see DocIterator::boundary_).
return beg.boundary() && !end.boundary();
else if (end.pos() == margin_pos)
// If the selection ends around the margin, it is only
// drawn if the cursor is after the margin.
return !end.boundary();
else if (beg.pos() == margin_pos)
// If the selection begins around the margin, it is
// only drawn if the cursor is before the margin.
return beg.boundary();
else
return true;
}
return false;
}
示例12: addToToc
void InsetText::addToToc(DocIterator const & cdit) const
{
DocIterator dit = cdit;
dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
Toc & toc = buffer().tocBackend().toc("tableofcontents");
BufferParams const & bufparams = buffer_->params();
int const min_toclevel = bufparams.documentClass().min_toclevel();
// For each paragraph, traverse its insets and let them add
// their toc items
ParagraphList const & pars = paragraphs();
pit_type pend = paragraphs().size();
for (pit_type pit = 0; pit != pend; ++pit) {
Paragraph const & par = pars[pit];
dit.pit() = pit;
// if we find an optarg, we'll save it for use later.
InsetText const * arginset = 0;
InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
dit.pos() = it->pos;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
inset.addToToc(dit);
if (inset.lyxCode() == ARG_CODE)
arginset = inset.asInsetText();
}
// now the toc entry for the paragraph
int const toclevel = par.layout().toclevel;
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
// insert this into the table of contents
docstring tocstring;
if (arginset) {
tocstring = par.labelString();
if (!tocstring.empty())
tocstring += ' ';
arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH);
} else
par.forToc(tocstring, TOC_ENTRY_LENGTH);
dit.pos() = 0;
toc.push_back(TocItem(dit, toclevel - min_toclevel,
tocstring, tocstring));
}
// And now the list of changes.
par.addChangesToToc(dit, buffer());
}
}
示例13: onFileChanged
void DocumentManager::onFileChanged( const QString & path )
{
DocIterator it;
for( it = mDocHash.begin(); it != mDocHash.end(); ++it )
{
Document *doc = it.value();
if (doc->mFilePath == path) {
QFileInfo info(doc->mFilePath);
if (doc->mSaveTime < info.lastModified()) {
doc->mDoc->setModified(true);
emit changedExternally(doc);
}
}
}
}
示例14: info
void DocumentManager::open( const QString & path, int initialCursorPosition, bool toRecent )
{
QFileInfo info(path);
QString cpath = info.canonicalFilePath();
info.setFile(cpath);
if (cpath.isEmpty()) {
qWarning() << "DocumentManager: Can not open file: canonical path is empty.";
return;
}
// Check if file already opened
DocIterator it;
for( it = mDocHash.begin(); it != mDocHash.end(); ++it )
{
Document *doc = it.value();
if(doc->mFilePath == cpath) {
Q_EMIT( showRequest(doc, initialCursorPosition) );
if (toRecent) addToRecent(doc);
return;
}
}
// Open the file
QFile file(cpath);
if(!file.open(QIODevice::ReadOnly)) {
qWarning() << "DocumentManager: the file" << cpath << "could not be opened for reading.";
return;
}
QByteArray bytes( file.readAll() );
file.close();
Document *doc = new Document();
doc->mDoc->setPlainText( QString::fromUtf8( bytes.data(), bytes.size() ) );
doc->mDoc->setModified(false);
doc->mFilePath = cpath;
doc->mTitle = info.fileName();
mDocHash.insert( doc->id(), doc );
mFsWatcher.addPath(cpath);
Q_EMIT( opened(doc, initialCursorPosition) );
if (toRecent) this->addToRecent(doc);
}
示例15: addToToc
void InsetCaption::addToToc(DocIterator const & cpit, bool output_active) const
{
if (floattype_.empty())
return;
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetCaption &>(*this)));
Toc & toc = buffer().tocBackend().toc(floattype_);
docstring str = full_label_;
int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
text().forToc(str, length);
toc.push_back(TocItem(pit, 0, str, output_active));
// Proceed with the rest of the inset.
InsetText::addToToc(cpit, output_active);
}