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

Barth Netterfield netterfield at astro.utoronto.ca
Thu Sep 27 19:35:59 UTC 2012


SVN commit 1318197 by netterfield:

BUG:
Plots dragged to a new tab did not show up in plot lists in dialogs.
This fixes that.


 M  +0 -4      plotitem.cpp  
 M  +34 -71    plotitemmanager.cpp  
 M  +1 -7      plotitemmanager.h  
 M  +0 -1      view.cpp  
 M  +1 -4      viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1318196:1318197
@@ -135,8 +135,6 @@
 
   createActions();
 
-  PlotItemManager::self()->addPlot(this);
-
   // Set the initial projection.
   setProjectionRect(QRectF(QPointF(-0.1, -0.1), QPointF(0.1, 0.1)));
   renderItem(PlotRenderItem::Cartesian);
@@ -281,8 +279,6 @@
   delete _filterMenu;
   delete _fitMenu;
   delete _editMenu;
-
-  PlotItemManager::self()->removePlot(this);
 }
 
 void PlotItem::_initializeShortName() {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemmanager.cpp #1318196:1318197
@@ -44,47 +44,6 @@
 }
 
 
-void PlotItemManager::addPlot(PlotItem *plotItem) {
-  if (!_plotLists.contains(plotItem->view())) {
-    _plotLists.insert(plotItem->view(), QList<PlotItem*>() << plotItem);
-  } else {
-    QList<PlotItem*> list = _plotLists.value(plotItem->view());
-    list << plotItem;
-    _plotLists.insert(plotItem->view(), list);
-  }
-}
-
-
-void PlotItemManager::addViewItem(ViewItem *viewItem) {
-  if (!_viewItemLists.contains(viewItem->view())) {
-    _viewItemLists.insert(viewItem->view(), QList<ViewItem*>() << viewItem);
-  } else {
-    QList<ViewItem*> list = _viewItemLists.value(viewItem->view());
-    list << viewItem;
-    _viewItemLists.insert(viewItem->view(), list);
-  }
-}
-
-
-void PlotItemManager::removePlot(PlotItem *plotItem) {
-  if (!_plotLists.contains(plotItem->view()))
-    return;
-  QList<PlotItem*> list = _plotLists.value(plotItem->view());
-  list.removeAll(plotItem);
-  _plotLists.insert(plotItem->view(), list);
-}
-
-
-void PlotItemManager::removeViewItem(ViewItem *viewItem) {
-  if (!_viewItemLists.contains(viewItem->view()))
-    return;
-
-  QList<ViewItem*> list = _viewItemLists.value(viewItem->view());
-  list.removeAll(viewItem);
-  _viewItemLists.insert(viewItem->view(), list);
-}
-
-
 void PlotItemManager::addTiedZoomPlot(PlotItem *plotItem, bool checkAll) {
   if (!_tiedZoomViewPlotLists.contains(plotItem->view())) {
     _tiedZoomViewPlotLists.insert(plotItem->view(), QList<PlotItem*>() << plotItem);
@@ -101,20 +60,12 @@
 
 void PlotItemManager::checkAllTied(View* view) {
   bool bAllTied = true;
-  if (_plotLists.contains(view)) {
-    foreach(PlotItem* plot, _plotLists[view]) {
-      if (plot->supportsTiedZoom() && !plot->isTiedZoom()) {
+  QList<ViewItem*> items = tieableItemsForView(view);
+  foreach (ViewItem* item, items) {
+    if (!item->isTiedZoom()) {
         bAllTied = false;
       }
     }
-  }
-  if (_viewItemLists.contains(view)) {
-    foreach(ViewItem* viewItem, _viewItemLists[view]) {
-      if (viewItem->supportsTiedZoom() && !viewItem->isTiedZoom()) {
-        bAllTied = false;
-      }
-    }
-  }
   if (bAllTied) {
     emit allPlotsTiedZoom();
   }
@@ -127,8 +78,8 @@
 
   // vote on if we should tie all, or untie all
   int n_plots=0, n_tied=0;
-  if (_viewItemLists.contains(view)) {
-    foreach(ViewItem* viewItem, _viewItemLists[view]) {
+  QList<ViewItem *> tieableItems = tieableItemsForView(view);
+  foreach(ViewItem* viewItem, tieableItems) {
       if (viewItem->supportsTiedZoom()) {
         ++n_plots;
         if (viewItem->isTiedZoom()) {
@@ -136,7 +87,6 @@
         }
       }
     }
-  }
 
   if (double(n_tied) > (double)n_plots*0.5) {
     tiedZoom = false;
@@ -144,14 +94,12 @@
     tiedZoom = true;
   }
 
-  if (_viewItemLists.contains(view)) {
-    foreach(ViewItem* viewItem, _viewItemLists[view]) {
+  foreach(ViewItem* viewItem, tieableItems) {
       if (viewItem->supportsTiedZoom()) {
         viewItem->setTiedZoom(tiedZoom, tiedZoom, false);
       }
     }
   }
-}
 
 
 void PlotItemManager::addTiedZoomViewItem(ViewItem *viewItem, bool checkAll) {
@@ -191,22 +139,39 @@
   }
 }
 
-
 QList<PlotItem*> PlotItemManager::plotsForView(View *view) {
-  if (PlotItemManager::self()->_plotLists.contains(view)) {
-    return PlotItemManager::self()->_plotLists.value(view);
+  QList<QGraphicsItem*> graphics_items = view->scene()->items();
+  QList<PlotItem *> plot_items;
+
+  foreach(QGraphicsItem* graphics_item, graphics_items) {
+    PlotItem *item = dynamic_cast<PlotItem*>(graphics_item);
+    if (item && item->isVisible()) {
+      plot_items.append(item);
   }
-  return QList<PlotItem*>();
 }
 
+  qSort(plot_items.begin(), plot_items.end(), shortNameLessThan);
 
-void PlotItemManager::clearPlotsForView(View *view) {
-  if (PlotItemManager::self()->_plotLists.contains(view)) {
-    PlotItemManager::self()->_plotLists.remove(view);
+  return plot_items;
   }
+
+QList<ViewItem*> PlotItemManager::tieableItemsForView(View *view) {
+  QList<QGraphicsItem*> graphics_items = view->scene()->items();
+  QList<ViewItem *> view_items;
+
+  foreach(QGraphicsItem* graphics_item, graphics_items) {
+    ViewItem *item = dynamic_cast<ViewItem*>(graphics_item);
+    if (item && item->isVisible() && item->supportsTiedZoom()) {
+      view_items.append(item);
 }
+  }
 
+  qSort(view_items.begin(), view_items.end(), shortNameLessThan);
 
+  return view_items;
+
+}
+
 QList<PlotItem*> PlotItemManager::tiedZoomPlotsForView(View *view) {
   if (kstApp->mainWindow()->isTiedTabs()) {
     QList<PlotItem*> plots;
@@ -243,14 +208,13 @@
 
 void PlotItemManager::setFocusPlot(PlotItem *plotItem) {
   _focusedPlots.append(plotItem);
-  if (_plotLists.contains(plotItem->view())) {
-    foreach (PlotItem* plot, _plotLists.value(plotItem->view())) {
+  QList<PlotItem*> plots = plotsForView(plotItem->view());
+  foreach (PlotItem* plot, plots) {
       if (plotItem != plot) {
         plot->setAllowUpdates(false);
       }
     }
   }
-}
 
 
 QList<PlotItem*> PlotItemManager::tiedZoomPlots(PlotItem* plotItem) {
@@ -282,14 +246,13 @@
 
 void PlotItemManager::removeFocusPlot(PlotItem *plotItem) {
   _focusedPlots.removeAll(plotItem);
-  if (_plotLists.contains(plotItem->view())) {
-    foreach (PlotItem* plot, _plotLists.value(plotItem->view())) {
+  QList<PlotItem*> plots = plotsForView(plotItem->view());
+  foreach (PlotItem* plot, plots) {
       if (plotItem != plot) {
         plot->setAllowUpdates(true);
       }
     }
   }
-}
 
 
 void PlotItemManager::clearFocusedPlots() {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemmanager.h #1318196:1318197
@@ -33,6 +33,7 @@
     static PlotItemManager *self();
 
     static QList<PlotItem*> plotsForView(View *view);
+    static QList<ViewItem*> tieableItemsForView(View *view);
     static void clearPlotsForView(View *view);
 
     static QList<PlotItem*> tiedZoomPlotsForView(View *view);
@@ -55,11 +56,6 @@
     PlotItemManager();
     virtual ~PlotItemManager();
 
-    void addPlot(PlotItem *plotItem);
-    void addViewItem(ViewItem *viewItem);
-    void removePlot(PlotItem *plotItem);
-    void removeViewItem(ViewItem *viewItem);
-
     void addTiedZoomPlot(PlotItem *plotItem, bool checkAll = true);
     void addTiedZoomViewItem(ViewItem *viewItem, bool checkAll = true);
     void removeTiedZoomPlot(PlotItem *plotItem);
@@ -74,8 +70,6 @@
     friend class ViewItem;
     friend class PlotItem;
     friend class SharedAxisBoxItem;
-    QHash< View*, QList<PlotItem*> > _plotLists;
-    QHash< View*, QList<ViewItem*> > _viewItemLists;
     QHash< View*, QList<PlotItem*> > _tiedZoomViewPlotLists;
     QHash< View*, QList<ViewItem*> > _tiedZoomViewItemLists;
     QHash< ViewItem*, QList<PlotItem*> > _tiedZoomViewItemPlotLists;
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #1318196:1318197
@@ -119,7 +119,6 @@
 
 View::~View() {
   // PlotItems are QGraphicsItems and managed by Qt's graphic view
-  PlotItemManager::clearPlotsForView(this);
   delete _undoStack;
   delete _layoutBoxItem;
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1318196:1318197
@@ -2311,11 +2311,8 @@
       setLayoutMargins(layoutMargins().expandedTo(tiedZoomSize()));
     }
 
-    if (_supportsTiedZoom) {
-      PlotItemManager::self()->addViewItem(this);
-    } else {
+    if (!_supportsTiedZoom) {
       setTiedZoom(false, false, false);
-      PlotItemManager::self()->removeViewItem(this);
     }
   }
 }


More information about the Kst mailing list