codegenerationoptionspage.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "codegenerationoptionspage.h"
00019
00020 #include <qcheckbox.h>
00021 #include <kdebug.h>
00022
00023 #include "../codegenerator.h"
00024 #include "codegenerationpolicypage.h"
00025 #include "../codegenerators/codegenpolicyext.h"
00026 #include "defaultcodegenpolicypage.h"
00027 #include "../model_utils.h"
00028 #include "../uml.h"
00029
00030
00031 #include <knuminput.h>
00032 #include <kfiledialog.h>
00033 #include <klocale.h>
00034
00035
00036 #include <qlineedit.h>
00037 #include <qlistview.h>
00038 #include <qbuttongroup.h>
00039
00040 CodeGenerationOptionsPage::CodeGenerationOptionsPage(QWidget *parent)
00041 : CodeGenerationOptionsBase(parent)
00042 {
00043 init();
00044 }
00045
00046 CodeGenerationOptionsPage::~CodeGenerationOptionsPage() { }
00047
00048 void CodeGenerationOptionsPage::init()
00049 {
00050 m_pCodePolicyPage = 0;
00051
00052 CodeGenerationPolicy *policy = UMLApp::app()->getCommonPolicy();
00053 m_parentPolicy = policy;
00054 CodeGenerator *gen = UMLApp::app()->getGenerator();
00055
00056 m_forceDoc->setChecked(policy->getCodeVerboseDocumentComments());
00057 m_forceSections->setChecked(policy->getCodeVerboseSectionComments());
00058
00059 m_outputDir->setText(policy->getOutputDirectory().absPath());
00060 m_includeHeadings->setChecked(policy->getIncludeHeadings());
00061 m_headingsDir->setText(policy->getHeadingFileDir());
00062 m_overwriteGroup->setButton(overwriteToInteger(policy->getOverwritePolicy()));
00063
00064 m_SelectEndLineCharsBox->setCurrentItem(newLineToInteger(policy->getLineEndingType()));
00065 m_SelectIndentationTypeBox->setCurrentItem(indentTypeToInteger(policy->getIndentationType()));
00066 m_SelectIndentationNumber->setValue(policy->getIndentationAmount());
00067
00068 connect(this,SIGNAL(syncCodeDocumentsToParent()),gen,SLOT(syncCodeToDocument()));
00069
00070
00071 updateCodeGenerationPolicyTab();
00072
00073 setupActiveLanguageBox();
00074 }
00075
00076 void CodeGenerationOptionsPage::setupActiveLanguageBox()
00077 {
00078 int indexCounter = 0;
00079 while (indexCounter < Uml::pl_Reserved) {
00080 QString language = Model_Utils::progLangToString((Uml::Programming_Language) indexCounter);
00081 m_SelectLanguageBox->insertItem(language, indexCounter);
00082 indexCounter++;
00083 }
00084 m_SelectLanguageBox->setCurrentItem(UMLApp::app()->getActiveLanguage());
00085 }
00086
00087 int CodeGenerationOptionsPage::indentTypeToInteger(CodeGenerationPolicy::IndentationType value) {
00088 switch (value) {
00089 case CodeGenerationPolicy::SPACE:
00090 return 2;
00091 case CodeGenerationPolicy::TAB:
00092 return 1;
00093 default:
00094 case CodeGenerationPolicy::NONE:
00095 return 0;
00096 }
00097 }
00098
00099 int CodeGenerationOptionsPage::newLineToInteger(CodeGenerationPolicy::NewLineType value) {
00100 switch (value) {
00101 case CodeGenerationPolicy::DOS:
00102 return 1;
00103 case CodeGenerationPolicy::MAC:
00104 return 2;
00105 default:
00106 case CodeGenerationPolicy::UNIX:
00107 return 0;
00108 }
00109 }
00110
00111
00112 int CodeGenerationOptionsPage::overwriteToInteger(CodeGenerationPolicy::OverwritePolicy value) {
00113 switch (value) {
00114 case CodeGenerationPolicy::Ok:
00115 return 0;
00116 case CodeGenerationPolicy::Never:
00117 return 2;
00118 default:
00119 case CodeGenerationPolicy::Ask:
00120 return 1;
00121 }
00122 }
00123
00124 void CodeGenerationOptionsPage::updateCodeGenerationPolicyTab() {
00125
00126 if(m_pCodePolicyPage)
00127 {
00128 m_pCodePolicyPage->disconnect();
00129 m_pCodePolicyPage = 0;
00130 }
00131
00132 CodeGenPolicyExt *policyExt = UMLApp::app()->getPolicyExt();
00133 if (policyExt)
00134 m_pCodePolicyPage = policyExt->createPage(languageOptionsFrame, "codelangpolicypage");
00135 else
00136 m_pCodePolicyPage = new DefaultCodeGenPolicyPage(languageOptionsFrame, "codelangpolicypage");
00137
00138 connect(this,SIGNAL(applyClicked()),m_pCodePolicyPage,SLOT(apply()));
00139
00140 }
00141
00142 void CodeGenerationOptionsPage::apply() {
00143
00144 if(m_parentPolicy) {
00145
00146 m_parentPolicy->setCodeVerboseDocumentComments(m_forceDoc->isChecked());
00147 m_parentPolicy->setCodeVerboseSectionComments(m_forceSections->isChecked());
00148 m_parentPolicy->setOutputDirectory(QDir(m_outputDir->text()));
00149 m_parentPolicy->setIncludeHeadings(m_includeHeadings->isChecked());
00150 m_parentPolicy->setHeadingFileDir(m_headingsDir->text());
00151 m_parentPolicy->setOverwritePolicy((CodeGenerationPolicy::OverwritePolicy)m_overwriteGroup->id(m_overwriteGroup->selected()));
00152 m_parentPolicy->setLineEndingType((CodeGenerationPolicy::NewLineType) m_SelectEndLineCharsBox->currentItem());
00153 m_parentPolicy->setIndentationType((CodeGenerationPolicy::IndentationType) m_SelectIndentationTypeBox->currentItem());
00154 m_parentPolicy->setIndentationAmount(m_SelectIndentationNumber->value());
00155
00156
00157
00158
00159 emit applyClicked();
00160 emit syncCodeDocumentsToParent();
00161 }
00162 }
00163
00164 void CodeGenerationOptionsPage::activeLanguageChanged(int )
00165 {
00166 emit languageChanged();
00167 }
00168
00169 void CodeGenerationOptionsPage::setDefaults() {
00170 }
00171
00172 void CodeGenerationOptionsPage::browseClicked() {
00173
00174 QString button = sender()->name();
00175 QString dir = KFileDialog::getExistingDirectory();
00176 if(dir.isEmpty())
00177 return;
00178 if(button=="m_browseOutput")
00179 m_outputDir->setText(dir);
00180 else if(button=="m_browseHeadings")
00181 m_headingsDir->setText(dir);
00182 }
00183
00184 QString CodeGenerationOptionsPage::getCodeGenerationLanguage() {
00185 return m_SelectLanguageBox->currentText();
00186 }
00187
00188 #include "codegenerationoptionspage.moc"
This file is part of the documentation for umbrello Version 3.1.0.