• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.14
  • kdesdk
  • umbrello
  • umbrello
  • codegenerators
  • ruby
rubycodedocumentation.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2005 *
8  * Richard Dale <Richard_Dale@tipitina.demon.co.uk> *
9  * copyright (C) 2006-2014 *
10  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
11  ***************************************************************************/
12 
13 // own header
14 #include "rubycodedocumentation.h"
15 
16 // local includes
17 #include "rubyclassifiercodedocument.h"
18 #include "rubycodegenerationpolicy.h"
19 #include "uml.h"
20 
21 // qt includes
22 #include <QRegExp>
23 
24 RubyCodeDocumentation::RubyCodeDocumentation(RubyClassifierCodeDocument * doc, const QString & text)
25  : CodeComment((CodeDocument*) doc, text)
26 {
27 }
28 
29 RubyCodeDocumentation::~RubyCodeDocumentation()
30 {
31 }
32 
33 void RubyCodeDocumentation::saveToXMI(QDomDocument & doc, QDomElement & root)
34 {
35  QDomElement blockElement = doc.createElement(QLatin1String("rubycodedocumentation"));
36  setAttributesOnNode(doc, blockElement); // as we added no additional fields to this class we may
37  // just use parent TextBlock method
38  root.appendChild(blockElement);
39 }
40 
41 QString RubyCodeDocumentation::toString() const
42 {
43  QString output;
44 
45  // simple output method
46  if (getWriteOutText())
47  {
48  bool useHashOutput = true;
49 
50  // need to figure out output type from ruby policy
51  CodeGenerationPolicy *p = UMLApp::app()->commonPolicy();
52  if (p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
53  useHashOutput = false;
54 
55  QString indent = getIndentationString();
56  QString endLine = getNewLineEndingChars();
57  QString body = getText();
58  if (useHashOutput)
59  {
60  if (!body.isEmpty())
61  output.append(formatMultiLineText (body, indent + QLatin1String("# "), endLine));
62  } else {
63  output.append(QLatin1String("=begin rdoc") + endLine);
64  output.append(formatMultiLineText (body, indent + QLatin1Char(' '), endLine));
65  output.append(QLatin1String("=end") + endLine);
66  }
67  }
68 
69  return output;
70 }
71 
72 QString RubyCodeDocumentation::getNewEditorLine(int amount)
73 {
74  CodeGenerationPolicy *p = UMLApp::app()->commonPolicy();
75  if (p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
76  return getIndentationString(amount) + QLatin1Char(' ');
77  else
78  return getIndentationString(amount) + QLatin1String("# ");
79 }
80 
81 int RubyCodeDocumentation::firstEditableLine()
82 {
83  CodeGenerationPolicy *p = UMLApp::app()->commonPolicy();
84  if (p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
85  return 1;
86  return 0;
87 }
88 
89 int RubyCodeDocumentation::lastEditableLine()
90 {
91  CodeGenerationPolicy *p = UMLApp::app()->commonPolicy();
92  if (p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
93  {
94  return -1; // very last line is NOT editable
95  }
96  return 0;
97 }
98 
99 QString RubyCodeDocumentation::unformatText(const QString & text, const QString & indent)
100 {
101  QString mytext = TextBlock::unformatText(text, indent);
102  CodeGenerationPolicy *p = UMLApp::app()->commonPolicy();
103  // remove leading or trailing comment stuff
104  mytext.remove(QRegExp(QLatin1Char('^') + indent));
105  if (p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
106  {
107  mytext.remove(QRegExp(QLatin1String("^=begin\\s*(rdoc)?\\s*\n?")));
108  mytext.remove(QRegExp(QLatin1String("^=end\\s*\n?$")));
109  } else
110  mytext.remove(QRegExp(QLatin1String("^#\\s*")));
111 
112  return mytext;
113 }
QString::append
QString & append(QChar ch)
QDomNode::appendChild
QDomNode appendChild(const QDomNode &newChild)
rubycodegenerationpolicy.h
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:214
CodeGenerationPolicy
class CodeGenerationPolicy This class describes the code generation policy for this project...
Definition: codegenerationpolicy.h:29
QString::remove
QString & remove(int position, int n)
TextBlock::getNewLineEndingChars
static QString getNewLineEndingChars()
Get the new line chars which ends the line.
Definition: textblock.cpp:172
RubyCodeDocumentation::RubyCodeDocumentation
RubyCodeDocumentation(RubyClassifierCodeDocument *doc, const QString &text=QString())
Constructors.
Definition: rubycodedocumentation.cpp:24
QRegExp
TextBlock::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: textblock.cpp:322
CodeGenerationPolicy::MultiLine
Definition: codegenerationpolicy.h:50
RubyClassifierCodeDocument
class RubyClassifierCodeDocument A Ruby UMLClassifier Code Document.
Definition: rubyclassifiercodedocument.h:36
QString::isEmpty
bool isEmpty() const
RubyCodeDocumentation::toString
QString toString() const
Definition: rubycodedocumentation.cpp:41
CodeDocument
A document containing the code for one file.
Definition: codedocument.h:32
rubycodedocumentation.h
RubyCodeDocumentation::unformatText
virtual QString unformatText(const QString &text, const QString &indent=QString())
UnFormat a long text string.
Definition: rubycodedocumentation.cpp:99
QString
UMLApp::commonPolicy
CodeGenerationPolicy * commonPolicy() const
Returns the default code generation policy.
Definition: uml.cpp:2219
QLatin1Char
QDomDocument
RubyCodeDocumentation::getNewEditorLine
virtual QString getNewEditorLine(int amount)
A special version here because we want to not only indent the new line, but to add the "# " sequence ...
Definition: rubycodedocumentation.cpp:72
QLatin1String
rubyclassifiercodedocument.h
TextBlock::formatMultiLineText
static QString formatMultiLineText(const QString &work, const QString &linePrefix, const QString &breakStr, bool addBreak=true, bool lastLineHasBreak=true)
Format a long text string to be more readable.
Definition: textblock.cpp:288
RubyCodeDocumentation::firstEditableLine
virtual int firstEditableLine()
Ush.
Definition: rubycodedocumentation.cpp:81
RubyCodeDocumentation::lastEditableLine
virtual int lastEditableLine()
Definition: rubycodedocumentation.cpp:89
RubyCodeDocumentation::~RubyCodeDocumentation
virtual ~RubyCodeDocumentation()
Empty Destructor.
Definition: rubycodedocumentation.cpp:29
TextBlock::getIndentationString
QString getIndentationString(int level=0) const
Get the actual amount of indentation for a given level of indentation.
Definition: textblock.cpp:193
TextBlock::getWriteOutText
bool getWriteOutText() const
Get the value of m_writeOutText Whether or not to include the text of this TextBlock into a file...
Definition: textblock.cpp:141
QDomDocument::createElement
QDomElement createElement(const QString &tagName)
CodeComment
Text which will be comments.
Definition: codecomment.h:23
QDomElement
CodeGenerationPolicy::getCommentStyle
CommentStyle getCommentStyle()
Get the value of m_commentStyle.
Definition: codegenerationpolicy.cpp:99
TextBlock::getText
QString getText() const
Get the value of m_text The actual text of this code block.
Definition: textblock.cpp:99
RubyCodeDocumentation::saveToXMI
virtual void saveToXMI(QDomDocument &doc, QDomElement &root)
Save the XMI representation of this object.
Definition: rubycodedocumentation.cpp:33
uml.h
TextBlock::unformatText
virtual QString unformatText(const QString &text, const QString &indent=QString())
UnFormat a long text string.
Definition: textblock.cpp:253
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal