当前位置: 首页>>代码示例>>C++>>正文


C++ TextEditor::textCursor方法代码示例

本文整理汇总了C++中TextEditor::textCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ TextEditor::textCursor方法的具体用法?C++ TextEditor::textCursor怎么用?C++ TextEditor::textCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextEditor的用法示例。


在下文中一共展示了TextEditor::textCursor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: replaceAll

void FindDialog::replaceAll() {
   TextEditor *current = m_parent->m_activeEditor;
   QTextDocument *doc  = current->getTextDocument();
   QTextCursor start   = current->textCursor();
   QTextCursor result, last;
   int noOccurrences = 0, startPos = -1, endPos = -1;
   m_searching = false;
   
   // search within a selection
   if (start.hasSelection() && searchSelection()) {
      startPos = start.selectionStart();
      endPos = start.selectionEnd();
      
      // get rid of selection
      if (findBackwards())
         start.setPosition(endPos);
      else start.setPosition(startPos);
   } else start.movePosition(QTextCursor::Start);
   
   start.beginEditBlock();
   result = start;
   
   do {
      last   = result;
      result = replace(result, doc, startPos, endPos);
      if (result.isNull())
         break;
      
      // disallow infinite replacements of similar terms ('life' w/ 'LIFE')
      result.setPosition(result.selectionEnd());
      ++noOccurrences;
   } while(true);
   
   start.endEditBlock();
   if (noOccurrences <= 0) {
      STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
   } else {
      current->changeTextCursor(last);
      STATUS_BAR->showMessage(QString("Replaced %1 occurence%2.").arg(QString::number(noOccurrences), (noOccurrences != 1 ? QString("s") : QString(""))));
   }
   
   updateReplace(true);
}
开发者ID:MipScope,项目名称:mipscope,代码行数:43,代码来源:FindDialog.cpp

示例2: accept

void FindDialog::accept() {
   TextEditor *current = m_parent->m_activeEditor;
   QTextDocument *doc  = current->getTextDocument();
   QTextCursor start   = current->textCursor();
   QTextCursor result;
   int startPos = -1, endPos = -1;
   
   // see if we're supposed to search within a selection
   if (start.hasSelection() && searchSelection()) {
      startPos = start.selectionStart();
      endPos = start.selectionEnd();
      
      // get rid of selection
      if (findBackwards())
         start.setPosition(endPos);
      else start.setPosition(startPos);
   } else if (!fromCursor() && !m_searching)
      start.movePosition(QTextCursor::Start);
   
   if (isFind()) {
      result = find(start, doc);
      
      // test if result was outside of selection
      if (!result.isNull() && 
          ((endPos > 0 && result.selectionEnd() > endPos) || 
          (startPos > 0 && result.selectionStart() < startPos)))
         result = QTextCursor(); // null cursor
   } else result = replace(start, doc, endPos);
   
   if (result.isNull()) {
      STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
      
      m_searching = false;
      updateReplace(isReplace());
   } else {
      current->changeTextCursor(result);
      STATUS_BAR->clearMessage();
      
      m_searching = true;
      updateReplace(isReplace());
   }
}
开发者ID:MipScope,项目名称:mipscope,代码行数:42,代码来源:FindDialog.cpp


注:本文中的TextEditor::textCursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。