kivio
kivio_map.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00102
00103 QPtrListIterator<KivioPage> it2(m_lstPages);
00104 for( ; it2.current(); ++it2 )
00105 {
00106 next = it2.current()->generateStencilIds( next );
00107 }
00108
00109
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
00138
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 }
|