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

Mike Fenton mike at staikos.net
Tue Jul 7 17:17:14 CEST 2009


SVN commit 992677 by fenton:

Remove TiedZoom support from SharedAxisBoxItem.
Add KeyPlot to SharedAxisBoxItem for displaying TiedZoom in ShareX & ShareY mode.
Fix RMB Menu for PlotItem.
Fix Tied Zoom with plots outside of the SharedAxisBoxItem.


 M  +20 -56    plotitem.cpp  
 M  +1 -3      plotitem.h  
 M  +40 -50    sharedaxisboxitem.cpp  
 M  +3 -4      sharedaxisboxitem.h  
 M  +1 -1      viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #992676:992677
@@ -367,9 +367,6 @@
 
   _shareBoxShareX = 0;
   _shareBoxShareY = 0;
-  _shareBoxTieZoom = 0;
-  _shareBoxTieXZoom = 0;
-  _shareBoxTieYZoom = 0;
 }
 
 
@@ -463,13 +460,8 @@
   if (_sharedAxisBoxMenu) {
     delete _shareBoxShareX;
     delete _shareBoxShareY;
-    delete _shareBoxTieZoom;
-    delete _shareBoxTieXZoom;
-    delete _shareBoxTieYZoom;
-
     delete _sharedAxisBoxMenu;
   }
-
   _sharedAxisBoxMenu = new QMenu;
   _sharedAxisBoxMenu->setTitle(tr("Shared Axis Box Settings"));
 
@@ -477,7 +469,6 @@
   _shareBoxShareX->setShortcut(Qt::Key_X);
   connect(_shareBoxShareX, SIGNAL(triggered()), _sharedBox, SLOT(shareXAxis()));
   _shareBoxShareX->setCheckable(true);
-  _shareBoxShareX->setChecked(_sharedBox->isXAxisShared());
   registerShortcut(_shareBoxShareX);
   _sharedAxisBoxMenu->addAction(_shareBoxShareX);
 
@@ -485,35 +476,8 @@
   _shareBoxShareY->setShortcut(Qt::Key_Y);
   connect(_shareBoxShareY, SIGNAL(triggered()), _sharedBox, SLOT(shareYAxis()));
   _shareBoxShareY->setCheckable(true);
-  _shareBoxShareY->setChecked(_sharedBox->isYAxisShared());
   registerShortcut(_shareBoxShareY);
   _sharedAxisBoxMenu->addAction(_shareBoxShareY);
-
-  _sharedAxisBoxMenu->addSeparator();
-
-  _shareBoxTieZoom = new QAction(tr("Tie Zoom of Shared Axis Box"), this);
-  _shareBoxTieZoom->setShortcut(Qt::Key_O);
-  connect(_shareBoxTieZoom, SIGNAL(triggered()), _sharedBox, SLOT(zoomTied()));
-  _shareBoxTieZoom->setCheckable(true);
-  _shareBoxTieZoom->setChecked(_sharedBox->isTiedZoom());
-  registerShortcut(_shareBoxTieZoom);
-  _sharedAxisBoxMenu->addAction(_shareBoxTieZoom);
-
-  _shareBoxTieXZoom = new QAction(tr("Tie X Zoom of Shared Axis Box"), this);
-  _shareBoxTieXZoom->setShortcut(Qt::SHIFT+Qt::Key_O);
-  connect(_shareBoxTieXZoom, SIGNAL(triggered()), _sharedBox, SLOT(zoomXTied()));
-  _shareBoxTieXZoom->setCheckable(true);
-  _shareBoxTieXZoom->setChecked(_sharedBox->isXTiedZoom());
-  registerShortcut(_shareBoxTieXZoom);
-  _sharedAxisBoxMenu->addAction(_shareBoxTieXZoom);
-
-  _shareBoxTieYZoom = new QAction(tr("Tie Y Zoom of Shared Axis Box"), this);
-  _shareBoxTieYZoom->setShortcut(Qt::CTRL+Qt::Key_O);
-  connect(_shareBoxTieYZoom, SIGNAL(triggered()), _sharedBox, SLOT(zoomYTied()));
-  _shareBoxTieYZoom->setCheckable(true);
-  _shareBoxTieYZoom->setChecked(_sharedBox->isYTiedZoom());
-  registerShortcut(_shareBoxTieYZoom);
-  _sharedAxisBoxMenu->addAction(_shareBoxTieYZoom);
 }
 
 
