本文整理汇总了C++中ktexteditor::Range::setRange方法的典型用法代码示例。如果您正苦于以下问题:C++ Range::setRange方法的具体用法?C++ Range::setRange怎么用?C++ Range::setRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ktexteditor::Range
的用法示例。
在下文中一共展示了Range::setRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rangeCheck
void RangeTest::rangeCheck(KTextEditor::Range &valid)
{
QVERIFY(valid.isValid() && valid.start() <= valid.end());
KTextEditor::Cursor before(0, 1), start(0, 2), end(1, 4), after(1, 10);
KTextEditor::Range result(start, end);
QVERIFY(valid.isValid() && valid.start() <= valid.end());
valid.setRange(start, end);
QVERIFY(valid.isValid() && valid.start() <= valid.end());
QCOMPARE(valid, result);
valid.setRange(end, start);
QVERIFY(valid.isValid() && valid.start() <= valid.end());
QCOMPARE(valid, result);
valid.setStart(after);
QVERIFY(valid.isValid() && valid.start() <= valid.end());
QCOMPARE(valid, KTextEditor::Range(after, after));
valid = result;
QCOMPARE(valid, result);
valid.setEnd(before);
QVERIFY(valid.isValid() && valid.start() <= valid.end());
QCOMPARE(valid, KTextEditor::Range(before, before));
}
示例2: textChanged
void AdaptSignatureAssistant::textChanged(KTextEditor::View* view, const KTextEditor::Range& invocationRange, const QString& removedText)
{
reset();
m_view = view;
//FIXME: update signature assistant to play well with the rename assistant
KTextEditor::Range sigAssistRange = invocationRange;
if (!removedText.isEmpty()) {
sigAssistRange.setRange(sigAssistRange.start(), sigAssistRange.start());
}
m_document = view->document()->url();
DUChainReadLocker lock(DUChain::lock(), 300);
if(!lock.locked()) {
qCDebug(CPP) << "failed to lock duchain in time";
return;
}
KTextEditor::Range simpleInvocationRange = KTextEditor::Range(sigAssistRange);
Declaration* funDecl = getDeclarationAtCursor(simpleInvocationRange.start(), m_document);
if(!funDecl || !funDecl->type<FunctionType>())
return;
if(QtFunctionDeclaration* classFun = dynamic_cast<QtFunctionDeclaration*>(funDecl)) {
if (classFun->isSignal()) {
// do not offer to change signature of a signal, as the implementation will be generated by moc
return;
}
}
Declaration* otherSide = 0;
FunctionDefinition* definition = dynamic_cast<FunctionDefinition*>(funDecl);
if (definition)
{
m_editingDefinition = true;
otherSide = definition->declaration();
}
else if ((definition = FunctionDefinition::definition(funDecl)))
{
m_editingDefinition = false;
otherSide = definition;
}
if (!otherSide)
return;
m_otherSideContext = DUContextPointer(DUChainUtils::getFunctionContext(otherSide));
if (!m_otherSideContext)
return;
m_declarationName = funDecl->identifier();
m_otherSideId = otherSide->id();
m_otherSideTopContext = ReferencedTopDUContext(otherSide->topContext());
m_oldSignature = getDeclarationSignature(otherSide, m_otherSideContext.data(), true);
//Schedule an update, to make sure the ranges match
DUChain::self()->updateContextForUrl(m_otherSideTopContext->url(), TopDUContext::AllDeclarationsAndContexts);
}
示例3: transformRange
void TextHistory::transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision)
{
/**
* invalidate on empty?
*/
bool invalidateIfEmpty = emptyBehavior == KTextEditor::MovingRange::InvalidateIfEmpty;
if (invalidateIfEmpty && range.end() <= range.start()) {
range = KTextEditor::Range::invalid();
return;
}
/**
* -1 special meaning for from/toRevision
*/
if (fromRevision == -1) {
fromRevision = revision();
}
if (toRevision == -1) {
toRevision = revision();
}
/**
* shortcut, same revision
*/
if (fromRevision == toRevision) {
return;
}
/**
* some invariants must hold
*/
Q_ASSERT(!m_historyEntries.empty());
Q_ASSERT(fromRevision != toRevision);
Q_ASSERT(fromRevision >= m_firstHistoryEntryRevision);
Q_ASSERT(fromRevision < (m_firstHistoryEntryRevision + m_historyEntries.size()));
Q_ASSERT(toRevision >= m_firstHistoryEntryRevision);
Q_ASSERT(toRevision < (m_firstHistoryEntryRevision + m_historyEntries.size()));
/**
* transform cursors
*/
// first: copy cursors, without range association
int startLine = range.start().line(), startColumn = range.start().column(), endLine = range.end().line(), endColumn = range.end().column();
bool moveOnInsertStart = !(insertBehaviors & KTextEditor::MovingRange::ExpandLeft);
bool moveOnInsertEnd = (insertBehaviors & KTextEditor::MovingRange::ExpandRight);
/**
* forward or reverse transform?
*/
if (toRevision > fromRevision) {
for (int rev = fromRevision - m_firstHistoryEntryRevision + 1; rev <= (toRevision - m_firstHistoryEntryRevision); ++rev) {
const Entry &entry = m_historyEntries.at(rev);
entry.transformCursor(startLine, startColumn, moveOnInsertStart);
entry.transformCursor(endLine, endColumn, moveOnInsertEnd);
// got empty?
if (endLine < startLine || (endLine == startLine && endColumn <= startColumn)) {
if (invalidateIfEmpty) {
range = KTextEditor::Range::invalid();
return;
} else {
// else normalize them
endLine = startLine;
endColumn = startColumn;
}
}
}
} else {
for (int rev = fromRevision - m_firstHistoryEntryRevision; rev >= (toRevision - m_firstHistoryEntryRevision + 1); --rev) {
const Entry &entry = m_historyEntries.at(rev);
entry.reverseTransformCursor(startLine, startColumn, moveOnInsertStart);
entry.reverseTransformCursor(endLine, endColumn, moveOnInsertEnd);
// got empty?
if (endLine < startLine || (endLine == startLine && endColumn <= startColumn)) {
if (invalidateIfEmpty) {
range = KTextEditor::Range::invalid();
return;
} else {
// else normalize them
endLine = startLine;
endColumn = startColumn;
}
}
}
}
// now, copy cursors back
range.setRange(KTextEditor::Cursor(startLine, startColumn), KTextEditor::Cursor(endLine, endColumn));
}