[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Fri Sep 14 02:45:47 CEST 2007


SVN commit 712231 by treat:

* Enforce the rules according to layout spec page 2.


 M  +3 -3      plotitem.cpp  
 M  +29 -11    viewgridlayout.cpp  
 M  +7 -4      viewgridlayout.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #712230:712231
@@ -45,7 +45,7 @@
   if (COUNT % 2) {
     yTest2->setLabel("another nice y label");
   } else {
-    yTest2->setLabel("another really REALLY REALLY REALLY nice y label");
+    yTest2->setLabel("another much much longer nice y label");
   }
   COUNT = COUNT + 1;
 
@@ -191,7 +191,7 @@
 qreal PlotItem::marginWidth() const {
   ViewItem *viewItem = dynamic_cast<ViewItem*>(parentItem());
   if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotMarginWidth();
+    return viewItem->layout()->plotMarginWidth(this);
   } else {
     return calculatedMarginWidth();
   }
@@ -201,7 +201,7 @@
 qreal PlotItem::marginHeight() const {
   ViewItem *viewItem = dynamic_cast<ViewItem*>(parentItem());
   if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotMarginHeight();
+    return viewItem->layout()->plotMarginHeight(this);
   } else {
     return calculatedMarginHeight();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #712230:712231
@@ -27,9 +27,7 @@
     _rowCount(0),
     _columnCount(0),
     _spacing(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)),
-    _margin(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)),
-    _plotMarginWidth(0.0),
-    _plotMarginHeight(0.0) {
+    _margin(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)) {
 
   parent->setLayout(this);
 }
@@ -65,6 +63,7 @@
   _columnCount = maxColumn > _columnCount ? maxColumn : _columnCount;
 
   _items.append(item);
+  _itemInfos.insert(viewItem, item);
 }
 
 
@@ -78,13 +77,25 @@
 }
 
 
-qreal ViewGridLayout::plotMarginWidth() const {
-  return _plotMarginWidth;
+qreal ViewGridLayout::plotMarginWidth(const PlotItem *plotItem) const {
+  if (_itemInfos.contains(plotItem)) {
+    LayoutItem item = _itemInfos.value(plotItem);
+    if (_plotMarginWidth.contains(item.columnSpan))
+      return _plotMarginWidth.value(item.columnSpan);
+  }
+
+  return 0.0;
 }
 
 
-qreal ViewGridLayout::plotMarginHeight() const {
-  return _plotMarginHeight;
+qreal ViewGridLayout::plotMarginHeight(const PlotItem *plotItem) const {
+  if (_itemInfos.contains(plotItem)) {
+    LayoutItem item = _itemInfos.value(plotItem);
+    if (_plotMarginHeight.contains(item.rowSpan))
+      return _plotMarginHeight.value(item.rowSpan);
+  }
+
+  return 0.0;
 }
 
 
@@ -146,16 +157,23 @@
 
 
 void ViewGridLayout::updatePlotMargins() {
-  _plotMarginWidth = 0.0;
-  _plotMarginHeight = 0.0;
+  _plotMarginWidth.clear();
+  _plotMarginHeight.clear();
   foreach (LayoutItem item, _items) {
     PlotItem *plotItem = dynamic_cast<PlotItem*>(item.viewItem);
 
     if (!plotItem)
       continue;
 
-    _plotMarginWidth = qMax(_plotMarginWidth, plotItem->calculatedMarginWidth());
-    _plotMarginHeight = qMax(_plotMarginHeight, plotItem->calculatedMarginHeight());
+    qreal marginForColumnSpan = plotItem->calculatedMarginWidth();
+    if (_plotMarginWidth.contains(item.columnSpan))
+      marginForColumnSpan = qMax(marginForColumnSpan, _plotMarginWidth.value(item.columnSpan));
+    _plotMarginWidth.insert(item.columnSpan, marginForColumnSpan);
+
+    qreal marginForRowSpan = plotItem->calculatedMarginHeight();
+    if (_plotMarginHeight.contains(item.rowSpan))
+      marginForRowSpan = qMax(marginForRowSpan, _plotMarginHeight.value(item.rowSpan));
+    _plotMarginHeight.insert(item.rowSpan, marginForRowSpan);
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #712230:712231
@@ -14,10 +14,12 @@
 
 #include <QObject>
 #include <QSizeF>
+#include <QHash>
 
 namespace Kst {
 
 class ViewItem;
+class PlotItem;
 
 class ViewGridLayout : public QObject
 {
@@ -40,8 +42,8 @@
     QSizeF margin() const { return _margin; }
     void setMargin(const QSizeF &margin) { _margin = margin; }
 
-    qreal plotMarginWidth() const;
-    qreal plotMarginHeight() const;
+    qreal plotMarginWidth(const PlotItem *plotItem) const;
+    qreal plotMarginHeight(const PlotItem *plotItem) const;
 
   public Q_SLOTS:
     void update();
@@ -65,8 +67,9 @@
     QSizeF _margin;
 
     QList<LayoutItem> _items;
-    qreal _plotMarginWidth;
-    qreal _plotMarginHeight;
+    QHash<int, qreal> _plotMarginWidth;
+    QHash<int, qreal> _plotMarginHeight;
+    QHash<const ViewItem*, LayoutItem> _itemInfos;
 };
 
 }


More information about the Kst mailing list