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

List:       kde-commits
Subject:    [calligra] sheets: Sheets: Fix eratic loading of styles due to improper use of default style
From:       Dag Andersen <danders () get2net ! dk>
Date:       2016-11-18 10:05:03
Message-ID: E1c7g2Z-0006Na-RZ () code ! kde ! org
[Download RAW message or body]

Git commit 2566337e2186e971bba262413a7419ed1a05a0c2 by Dag Andersen.
Committed on 18/11/2016 at 09:59.
Pushed by danders into branch 'master'.

Sheets: Fix eratic loading of styles due to improper use of default style

Test:
Format a cell as scientific number
Save to file
Open file a number of times

Result:
Before: Sometimes number presented is float, sometimes scientific
After: Always scientific

Differential Revision: https://phabricator.kde.org/D3328

(Somehow messed up my branch and arc, so hope this works)

M  +2    -2    sheets/Style.h
M  +15   -5    sheets/StyleStorage.cpp

http://commits.kde.org/calligra/2566337e2186e971bba262413a7419ed1a05a0c2

diff --git a/sheets/Style.h b/sheets/Style.h
index 2235cbc..7ab509c 100644
--- a/sheets/Style.h
+++ b/sheets/Style.h
@@ -375,7 +375,7 @@ public:
         return Style::DefaultStyleKey;
     }
     virtual void dump() const {
-        debugSheets << debugData();
+        debugSheetsStyle << debugData();
     }
     virtual QString debugData(bool withName = true) const {
         QString out; if (withName) out = name(Style::DefaultStyleKey); return out;
@@ -423,7 +423,7 @@ public:
         return Style::NamedStyleKey;
     }
     virtual void dump() const {
-        debugSheets << debugData();
+        debugSheetsStyle << debugData();
     }
     virtual QString debugData(bool withName = true) const {
         QString out; if (withName) out = SubStyle::name(Style::NamedStyleKey) + ' '; \
                out += name; return out;
diff --git a/sheets/StyleStorage.cpp b/sheets/StyleStorage.cpp
index eae15d2..0c9be01 100644
--- a/sheets/StyleStorage.cpp
+++ b/sheets/StyleStorage.cpp
@@ -858,14 +858,15 @@ Style StyleStorage::composeStyle(const QList<SharedSubStyle>& \
subStyles) const  {
     d->ensureLoaded();
 
-    if (subStyles.isEmpty())
+    if (subStyles.isEmpty()) {
+//         debugSheetsStyle <<"StyleStorage:" << "nothing to merge, return the \
default style";  return *styleManager()->defaultStyle();
-
+    }
     Style style;
     for (int i = 0; i < subStyles.count(); ++i) {
-        if (subStyles[i]->type() == Style::DefaultStyleKey)
-            style = *styleManager()->defaultStyle();
-        else if (subStyles[i]->type() == Style::NamedStyleKey) {
+        if (subStyles[i]->type() == Style::DefaultStyleKey) {
+            // skip
+        } else if (subStyles[i]->type() == Style::NamedStyleKey) {
             style.clear();
             const CustomStyle* namedStyle = styleManager()->style(static_cast<const \
NamedStyle*>(subStyles[i].data())->name);  if (namedStyle) {
@@ -927,6 +928,15 @@ Style StyleStorage::composeStyle(const QList<SharedSubStyle>& \
subStyles) const  style.clearAttribute(Style::DefaultStyleKey);
         }
     }
+    if (!styleManager()->defaultStyle()->isEmpty()) {
+        // Get any substyles from default style that is not present in style.
+        // NOTE: According to spec this should be the family default, see:
+        // http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1416276_253892949
 +        Style tmpStyle = *styleManager()->defaultStyle();
+        tmpStyle.clearAttribute(Style::DefaultStyleKey);
+        tmpStyle.merge(style);
+        style = tmpStyle;
+    }
     return style;
 }
 


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

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