本文整理汇总了C++中QDocumentCursor类的典型用法代码示例。如果您正苦于以下问题:C++ QDocumentCursor类的具体用法?C++ QDocumentCursor怎么用?C++ QDocumentCursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDocumentCursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qceEqual
void qceEqual(const QDocumentCursor& c, const QDocumentCursor& expected, const QString& message){
QEQUAL2(c.hasSelection(),expected.hasSelection(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
QEQUAL2(c.anchorLineNumber(),expected.anchorLineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
QEQUAL2(c.anchorColumnNumber(),expected.anchorColumnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
QEQUAL2(c.lineNumber(),expected.lineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
QEQUAL2(c.columnNumber(),expected.columnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message);
}
示例2: buffer
/*!
\brief Completion callback
*/
void QCodeCompletionEngine::complete(const QDocumentCursor& c, const QString& trigger)
{
#ifdef _QCODE_MODEL_
// TODO :
// * use a more efficient design by avoiding deep copy of the data
// * only lex the requested part (stop at cursor or topmost frame required for proper class hierarchy)
QDocumentCursor cc = c;
cc.movePosition(1, QDocumentCursor::Start, QDocumentCursor::KeepAnchor);
//qDebug("%s", qPrintable(cc.selectedText()));
QCodeBuffer buffer(cc.selectedText());
//QCodeBuffer buffer(c.document()->text());
complete(&buffer, trigger);
#else
// remove unused argument warnings
(void) c;
(void) trigger;
qWarning("From complete(QDocumentCursor, QString)");
qWarning("QCodeCompletionEngine is not self-sufficient : subclasses should "
"reimplement at least on of the complete() method...");
#endif
}
示例3: QFETCH
//tests if folded text can be edited
void QEditorTest::activeFolding(){
QFETCH(QString, editorText);
QFETCH(QList<int>, foldAt);
QFETCH(QList<int>, hiddenLines);
QFETCH(int, cursorAL);
QFETCH(int, cursorAC);
QFETCH(int, cursorL);
QFETCH(int, cursorC);
QFETCH(QString, textToInsert);
QFETCH(QString, newEditorText);
QFETCH(QList<int>, newHiddenLines);
editor->setText(editorText, false);
foreach(const int &i, foldAt)
editor->document()->collapse(i);
for (int i=0;i<editor->document()->lines();i++)
QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines.contains(i),qPrintable(QString::number(i)));
compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines);
QDocumentCursor editCursor = editor->document()->cursor(cursorAL,cursorAC,cursorL,cursorC);
editCursor.insertText(textToInsert);
QEQUAL(editor->document()->text(), newEditorText);
for (int i=0;i<editor->document()->lines();i++)
QVERIFY2(editor->document()->line(i).isHidden() == newHiddenLines.contains(i),qPrintable(QString::number(i)));
compareLists(editor->document()->impl()->testGetHiddenLines(), newHiddenLines);
}
示例4: editor
/*!
\internal
*/
bool QCodeCompletionEngine::eventFilter(QObject *o, QEvent *e)
{
if ( !e || !o || (e->type() != QEvent::KeyPress) || (o != pEdit) )
return false;
//qDebug("should trigger completion?");
QDocumentCursor cur = editor()->cursor();
QKeyEvent *k = static_cast<QKeyEvent*>(e);
QString s, txt = s = k->text();
int count = txt.count();
if ( txt.isEmpty() || m_triggers.isEmpty() )
return false; // QThread::eventFilter(o, e);
//qDebug("should trigger completion? (bis)");
if ( count > m_max )
{
txt = txt.right(m_max);
} else if ( count < m_max ) {
QDocumentCursor c(cur);
c.movePosition(m_max - count, QDocumentCursor::Left, QDocumentCursor::KeepAnchor);
//qDebug("prev text : %s", qPrintable(c.selectedText()));
txt.prepend(c.selectedText());
}
//qDebug("text : %s", qPrintable(txt));
foreach ( QString trig, m_triggers )
{
if ( txt.endsWith(trig) )
{
editor()->write(s);
cur = editor()->cursor();
cur.movePosition(trig.count(), QDocumentCursor::PreviousCharacter);
// notify completion trigger
emit completionTriggered(trig);
//get rid of previous calltips/completions
editor()->setFocus();
// trigger completion
complete(cur, trig);
return true;
}
}
return false;
}
示例5: _warn
/*!
*/
bool QHexPanel::paint(QPainter *p, QEditor *e)
{
// qWarning("drawing Hex panel... [%i, %i, %i, %i]",
// geometry().x(),
// geometry().y(),
// geometry().width(),
// geometry().height());
#if 1
//hexeditor->resize(geometry().size());
#else
static QPixmap _warn(":/warning.png"), _mod(":/save.png");
QString s;
int xpos = 10;
QDocumentCursor c = e->cursor();
const QFontMetrics fm(fontMetrics());
const int ls = fm.lineSpacing();
const int ascent = fm.ascent() + 3;
s = tr("Line : %1 Visual column : %2 Text column : %3")
.arg(c.lineNumber() + 1)
.arg(c.visualColumnNumber())
.arg(c.columnNumber());
p->drawText(xpos, ascent, s);
xpos += fm.width(s) + 10;
int sz = qMin(height(), _mod.height());
//int lastMod = d->lastModified().secsTo(QDateTime::currentDateTime());
//QString timeDiff = tr("(%1 min %2 s ago)").arg(lastMod / 60).arg(lastMod % 60);
//xpos += 10;
if ( e->isContentModified() )
{
p->drawPixmap(xpos, (height() - sz) / 2, sz, sz, _mod);
//xpos += sz;
//xpos += 10;
//p->drawText(xpos, ascent, timeDiff);
}
xpos += sz + 10;
//xpos += fm.width(timeDiff);
//xpos += 20;
// s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT");
// p->drawText(xpos, ascent, s);
// xpos += fm.width(s) + 10;
#endif
return true;
}
示例6: findNextToken
int LatexTables::findNextToken(QDocumentCursor &cur,QStringList tokens,bool keepAnchor,bool backwards){
int pos=-1;
int nextToken=-1;
int offset=0;
QDocumentCursor::MoveOperation mvNextLine= backwards ? QDocumentCursor::PreviousLine : QDocumentCursor::NextLine;
QDocumentCursor::MoveOperation mvNextChar= backwards ? QDocumentCursor::Left : QDocumentCursor::Right;
QDocumentCursor::MoveOperation mvStartOfLine= backwards ? QDocumentCursor::EndOfLine : QDocumentCursor::StartOfLine;
QDocumentCursor::MoveFlag mvFlag= keepAnchor ? QDocumentCursor::KeepAnchor : QDocumentCursor::MoveAnchor;
do{
QString line=cur.line().text();
if(backwards){
offset=line.length();
}
line=LatexParser::cutComment(line);
if(backwards){
offset=offset-line.length();
QString help;
foreach(const QChar& elem,line)
help.prepend(elem);
line=help;
}
if(line.contains("\\end{")&&!backwards) {
nextToken=-2;
break;
}
if(line.contains("{nigeb\\")&&backwards) {
nextToken=-2;
break;
}
pos=-1;
for(int i=0;i<tokens.count();i++){
QString elem=tokens.at(i);
int colNumber= cur.columnNumber();
if(backwards) colNumber=line.length()+offset-colNumber ;
int zw=line.indexOf(elem,colNumber);
if(zw>-1) {
if(pos>zw || pos==-1){
pos=zw;
nextToken=i;
}
}
}
if(pos<0){
if(!backwards&&cur.lineNumber()>=cur.document()->lineCount()-1) break;
if(backwards&&cur.lineNumber()<=0) break;
cur.movePosition(1,mvNextLine,mvFlag);
cur.movePosition(1,mvStartOfLine,mvFlag);
}
}while(pos<0);
if(pos>-1) {
cur.movePosition(1,mvStartOfLine,mvFlag);
cur.movePosition(pos+tokens.at(nextToken).length()+offset,mvNextChar,mvFlag);
}
return nextToken;
}
示例7: _warn
/*!
*/
void QStatusPanel::paint(QPainter *p, QEditor *e)
{
//qDebug("drawing status panel... [%i, %i, %i, %i]",
// geometry().x(),
// geometry().y(),
// geometry().width(),
// geometry().height());
static QPixmap _warn(":/warning.png");
QString s;
int xpos = 10;
QDocumentCursor c = e->cursor();
const QFontMetrics fm(fontMetrics());
const int ls = fm.lineSpacing();
const int ascent = fm.ascent() + 3;
s = tr("Line : %1 Visual column : %2 Text column : %3")
.arg(c.lineNumber() + 1)
.arg(c.visualColumnNumber())
.arg(c.columnNumber());
p->drawText(xpos, ascent, s);
xpos += fm.width(s) + 10;
// TODO : draw icon to show mod status
s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT");
p->drawText(xpos, ascent, s);
xpos += fm.width(s) + 10;
m_conflictSpot = 0;
if ( editor()->isInConflict() )
{
s = tr("Conflict");
int w = fm.width(s) + 30;
if ( xpos + w + _warn.width() < width() )
{
m_conflictSpot = width() - (w + _warn.width());
p->drawText(width() - w + 15, ascent, s);
p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
} else if ( xpos + _warn.width() < width() ) {
m_conflictSpot = width() - _warn.width();
p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn);
}
}
setFixedHeight(ls + 4);
}
示例8: simpleRestoreAutoOverride
void simpleRestoreAutoOverride(const QString& written="????"){ //simple means without protecting the change from undo/redo
if (!autoOverridenText.isEmpty() && !editor->isAutoOverrideText(written)) {
int curpos = editor->cursor().columnNumber();
if (curpos < maxWritten) {
QDocumentCursor c = editor->cursor();
c.movePosition(maxWritten-curpos, QDocumentCursor::Right);
editor->setCursor(c);
}
editor->insertText(autoOverridenText);
QDocumentCursor c = editor->cursor();
c.movePosition(autoOverridenText.length() + (curpos<maxWritten?maxWritten-curpos:0), QDocumentCursor::Left);
editor->setCursor(c);
editor->resizeAutoOverridenPlaceholder(c, autoOverridenText.size());
}
}
示例9: cur
void LatexTables::removeRow(QDocumentCursor &c){
QDocumentCursor cur(c);
const QStringList tokens("\\\\");
if(cur.hasSelection()){
if(cur.lineNumber()>cur.anchorLineNumber()||(cur.lineNumber()==cur.anchorLineNumber() && cur.columnNumber()>cur.anchorColumnNumber())){
cur.moveTo(cur.anchorLineNumber(),cur.anchorColumnNumber());
}
}
int result=findNextToken(cur,tokens,false,true);
if(result==0) cur.movePosition(2,QDocumentCursor::Right);
if(result==-2) cur.movePosition(1,QDocumentCursor::EndOfLine);
bool breakLoop=false;
while(!(breakLoop=(findNextToken(cur,tokens,true)==-1)) && c.isWithinSelection(cur) ){
}
if(!breakLoop) {
// check if end of cursor is at line end
QDocumentCursor c2(cur.document(),cur.anchorLineNumber(),cur.anchorColumnNumber());
if(c2.atLineEnd()) {
c2.movePosition(1,QDocumentCursor::Right);
cur.moveTo(c2,QDocumentCursor::KeepAnchor);
}
// remove text
cur.beginEditBlock();
cur.removeSelectedText();
if(cur.line().text().isEmpty()) cur.deleteChar(); // don't leave empty lines
cur.endEditBlock();
}
}
示例10: getLastToken
/*!
\brief
\fn CCompletion::getLastToken
\param c
\return QString
*/
QString CCompletion::getLastToken(const QDocumentCursor &c) {
QString line = c.line().text();
QString Token = c.selectedText();
if (Token.isEmpty()) {
if (line.size()>1) {
int i = c.columnNumber()-1;
while (QString("_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").contains(line.at(i).toUpper())) {
Token = line.at(i)+Token;
i--;
if (i<0) break;
}
}
}
return Token;
}
示例11: rx
QString LatexTables::getTableText(QDocumentCursor &cur){
int result=findNextToken(cur,QStringList(),false,true);
if(result!=-2) return QString();
QString line=cur.line().text();
int i=line.indexOf("\\begin");
if(i>=0)
cur.setColumnNumber(i);
result=findNextToken(cur,QStringList(),true,false);
if(result!=-2) return QString();
line=cur.line().text();
QRegExp rx("\\\\end\\{.*\\}");
i=rx.indexIn(line);
if(i>=0)
cur.setColumnNumber(i+rx.cap(0).length(),QDocumentCursor::KeepAnchor);
QString res=cur.selectedText();
return res;
}
示例12: keyPressEvent
bool QSnippetBinding::keyPressEvent(QKeyEvent *event, QEditor *editor)
{
/*
if ( event->modifiers() & Qt::ControlModifier )
{
for ( int i = 0; i < qMin(10, m->snippetCount()); ++i )
{
if ( event->key() == (Qt::Key_F1 + i) )
{
m->snippet(i)->insert(editor);
return true;
}
}
}
*/
if ( (event->modifiers() & Qt::AltModifier) && (event->key() == Qt::Key_Space || event->text() == " ") )
{
QDocumentCursor c = editor->cursor();
//c.select(QDocumentCursor::SelectWord);
if ( !c.hasSelection() )
{
c.movePosition(1, QDocumentCursor::PreviousWord, QDocumentCursor::KeepAnchor);
editor->setCursor(c);
}
QString s = c.selectedText();
for ( int i = 0; i < m_manager->snippetCount(); ++i )
{
QSnippet *snip = m_manager->snippet(i);
if ( snip->name() == s )
{
snip->insert(editor);
return true;
}
}
}
return QEditorInputBinding::keyPressEvent(event, editor);
}
示例13: alignTableCols
void LatexTables::alignTableCols(QDocumentCursor &cur){
QString text = getTableText(cur);
if (!cur.hasSelection()) return;
QString indentation = cur.selectionStart().line().indentation();
// split off \begin and \end parts
int index = text.indexOf("\\begin{")+6;
int cellsStart;
QList<CommandArgument> args = getCommandOptions(text, index, &cellsStart);
if (args.count() < 2) return;
QString tableType = args.at(0).value;
// assume alignment in second arg except for the following environments (which have it in the third one)
QString alignment;
if (tabularNames.contains(tableType)) {
alignment = args.at(1).value;
} else if (tabularNamesWithOneOption.contains(tableType)) {
if (args.count()<3) alignment = ""; // incomplete definition -> fall back to defaults
else alignment = args.at(2).value;
} else return; // not a registered table environment
int cellsEnd = text.indexOf("\\end{"+tableType);
if (cellsEnd<0) return;
QString beginPart = text.left(cellsStart);
QString endPart = text.mid(cellsEnd);
LatexTableModel ltm;
ltm.setContent(text.mid(cellsStart, cellsEnd-cellsStart));
QStringList l_defs=splitColDef(alignment);
simplifyColDefs(l_defs);
QStringList content(ltm.getAlignedLines(l_defs));
QString result = beginPart + '\n';
for (int i=0; i<content.count(); i++) {
result.append(indentation + content.at(i));
}
result.append(indentation + endPart);
cur.replaceSelectedText(result);
}
示例14: c
bool LatexTables::inTableEnv(QDocumentCursor &cur){
QDocumentCursor c(cur);
int result=findNextToken(c,QStringList(),false,true);
if(result!=-2) return false;
if(c.lineNumber()==cur.lineNumber()) return false;
QString line=c.line().text();
int pos=line.indexOf("\\begin");
if(pos>-1){
QStringList values;
LatexParser::resolveCommandOptions(line,pos,values);
QString env=values.takeFirst();
if(!env.startsWith("{")||!env.endsWith("}")) return -1;
env=env.mid(1);
env.chop(1);
if(tabularNames.contains(env,Qt::CaseSensitive)||tabularNamesWithOneOption.contains(env,Qt::CaseSensitive)){
int result=findNextToken(c,QStringList());
if(result!=-2) return false;
if(c.lineNumber()>cur.lineNumber()) return true;
}
}
return false;
}
示例15: updateNavActions
QDocumentCursor CursorHistory::back(const QDocumentCursor ¤tCursor) {
if (currentEntry == history.begin()) {
updateNavActions();
return QDocumentCursor();
}
// insert currentCursor to be able to go back
if (currentCursor.isValid() && insertPos(currentCursor, false)) {
currentEntry--;
}
CursorPosition pos(currentCursor);
if (pos.isValid() && !pos.equals(*currentEntry)) {
updateNavActions();
return currentPos();
}
currentEntry = prevValidEntry(currentEntry);
updateNavActions();
return currentPos();
}