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

Mike Fenton mike at staikos.net
Wed Jul 16 17:33:47 CEST 2008


SVN commit 833284 by fenton:

Remove persisted Layouts.
Fix label overdrawing.


 M  +3 -13     layoutboxitem.cpp  
 M  +0 -19     mainwindow.cpp  
 M  +0 -2      mainwindow.h  
 M  +10 -40    plotitem.cpp  
 M  +0 -5      plotrenderitem.cpp  
 M  +0 -1      plotrenderitem.h  
 M  +6 -3      view.cpp  
 M  +1 -3      viewgridlayout.cpp  
 M  +16 -62    viewitem.cpp  
 M  +0 -8      viewitem.h  
 M  +4 -4      viewitemdialog.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.cpp #833283:833284
@@ -45,11 +45,11 @@
     return;
 
   item->setParent(this);
-  layout()->addViewItem(item, layout()->rowCount(), 0, 1, layout()->columnCount());
+//   layout()->addViewItem(item, layout()->rowCount(), 0, 1, layout()->columnCount());
   setPos(parentView()->sceneRect().topLeft());
   setViewRect(parentView()->sceneRect());
   //singleshot to give plots a chance to set a projection rect
-  QTimer::singleShot(0, layout(), SLOT(update()));
+//   QTimer::singleShot(0, layout(), SLOT(update()));
 }
 
 
@@ -121,17 +121,7 @@
 
 
 void LayoutBoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
-  QMenu menu;
-
-  addTitle(&menu);
-
-  QAction *editAction = menu.addAction(tr("Edit"));
-  connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
-
-  QAction *breakLayoutAction = menu.addAction(tr("Break layout"));
-  connect(breakLayoutAction, SIGNAL(triggered()), this, SLOT(breakLayout()));
-
-  menu.exec(event->screenPos());
+  event->ignore();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #833283:833284
@@ -132,7 +132,6 @@
   _createPlotAct->setEnabled(layoutMode);
   _createSvgAct->setEnabled(layoutMode);
   _createLayoutAct->setEnabled(layoutMode);
-  _breakLayoutAct->setEnabled(layoutMode);
 
   _layoutToolBar->setVisible(layoutMode);
   _zoomToolBar->setVisible(!layoutMode);
@@ -415,17 +414,6 @@
 }
 
 
