Commit ae761f1b authored by Peter Simonsson's avatar Peter Simonsson

Begin implementing odf loading for kopageapp... only loads names of...

Begin implementing odf loading for kopageapp... only loads names of masterpages and pages and pagelayout atm

svn path=/trunk/koffice/; revision=693395
parent 23832c45
......@@ -19,6 +19,7 @@ set( kopageapp_LIB_SRCS
KoPAPage.cpp
KoPAViewMode.cpp
KoPAViewModeNormal.cpp
KoPALoadingContext.cpp
commands/KoPAPageInsertCommand.cpp
commands/KoPAPageDeleteCommand.cpp
commands/KoPAPageMoveCommand.cpp
......
......@@ -32,6 +32,8 @@
#include <KoShapeLayer.h>
#include <KoPathShape.h>
#include <KoLineBorder.h>
#include <KoDom.h>
#include <KoXmlNS.h>
#include "KoPACanvas.h"
#include "KoPAView.h"
......@@ -39,16 +41,16 @@
#include "KoPAMasterPage.h"
#include "KoPASavingContext.h"
#include "KoPAStyles.h"
#include "KoPALoadingContext.h"
KoPADocument::KoPADocument( QWidget* parentWidget, QObject* parent, bool singleViewMode )
: KoDocument( parentWidget, parent, singleViewMode )
{
KoPAMasterPage * masterPage = new KoPAMasterPage();
m_masterPages.append( masterPage );
insertPage( new KoPAPage( masterPage ), 0 /*add first*/ );
// KoPAMasterPage * masterPage = new KoPAMasterPage();
// m_masterPages.append( masterPage );
#ifndef NDEBUG
//TODO This produces some pages to be used for testing remove when we have loading support
KoPathShape *pathShape = new KoPathShape();
/* KoPathShape *pathShape = new KoPathShape();
pathShape->lineTo( QPointF( 100, 100 ) );
pathShape->setPosition( QPointF( 100, 100 ) );
pathShape->setBorder( new KoLineBorder( 1.0 ) );
......@@ -58,7 +60,7 @@ KoPADocument::KoPADocument( QWidget* parentWidget, QObject* parent, bool singleV
parentShape->addChild( pathShape );
}
insertPage( new KoPAPage( masterPage ), 1 );
insertPage( new KoPAPage( masterPage ), 2 );
insertPage( new KoPAPage( masterPage ), 2 );*/
#endif
}
......@@ -89,7 +91,24 @@ bool KoPADocument::loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisSty
Q_UNUSED( doc );
Q_UNUSED( settings );
emit sigProgress( 0 );
KoOasisLoadingContext loadingContext( this, oasisStyles, store );
KoPALoadingContext paContext( loadingContext );
KoXmlElement content = doc.documentElement();
KoXmlElement realBody ( KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
if ( realBody.isNull() ) {
kError() << "No body tag found!" << endl;
return false;
}
KoXmlElement body = KoDom::namedItemNS(realBody, KoXmlNS::office, odfTagName());
if ( body.isNull() ) {
kError() << "No office:" << odfTagName() << " tag found!" << endl;
return false;
}
//load master pages
const QHash<QString, KoXmlElement*> masterStyles( oasisStyles.masterPages() );
......@@ -97,9 +116,22 @@ bool KoPADocument::loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisSty
for ( ; it != masterStyles.constEnd(); ++it )
{
qDebug() << "Master:" << it.key();
m_masterPages[0]->loadOdf( *( it.value() ), loadingContext );
KoPAMasterPage * masterPage = new KoPAMasterPage();
masterPage->loadOdf( *( it.value() ), paContext );
m_masterPages.append( masterPage );
paContext.addMasterPage (it.key(), masterPage);
}
KoXmlElement pageElement;
forEachElement( pageElement, body )
{
KoPAPage* page = new KoPAPage();
page->loadOdf(pageElement, paContext);
insertPage( page, -1 );
}
emit sigProgress( 100 );
return true;
}
......
......@@ -21,13 +21,18 @@
#include <KoGenStyle.h>
#include <KoXmlWriter.h>
#include <KoXmlNS.h>
#include <KoOasisStyles.h>
#include <KoOasisLoadingContext.h>
#include "KoPASavingContext.h"
#include "KoPALoadingContext.h"
KoPAMasterPage::KoPAMasterPage()
: KoPAPageBase()
{
m_pageLayout = KoPageLayout::standardLayout();
setPageTitle ( "Standard" );
}
KoPAMasterPage::~KoPAMasterPage()
......@@ -42,7 +47,22 @@ void KoPAMasterPage::createOdfPageTag( KoPASavingContext &paContext ) const
QString pageLayoutName( paContext.mainStyles().lookup( pageLayoutStyle, "pm" ) );
paContext.xmlWriter().startElement( "style:master-page" );
paContext.xmlWriter().addAttribute( "style:name", "Standard" ); //TODO
paContext.addMasterPage( this, "Standard" );
paContext.xmlWriter().addAttribute( "style:name", pageTitle() );
paContext.addMasterPage( this, pageTitle() );
paContext.xmlWriter().addAttribute( "style:page-layout-name", pageLayoutName );
}
void KoPAMasterPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
setPageTitle( element.attributeNS( KoXmlNS::style, "name" ) );
QString pageLayoutName = element.attributeNS( KoXmlNS::style, "page-layout-name" );
const KoOasisStyles& styles = loadingContext.koLoadingContext().oasisStyles();
const KoXmlElement* masterPageStyle = styles.findStyle( pageLayoutName );
KoPageLayout pageLayout = KoPageLayout::standardLayout();
if ( masterPageStyle ) {
pageLayout.loadOasis( *masterPageStyle );
}
setPageLayout( pageLayout );
}
......@@ -42,6 +42,9 @@ public:
protected:
virtual void createOdfPageTag( KoPASavingContext &paContext ) const;
/// Reimplemented from KoPageBase
virtual void loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext );
KoPageLayout m_pageLayout;
};
......
......@@ -22,9 +22,11 @@
#include <KoShapeSavingContext.h>
#include <KoShapeLayer.h>
#include <KoXmlWriter.h>
#include <KoXmlNS.h>
#include "KoPAMasterPage.h"
#include "KoPASavingContext.h"
#include "KoPALoadingContext.h"
KoPAPage::KoPAPage( KoPAMasterPage * masterPage )
: KoPAPageBase()
......@@ -32,12 +34,20 @@ KoPAPage::KoPAPage( KoPAMasterPage * masterPage )
{
}
KoPAPage::KoPAPage()
:KoPAPageBase()
, m_masterPage( 0 )
{
}
KoPAPage::~KoPAPage()
{
}
KoPageLayout & KoPAPage::pageLayout()
{
Q_ASSERT( m_masterPage );
return m_masterPage->pageLayout();
}
......@@ -47,3 +57,15 @@ void KoPAPage::createOdfPageTag( KoPASavingContext &paContext ) const
paContext.xmlWriter().addAttribute( "draw:id", "page" + QString::number( paContext.page() ) );
paContext.xmlWriter().addAttribute( "draw:master-page-name", paContext.masterPageName( m_masterPage ) );
}
void KoPAPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
setPageTitle( element.attributeNS( KoXmlNS::draw, "name" ) );
QString master = element.attributeNS (KoXmlNS::draw, "master-page-name" );
setMasterPage( loadingContext.masterPageFromName( master ) );
}
void KoPAPage::setMasterPage( KoPAMasterPage * masterPage )
{
m_masterPage = masterPage;
}
......@@ -32,6 +32,7 @@ public:
* @param masterPage masterpage used for this page
*/
explicit KoPAPage( KoPAMasterPage * masterPage );
KoPAPage ();
~KoPAPage();
/// @return the layout set by the masterpage
......@@ -44,6 +45,9 @@ public:
protected:
virtual void createOdfPageTag( KoPASavingContext &paContext ) const;
/// Reimplemented from KoPageBase
virtual void loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext );
KoPAMasterPage * m_masterPage;
};
......
......@@ -20,6 +20,7 @@
#include "KoPAPageBase.h"
#include "KoPASavingContext.h"
#include "KoPAStyles.h"
#include "KoPALoadingContext.h"
#include <QDebug>
#include <QPainter>
......@@ -74,10 +75,6 @@ void KoPAPageBase::saveOdf( KoShapeSavingContext & context ) const
context.xmlWriter().endElement(); //draw:page
}
bool KoPAPageBase::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context ) {
return false; // TODO
}
void KoPAPageBase::saveOdfShapes( KoShapeSavingContext &context ) const
{
QList<KoShape*> shapes( iterator() );
......@@ -122,8 +119,12 @@ void KoPAPageBase::saveOdfPageStyleData( KoGenStyle &style, KoPASavingContext &p
KoOasisStyles::saveOasisFillStyle( style, paContext.mainStyles(), background );
}
bool KoPAPageBase::loadOdf( const KoXmlElement &element, KoOasisLoadingContext & loadingContext )
bool KoPAPageBase::loadOdf( const KoXmlElement &element, KoShapeLoadingContext & loadingContext )
{
KoPALoadingContext &paContext = static_cast<KoPALoadingContext&>( loadingContext );
loadOdfPageTag(element, paContext);
// load shapes, this is only for testing
KoXmlNode n = element.firstChild();
for ( ; !n.isNull(); n = n.nextSibling() )
......@@ -136,3 +137,7 @@ bool KoPAPageBase::loadOdf( const KoXmlElement &element, KoOasisLoadingContext &
}
return true;
}
void KoPAPageBase::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
}
......@@ -34,6 +34,7 @@ struct KoPageLayout;
class KoOasisLoadingContext;
class KoGenStyle;
class KoShape;
class KoPALoadingContext;
/**
* Base class used for KoPAMasterPage and KoPAPage
......@@ -60,8 +61,6 @@ public:
// reimplemented
virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext & context );
bool loadOdf( const KoXmlElement &element, KoOasisLoadingContext & loadingContext );
/// @return the layout of the page
virtual KoPageLayout & pageLayout() = 0;
......@@ -138,6 +137,14 @@ protected:
*/
virtual void saveOdfPageStyleData( KoGenStyle &style, KoPASavingContext &paContext ) const;
/**
* @brief Load page data
*
* @param element the page element
* @param paContext the pageapp loading context
*/
virtual void loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext );
private:
QString m_pageTitle;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment