astyle_adaptor.cpp
Go to the documentation of this file.00001 #include "astyle_adaptor.h"
00002
00003 #include <string>
00004
00005 #include <kapplication.h>
00006 #include <kconfig.h>
00007
00008
00009
00010 ASStringIterator::ASStringIterator(const QString &text)
00011 : ASSourceIterator(), _content(text)
00012 {
00013 _is = new QTextStream(&_content, IO_ReadOnly);
00014 }
00015
00016
00017 ASStringIterator::~ASStringIterator()
00018 {
00019 delete _is;
00020 }
00021
00022
00023 bool ASStringIterator::hasMoreLines() const
00024 {
00025 return !_is->eof();
00026 }
00027
00028
00029 string ASStringIterator::nextLine()
00030 {
00031 return _is->readLine().utf8().data();
00032 }
00033
00034
00035
00036
00037 KDevFormatter::KDevFormatter()
00038 {
00039 KConfig *config = kapp->config();
00040 config->setGroup("AStyle");
00041
00042
00043 QString s = config->readEntry("Style");
00044 if (s == "ANSI")
00045 {
00046 setBracketIndent(false);
00047 setSpaceIndentation(4);
00048 setBracketFormatMode(BREAK_MODE);
00049 setClassIndent(false);
00050 setSwitchIndent(false);
00051 setNamespaceIndent(false);
00052 return;
00053 }
00054 if (s == "KR")
00055 {
00056 setBracketIndent(false);
00057 setSpaceIndentation(4);
00058 setBracketFormatMode(ATTACH_MODE);
00059 setClassIndent(false);
00060 setSwitchIndent(false);
00061 setNamespaceIndent(false);
00062 return;
00063 }
00064 if (s == "Linux")
00065 {
00066 setBracketIndent(false);
00067 setSpaceIndentation(8);
00068 setBracketFormatMode(BDAC_MODE);
00069 setClassIndent(false);
00070 setSwitchIndent(false);
00071 setNamespaceIndent(false);
00072 return;
00073 }
00074 if (s == "GNU")
00075 {
00076 setBlockIndent(true);
00077 setSpaceIndentation(2);
00078 setBracketFormatMode(BREAK_MODE);
00079 setClassIndent(false);
00080 setSwitchIndent(false);
00081 setNamespaceIndent(false);
00082 return;
00083 }
00084 if (s == "JAVA")
00085 {
00086 setJavaStyle();
00087 setBracketIndent(false);
00088 setSpaceIndentation(4);
00089 setBracketFormatMode(ATTACH_MODE);
00090 setSwitchIndent(false);
00091 return;
00092 }
00093
00094
00095 if (config->readEntry("Fill", "Tabs") != "Tabs")
00096 setSpaceIndentation(config->readNumEntry("FillSpaces",2));
00097 else
00098 setTabIndentation();
00099
00100
00101 setSwitchIndent(config->readBoolEntry("IndentSwitches", false));
00102 setClassIndent(config->readBoolEntry("IndentClasses", false));
00103 setCaseIndent(config->readBoolEntry("IndentCases", false));
00104 setBracketIndent(config->readBoolEntry("IndentBrackets", false));
00105 setNamespaceIndent(config->readBoolEntry("IndentNamespaces", true));
00106 setLabelIndent(config->readBoolEntry("IndentLabels", true));
00107
00108
00109 setMaxInStatementIndentLength(config->readNumEntry("MaxStatement", 40));
00110 if (config->readNumEntry("MinConditional", -1) != -1)
00111 setMinConditionalIndentLength(config->readNumEntry("MinConditional"));
00112
00113
00114 s = config->readEntry("Brackets", "Break");
00115 if (s == "Break")
00116 setBracketFormatMode(BREAK_MODE);
00117 if (s == "Attach")
00118 setBracketFormatMode(ATTACH_MODE);
00119 if (s == "Linux")
00120 setBracketFormatMode(BDAC_MODE);
00121
00122
00123 setOperatorPaddingMode(config->readBoolEntry("PadOperators", false));
00124 setParenthesisPaddingMode(config->readBoolEntry("PadOperators", false));
00125
00126
00127 setBreakOneLineBlocksMode(config->readBoolEntry("KeepBlocks", false));
00128 setSingleStatementsMode(config->readBoolEntry("KeepStatements", false));
00129 }
This file is part of the documentation for KDevelop Version 3.1.2.