-void MainWindow::breakLayout() {
-  View *view = tabWidget()->currentView();
-  QList<QGraphicsItem*> selectedItems = view->scene()->selectedItems();
-  if (!selectedItems.isEmpty()) {
-    ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(selectedItems.first());
-    Q_ASSERT(viewItem);
-    viewItem->breakLayout();
-  }
-}
-
-
 void MainWindow::demoModel() {
 /*  Q_ASSERT(document() && document()->objectStore());
   VectorPtr v = kst_cast<Vector>(document()->objectStore()->createObject<Vector>());
@@ -525,12 +513,6 @@
   _createLayoutAct->setEnabled(false);
   connect(_createLayoutAct, SIGNAL(triggered()), this, SLOT(createLayout()));
 
-  _breakLayoutAct = new QAction(tr("&Break layout"), this);
-  _breakLayoutAct->setStatusTip(tr("Break the layout for the current item"));
-  _breakLayoutAct->setIcon(QPixmap(":kst_gfx_breaklayout.png"));
-  _breakLayoutAct->setEnabled(false);
-  connect(_breakLayoutAct, SIGNAL(triggered()), this, SLOT(breakLayout()));
-
   // ****************************************************************************** //
 
   // ********************* Object Dialog Actions ********************************** //
@@ -783,7 +765,6 @@
   _layoutToolBar->addSeparator();
 
   _layoutToolBar->addAction(_createLayoutAct);
-  _layoutToolBar->addAction(_breakLayoutAct);
   _layoutToolBar->setVisible(false);
   _zoomToolBar->setVisible(true);
 
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #833283:833284
@@ -90,7 +90,6 @@
     void createPlot();
     void createSvg();
     void createLayout();
-    void breakLayout();
 
     void demoModel();
 
@@ -158,7 +157,6 @@
     QAction *_createPlotAct;
     QAction *_createSvgAct;
     QAction *_createLayoutAct;
-    QAction *_breakLayoutAct;
 
     QAction *_aboutAct;
     QAction *_closeTabAct;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #833283:833284
@@ -714,62 +714,32 @@
 
 
 qreal PlotItem::leftLabelMargin() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotLabelMarginWidth(this);
-  } else {
-    return calculatedLeftLabelMargin();
-  }
+  return calculatedLeftLabelMargin();
 }
 
 
 qreal PlotItem::rightLabelMargin() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotLabelMarginWidth(this);
-  } else {
-    return calculatedRightLabelMargin();
-  }
+  return calculatedRightLabelMargin();
 }
 
 
 qreal PlotItem::topLabelMargin() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotLabelMarginHeight(this);
-  } else {
-    return calculatedTopLabelMargin();
-  }
+  return calculatedTopLabelMargin();
 }
 
 
 qreal PlotItem::bottomLabelMargin() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotLabelMarginHeight(this);
-  } else {
-    return calculatedBottomLabelMargin();
-  }
+  return calculatedBottomLabelMargin();
 }
 
 
 qreal PlotItem::axisMarginWidth() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotAxisMarginWidth(this);
-  } else {
-    return calculatedAxisMarginWidth();
-  }
+  return calculatedAxisMarginWidth();
 }
 
 
 qreal PlotItem::axisMarginHeight() const {
-  ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(parentItem());
-  if (viewItem && viewItem->layout()) {
-    return viewItem->layout()->plotAxisMarginHeight(this);
-  } else {
-    return calculatedAxisMarginHeight();
-  }
+  return calculatedAxisMarginHeight();
 }
 
 
@@ -1380,7 +1350,7 @@
     t.rotate(90.0);
     painter->rotate(-90.0);
 
-    painter->drawPixmap(t.mapRect(leftLabel).topLeft(), pixmap);
+    painter->drawPixmap(t.mapRect(leftLabel).topLeft(), pixmap, QRectF(0, 0, rc.x, leftLabel.height()));
 
     painter->restore();
     delete parsed;
@@ -1448,7 +1418,7 @@
     bottomLabel.moveTopLeft(plotAxisRect().bottomLeft());
     bottomLabel.moveTopLeft(QPointF(bottomLabel.topLeft().x() + ((bottomLabel.width() / 2) - (rc.x / 2)), bottomLabel.topLeft().y()));
 
-    painter->drawPixmap(bottomLabel.topLeft(), pixmap);
+    painter->drawPixmap(bottomLabel.topLeft(), pixmap, QRectF(0, 0, rc.x, bottomLabel.height()));
 
     painter->restore();
     delete parsed;
@@ -1514,7 +1484,7 @@
       t.rotate(-90.0);
       painter->rotate(90.0);
 
-      painter->drawPixmap(t.mapRect(rightLabel).topLeft(), pixmap);
+      painter->drawPixmap(t.mapRect(rightLabel).topLeft(), pixmap, QRectF(0, 0, rc.x, rightLabel.height()));
     }
     painter->restore();
 
@@ -1584,7 +1554,7 @@
       topLabel.moveBottomLeft(plotAxisRect().topLeft());
       topLabel.moveTopLeft(QPointF(topLabel.topLeft().x() + ((topLabel.width() / 2) - (rc.x / 2)), topLabel.topLeft().y()));
 
-      painter->drawPixmap(topLabel.topLeft(), pixmap);
+      painter->drawPixmap(topLabel.topLeft(), pixmap, QRectF(0, 0, rc.x, topLabel.height()));
     }
     painter->restore();
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #833283:833284
@@ -555,11 +555,6 @@
 }
 
 
-void PlotRenderItem::breakLayout() {
-  plotItem()->breakLayout();
-}
-
-
 void PlotRenderItem::remove() {
   plotItem()->remove();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #833283:833284
@@ -71,7 +71,6 @@
     virtual void raise();
     virtual void lower();
     virtual void createLayout();
-    virtual void breakLayout();
     virtual void remove();
     virtual void relationUpdated(ObjectPtr object);
 
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #833283:833284
@@ -254,11 +254,14 @@
 
 
 void View::createLayout() {
-  if (_layoutBoxItem && _layoutBoxItem->isVisible() && _layoutBoxItem->layout() )
-    return;
-
   LayoutCommand *layout = new LayoutCommand(new LayoutBoxItem(this));
   layout->createLayout();
+
+  if (_layoutBoxItem) {
+    _layoutBoxItem->setEnabled(false);
+    delete _layoutBoxItem;
+    _layoutBoxItem = 0;
+  }
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #833283:833284
@@ -16,7 +16,7 @@
 
 #include <QDebug>
 
-//#define DEBUG_LAYOUT
+// #define DEBUG_LAYOUT
 
 static qreal DEFAULT_STRUT = 20.0;
 
@@ -29,8 +29,6 @@
     _columnCount(0),
     _spacing(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)),
     _margin(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)) {
-
-  parent->setLayout(this);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #833283:833284
@@ -51,7 +51,6 @@
     _hovering(false),
     _acceptsChildItems(true),
     _acceptsContextMenuEvents(true),
-    _layout(0),
     _activeGrip(NoGrip),
     _allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
                   TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip),
@@ -277,11 +276,6 @@
 }
 
 
-bool ViewItem::itemInLayout() const {
-  return parentViewItem() && parentViewItem()->layout() && allowsLayout();
-}
-
-
 ViewItem::GripMode ViewItem::gripMode() const {
   return _gripMode;
 }
@@ -308,30 +302,6 @@
 }
 
 
-ViewGridLayout *ViewItem::layout() const {
-  return _layout;
-}
-
-
-void ViewItem::setLayout(ViewGridLayout *layout) {
-  if (_layout == layout)
-    return;
-
-  //disconnect previous layout...
-  if (_layout) {
-    _layout->setEnabled(false);
-    disconnect(this, SIGNAL(geometryChanged()), _layout, SLOT(update()));
-  }
-
-  _layout = layout;
-
-  if (_layout) {
-    _layout->setEnabled(true);
-    connect(this, SIGNAL(geometryChanged()), _layout, SLOT(update()));
-  }
-}
-
-
 QRectF ViewItem::viewRect() const {
   return rect();
 }
@@ -363,9 +333,7 @@
       continue;
 
 
-    if (!layout() || !viewItem->allowsLayout()) {
-      viewItem->updateChildGeometry(oldViewRect, viewRect);
-    }
+    viewItem->updateChildGeometry(oldViewRect, viewRect);
   }
 }
 
@@ -685,20 +653,15 @@
 
 
 void ViewItem::createLayout() {
-  LayoutCommand *layout = new LayoutCommand(this);
-  layout->createLayout();
+  if (parentViewItem()) {
+    LayoutCommand *layout = new LayoutCommand(parentViewItem());
+    layout->createLayout();
+  } else if (parentView()) {
+    parentView()->createLayout();
+  }
 }
 
 
-void ViewItem::breakLayout() {
-  if (!layout())
-    return;
-
-  BreakLayoutCommand *layout = new BreakLayoutCommand(this);
-  layout->redo();
-}
-
-
 void ViewItem::raise() {
   RaiseCommand *up = new RaiseCommand(this);
   up->redo();
@@ -790,13 +753,13 @@
   QAction *lowerAction = menu.addAction(tr("Lower"));
   connect(lowerAction, SIGNAL(triggered()), this, SLOT(lower()));
 
-  QAction *layoutAction = menu.addAction(tr("Create layout"));
+  QMenu layoutMenu;
+  layoutMenu.setTitle(tr("Cleanup Layout"));
+
+  QAction *layoutAction = layoutMenu.addAction(tr("Automatic Cleanup"));
   connect(layoutAction, SIGNAL(triggered()), this, SLOT(createLayout()));
-  layoutAction->setEnabled(!layout());
 
-  QAction *breakLayoutAction = menu.addAction(tr("Break layout"));
-  connect(breakLayoutAction, SIGNAL(triggered()), this, SLOT(breakLayout()));
-  breakLayoutAction->setEnabled(layout());
+  menu.addMenu(&layoutMenu);
 
   QAction *removeAction = menu.addAction(tr("Remove"));
   connect(removeAction, SIGNAL(triggered()), this, SLOT(remove()));
@@ -814,7 +777,7 @@
 
 void ViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (parentView()->viewMode() == View::Data || itemInLayout()) {
+  if (parentView()->viewMode() == View::Data) {
     event->ignore();
     return;
   }
@@ -1321,9 +1284,6 @@
       return false;
     }
 
-    if (viewItem->layout()) /*don't crash existing layout*/
-      continue;
-
 #ifdef DEBUG_REPARENT
     qDebug() << "reparent to" << viewItem << endl;
 
@@ -1542,7 +1502,7 @@
 
 
 void ViewItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
-  if (parentView()->viewMode() == View::Data || itemInLayout()) {
+  if (parentView()->viewMode() == View::Data) {
     event->ignore();
     return;
   }
@@ -1551,7 +1511,7 @@
 
 void ViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (parentView()->viewMode() == View::Data || itemInLayout()) {
+  if (parentView()->viewMode() == View::Data) {
     event->ignore();
     return;
   }
@@ -1624,7 +1584,7 @@
 
 void ViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (parentView()->viewMode() == View::Data || itemInLayout()) {
+  if (parentView()->viewMode() == View::Data) {
     event->ignore();
     return;
   }
@@ -1830,13 +1790,11 @@
 void LayoutCommand::undo() {
   Q_ASSERT(_layout);
   _layout->reset();
-  _item->setLayout(0);
 }
 
 
 void LayoutCommand::redo() {
   Q_ASSERT(_layout);
-  _item->setLayout(_layout);
   _layout->update();
 }
 
@@ -1892,17 +1850,13 @@
 
 void BreakLayoutCommand::undo() {
   Q_ASSERT(_layout);
-  _item->setLayout(_layout);
   _layout->update();
 }
 
 
 void BreakLayoutCommand::redo() {
-  _layout = _item->layout();
   Q_ASSERT(_layout);
   _layout->resetSharedAxis();
-  _item->setLayout(0);
-
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #833283:833284
@@ -63,7 +63,6 @@
     View *parentView() const;
     ViewItem *parentViewItem() const;
     void setParent(ViewItem *parent);
-    bool itemInLayout() const;
     virtual void updateRelativeSize();
     qreal relativeHeight() const { return _parentRelativeHeight; }
     qreal relativeWidth() const { return _parentRelativeWidth; }
@@ -91,11 +90,6 @@
     bool allowsLayout() const { return _allowsLayout; }
     void setAllowsLayout(bool allowsLayout ) { _allowsLayout = allowsLayout; }
 
-    //NOTE We can change this to a generic abstract class once we have
-    //more layouts besides grid layout...
-    ViewGridLayout *layout() const;
-    void setLayout(ViewGridLayout *layout);
-
     //NOTE This should be used in place of QGraphicsRectItem::setRect()...
     QRectF viewRect() const;
     void setViewRect(const QRectF &viewRect, bool automaticChange = false);
@@ -150,7 +144,6 @@
     virtual void raise();
     virtual void lower();
     virtual void createLayout();
-    virtual void breakLayout();
     virtual void remove();
     void resizeTopLeft(const QPointF &offset);
     void resizeTopRight(const QPointF &offset);
@@ -221,7 +214,6 @@
     bool _hovering;
     bool _acceptsChildItems;
     bool _acceptsContextMenuEvents;
-    ViewGridLayout *_layout;
     QPointF _originalPosition;
     QRectF _originalRect;
     QTransform _originalTransform;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.cpp #833283:833284
@@ -88,7 +88,7 @@
 
 void ViewItemDialog::setupLayout() {
   Q_ASSERT(_item);
-  ViewGridLayout *layout = _item->layout();
+/*  ViewGridLayout *layout = _item->layout();
 
   _layoutTab->setLockAspectRatio(_item->lockAspectRatio());
   _layoutTab->enableLockAspectRatio(!_item->lockAspectRatioFixed());
@@ -101,7 +101,7 @@
   _layoutTab->setHorizontalMargin(layout->margin().width());
   _layoutTab->setVerticalMargin(layout->margin().height());
   _layoutTab->setHorizontalSpacing(layout->spacing().width());
-  _layoutTab->setVerticalSpacing(layout->spacing().height());
+  _layoutTab->setVerticalSpacing(layout->spacing().height());*/
 }
 
 
@@ -143,7 +143,7 @@
 
 void ViewItemDialog::layoutChanged() {
   Q_ASSERT(_item);
-  ViewGridLayout *layout = _item->layout();
+/*  ViewGridLayout *layout = _item->layout();
 
   _item->setLockAspectRatio(_layoutTab->lockAspectRatio());
   if (!layout) {
@@ -155,7 +155,7 @@
                            _layoutTab->verticalMargin()));
   layout->setSpacing(QSizeF(_layoutTab->horizontalSpacing(),
                             _layoutTab->verticalSpacing()));
-  layout->update();
+  layout->update();*/
 }
 
 


More information about the Kst mailing list