[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/libs/kotext
From:       Pierre Ducroquet <pinaraf () gmail ! com>
Date:       2008-07-15 6:12:26
Message-ID: 1216102346.652534.22703.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 832683 by ducroquet:

Ok, now, we have ***basic*** support for saving list styles...
I said basic.

Well, primitive would perhaps be more adequate...
Anyway, it's working, that's what matters.



 M  +20 -0     KoTextShapeData.cpp  
 M  +30 -0     styles/KoListLevelProperties.cpp  
 M  +6 -0      styles/KoListLevelProperties.h  
 M  +17 -2     styles/KoListStyle.cpp  
 M  +7 -1      styles/KoListStyle.h  


--- trunk/koffice/libs/kotext/KoTextShapeData.cpp #832682:832683
@@ -255,7 +255,26 @@
             }
         }
     }
+    
+    //TODO: The list formats are currently not stored in the KoStyleManager ??
+    QMap<QTextList *, QString> listStyleNames;
+    QTextBlock startBlock = block;
     while(block.isValid() && ((to == -1) || (block.position() < to))) {
+	if ((block.textList()) and (!listStyleNames.contains(block.textList()))) {
+	    // Generate a style from that...
+	    KoGenStyle style(KoGenStyle::StyleList);
+            KoListStyle *listStyle = KoListStyle::fromTextList(block.textList());
+	    listStyle->saveOdf(style);
+            QString generatedName = context.mainStyles().lookup(style, \
listStyle->name()); +	    listStyleNames[block.textList()] = generatedName;
+	    delete(listStyle);
+	}
+	block = block.next();
+    }
+    block = startBlock;
+    
+    // Ok, now that the styles are done, we can store the blocks themselves.
+    while(block.isValid() && ((to == -1) || (block.position() < to))) {
         if ((block.begin().atEnd()) && (!block.next().isValid()))   // Do not add an \
extra empty line at the end...  break;
 
@@ -266,6 +285,7 @@
 	    if ((textLists.isEmpty()) or (!textLists.contains(block.textList()))) {
 		kDebug() << "This is a text list we never met before, adding it.";
 		writer->startElement( "text:list", false );
+		writer->addAttribute("text:style-name", listStyleNames[block.textList()]);
 		textLists.append(block.textList());
 	    } else if (block.textList() != textLists.last()) {
 		kDebug() << "We will close every text:list element until we reach the right \
                list...";
--- trunk/koffice/libs/kotext/styles/KoListLevelProperties.cpp #832682:832683
@@ -27,6 +27,7 @@
 
 #include <KoXmlNS.h>
 #include <KoOdfLoadingContext.h>
+#include <KoXmlWriter.h>
 
 class KoListLevelProperties::Private {
 public:
@@ -382,3 +383,32 @@
     if( ! displayLevel.isNull() )
         setDisplayLevel(displayLevel.toInt());
 }
+
+void KoListLevelProperties::saveOdf (KoXmlWriter *writer) const
+{
+    switch (d->stylesPrivate.value(QTextListFormat::ListStyle).toInt()) {
+	case KoListStyle::DecimalItem:
+	case KoListStyle::AlphaLowerItem:
+	case KoListStyle::UpperAlphaItem:
+	case KoListStyle::RomanLowerItem:
+	case KoListStyle::UpperRomanItem:
+	    writer->startElement("list-level-style-number");
+	    break;
+	default:
+	    writer->startElement("text:list-style-content");
+	    break;
+    }
+    if (d->stylesPrivate.contains(KoListStyle::Level))
+	writer->addAttribute("text:level", \
d->stylesPrivate.value(KoListStyle::Level).toInt()); +    if \
(d->stylesPrivate.contains(KoListStyle::BulletCharacter)) \
+	writer->addAttribute("text:bullet-char", \
QChar(d->stylesPrivate.value(KoListStyle::BulletCharacter).toInt())); +    kDebug() \
<< "Key KoListStyle::ListItemPrefix :" << \
d->stylesPrivate.value(KoListStyle::ListItemPrefix); +    kDebug() << "Key \
KoListStyle::ListItemSuffix :" << \
d->stylesPrivate.value(KoListStyle::ListItemSuffix); +    kDebug() << "Key \
KoListStyle::StartValue :" << d->stylesPrivate.value(KoListStyle::StartValue); +    \
kDebug() << "Key KoListStyle::DisplayLevel :" << \
d->stylesPrivate.value(KoListStyle::DisplayLevel); +    kDebug() << "Key \
KoListStyle::CharacterStyleId :" << \
d->stylesPrivate.value(KoListStyle::CharacterStyleId); +    kDebug() << "Key \
KoListStyle::BulletSize :" << d->stylesPrivate.value(KoListStyle::BulletSize); +    \
kDebug() << "Key KoListStyle::Alignment :" << \
d->stylesPrivate.value(KoListStyle::Alignment); +    kDebug() << "Key \
KoListStyle::LetterSynchronization :" << \
d->stylesPrivate.value(KoListStyle::LetterSynchronization); +    \
writer->endElement(); +}
--- trunk/koffice/libs/kotext/styles/KoListLevelProperties.h #832682:832683
@@ -29,6 +29,7 @@
 
 class KoListStyle;
 class KoOdfLoadingContext;
+class KoXmlWriter;
 
 class KOTEXT_EXPORT KoListLevelProperties {
 public:
@@ -118,6 +119,11 @@
      * Load the properties from the \p style using the OpenDocument format.
      */
     void loadOdf(KoOdfLoadingContext& context, const KoXmlElement& style);
+    
+    /**
+     * Save the properties of the style using the OpenDocument format
+     */
+    void saveOdf (KoXmlWriter *writer) const;
 
 private:
     void setProperty(int key, const QVariant &value);
--- trunk/koffice/libs/kotext/styles/KoListStyle.cpp #832682:832683
@@ -24,8 +24,11 @@
 #include <KoStyleStack.h>
 #include <KoOdfStylesReader.h>
 #include <KoXmlNS.h>
+#include <KoXmlWriter.h>
+#include <KoGenStyle.h>
 #include <kdebug.h>
 #include <QTextCursor>
+#include <QBuffer>
 
 class KoListStyle::Private {
 public:
@@ -203,8 +206,6 @@
 
 void KoListStyle::loadOdf(KoOdfLoadingContext& context, const KoXmlElement& style)
 {
-    //kDebug(32500)<<"KoListStyle::loadOasis style.localName="<<style.localName();
-    //KoStyleStack &styleStack = context.styleStack();
     KoXmlElement styleElem;
     forEachElement(styleElem, style) {
         KoListLevelProperties properties;
@@ -212,3 +213,17 @@
         setLevel(properties);
     }
 }
+
+void KoListStyle::saveOdf(KoGenStyle &style)
+{
+    QBuffer buffer;
+    buffer.open( QIODevice::WriteOnly );
+    KoXmlWriter elementWriter( &buffer );  // TODO pass indentation level
+    QMapIterator<int, KoListLevelProperties> it(d->levels);
+    while (it.hasNext()) {
+	it.next();
+	it.value().saveOdf(&elementWriter);
+    }
+    QString elementContents = QString::fromUtf8( buffer.buffer(), \
buffer.buffer().size() ); +    style.addChildElement( \
"text-list-level-style-content", elementContents ); +}
--- trunk/koffice/libs/kotext/styles/KoListStyle.h #832682:832683
@@ -30,6 +30,7 @@
 
 class KoListLevelProperties;
 class KoOdfLoadingContext;
+class KoGenStyle;
 
 /**
  * This class groups all styling-options for lists.
@@ -180,7 +181,12 @@
      * OpenDocument format.
      */
     void loadOdf(KoOdfLoadingContext& context, const KoXmlElement& style = \
                KoXmlElement());
-
+    
+    /**
+     * Save the style to a KoGenStyle object using the OpenDocument format
+     */
+    void saveOdf( KoGenStyle &style );
+    
 protected:
     friend class KoParagraphStyle;
     void apply(const KoListStyle &other);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic