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

List:       kde-commits
Subject:    koffice/libs/kotext/opendocument
From:       Thomas Zander <zander () kde ! org>
Date:       2010-11-07 18:04:18
Message-ID: 20101107180418.33E65AC89B () svn ! kde ! org
[Download RAW message or body]

SVN commit 1193959 by zander:

Fix loading of character styles to remember the name.

In many cases a character style applied to a smaller piece of text
will have an automatic-style introduced in between to store any extra
properties.  It is important to remember the parent on loading since
otherwise the text just becomes an anonymous piece of formatted
text and we loose the whole advantage of characters styles.

This commit makes sure that we keep this relationship in tact.

BUG:246067

 M  +27 -16    KoTextSharedLoadingData.cpp  
 M  +7 -1      KoTextSharedLoadingData.h  
 M  +6 -0      tests/CMakeLists.txt  
 A             tests/data/TextContents/TextFormatting/charStyle.odt  


--- trunk/koffice/libs/kotext/opendocument/KoTextSharedLoadingData.cpp \
#1193958:1193959 @@ -1,6 +1,6 @@
 /* This file is part of the KDE project
  * Copyright (C) 2004-2006 David Faure <faure@kde.org>
- * Copyright (C) 2007 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2007, 2010 Thomas Zander <zander@kde.org>
  * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
  * Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
  * Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
@@ -122,10 +122,10 @@
 {
     KoOdfLoadingContext &context = shapeContext.odfLoadingContext();
 
+    addCharacterStyles(shapeContext, \
context.stylesReader().customStyles("text").values(), ContentDotXml | StylesDotXml, \
styleManager); +    addCharacterStyles(shapeContext, \
                context.stylesReader().autoStyles("text", true).values(), \
                StylesDotXml);
     addCharacterStyles(shapeContext, \
                context.stylesReader().autoStyles("text").values(), ContentDotXml);
-    addCharacterStyles(shapeContext, context.stylesReader().autoStyles("text", \
true).values(), StylesDotXml);  // only add styles of office:styles to the style \
                manager
-    addCharacterStyles(shapeContext, \
context.stylesReader().customStyles("text").values(), ContentDotXml | StylesDotXml, \
styleManager);  
     addListStyles(shapeContext, context.stylesReader().autoStyles("list").values(), \
                ContentDotXml);
     addListStyles(shapeContext, context.stylesReader().autoStyles("list", \
true).values(), StylesDotXml); @@ -239,30 +239,37 @@
 void KoTextSharedLoadingData::addCharacterStyles(KoShapeLoadingContext &context, \
QList<KoXmlElement*> styleElements,  int styleTypes, KoStyleManager *styleManager)
 {
-    QList<QPair<QString, KoCharacterStyle *> > \
characterStyles(loadCharacterStyles(context, styleElements)); +    \
QList<OdfCharStyle> characterStyles(loadCharacterStyles(context, styleElements));  
-    QList<QPair<QString, KoCharacterStyle *> >::iterator \
                it(characterStyles.begin());
-    for (; it != characterStyles.end(); ++it) {
+    foreach (const OdfCharStyle &odfStyle, characterStyles) {
         if (styleTypes & ContentDotXml) {
-            d->characterContentDotXmlStyles.insert(it->first, it->second);
+            d->characterContentDotXmlStyles.insert(odfStyle.odfName, \
odfStyle.style);  }
         if (styleTypes & StylesDotXml) {
-            d->characterStylesDotXmlStyles.insert(it->first, it->second);
+            d->characterStylesDotXmlStyles.insert(odfStyle.odfName, odfStyle.style);
         }
 
-        // TODO check if it a know style set the styleid so that the custom styles \
                are kept during copy and paste
-        // in case styles are not added to the style manager they have to be deleted \
after loading to avoid leaking memeory  if (styleManager) {
-            styleManager->add(it->second);
+            styleManager->add(odfStyle.style);
         } else {
-            d->characterStylesToDelete.append(it->second);
+            if (!odfStyle.parentStyle.isEmpty()) { // an auto style with a parent.
+                // lets find the parent and set the styleId of that one on the \
auto-style too. +                // this will have the effect that whereever the \
autostyle is applied, it will +                // cause the parent style-id to be \
applied. So we don't loose this info. +                KoCharacterStyle *parent = \
characterStyle(odfStyle.parentStyle, false); +                if (!parent)
+                    parent = characterStyle(odfStyle.parentStyle, true); // try \
harder +                if (parent)
+                    odfStyle.style->setStyleId(parent->styleId());
         }
+            d->characterStylesToDelete.append(odfStyle.style);
     }
 }
+}
 
-QList<QPair<QString, KoCharacterStyle *> > \
KoTextSharedLoadingData::loadCharacterStyles(KoShapeLoadingContext &shapeContext, \
QList<KoXmlElement*> styleElements) +QList<KoTextSharedLoadingData::OdfCharStyle> \
KoTextSharedLoadingData::loadCharacterStyles(KoShapeLoadingContext &shapeContext, \
QList<KoXmlElement*> styleElements)  {
-    QList<QPair<QString, KoCharacterStyle *> > characterStyles;
+    QList<OdfCharStyle> characterStyles;
     KoOdfLoadingContext &context = shapeContext.odfLoadingContext();
 
     foreach(KoXmlElement *styleElem, styleElements) {
@@ -274,6 +281,7 @@
         if (displayName.isEmpty()) {
             displayName = name;
         }
+        QString parent = styleElem->attributeNS(KoXmlNS::style, \
"parent-style-name");  
         kDebug(32500) << "styleName =" << name << "styleDisplayName =" << \
displayName;  
@@ -285,10 +293,13 @@
         KoCharacterStyle *characterStyle = new KoCharacterStyle();
         characterStyle->setName(displayName);
         characterStyle->loadOdf(shapeContext);
-
         context.styleStack().restore();
 
-        characterStyles.append(QPair<QString, KoCharacterStyle *>(name, \
characterStyle)); +        OdfCharStyle answer;
+        answer.odfName = name;
+        answer.parentStyle = parent;
+        answer.style = characterStyle;
+        characterStyles.append(answer);
     }
     return characterStyles;
 }
--- trunk/koffice/libs/kotext/opendocument/KoTextSharedLoadingData.h #1193958:1193959
@@ -1,6 +1,7 @@
 /* This file is part of the KDE project
  * Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
  * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
+ * Copyright (C) 2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -190,7 +191,12 @@
     // helper functions for loading of character styles
     void addCharacterStyles(KoShapeLoadingContext &context, QList<KoXmlElement*> \
styleElements, int styleTypes,  KoStyleManager *styleManager = 0);
-    QList<QPair<QString, KoCharacterStyle *> > \
loadCharacterStyles(KoShapeLoadingContext &context, QList<KoXmlElement*> \
styleElements); +    struct OdfCharStyle {
+        QString odfName;
+        QString parentStyle;
+        KoCharacterStyle *style;
+    };
+    QList<OdfCharStyle> loadCharacterStyles(KoShapeLoadingContext &context, \
QList<KoXmlElement*> styleElements);  
     // helper functions for loading of list styles
     void addListStyles(KoShapeLoadingContext &context, QList<KoXmlElement*> \
                styleElements, int styleTypes,
--- trunk/koffice/libs/kotext/opendocument/tests/CMakeLists.txt #1193958:1193959
@@ -6,6 +6,12 @@
 
 ########### next target ###############
 
+set(TestLoadStyle_test_SRCS TestLoadStyle.cpp)
+kde4_add_unit_test(TestLoadStyle TESTNAME kotext-odf-TestLoadStyle \
${TestLoadStyle_test_SRCS}) +target_link_libraries(TestLoadStyle kotext \
${QT_QTTEST_LIBRARY}) +
+########### next target ###############
+
 set(TestLoading_test_SRCS TestLoading.cpp)
 kde4_add_unit_test(TestLoading TESTNAME kotext-odf-TestLoading \
${TestLoading_test_SRCS})  target_link_libraries(TestLoading kotext \
${QT_QTTEST_LIBRARY}  ${QT_QTSCRIPT_LIBRARY})


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

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