umbrello API Documentation

diagramprintpage.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2002-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "diagramprintpage.h"
00014 
00015 // qt/kde includes
00016 #include <qlayout.h>
00017 #include <qptrlist.h>
00018 #include <qlistbox.h>
00019 #include <qradiobutton.h>
00020 #include <qcombobox.h>
00021 #include <qbuttongroup.h>
00022 #include <qgroupbox.h>
00023 #include <klocale.h>
00024 
00025 // local includes
00026 #include "../uml.h"
00027 #include "../umldoc.h"
00028 #include "../umlview.h"
00029 #include "../umlviewlist.h"
00030 #include "../umlnamespace.h"
00031 
00032 
00033 DiagramPrintPage::DiagramPrintPage(QWidget * parent, UMLDoc * m_pDoc) : KPrintDialogPage(parent), m_pDoc(m_pDoc) {
00034     int margin = fontMetrics().height();
00035     setTitle(i18n("&Diagrams"));
00036     QHBoxLayout * mainLayout = new QHBoxLayout(this);
00037     mainLayout -> setSpacing(10);
00038     mainLayout -> setMargin(margin);
00039 
00040     m_pFilterBG = new QButtonGroup(i18n("Filter"), this);
00041     mainLayout -> addWidget(m_pFilterBG);
00042     m_pFilterBG -> setExclusive(true);
00043 
00044     QVBoxLayout * filter = new QVBoxLayout(m_pFilterBG);
00045     filter -> setSpacing(10);
00046     filter-> setMargin(margin);
00047 
00048     m_pCurrentRB = new QRadioButton(i18n("&Current diagram"), m_pFilterBG);
00049     filter -> addWidget(m_pCurrentRB);
00050     m_pCurrentRB -> setChecked(true);
00051     m_pFilterBG -> insert(m_pCurrentRB, Current);
00052 
00053     m_pAllRB = new QRadioButton(i18n("&All diagrams"), m_pFilterBG);
00054     filter -> addWidget(m_pAllRB);
00055     m_pFilterBG -> insert(m_pAllRB, All);
00056 
00057     m_pSelectRB = new QRadioButton(i18n("&Select diagrams"), m_pFilterBG);
00058     filter -> addWidget(m_pSelectRB);
00059     m_pFilterBG -> insert(m_pSelectRB, Select);
00060 
00061     m_pTypeRB = new QRadioButton(i18n("&Type of diagram"), m_pFilterBG);
00062     filter -> addWidget(m_pTypeRB);
00063     m_pFilterBG -> insert(m_pTypeRB, Type);
00064 
00065     m_pSelectGB = new QGroupBox(i18n("Selection"), this);
00066     mainLayout -> addWidget(m_pSelectGB);
00067 
00068     QVBoxLayout * select = new QVBoxLayout(m_pSelectGB);
00069     select -> setSpacing(10);
00070     select-> setMargin(margin);
00071 
00072     m_pTypeCB = new QComboBox(m_pSelectGB);
00073     select -> addWidget(m_pTypeCB);
00074     m_pTypeCB -> setEnabled(false);
00075 
00076     m_pSelectLB = new QListBox(m_pSelectGB);
00077     select -> addWidget(m_pSelectLB);
00078     m_pSelectLB -> setEnabled(false);
00079     m_pSelectLB -> setSelectionMode(QListBox::Multi);
00080     m_pSelectLB -> insertItem(UMLApp::app()->getCurrentView()->getName());
00081     m_pSelectLB -> setSelected(0, true);
00082     m_nIdList.clear();
00083     m_nIdList.append(UMLApp::app()->getCurrentView()->getID());
00084 
00085 
00086 
00087     m_ViewType = Uml::dt_Class;
00088     connect(m_pFilterBG, SIGNAL(clicked(int)), this, SLOT(slotClicked(int)));
00089     connect(m_pTypeCB, SIGNAL(activated(const QString&)), this, SLOT(slotActivated(const QString&)));
00090 
00091     m_pTypeCB -> insertItem(i18n("Class"));
00092     m_pTypeCB -> insertItem(i18n("Use Case"));
00093     m_pTypeCB -> insertItem(i18n("Collaboration"));
00094     m_pTypeCB -> insertItem(i18n("Sequence"));
00095     m_pTypeCB -> insertItem(i18n("State"));
00096     m_pTypeCB -> insertItem(i18n("Activity"));
00097     m_pTypeCB -> insertItem(i18n("Component"));
00098     m_pTypeCB -> insertItem(i18n("Deployment"));
00099 }
00100 
00101 DiagramPrintPage::~DiagramPrintPage()
00102 {
00103     disconnect(m_pFilterBG, SIGNAL(clicked(int)), this, SLOT(slotClicked(int)));
00104     disconnect(m_pTypeCB, SIGNAL(activated(const QString&)), this, SLOT(slotActivated(const QString&)));
00105 }
00106 
00107 void DiagramPrintPage::getOptions( QMap<QString,QString>& opts, bool /*incldef = false*/ ) {
00108     int listCount = m_pSelectLB -> count();
00109     int count = 0;
00110 
00111     QString diagram(i18n("kde-uml-Diagram"));
00112     for(int     i=0;i<listCount;i++) {
00113         if(m_pSelectLB -> isSelected(i)) {
00114             UMLView *view = (UMLView *)m_pDoc -> findView(m_nIdList[i]);
00115             QString sCount = QString("%1").arg(count);
00116             QString sID = QString("%1").arg(ID2STR(view -> getID()));
00117             opts.insert(diagram + sCount, sID);
00118             count++;
00119         }
00120     }
00121     opts.insert("kde-uml-count", QString("%1").arg(count));
00122 }
00123 
00124 void DiagramPrintPage::setOptions( const QMap<QString,QString>& /*opts*/ ) {}
00125 
00126 bool DiagramPrintPage::isValid( QString& msg ) {
00127     int listCount = m_pSelectLB -> count();
00128     bool sel = false;
00129     for(int i =0;i<listCount;i++) {
00130         if(m_pSelectLB -> isSelected(i)) {
00131             sel = true;
00132             i = listCount;
00133         }
00134     }
00135     msg = i18n("No diagrams selected.");
00136     return sel;
00137 }
00138 
00139 void DiagramPrintPage::slotClicked(int id) {
00140     UMLViewList list = m_pDoc -> getViewIterator();
00141     UMLView * view = 0;
00142     QString type;
00143 
00144     // clear list with diagrams to print
00145     m_nIdList.clear();
00146 
00147     switch(id) {
00148     case Current:
00149         m_pTypeCB -> setEnabled(false);
00150         m_pSelectLB -> setEnabled(false);
00151         m_pSelectLB -> clear();
00152         m_pSelectLB -> insertItem(UMLApp::app()->getCurrentView()->getName());
00153         m_pSelectLB -> setSelected(0, true);
00154         m_nIdList.append(UMLApp::app()->getCurrentView()->getID());
00155         break;
00156 
00157     case All:
00158 
00159         m_pTypeCB -> setEnabled(false);
00160         m_pSelectLB -> setEnabled(false);
00161         m_pSelectLB -> clear();
00162         for(view = list.first(); view; view = list.next()) {
00163             m_pSelectLB -> insertItem(view -> getName());
00164             m_nIdList.append(view -> getID());
00165         }
00166         m_pSelectLB -> selectAll(true);
00167         break;
00168 
00169     case Select:
00170         m_pTypeCB -> setEnabled(false);
00171         m_pSelectLB -> setEnabled(true);
00172         m_pSelectLB -> clear();
00173         for(view = list.first(); view; view = list.next()) {
00174             m_pSelectLB -> insertItem(view -> getName());
00175             m_nIdList.append(view -> getID());
00176         }
00177         break;
00178 
00179     case Type:
00180         m_pTypeCB -> setEnabled(true);
00181         m_pSelectLB -> setEnabled(true);
00182         m_pSelectLB -> clear();
00183         for(view = list.first(); view; view = list.next()) {
00184             if(view -> getType() == m_ViewType) {
00185                 m_pSelectLB -> insertItem(view -> getName());
00186                 m_nIdList.append(view -> getID());
00187             }
00188         }
00189         m_pSelectLB -> selectAll(true);
00190         break;
00191     }
00192 }
00193 
00194 void DiagramPrintPage::slotActivated(const QString & text) {
00195     UMLViewList list = m_pDoc -> getViewIterator();
00196     UMLView * view = 0;
00197 
00198     if(text == i18n("Class"))
00199         m_ViewType = Uml::dt_Class;
00200     else if(text == i18n("Sequence"))
00201         m_ViewType = Uml::dt_Sequence;
00202     else if(text == i18n("Use Case"))
00203         m_ViewType = Uml::dt_UseCase;
00204     else if(text == i18n("Collaboration"))
00205         m_ViewType = Uml::dt_Collaboration;
00206     else if(text == i18n("State"))
00207         m_ViewType = Uml::dt_State;
00208     else if(text == i18n("Activity"))
00209         m_ViewType = Uml::dt_Activity;
00210     else if(text == i18n("Component"))
00211         m_ViewType = Uml::dt_Component;
00212     else if(text == i18n("Deployment"))
00213         m_ViewType = Uml::dt_Deployment;
00214     m_pSelectLB -> clear();
00215     m_nIdList.clear();
00216     for(view = list.first(); view; view = list.next()) {
00217         if(view -> getType() == m_ViewType) {
00218             m_pSelectLB -> insertItem(view -> getName());
00219             m_nIdList.append(view -> getID());
00220         }
00221     }
00222     m_pSelectLB -> selectAll(true);
00223 }
00224 
00225 #include "diagramprintpage.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:56 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003