kivio

kivio_map.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include <qprinter.h>
00020 #include <qdom.h>
00021 #include <qmessagebox.h>
00022 
00023 #include <KoStore.h>
00024 #include <KoXmlWriter.h>
00025 #include <KoGenStyles.h>
00026 
00027 #include "kivio_map.h"
00028 #include "kivio_doc.h"
00029 #include "kivio_view.h"
00030 #include "kivio_canvas.h"
00031 #include "kivio_page.h"
00032 #include "KIvioMapIface.h"
00033 
00034 #include <time.h>
00035 #include <stdlib.h>
00036 
00037 KivioMap::KivioMap( KivioDoc* doc, const char* name )
00038 : QObject(doc,name)
00039 {
00040   m_pDoc = doc;
00041   m_lstPages.setAutoDelete(true);
00042   m_dcop = 0;
00043 
00044 }
00045 
00046 KivioMap::~KivioMap()
00047 {
00048     delete m_dcop;
00049 
00050 }
00051 
00052 void KivioMap::takePage( KivioPage* page )
00053 {
00054     int pos=m_lstPages.findRef(page);
00055     m_lstPages.take( pos );
00056     m_lstDeletedPages.append( page );
00057 }
00058 
00059 void KivioMap::insertPage( KivioPage* page )
00060 {
00061     int pos=m_lstDeletedPages.findRef(page);
00062     if ( pos != -1 )
00063         m_lstDeletedPages.take( pos);
00064     m_lstPages.append(page);
00065 }
00066 
00067 void KivioMap::addPage( KivioPage* page )
00068 {
00069   m_lstPages.append(page);
00070 }
00071 
00072 void KivioMap::movePage( const QString& fromPageName, const QString& toPageName, bool before )
00073 {
00074   KivioPage* pagefrom = findPage(fromPageName);
00075   KivioPage* pageto = findPage(toPageName);
00076 
00077   int from = m_lstPages.find(pagefrom);
00078   int to = m_lstPages.find(pageto);
00079   if (!before)
00080     ++to;
00081 
00082   if ( to > (int)m_lstPages.count() ) {
00083     m_lstPages.append(pagefrom);
00084     m_lstPages.take(from);
00085   } else
00086     if ( from < to ) {
00087       m_lstPages.insert(to,pagefrom);
00088       m_lstPages.take(from);
00089     } else {
00090       m_lstPages.take(from);
00091       m_lstPages.insert(to,pagefrom);
00092     }
00093 }
00094 
00095 QDomElement KivioMap::save( QDomDocument& doc )
00096 {
00097     int next = 1;
00098 
00099   QDomElement mymap = doc.createElement("KivioMap");
00100 
00101   // Before we save, tell all the pages/layers/stencil/targets/connectors to generate
00102   // their ids so we can restore connections when reloaded.
00103   QPtrListIterator<KivioPage> it2(m_lstPages);
00104   for( ; it2.current(); ++it2 )
00105   {
00106     next = it2.current()->generateStencilIds( next );
00107   }
00108 
00109   // Now save the pages
00110   QPtrListIterator<KivioPage> it(m_lstPages);
00111   for( ; it.current(); ++it )
00112   {
00113     QDomElement e = it.current()->save(doc);
00114     if (e.isNull())
00115       return e;
00116     mymap.appendChild(e);
00117   }
00118 
00119   return mymap;
00120 }
00121 
00122 void KivioMap::saveOasis(KoStore* store, KoXmlWriter* docWriter, KoGenStyles* styles)
00123 {
00124   QPtrListIterator<KivioPage> it(m_lstPages);
00125   
00126   for( ; it.current(); ++it )
00127   {
00128     it.current()->saveOasis(store, docWriter, styles);
00129   }
00130 }
00131 
00132 bool KivioMap::loadXML( const QDomElement& mymap )
00133 {
00134   m_lstPages.clear();
00135   m_lstDeletedPages.clear();
00136 
00137   // FIXME: make this load the real page units and whatever
00138   // else
00139   QDomNode n = mymap.firstChild();
00140   while( !n.isNull() ) {
00141     QDomElement e = n.toElement();
00142     if ( !e.isNull() && e.tagName() == "KivioPage" ) {
00143       KivioPage *t = m_pDoc->createPage();
00144       m_pDoc->addPage( t );
00145       if ( !t->loadXML( e ) )
00146         return false;
00147     }
00148     n = n.nextSibling();
00149   }
00150   return true;
00151 }
00152 
00153 void KivioMap::update()
00154 {
00155   QPtrListIterator<KivioPage> it( m_lstPages );
00156   for( ; it.current(); ++it )
00157     it.current()->update();
00158 }
00159 
00160 KivioPage* KivioMap::findPage( const QString& name )
00161 {
00162   KivioPage *t;
00163 
00164   for ( t = m_lstPages.first(); t; t = m_lstPages.next() ) {
00165     if ( name == t->pageName() )
00166       return t;
00167     }
00168 
00169   return 0L;
00170 }
00171 
00172 KivioDoc* KivioMap::doc()const
00173 {
00174   return m_pDoc;
00175 }
00176 
00177 KivioPage* KivioMap::firstPage()
00178 {
00179   return m_lstPages.first();
00180 }
00181 
00182 KivioPage* KivioMap::lastPage()
00183 {
00184   return m_lstPages.last();
00185 }
00186 
00187 KivioPage* KivioMap::nextPage()
00188 {
00189   return m_lstPages.next();
00190 }
00191 
00192 int KivioMap::count() const
00193 {
00194   return m_lstPages.count();
00195 }
00196 
00197 DCOPObject* KivioMap::dcopObject()
00198 {
00199     if ( !m_dcop )
00200         m_dcop = new KIvioMapIface( this );
00201 
00202     return m_dcop;
00203 }
00204 
00205 QStringList KivioMap::visiblePages() const
00206 {
00207   QStringList pages;
00208   
00209   QPtrListIterator<KivioPage> it( m_lstPages );
00210   for( ; it.current(); ++it )
00211   {
00212     KivioPage* page = it.current();
00213     if( !page->isHidden() )
00214       pages.append( page->pageName() );
00215   }
00216   
00217   return pages;
00218 }
00219 
00220 QStringList KivioMap::hiddenPages() const
00221 {
00222   QStringList pages;
00223   
00224   QPtrListIterator<KivioPage> it( m_lstPages );
00225   for( ; it.current(); ++it )
00226   {
00227     KivioPage* page = it.current();
00228     if( page->isHidden() )
00229       pages.append( page->pageName() );
00230   }
00231   
00232   return pages;
00233 }
00234 
00235 void KivioMap::clear()
00236 {
00237   m_lstPages.clear();
00238   m_lstDeletedPages.clear();
00239 }
KDE Home | KDE Accessibility Home | Description of Access Keys