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

List:       kde-commits
Subject:    koffice/lib/kotext
From:       David Faure <faure () kde ! org>
Date:       2006-01-30 11:14:16
Message-ID: 1138619656.969039.31408.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 503777 by dfaure:

Don't delete the default style if we're not going to find any paragraph \
style.

Fixed logic with "overwriting previous style", once it happened, any style \
after that would still think it's "overwriting a previous style", so this \
probably broke "following style" in some cases.


 M  +16 -9     KoStyleCollection.cpp  
 M  +4 -2      KoStyleCollection.h  


--- trunk/koffice/lib/kotext/KoStyleCollection.cpp #503776:503777
@@ -40,17 +40,13 @@
 {
 }
 
-void KoStyleCollection::loadOasisStyles( KoOasisContext& context )
+int KoStyleCollection::loadOasisStyles( KoOasisContext& context )
 {
     QStringList followingStyles;
     QValueVector<QDomElement> userStyles = \
                context.oasisStyles().userStyles();
-    uint nStyles = userStyles.count();
-    if( nStyles ) { // we are going to import at least one style.
-        KoParagStyle *s = defaultStyle();
-        //kdDebug() << "loadOasisStyles looking for Standard, to delete \
                it. Found " << s << endl;
-        if(s) // delete the standard style.
-            removeStyle(s);
-    }
+    bool defaultStyleDeleted = false;
+    int stylesLoaded = 0;
+    const unsigned int nStyles = userStyles.count();
     for (unsigned int item = 0; item < nStyles; item++) {
         QDomElement styleElem = userStyles[item];
 	Q_ASSERT( !styleElem.isNull() );
@@ -58,20 +54,30 @@
         if ( styleElem.attributeNS( KoXmlNS::style, "family", \
QString::null ) != "paragraph" )  continue;
 
+        if( !defaultStyleDeleted ) { // we are going to import at least \
one style. +            KoParagStyle *s = defaultStyle();
+            //kdDebug() << "loadOasisStyles looking for Standard, to \
delete it. Found " << s << endl; +            if(s) // delete the standard \
style. +                removeStyle(s);
+            defaultStyleDeleted = true;
+        }
+
         KoParagStyle *sty = new KoParagStyle( QString::null );
         // Load the style
         sty->loadStyle( styleElem, context );
         // Style created, now let's try to add it
+        const int oldStyleCount = count();
         sty = addStyle( sty );
         // the real value of followingStyle is set below after loading all \
styles  sty->setFollowingStyle( sty );
 
         kdDebug() << " Loaded style " << sty->name() << endl;
 
-        if(styleList().count() > followingStyles.count() )
+        if ( count() > oldStyleCount )
         {
             const QString following = styleElem.attributeNS( \
KoXmlNS::style, "next-style-name", QString::null );  \
followingStyles.append( following ); +            ++stylesLoaded;
         }
         else
             kdWarning() << "Found duplicate style declaration, overwriting \
former " << sty->name() << endl; @@ -95,6 +101,7 @@
     // TODO the same thing for style inheritance (style:parent-style-name) \
and setParentStyle()  
     Q_ASSERT( defaultStyle() );
+    return stylesLoaded;
 }
 
 void KoStyleCollection::saveOasis( KoGenStyles& styles, int styleType, \
                KoSavingContext& context ) const
--- trunk/koffice/lib/kotext/KoStyleCollection.h #503776:503777
@@ -88,9 +88,11 @@
     /// Import a number of styles (e.g. loaded from another document)
     void importStyles( const KoStyleCollection& styleList );
 
-    void loadOasisStyles( KoOasisContext& context );
+    /// Loads the entire style collection, in the OASIS OpenDocument \
format +    /// @return the number of new styles loaded
+    int loadOasisStyles( KoOasisContext& context );
 
-    /// Save the entire style collection to OASIS
+    /// Save the entire style collection in the OASIS OpenDocument format
     /// @p styleType is the STYLE_* value for this style.
     void saveOasis( KoGenStyles& styles, int styleType, KoSavingContext& \
context ) const;  


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

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