Beispiel #1
0
/**
 * Set attributes of the node that represents this class
 * in the XMI document.
 * @param doc            the xmi document
 * @param blockElement   the xmi element holding the attributes
 */
void TextBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement)
{
    Q_UNUSED(doc);

    QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();

    blockElement.setAttribute("tag",getTag());

    // only write these if different from defaults
    if (getIndentationLevel())
        blockElement.setAttribute("indentLevel", QString::number(getIndentationLevel()));
    if (!m_text.isEmpty())
        blockElement.setAttribute("text", encodeText(m_text, endLine));
    if (!getWriteOutText())
        blockElement.setAttribute("writeOutText", getWriteOutText()?"true":"false");
    if (!canDelete())
        blockElement.setAttribute("canDelete", canDelete()?"true":"false");
}
Beispiel #2
0
void TextEditWidget::formatText( int changedPosition )
{
   // check if it's the new line that was created
   QTextCursor cursor = m_editor->textCursor();
   QString text = m_editor->document()->toPlainText();
   if ( changedPosition < 0 || changedPosition >= text.length() )
   {
      return;
   }

   // check if a tab should be inserted
   int tabsToInsert = 0;
   int tabsInsertionPos = 0;
   QChar newChar = text.at( changedPosition );
   if ( newChar == '\n' )
   {
      tabsToInsert = getIndentationLevel( text, changedPosition );

      // insert tabs
      cursor.setPosition( changedPosition + 1 );
      for( int i = 0; i < tabsToInsert; ++i )
      {
         cursor.insertText( "\t" );
      }
   }

   if ( newChar == '}' && changedPosition > 0 )
   {
      QChar prevChar;
      int testedPos = changedPosition - 1;
      int removalStartPos = -1;
      do
      {
         prevChar = text.at( testedPos );
         --testedPos;

         if ( prevChar == '\t' && removalStartPos < 0 )
         {
            removalStartPos = testedPos + 1;
         }
      } while ( prevChar == '\t' || prevChar == ' ' );

      if ( prevChar == '\n' && removalStartPos >= 0 )
      {
         // remove one tab
         cursor.setPosition( removalStartPos );
         cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, changedPosition - removalStartPos );
         cursor.removeSelectedText();
      }
   }
}