@@ -529,6 +493,9 @@
       breakSharedBox->setShortcut(Qt::Key_B);
       connect(breakSharedBox, SIGNAL(triggered()), _sharedBox, SLOT(breakShare()));
       menu.addAction(breakSharedBox);
+
+      _shareBoxShareX->setChecked(_sharedBox->isXAxisShared());
+      _shareBoxShareY->setChecked(_sharedBox->isYAxisShared());
     }
   }
 
@@ -539,19 +506,11 @@
 
   _zoomLogX->setChecked(xAxis()->axisLog());
   _zoomLogY->setChecked(yAxis()->axisLog());
-  if (isInSharedAxisBox() && sharedAxisBox()->isXAxisShared() && sharedAxisBox()->isYAxisShared()) {
-    _zoomTied->setVisible(false);
-    _zoomXTied->setVisible(false);
-    _zoomYTied->setVisible(false);
-  } else {
-    _zoomTied->setVisible(true);
-    _zoomXTied->setVisible(true);
-    _zoomYTied->setVisible(true);
 
-    _zoomTied->setChecked(isTiedZoom());
-    _zoomXTied->setChecked(isXTiedZoom());
-    _zoomYTied->setChecked(isYTiedZoom());
-  }
+  _zoomTied->setChecked(isTiedZoom());
+  _zoomXTied->setChecked(isXTiedZoom());
+  _zoomYTied->setChecked(isYTiedZoom());
+
   _zoomPrevious->setVisible(!isInSharedAxisBox());
   menu.addMenu(_zoomMenu);
   if (!DataObject::filterPluginList().empty()) {
@@ -2450,11 +2409,6 @@
 
 
 void PlotItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
-  if (isInSharedAxisBox() && _sharedBox) {
-    if (_sharedBox->tryMousePressEvent(this, event)) {
-      return;
-    }
-  }
   if (event->button() == Qt::LeftButton) {
     if (checkBox().contains(event->pos())) {
       setTiedZoom(!isTiedZoom(), !isTiedZoom());
@@ -2467,9 +2421,8 @@
 }
 
 
-
 QPainterPath PlotItem::checkBox() const {
-  if (!isInSharedAxisBox()) {
+  if (!isInSharedAxisBox() || (sharedAxisBox() && sharedAxisBox()->isXAxisShared() && sharedAxisBox()->isYAxisShared())) {
     return ViewItem::checkBox();
   } else {
     QRectF bound = selectBoundingRect();
@@ -2487,7 +2440,7 @@
 
 
 QPainterPath PlotItem::tiedZoomCheck() const {
-  if (!isInSharedAxisBox()) {
+  if (!isInSharedAxisBox() || (sharedAxisBox() && sharedAxisBox()->isXAxisShared() && sharedAxisBox()->isYAxisShared())) {
     return ViewItem::tiedZoomCheck();
   } else {
     QRectF bound = selectBoundingRect();
@@ -2512,6 +2465,17 @@
 }
 
 
+bool PlotItem::supportsTiedZoom() const {
+  if (isInSharedAxisBox()) {
+    if (sharedAxisBox() && sharedAxisBox()->isXAxisShared() && sharedAxisBox()->isYAxisShared() &&
+        sharedAxisBox()->keyPlot() == this) {
+      return true;
+    }
+  }
+  return ViewItem::supportsTiedZoom();
+}
+
+
 void PlotItem::setAllowUpdates(bool allowed) {
   if (allowed == _allowUpdates)
     return;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #992676:992677
@@ -243,6 +243,7 @@
 
     virtual QPainterPath checkBox() const;
     virtual QPainterPath tiedZoomCheck() const;
+    virtual bool supportsTiedZoom() const;
 
   protected:
     virtual QString _automaticDescriptiveName() const;
@@ -477,9 +478,6 @@
     QMenu *_sharedAxisBoxMenu;
     QAction *_shareBoxShareX;
     QAction *_shareBoxShareY;
-    QAction *_shareBoxTieZoom;
-    QAction *_shareBoxTieXZoom;
-    QAction *_shareBoxTieYZoom;
 
     SharedAxisBoxItem * _sharedBox;
 
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #992676:992677
@@ -66,7 +66,18 @@
       sharePlots(painter, false);
     }
     updatePlotTiedZoomSupport();
+    _keyPlot = 0;
+    foreach (PlotItem* plotItem, _sharedPlots) {
+      if (!_keyPlot) {
+        _keyPlot = plotItem;
+      } else {
+        if ((plotItem->pos().x() > _keyPlot->pos().x()) || ((plotItem->pos().y() < _keyPlot->pos().y()))) {
+          _keyPlot = plotItem;
+        }
+      }
+    }
     _dirty = false;
+
   }
   painter->drawRect(rect());
 }
@@ -79,35 +90,9 @@
 }
 
 
-void SharedAxisBoxItem::zoomTied() {
-#if DEBUG_ZOOM
-  qDebug() << "zoomTied" << endl;
-#endif
-  setTiedZoom(!isTiedZoom(), !isTiedZoom());
-}
-
-
-void SharedAxisBoxItem::zoomXTied() {
-#if DEBUG_ZOOM
-  qDebug() << "zoomXTied" << endl;
-#endif
-  setTiedZoom(!isXTiedZoom(), isYTiedZoom());
-}
-
-
-void SharedAxisBoxItem::zoomYTied() {
-#if DEBUG_ZOOM
-  qDebug() << "zoomYTied" << endl;
-#endif
-  setTiedZoom(isXTiedZoom(), !isYTiedZoom());
-}
-
-
 void SharedAxisBoxItem::save(QXmlStreamWriter &xml) {
   if (isVisible()) {
     xml.writeStartElement("sharedaxisbox");
-    xml.writeAttribute("tiedxzoom", QVariant(isXTiedZoom()).toString());
-    xml.writeAttribute("tiedyzoom", QVariant(isYTiedZoom()).toString());
     xml.writeAttribute("sharex", QVariant(isXAxisShared()).toString());
     xml.writeAttribute("sharey", QVariant(isYAxisShared()).toString());
     xml.writeAttribute("xzoommode", QVariant(xAxisZoomMode()).toString());
@@ -181,6 +166,7 @@
           continue;
         }
         plotItem->setSharedAxisBox(this);
+
         _sharedPlots << plotItem;
         child = plotItem;
         if (!maxSize.contains(plotItem->mapToParent(plotItem->viewRect().topLeft()))) {
@@ -196,7 +182,6 @@
     if (child) {
       setPen(QPen(Qt::white));
       setBrush(Qt::white);
-      setSupportsTiedZoom(true);
       ViewGridLayout::updateProjections(this);
       _dirty = true;
       bReturn =  true;
@@ -243,6 +228,7 @@
     if (PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem)) {
       plotItem->setAllowedGripModes(0);
       plotItem->setFlags(0);
+
       _sharedPlots << plotItem;
     }
   }
@@ -397,6 +383,16 @@
   QList<PlotItem*> plotTied;
   if (originPlotItem && originPlotItem->isTiedZoom() && originPlotItem->isInSharedAxisBox() && (originPlotItem->sharedAxisBox() == this)) {
     plotTied = PlotItemManager::tiedZoomPlotsForView(parentView());
+
+    foreach (PlotItem* plotItem, plotTied) {
+      if ((originPlotItem->isXTiedZoom() && plotItem->isXTiedZoom()) && (originPlotItem->isYTiedZoom() && plotItem->isYTiedZoom())) {
+        plotItem->zoomFixedExpression(projection, true);
+      } else if (originPlotItem->isXTiedZoom() && plotItem->isXTiedZoom()) {
+        plotItem->zoomFixedExpression(QRectF(projection.x(), plotItem->projectionRect().y(), projection.width(), plotItem->projectionRect().height()), true);
+      } else if (originPlotItem->isYTiedZoom() && plotItem->isYTiedZoom()) {
+        plotItem->zoomFixedExpression(QRectF(plotItem->projectionRect().x(), projection.y(), plotItem->projectionRect().width(), projection.height()), true);
+      }
+    }
   }
   foreach (PlotItem* plotItem, allPlots) {
     if ((applyX && applyY) && ((_shareX && _shareY) || (isXTiedZoom() && isYTiedZoom()) || (plotItem == originPlotItem))) {
@@ -407,17 +403,6 @@
       plotItem->zoomFixedExpression(QRectF(plotItem->projectionRect().x(), projection.y(), plotItem->projectionRect().width(), projection.height()), true);
     }
   }
-  foreach (PlotItem* plotItem, plotTied) {
-    if (!allPlots.contains(plotItem)) {
-      if ((originPlotItem->isXTiedZoom() && plotItem->isXTiedZoom()) && (originPlotItem->isYTiedZoom() && plotItem->isYTiedZoom())) {
-        plotItem->zoomFixedExpression(projection, true);
-      } else if (originPlotItem->isXTiedZoom() && plotItem->isXTiedZoom()) {
-        plotItem->zoomFixedExpression(QRectF(projection.x(), plotItem->projectionRect().y(), projection.width(), plotItem->projectionRect().height()), true);
-      } else if (originPlotItem->isYTiedZoom() && plotItem->isYTiedZoom()) {
-        plotItem->zoomFixedExpression(QRectF(plotItem->projectionRect().x(), projection.y(), plotItem->projectionRect().width(), projection.height()), true);
-      }
-    }
-  }
 }
 
 
@@ -438,6 +423,14 @@
   if (!_shareX) {
     if (originPlotItem) {
       originPlotItem->zoomXRange(projection, true);
+
+      if (originPlotItem->isTiedZoom() && originPlotItem->isInSharedAxisBox() && (originPlotItem->sharedAxisBox() == this)) {
+        QList<PlotItem*> plotTied = PlotItemManager::tiedZoomPlotsForView(parentView());
+
+        foreach(PlotItem* plotItem, plotTied) {
+          plotItem->zoomXRange(projection, true);
+        }
+      }
     }
   } else {
     _xAxisZoomMode = PlotAxis::FixedExpression;
@@ -453,6 +446,14 @@
   if (!_shareY) {
     if (originPlotItem) {
       originPlotItem->zoomYRange(projection, true);
+
+      if (originPlotItem->isTiedZoom() && originPlotItem->isInSharedAxisBox() && (originPlotItem->sharedAxisBox() == this)) {
+        QList<PlotItem*> plotTied = PlotItemManager::tiedZoomPlotsForView(parentView());
+
+        foreach(PlotItem* plotItem, plotTied) {
+          plotItem->zoomYRange(projection, true);
+        }
+      }
     }
   } else {
     _yAxisZoomMode = PlotAxis::FixedExpression;
@@ -1027,19 +1028,8 @@
           rc->setParent(parent);
         }
         QXmlStreamAttributes attrs = xml.attributes();
-        QStringRef av;
-        bool xTiedZoom = false, yTiedZoom = false;
-        av = attrs.value("tiedxzoom");
+        QStringRef av = attrs.value("sharex");
         if (!av.isNull()) {
-          xTiedZoom = QVariant(av.toString()).toBool();
-        }
-        av = attrs.value("tiedyzoom");
-        if (!av.isNull()) {
-          yTiedZoom = QVariant(av.toString()).toBool();
-        }
-        rc->setTiedZoom(xTiedZoom, yTiedZoom);
-        av = attrs.value("sharex");
-        if (!av.isNull()) {
           rc->setXAxisShared(QVariant(av.toString()).toBool());
         }
         av = attrs.value("sharey");
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.h #992676:992677
@@ -48,6 +48,8 @@
 
     void updateZoomForDataUpdate();
 
+    PlotItem* keyPlot() { return _keyPlot; };
+
   Q_SIGNALS:
     void breakShareSignal();
 
@@ -59,10 +61,6 @@
     void shareXAxis();
     void shareYAxis();
 
-    void zoomTied();
-    void zoomXTied();
-    void zoomYTied();
-
     void zoomFixedExpression(const QRectF &projection, PlotItem* originPlotItem);
     void zoomXRange(const QRectF &projection, PlotItem* originPlotItem);
     void zoomYRange(const QRectF &projection, PlotItem* originPlotItem);
@@ -110,6 +108,7 @@
     QPointer<ViewGridLayout> _layout;
     QList<PlotItem*> _highlightedPlots;
     QList<PlotItem*> _sharedPlots;
+    PlotItem* _keyPlot;
 
     bool _loaded;
     bool _firstPaint;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #992676:992677
@@ -689,7 +689,7 @@
       QColor highlightColor(QColor(255, 255, 0, 120));
       painter->fillPath(shape(), highlightColor);
     }
-    if (_supportsTiedZoom) {
+    if (supportsTiedZoom()) {
       painter->save();
       painter->setPen(Qt::black);
       painter->setRenderHint(QPainter::Antialiasing, true);


More information about the Kst mailing list