本文整理汇总了C++中ktexteditor::Range::onSingleLine方法的典型用法代码示例。如果您正苦于以下问题:C++ Range::onSingleLine方法的具体用法?C++ Range::onSingleLine怎么用?C++ Range::onSingleLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ktexteditor::Range
的用法示例。
在下文中一共展示了Range::onSingleLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rangeText
QString CodeRepresentation::rangeText(const KTextEditor::Range& range) const
{
Q_ASSERT(range.end().line() < lines());
//Easier for single line ranges which should happen most of the time
if(range.onSingleLine())
return QString( line( range.start().line() ).mid( range.start().column(), range.columnWidth() ) );
//Add up al the requested lines
QString rangedText = line(range.start().line()).mid(range.start().column());
for(int i = range.start().line() + 1; i <= range.end().line(); ++i)
rangedText += '\n' + ((i == range.end().line()) ? line(i).left(range.end().column()) : line(i));
return rangedText;
}
示例2: exportDocument
QString HighlighterByKate::exportDocument(KTextEditor::Document* note)
{
QString ret("");
KTextEditor::Range range;
range = note->documentRange();
KTextEditor::HighlightInterface* hiface = qobject_cast<KTextEditor::HighlightInterface*>(note);
const KTextEditor::Attribute::Ptr noAttrib(0);
for (int i = 0; i < note->lines(); ++i)
{
QString content("");
const QString &line = note->line(i);
QList<KTextEditor::HighlightInterface::AttributeBlock> attribs;
if ( hiface ) {
attribs = hiface->lineAttributes(i);
}
int lineStart = 0;
int remainingChars = line.length();
if ( range.onSingleLine() ) {
lineStart = range.start().column();
remainingChars = range.columnWidth();
} else if ( i == range.start().line() ) {
lineStart = range.start().column();
} else if ( i == range.end().line() ) {
remainingChars = range.end().column();
}
int handledUntil = lineStart;
foreach ( const KTextEditor::HighlightInterface::AttributeBlock& block, attribs ) {
// honor (block-) selections
if ( block.start + block.length <= lineStart ) {
continue;
} else if ( block.start >= lineStart + remainingChars ) {
break;
}
int start = qMax(block.start, lineStart);
if ( start > handledUntil ) {
exportText(content, line.mid( handledUntil, start - handledUntil ), noAttrib );
}
int length = qMin(block.length, remainingChars);
exportText(content, line.mid( start, length ), block.attribute);
handledUntil = start + length;
}
if ( handledUntil < lineStart + remainingChars ) {
exportText(content, line.mid( handledUntil, remainingChars ), noAttrib );
}
if (i != range.end().line()) {
ret.append(content.isEmpty() ? "\n" : content);
ret.append("\n");
}
}
return ret;
}
示例3: exportData
void ExporterPluginView::exportData(const bool useSelection, QTextStream &output)
{
const KTextEditor::Range range = useSelection ? m_view->selectionRange() : m_view->document()->documentRange();
const bool blockwise = useSelection ? m_view->blockSelection() : false;
if ( (blockwise || range.onSingleLine()) && (range.start().column() > range.end().column() ) ) {
return;
}
//outputStream.setEncoding(QTextStream::UnicodeUTF8);
output.setCodec(QTextCodec::codecForName("UTF-8"));
///TODO: add more exporters
AbstractExporter* exporter;
exporter = new HTMLExporter(m_view, output, !useSelection);
KTextEditor::HighlightInterface* hiface = qobject_cast<KTextEditor::HighlightInterface*>(m_view->document());
const KTextEditor::Attribute::Ptr noAttrib(0);
for (int i = range.start().line(); (i <= range.end().line()) && (i < m_view->document()->lines()); ++i)
{
const QString &line = m_view->document()->line(i);
QList<KTextEditor::HighlightInterface::AttributeBlock> attribs;
if ( hiface ) {
attribs = hiface->lineAttributes(i);
}
int lineStart = 0;
int remainingChars = line.length();
if ( blockwise || range.onSingleLine() ) {
lineStart = range.start().column();
remainingChars = range.columnWidth();
} else if ( i == range.start().line() ) {
lineStart = range.start().column();
} else if ( i == range.end().line() ) {
remainingChars = range.end().column();
}
int handledUntil = lineStart;
foreach ( const KTextEditor::HighlightInterface::AttributeBlock& block, attribs ) {
// honor (block-) selections
if ( block.start + block.length <= lineStart ) {
continue;
} else if ( block.start >= lineStart + remainingChars ) {
break;
}
int start = qMax(block.start, lineStart);
if ( start > handledUntil ) {
exporter->exportText( line.mid( handledUntil, start - handledUntil ), noAttrib );
}
int length = qMin(block.length, remainingChars);
exporter->exportText( line.mid( start, length ), block.attribute);
handledUntil = start + length;
}
if ( handledUntil < lineStart + remainingChars ) {
exporter->exportText( line.mid( handledUntil, remainingChars ), noAttrib );
}
exporter->closeLine(i == range.end().line());
}
delete exporter;
output.flush();
}