Commit fe0a2dc1 authored by Thorsten Zachmann's avatar Thorsten Zachmann

More on the way to a unified saving of styles in koffice

o save master pages as with the help of KoGenStyle::StyleMaster styles.

svn path=/trunk/koffice/; revision=724567
parent 590fc154
......@@ -229,6 +229,7 @@ void KoPADocument::saveOdfDocumentStyles( KoStore * store, KoShapeSavingContext
#if 1
mainStyles.saveOdfDocumentStyles( stylesWriter );
mainStyles.saveOdfAutomaticStyles( stylesWriter, true );
mainStyles.saveOdfMasterStyles( stylesWriter );
#else
stylesWriter->startElement( "office:styles" );
......@@ -240,9 +241,9 @@ void KoPADocument::saveOdfDocumentStyles( KoStore * store, KoShapeSavingContext
stylesWriter->startElement( "office:automatic-styles" );
saveOdfAutomaticStyles( *stylesWriter, mainStyles, true );
stylesWriter->endElement(); // office:automatic-styles
#endif
stylesWriter->addCompleteElement( masterStyles );
#endif
stylesWriter->endElement(); // root element (office:document-styles)
stylesWriter->endDocument();
......
......@@ -19,6 +19,7 @@
#include "KoPAMasterPage.h"
#include <QBuffer>
#include <KoGenStyle.h>
#include <KoXmlWriter.h>
#include <KoXmlNS.h>
......@@ -39,27 +40,49 @@ KoPAMasterPage::~KoPAMasterPage()
{
}
void KoPAMasterPage::createOdfPageTag( KoPASavingContext &paContext ) const
void KoPAMasterPage::saveOdf( KoShapeSavingContext & context ) const
{
KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );
KoGenStyle pageLayoutStyle = pageLayout().saveOasis();
pageLayoutStyle.setAutoStyleInStylesDotXml( true );
pageLayoutStyle.addAttribute( "style:page-usage", "all" );
QString pageLayoutName( paContext.mainStyles().lookup( pageLayoutStyle, "pm" ) );
paContext.xmlWriter().startElement( "style:master-page" );
paContext.xmlWriter().addAttribute( "style:name", pageTitle() );
paContext.addMasterPage( this, pageTitle() );
paContext.xmlWriter().addAttribute( "style:page-layout-name", pageLayoutName );
KoGenStyle pageMaster( KoGenStyle::StyleMaster );
pageMaster.addAttribute( "style:page-layout-name", pageLayoutName );
pageMaster.addAttribute( "style:display-name", pageTitle() );
KoXmlWriter &savedWriter = paContext.xmlWriter();
QBuffer buffer;
buffer.open( QIODevice::WriteOnly );
KoXmlWriter xmlWriter( &buffer );
paContext.setXmlWriter( xmlWriter );
saveOdfPageContent( paContext );
paContext.setXmlWriter( savedWriter );
QString contentElement = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
pageMaster.addChildElement( "content", contentElement );
paContext.addMasterPage( this, paContext.mainStyles().lookup( pageMaster, "Default" ) );
}
void KoPAMasterPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
{
setPageTitle( element.attributeNS( KoXmlNS::style, "name" ) );
if ( element.hasAttributeNS( KoXmlNS::style, "display-name" ) ) {
setPageTitle( element.attributeNS( KoXmlNS::style, "display-name" ) );
}
else {
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 );
}
......
......@@ -32,6 +32,9 @@ public:
explicit KoPAMasterPage();
~KoPAMasterPage();
/// reimplemented
virtual void saveOdf( KoShapeSavingContext & context ) const;
/// @return the page layout set for this masterpage
KoPageLayout & pageLayout() { return m_pageLayout; }
const KoPageLayout & pageLayout() const { return m_pageLayout; }
......@@ -40,11 +43,9 @@ public:
void setPageLayout(const KoPageLayout& layout) { m_pageLayout = layout; }
protected:
virtual void createOdfPageTag( KoPASavingContext &paContext ) const;
/// Reimplemented from KoPageBase
virtual void loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext );
KoPageLayout m_pageLayout;
};
......
......@@ -38,18 +38,25 @@ KoPAPage::~KoPAPage()
{
}
KoPageLayout & KoPAPage::pageLayout()
void KoPAPage::saveOdf( KoShapeSavingContext & context ) const
{
Q_ASSERT( m_masterPage );
return m_masterPage->pageLayout();
}
KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );
void KoPAPage::createOdfPageTag( KoPASavingContext &paContext ) const
{
paContext.xmlWriter().startElement( "draw:page" );
paContext.xmlWriter().addAttribute( "draw:id", "page" + QString::number( paContext.page() ) );
paContext.xmlWriter().addAttribute( "draw:master-page-name", paContext.masterPageName( m_masterPage ) );
paContext.xmlWriter().addAttribute( "draw:style-name", saveOdfPageStyle( paContext ) );
saveOdfPageContent( paContext );
paContext.xmlWriter().endElement();
}
KoPageLayout & KoPAPage::pageLayout()
{
Q_ASSERT( m_masterPage );
return m_masterPage->pageLayout();
}
void KoPAPage::loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext )
......
......@@ -34,6 +34,9 @@ public:
explicit KoPAPage( KoPAMasterPage * masterPage );
~KoPAPage();
/// reimplemented
virtual void saveOdf( KoShapeSavingContext & context ) const;
/// @return the layout set by the masterpage
KoPageLayout & pageLayout();
......@@ -41,12 +44,11 @@ public:
void setMasterPage( KoPAMasterPage * masterPage );
/// @return the masterpage of this page
KoPAMasterPage * masterPage() { return m_masterPage; }
protected:
virtual void createOdfPageTag( KoPASavingContext &paContext ) const;
protected:
/// Reimplemented from KoPageBase
virtual void loadOdfPageTag( const KoXmlElement &element, KoPALoadingContext &loadingContext );
KoPAMasterPage * m_masterPage;
};
......
......@@ -64,18 +64,11 @@ void KoPAPageBase::paintComponent(QPainter& painter, const KoViewConverter& conv
Q_UNUSED(converter);
}
void KoPAPageBase::saveOdf( KoShapeSavingContext & context ) const
void KoPAPageBase::saveOdfPageContent( KoPASavingContext & paContext ) const
{
KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );
createOdfPageTag( paContext );
context.xmlWriter().addAttribute( "draw:style-name", saveOdfPageStyle( paContext ) );
saveOdfShapes( context );
saveOdfShapes( paContext );
saveOdfAnimations( paContext );
saveOdfPresentationNotes();
context.xmlWriter().endElement(); //draw:page
saveOdfPresentationNotes();
}
void KoPAPageBase::saveOdfShapes( KoShapeSavingContext &context ) const
......
......@@ -56,7 +56,7 @@ public:
* @param context the pageapp saving context
* @return true on success, false otherwise
*/
virtual void saveOdf( KoShapeSavingContext & context ) const;
virtual void saveOdf( KoShapeSavingContext & context ) const = 0;
// reimplemented
virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext & context );
......@@ -81,13 +81,9 @@ public:
protected:
/**
* @brief Create the page tag
*
* Master pages and normal pages use different tags
*
* @param paContext the pageapp saving context
*/
virtual void createOdfPageTag( KoPASavingContext & paContext ) const = 0;
void saveOdfPageContent( KoPASavingContext & paContext ) const;
/**
* @brief Save the shapes of a page
......
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