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

List:       kde-commits
Subject:    koffice/lib/kofficecore
From:       David Faure <faure () kde ! org>
Date:       2006-03-10 17:31:26
Message-ID: 1142011886.621854.30888.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 517344 by dfaure:

Fix name clash between styles in content.xml and styles in styles.xml, leading to \
duplication when saving (both versions would end up in both files!)


 M  +27 -6     KoGenStyles.cpp  
 M  +5 -1      KoGenStyles.h  
 M  +26 -0     tests/kogenstylestest.cpp  


--- trunk/koffice/lib/kofficecore/KoGenStyles.cpp #517343:517344
@@ -61,7 +61,7 @@
             styleName = 'A'; // for "auto".
             flags &= ~DontForceNumbering; // i.e. force numbering
         }
-        styleName = makeUniqueName( styleName, flags, \
style.autoStyleInStylesDotXml() ); +        styleName = makeUniqueName( styleName, \
flags );  if ( style.autoStyleInStylesDotXml() )
             m_autoStylesInStylesDotXml.insert( styleName, true /*unused*/ );
         else
@@ -75,18 +75,20 @@
     return it.data();
 }
 
-QString KoGenStyles::makeUniqueName( const QString& base, int flags, bool \
autoStyleInStylesDotXml ) const +QString KoGenStyles::makeUniqueName( const QString& \
base, int flags ) const  {
-    bool dontForceNumbering = flags & DontForceNumbering;
-    const NameMap& nameMap = autoStyleInStylesDotXml ? m_autoStylesInStylesDotXml : \
                m_styleNames;
-    if ( dontForceNumbering && nameMap.find( base ) == nameMap.end() )
+    // If this name is not used yet, and numbering isn't forced, then the given name \
is ok. +    if ( ( flags & DontForceNumbering )
+         && m_autoStylesInStylesDotXml.find( base ) == \
m_autoStylesInStylesDotXml.end() +         && m_styleNames.find( base ) == \
m_styleNames.end() )  return base;
     int num = 1;
     QString name;
     do {
         name = base;
         name += QString::number( num++ );
-    } while ( nameMap.find( name ) != nameMap.end() );
+    } while ( m_autoStylesInStylesDotXml.find( name ) != \
m_autoStylesInStylesDotXml.end() +              || m_styleNames.find( name ) != \
m_styleNames.end() );  return name;
 }
 
@@ -129,6 +131,25 @@
     styleForModification( name )->setAutoStyleInStylesDotXml( true );
 }
 
+void KoGenStyles::dump()
+{
+    kdDebug() << "Style array:" << endl;
+    StyleArray::const_iterator it = m_styleArray.begin();
+    const StyleArray::const_iterator end = m_styleArray.end();
+    for ( ; it != end ; ++it ) {
+        kdDebug() << (*it).name << endl;
+    }
+    for ( NameMap::const_iterator it = m_styleNames.begin(); it != \
m_styleNames.end(); ++it ) { +        kdDebug() << "style: " << it.key() << endl;
+    }
+    for ( NameMap::const_iterator it = m_autoStylesInStylesDotXml.begin(); it != \
m_autoStylesInStylesDotXml.end(); ++it ) { +        kdDebug() << "auto style for \
style.xml: " << it.key() << endl; +        const KoGenStyle* s = style( it.key() );
+        Q_ASSERT( s );
+        Q_ASSERT( s->autoStyleInStylesDotXml() );
+    }
+}
+
 // Returns -1, 0 (equal) or 1
 static int compareMap( const QMap<QString, QString>& map1, const QMap<QString, \
QString>& map2 )  {
--- trunk/koffice/lib/kofficecore/KoGenStyles.h #517343:517344
@@ -146,9 +146,13 @@
      */
     void markStyleForStylesXml( const QString& name );
 
+    /**
+     * Outputs debug information
+     */
+    void dump();
 
 private:
-    QString makeUniqueName( const QString& base, int flags, bool \
autoStyleInStylesDotXml ) const; +    QString makeUniqueName( const QString& base, \
int flags ) const;  
     /// style definition -> name
     StyleMap m_styleMap;
--- trunk/koffice/lib/kofficecore/tests/kogenstylestest.cpp #517343:517344
@@ -230,6 +230,30 @@
     return 0;
 }
 
+int testStylesDotXml()
+{
+    kdDebug() << k_funcinfo << endl;
+    KoGenStyles coll;
+
+    // Check that an autostyle-in-style.xml and an autostyle-in-content.xml
+    // don't get the same name. It confuses KoGenStyle's named-based maps.
+    KoGenStyle headerStyle( KoGenStyle::STYLE_AUTO, "paragraph" );
+    headerStyle.addAttribute( "style:master-page-name", "Standard" );
+    headerStyle.addProperty( "style:page-number", "0" );
+    headerStyle.setAutoStyleInStylesDotXml( true );
+    QString headerStyleName = coll.lookup( headerStyle, "P" );
+    assert( headerStyleName == "P1" );
+
+    //coll.dump();
+
+    KoGenStyle first( KoGenStyle::STYLE_AUTO, "paragraph" );
+    first.addAttribute( "style:master-page-name", "Standard" );
+    QString firstName = coll.lookup( first, "P" );
+    kdDebug() << "The auto style got assigned the name " << firstName << endl;
+    assert( firstName == "P2" ); // anything but not P1.
+    return 0;
+}
+
 int main( int, char** ) {
     fprintf( stderr, "OK\n" );
 
@@ -239,6 +263,8 @@
         return 1;
     if ( testUserStyles() )
         return 1;
+    if ( testStylesDotXml() )
+        return 1;
 
     return 0;
 }


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

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