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

List:       kde-commits
Subject:    [kcachegrind/frameworks] libcore: Fix bug with derived event types with empty formula
From:       Josef Weidendorfer <Josef.Weidendorfer () gmx ! de>
Date:       2016-03-21 16:37:40
Message-ID: E1ai2po-0002WR-7h () scm ! kde ! org
[Download RAW message or body]

Git commit 1853b5c4b0d321c538e881ae73dd408e6cd28495 by Josef Weidendorfer.
Committed on 21/03/2016 at 11:55.
Pushed by weidendo into branch 'frameworks'.

Fix bug with derived event types with empty formula

Users can interactively add new event types (pane "Types", context
menu "New Event Types..."). This is meant to add derived event types,
ie. calculated from existing ones using a formula. However, the user
may not change the default empty formula.

Such inconsistent event types should not be saved in the config, as
they get restored as real types which results in buggy behavior.

M  +16   -10   libcore/globalconfig.cpp

http://commits.kde.org/kcachegrind/1853b5c4b0d321c538e881ae73dd408e6cd28495

diff --git a/libcore/globalconfig.cpp b/libcore/globalconfig.cpp
index 9860ec6..baa8e39 100644
--- a/libcore/globalconfig.cpp
+++ b/libcore/globalconfig.cpp
@@ -195,19 +195,25 @@ void GlobalConfig::saveOptions()
                             DEFAULT_HIDETEMPLATES);
     delete generalConfig;
 
-    // event types
+    // store known event types
     ConfigGroup* etConfig = ConfigStorage::group(QStringLiteral("EventTypes"));
     int etCount = EventType::knownTypeCount();
-    etConfig->setValue( QStringLiteral("Count"), etCount);
-    for (int i=0; i<etCount; i++) {
-	EventType* t = EventType::knownType(i);
-	etConfig->setValue( QStringLiteral("Name%1").arg(i+1), t->name());
-	etConfig->setValue( QStringLiteral("Longname%1").arg(i+1),
-			    t->longName(),
-			    knownLongName(t->name()) );
-	etConfig->setValue( QStringLiteral("Formula%1").arg(i+1),
-			    t->formula(), knownFormula(t->name()) );
+    int j = 0; // counter for config keys
+    for (int i = 0; i<etCount; i++) {
+        EventType* t = EventType::knownType(i);
+        // do not store derived event types with empty formula
+        // (these can exist when new type gets added with context menu)
+        if (!t->isReal() && t->formula().isEmpty()) continue;
+
+        etConfig->setValue( QStringLiteral("Name%1").arg(j+1), t->name());
+        etConfig->setValue( QStringLiteral("Longname%1").arg(j+1),
+                            t->longName(),
+                            knownLongName(t->name()) );
+        etConfig->setValue( QStringLiteral("Formula%1").arg(j+1),
+                            t->formula(), knownFormula(t->name()) );
+        j++;
     }
+    etConfig->setValue( QStringLiteral("Count"), j);
     delete etConfig;
 }
 

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

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