umbrello API Documentation

codegenerationoptionspage.cpp

00001 /***************************************************************************
00002     begin                : Thu Jul 25 2002
00003     copyright            : (C) 2002 by Luis De la Parra
00004     email                : luis@delaparra.org
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   copyright (C) 2003-2006                                               *
00015  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00016  ***************************************************************************/
00017 // own header
00018 #include "codegenerationoptionspage.h"
00019 // qt/kde includes
00020 #include <qcheckbox.h>
00021 #include <kdebug.h>
00022 // app includes
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 //kde include
00031 #include <knuminput.h>
00032 #include <kfiledialog.h>
00033 #include <klocale.h>
00034 
00035 //qt include
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     // now insert the language-dependant page, should there be one
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 //0 = overwrite, 1 = ask, 2 = change name
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         // emit in THIS order.. the first signal triggers any sub-class to do its apply
00157         // slot, THEN, once we are all updated, we may sync the parent generator's code
00158         // documents
00159         emit applyClicked();
00160         emit syncCodeDocumentsToParent();
00161     }
00162 }
00163 
00164 void CodeGenerationOptionsPage::activeLanguageChanged(int /*id*/)
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"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003