Bug 124986 - Legends are not updated when moved to a different plot
Summary: Legends are not updated when moved to a different plot
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Solaris
: NOR normal
Target Milestone: ---
Assignee: Duncan Hanson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-05 17:42 UTC by Nicolas Brisset
Modified: 2006-06-13 19:51 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed patch. (2.71 KB, patch)
2006-05-13 01:40 UTC, Duncan Hanson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Brisset 2006-04-05 17:42:39 UTC
Version:           1.3.0_devel (using KDE 3.4.0, compiled sources)
Compiler:          gcc version 3.4.3
OS:                SunOS (sun4u) release 5.8

When a legend is moved to a different plot than the one containing the corresponding curves, it is no longer updated.
To reproduce:
1) create two plots with 2 curves each
2) show the legend in P1
3) F6 -> move the legend to P2
4) in P1, edit the legend text for one curve: the legend is not updated
5) move the legend back to P1: it gets updated.

Expected behavior: the legendis updated regardless of which parent object it belongs to.
Comment 1 Duncan Hanson 2006-05-13 01:40:00 UTC
Created attachment 16056 [details]
Proposed patch.
Comment 2 Duncan Hanson 2006-05-13 01:40:29 UTC
Hello All,

Here is a small proposed patch for the problem. Are there any glaring problems?

Duncan.
Comment 3 George Staikos 2006-05-13 01:56:22 UTC
Quoting Duncan Hanson <duncan.hanson@gmail.com>:
> Created an attachment (id=16056)
>  --> (http://bugs.kde.org/attachment.cgi?id=16056&action=view)
> Proposed patch.


  Looks good.
Comment 4 Duncan Hanson 2006-05-13 01:58:01 UTC
Never mind- I've completely misunderstood the code. Please ignore this
patch.

On Fri, 2006-05-12 at 23:40 +0000, Duncan Hanson wrote:
[bugs.kde.org quoted mail]
Comment 5 George Staikos 2006-05-13 05:05:26 UTC
Hm it might still be a good idea to have a patch that updates the legend when the label is changed in the curve like that.
Comment 6 Duncan Hanson 2006-05-15 18:37:10 UTC
SVN commit 541132 by dhanson:

BUG:124986 this should cover all of the ways a curve's legend entry can be modified.

 M  +5 -0      libkstapp/kstviewlegend.cpp  
 M  +1 -0      libkstapp/kstviewlegend.h  
 M  +7 -0      libkstmath/kstbasecurve.cpp  
 M  +6 -2      libkstmath/kstbasecurve.h  
 M  +8 -0      libkstmath/kstvcurve.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.cpp #541131:541132
@@ -485,6 +485,9 @@
   setContentsRect(cr);
 }
 
+void KstViewLegend::modifiedLegendEntry() {
+  setDirty();
+}
 
 bool KstViewLegend::layoutPopupMenu(KPopupMenu *menu, const QPoint& pos, KstViewObjectPtr topLevelParent) {
   return KstViewObject::layoutPopupMenu(menu, pos, topLevelParent);
@@ -524,6 +527,7 @@
 void KstViewLegend::addCurve(KstBaseCurvePtr incurve) {
   if (!_curves.contains(incurve)) {
     _curves.append(incurve);
+    connect(incurve, SIGNAL(modifiedLegendEntry()), this, SLOT(modifiedLegendEntry()));
     setDirty();
   }
 }
@@ -532,6 +536,7 @@
 void KstViewLegend::removeCurve(KstBaseCurvePtr incurve) {
   if (_curves.contains(incurve)) {
     _curves.remove(incurve);
+    disconnect(incurve,SIGNAL(modifiedLegendEntry()), this, SLOT(modifiedLegendEntry()));
     setDirty();
   }
 }
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.h #541131:541132
@@ -93,6 +93,7 @@
 
   public slots:
     void adjustSizeForText(QRect w);
+    void modifiedLegendEntry(void);
 
   protected:
     KstViewObjectFactoryMethod factory() const;
--- trunk/extragear/graphics/kst/src/libkstmath/kstbasecurve.cpp #541131:541132
@@ -68,4 +68,11 @@
   }
   return _parsedLegendTag;
 }
+
+void KstBaseCurve::setLegendText(const QString& theValue) { 
+  _legendText = theValue; 
+  updateParsedLegendTag(); 
+  emit modifiedLegendEntry();
+}
+
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/libkstmath/kstbasecurve.h #541131:541132
@@ -46,6 +46,8 @@
 enum KstCurveType { KST_VCURVE, KST_HISTOGRAM, KST_IMAGE };
 
 class KST_EXPORT KstBaseCurve : public KstDataObject {
+  Q_OBJECT
+
   public:
     KstBaseCurve();
     KstBaseCurve(const QDomElement& e);
@@ -112,7 +114,7 @@
     virtual Label::Parsed *parsedLegendTag();
     virtual void updateParsedLegendTag();
     
-    void setLegendText(const QString& theValue) { _legendText = theValue; updateParsedLegendTag(); }
+    void setLegendText(const QString& theValue);
     QString legendText() const { return _legendText;}
 
   protected:
@@ -138,8 +140,10 @@
 
   private:
     void commonConstructor();
-private:
     QString _legendText;
+
+  signals: 
+    void modifiedLegendEntry(void);
 };
 
 
--- trunk/extragear/graphics/kst/src/libkstmath/kstvcurve.cpp #541131:541132
@@ -739,48 +739,56 @@
 void KstVCurve::setHasPoints(bool in_HasPoints) {
   HasPoints = in_HasPoints;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setHasLines(bool in_HasLines) {
   HasLines = in_HasLines;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setHasBars(bool in_HasBars) {
   HasBars = in_HasBars;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setLineWidth(int in_LineWidth) {
   LineWidth = in_LineWidth;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setLineStyle(int in_LineStyle) {
   LineStyle = in_LineStyle;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setBarStyle(int in_BarStyle) {
   BarStyle = in_BarStyle;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setPointDensity(int in_PointDensity) {
   PointDensity = in_PointDensity;
   setDirty();
+  emit modifiedLegendEntry();
 }
 
 
 void KstVCurve::setColor(const QColor& new_c) {
   setDirty();
   Color = new_c;
+  emit modifiedLegendEntry();
 }
 
 
Comment 7 Duncan Hanson 2006-05-15 18:38:29 UTC
There will still be some quirky legend behaviour associated with this bug. For example, when a legend is moved to a different plot, removing the curve from the plot will not remove the corresponding legend entry. I think that this is a tricky problem to fix, because the plot must remove the curve from the legend before the curve is deleted, but we can't expect the plot to know which curves belong to legends in other plots. It would be nice to be able to emit a deletedCurve() signal from the curve destructor, the appropriate legends could catch, but this won't work. The KstSharedPtr in the legend's list of curves keeps the curve from ever destructing. Can anyone think of a solution?
Comment 8 Duncan Hanson 2006-05-15 18:41:22 UTC
not completely fixed.
Comment 9 Duncan Hanson 2006-06-13 19:51:38 UTC
Current behaviour is probably best which is possible (without doing something complicated, like introducing a KstGuardedPtr.)