本文整理汇总了C++中ktexteditor::Range::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Range::end方法的具体用法?C++ Range::end怎么用?C++ Range::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ktexteditor::Range
的用法示例。
在下文中一共展示了Range::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: changeIndent
bool KateAutoIndent::changeIndent (const KTextEditor::Range &range, int change)
{
QList<int> skippedLines;
// loop over all lines given...
for (int line = range.start().line () < 0 ? 0 : range.start().line ();
line <= qMin (range.end().line (), doc->lines()-1); ++line)
{
// don't indent empty lines
if (doc->line(line).isEmpty())
{
skippedLines.append (line);
continue;
}
// don't indent the last line when the cursor is on the first column
if (line == range.end().line() && range.end().column() == 0)
{
skippedLines.append (line);
continue;
}
doIndentRelative(line, change * indentWidth);
}
if (skippedLines.count() > range.numberOfLines())
{
// all lines were empty, so indent them nevertheless
foreach (int line, skippedLines)
doIndentRelative(line, change * indentWidth);
}
示例2: rangeToScriptValue
/** Conversion function from QtScript range to KTextEditor::Range */
static QScriptValue rangeToScriptValue(QScriptEngine *engine, const KTextEditor::Range &range)
{
QString code = QString("new Range(%1, %2, %3, %4);").arg(range.start().line())
.arg(range.start().column())
.arg(range.end().line())
.arg(range.end().column());
return engine->evaluate(code);
}
示例3: removeText
void SwapFile::removeText (const KTextEditor::Range &range)
{
// skip if not open
if (!m_swapfile.isOpen ())
return;
// format: qint8, int, int, int
Q_ASSERT (range.start().line() == range.end().line());
m_stream << EA_RemoveText
<< range.start().line() << range.start().column()
<< range.end().column();
m_needSync = true;
}
示例4: 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;
}
示例5: getItemBoundingRect
QRect KTextEditorHelpers::getItemBoundingRect(const KTextEditor::View* view, const KTextEditor::Range& itemRange)
{
QPoint startPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.start()));
QPoint endPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.end()));
endPoint.ry() += getLineHeight(view, itemRange.start().line());
return QRect(startPoint, endPoint);
}
示例6: rangeFromScriptValue
/** Conversion function from QtScript range to KTextEditor::Range */
static void rangeFromScriptValue(const QScriptValue &obj, KTextEditor::Range &range)
{
range.start().setPosition(obj.property("start").property("line").toInt32(),
obj.property("start").property("column").toInt32());
range.end().setPosition(obj.property("end").property("line").toInt32(),
obj.property("end").property("column").toInt32());
}
示例7: textInserted
void KateViInsertMode::textInserted(KTextEditor::Document* document, KTextEditor::Range range)
{
if (m_isExecutingCompletion)
{
m_textInsertedByCompletion += document->text(range);
m_textInsertedByCompletionEndPos = range.end();
}
}
示例8: executed
void FunctionDeclarationCompletionItem::executed(KTextEditor::View* view, const KTextEditor::Range& word)
{
qCDebug(KDEV_PYTHON_CODECOMPLETION) << "FunctionDeclarationCompletionItem executed";
KTextEditor::Document* document = view->document();
auto resolvedDecl = Helper::resolveAliasDeclaration(declaration().data());
DUChainReadLocker lock;
auto functionDecl = Helper::functionForCalled(resolvedDecl).declaration;
lock.unlock();
if ( ! functionDecl && (! resolvedDecl || ! resolvedDecl->abstractType()
|| resolvedDecl->abstractType()->whichType() != AbstractType::TypeStructure) ) {
qCritical(KDEV_PYTHON_CODECOMPLETION) << "ERROR: could not get declaration data, not executing completion item!";
return;
}
QString suffix = "()";
KTextEditor::Range checkPrefix(word.start().line(), 0, word.start().line(), word.start().column());
KTextEditor::Range checkSuffix(word.end().line(), word.end().column(), word.end().line(), document->lineLength(word.end().line()));
if ( m_doNotCall || document->text(checkSuffix).trimmed().startsWith('(')
|| document->text(checkPrefix).trimmed().endsWith('@')
|| (functionDecl && Helper::findDecoratorByName(functionDecl, QLatin1String("property"))) )
{
// don't insert brackets if they're already there,
// the item is a decorator, or if it's an import item.
suffix.clear();
}
// place cursor behind bracktes by default
int skip = 2;
if ( functionDecl ) {
bool needsArguments = false;
int argumentCount = functionDecl->type<FunctionType>()->arguments().length();
if ( functionDecl->context()->type() == KDevelop::DUContext::Class ) {
// it's a member function, so it has the implicit self
// TODO static methods
needsArguments = argumentCount > 1;
}
else {
// it's a free function
needsArguments = argumentCount > 0;
}
if ( needsArguments ) {
// place cursor in brackets if there's parameters
skip = 1;
}
}
document->replaceText(word, declaration()->identifier().toString() + suffix);
view->setCursorPosition( Cursor(word.end().line(), word.end().column() + skip) );
}
示例9: completionInvoked
void PreprocessorCompletionModel::completionInvoked(
KTextEditor::View* const view
, const KTextEditor::Range& word
, InvocationType /*itype*/
)
{
// Reuse shouldStartCompletion to disable/enable completion
m_should_complete = shouldStartCompletion(view, QString{}, false, word.end());
}
示例10: assert
void ClangCodeCompletionModel::executeCompletionItem2(
KTextEditor::Document* const doc
, const KTextEditor::Range& word
, const QModelIndex& index
) const
{
assert("Active view expected to be equal to the stored one" && doc->activeView() == m_current_view);
assert("Invalid index is not expected here!" && index.isValid());
assert("Parent index is not valid" && index.parent().isValid());
assert("Parent index must be GROUP" && index.parent().internalId() == Level::GROUP);
assert(
"Parent index points to invalid group"
&& 0 <= index.internalId()
&& unsigned(index.internalId()) < m_groups.size()
);
assert(
"Index points to invalid item"
&& 0 <= index.row()
&& unsigned(index.row()) < m_groups[index.internalId()].second.m_completions.size()
);
auto* const template_iface = qobject_cast<KTextEditor::TemplateInterface2*>(m_current_view);
if (template_iface)
{
kDebug(DEBUG_AREA) << "TemplateInterface available for a view" << m_current_view;
const auto result = m_groups[index.internalId()]
.second.m_completions[index.row()]
.getCompletionTemplate();
kDebug(DEBUG_AREA) << "Template:" << result.m_tpl;
kDebug(DEBUG_AREA) << "Values:" << result.m_values;
// Check if current template is a function and there is a '()' right after cursor
auto range = word;
if (result.m_is_function)
{
const auto next_word_range = DocumentProxy(doc).firstWordAfterCursor(word.end());
kDebug(DEBUG_AREA) << "OK THIS IS FUNCTION TEMPLATE: next word range" << next_word_range;
kDebug(DEBUG_AREA) << "replace range before:" << range;
if (next_word_range.isValid() && doc->text(next_word_range).startsWith(QLatin1String("()")))
{
range.end().setColumn(next_word_range.start().column() + 2);
kDebug(DEBUG_AREA) << "replace range after:" << range;
}
}
doc->removeText(range);
template_iface->insertTemplateText(range.start(), result.m_tpl, result.m_values, nullptr);
}
else
{
kDebug(DEBUG_AREA) << "No TemplateInterface for a view" << m_current_view;
const auto p = m_groups[index.internalId()].second.m_completions[index.row()].executeCompletion();
doc->replaceText(word, p.first);
// Try to reposition a cursor inside a current (hope it still is) view
auto pos = word.start();
pos.setColumn(pos.column() + p.second);
m_current_view->setCursorPosition(pos);
}
}
示例11: execute
void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
{
auto document = view->document();
auto range = word;
const int lineNumber = word.end().line();
const QString line = document->line(lineNumber);
const auto properties = includePathProperties(line, word.end().column());
if (!properties.valid) {
return;
}
QString newText = includeItem.isDirectory ? (includeItem.name + QLatin1Char('/')) : includeItem.name;
if (properties.inputFrom == -1) {
newText.prepend(QLatin1Char('<'));
} else {
range.setStart({lineNumber, properties.inputFrom});
}
if (properties.inputTo == -1) {
// Add suffix
if (properties.local) {
newText += QLatin1Char('"');
} else {
newText += QLatin1Char('>');
}
// replace the whole line
range.setEnd({lineNumber, line.size()});
} else {
range.setEnd({lineNumber, properties.inputTo});
}
document->replaceText(range, newText);
if (includeItem.isDirectory) {
// ensure we can continue to add files/paths when we just added a directory
int offset = (properties.inputTo == -1) ? 1 : 0;
view->setCursorPosition(range.start() + KTextEditor::Cursor(0, newText.length() - offset));
} else {
// place cursor at end of line
view->setCursorPosition({lineNumber, document->lineLength(lineNumber)});
}
}
示例12: execute
void ImplementFunctionCompletionItem::execute(KTextEditor::Document* document, const KTextEditor::Range& word)
{
const QString finalText = m_name + "(" + m_arguments.join(", ") + "):";
document->replaceText(word, finalText);
// 4 spaces is indentation for python. everyone does it like this. you must, too.
// TODO use kate settings
document->insertLine(word.start().line() + 1, m_previousIndent + " ");
if ( View* view = document->activeView() ) {
view->setCursorPosition(Cursor(word.end().line() + 1, m_previousIndent.length() + 4));
}
}
示例13: removeText
void TextHistory::removeText(const KTextEditor::Range &range, int oldLineLength)
{
// create and add new entry
Entry entry;
entry.type = Entry::RemoveText;
entry.line = range.start().line();
entry.column = range.start().column();
entry.length = range.end().column() - range.start().column();
entry.oldLineLength = oldLineLength;
addEntry(entry);
}
示例14: sizeHint
QSize GrepOutputDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
const GrepOutputModel *model = dynamic_cast<const GrepOutputModel *>(index.model());
const GrepOutputItem *item = model ? dynamic_cast<const GrepOutputItem *>(model->itemFromIndex(index)) : nullptr;
QSize ret = QStyledItemDelegate::sizeHint(option, index);
//take account of additional width required for highlighting (bold text)
//and line numbers. These are not included in the default Qt size calculation.
if(item && item->isText())
{
QFont font = option.font;
QFontMetrics metrics(font);
font.setBold(true);
QFontMetrics bMetrics(font);
const KTextEditor::Range rng = item->change()->m_range;
int width = metrics.width(item->text().left(rng.start().column())) +
metrics.width(item->text().right(item->text().length() - rng.end().column())) +
bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) +
std::max(option.decorationSize.width(), 0);
ret.setWidth(width);
}else{
// This is only used for titles, so not very performance critical
QString text;
if(item)
text = item->text();
else
text = index.data().toString();
QTextDocument doc;
doc.setDocumentMargin(0);
doc.setHtml(text);
QSize newSize = doc.size().toSize();
if(newSize.height() > ret.height())
ret.setHeight(newSize.height());
}
return ret;
}
示例15: shouldAbortCompletion
/**
* We have to stop \c #include completion when current line would parsed well
* (i.e. contains complete \c #include expression) or have no \c #include at all.
*/
bool IncludeHelperCompletionModel::shouldAbortCompletion(
KTextEditor::View* view
, const KTextEditor::Range& range
, const QString& current_completion
)
{
kDebug(DEBUG_AREA) << "range=" << range << ", current_completion=" << current_completion;
kDebug(DEBUG_AREA) << "m_should_complete=" << m_should_complete << ", closer=" << m_closer;
// Get current line
const auto line = view->document()->line(range.end().line());
// Try to parse it...
auto r = parseIncludeDirective(line, false);
// nothing to complete for lines w/o #include
const auto need_abort = !r.m_range.isValid()
|| range.end().column() < r.m_range.start().column()
|| range.end().column() > (r.m_range.end().column() + 1)
;
kDebug(DEBUG_AREA) << "result=" << need_abort;
return need_abort;
}