[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Mon Jan 5 17:51:37 CET 2009
SVN commit 906144 by fenton:
Add projection size updating when applying a SharedAxisBoxItem.
Fix SharedAxisBoxItem parenting / undo crashes.
M +33 -7 sharedaxisboxitem.cpp
M +6 -1 sharedaxisboxitem.h
M +82 -0 viewgridlayout.cpp
M +1 -0 viewgridlayout.h
M +1 -1 viewitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #906143:906144
@@ -26,7 +26,7 @@
namespace Kst {
SharedAxisBoxItem::SharedAxisBoxItem(View *parent)
- : ViewItem(parent), _layout(0) {
+ : ViewItem(parent), _layout(0), _loaded(false) {
setName("Shared Axis Box");
setZValue(SHAREDAXISBOX_ZVALUE);
setBrush(Qt::transparent);
@@ -56,13 +56,21 @@
}
-void SharedAxisBoxItem::acceptItems() {
+bool SharedAxisBoxItem::acceptItems() {
+ bool bReturn = false;
+
+ if (_loaded) {
+ return true;
+ } else {
+ _loaded = true;
+ }
+
ViewItem* child = 0;
if (parentView()) {
QList<QGraphicsItem*> list = parentView()->items();
foreach (QGraphicsItem *item, list) {
ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
- if (!viewItem || !viewItem->isVisible() || viewItem == this || !collidesWithItem(viewItem, Qt::IntersectsItemBoundingRect)) {
+ if (!viewItem || !viewItem->isVisible() || viewItem == this || viewItem == parentItem() || !collidesWithItem(viewItem, Qt::IntersectsItemBoundingRect)) {
continue;
}
@@ -75,6 +83,8 @@
} else if (parent != parentItem()) {
continue;
}
+ } else if (parentItem()) {
+ continue;
}
plotItem->setSharedAxisBox(this);
child = plotItem;
@@ -82,16 +92,17 @@
}
if (child) {
setBrush(Qt::white);
-
+ ViewGridLayout::updateProjections(this);
sharePlots();
- } else {
- delete this;
+ bReturn = true;
}
}
+ return bReturn;
}
void SharedAxisBoxItem::breakShare() {
+ _loaded = false;
QList<QGraphicsItem*> list = QGraphicsItem::children();
foreach (QGraphicsItem *item, list) {
ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
@@ -161,11 +172,26 @@
_item->show();
SharedAxisBoxItem *shareBox = qobject_cast<SharedAxisBoxItem*>(_item);
if (shareBox) {
- shareBox->acceptItems();
+ if (!shareBox->acceptItems()) {
+ _item->hide();
+ }
}
}
+void CreateSharedAxisBoxCommand::creationComplete() {
+ Q_ASSERT(_item);
+ SharedAxisBoxItem *shareBox = qobject_cast<SharedAxisBoxItem*>(_item);
+ if (shareBox) {
+ if (shareBox->acceptItems()) {
+ CreateCommand::creationComplete();
+ } else {
+ delete _item;
+ }
+ }
+}
+
+
SharedAxisBoxItemFactory::SharedAxisBoxItemFactory()
: GraphicsFactory() {
registerFactory("sharedaxisbox", this);
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.h #906143:906144
@@ -35,16 +35,18 @@
public slots:
void breakShare();
- void acceptItems();
+ bool acceptItems();
void lockItems();
private:
QAction *_breakAction;
QPointer<ViewGridLayout> _layout;
+ bool _loaded;
};
class KST_EXPORT CreateSharedAxisBoxCommand : public CreateCommand
{
+ Q_OBJECT
public:
CreateSharedAxisBoxCommand() : CreateCommand(QObject::tr("Create Shared Axis Box")) {}
CreateSharedAxisBoxCommand(View *view) : CreateCommand(view, QObject::tr("Create Shared Axis Box")) {}
@@ -52,6 +54,9 @@
virtual void undo();
virtual void redo();
virtual void createItem();
+
+ public Q_SLOTS:
+ virtual void creationComplete();
};
class SharedAxisBoxItemFactory : public GraphicsFactory {
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #906143:906144
@@ -557,6 +557,88 @@
}
+void ViewGridLayout::updateProjections(ViewItem *item) {
+ bool xMatch = true;
+ bool yMatch = true;
+
+ bool first = true;
+
+ qreal xStart = 0.0, xStop = 0.0;
+ qreal yStart = 0.0, yStop = 0.0;
+ qreal xMin, xMax, yMin, yMax;
+
+ QList<ViewItem*> viewItems;
+ QList<QGraphicsItem*> list = item->QGraphicsItem::children();
+ if (list.isEmpty())
+ return; //not added to undostack
+
+ foreach (QGraphicsItem *graphicsItem, list) {
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(graphicsItem);
+ if (!viewItem || viewItem->hasStaticGeometry() || !viewItem->allowsLayout() || viewItem->parentItem() != item)
+ continue;
+
+ PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem);
+
+ if (!plotItem)
+ continue;
+
+ if (first) {
+ xStart = plotItem->projectionRect().left();
+ xStop = plotItem->projectionRect().right();
+ yStart = plotItem->projectionRect().top();
+ yStop = plotItem->projectionRect().bottom();
+ xMin = xStart;
+ xMax = xStop;
+ yMin = yStart;
+ yMax = yStop;
+ first = false;
+ } else {
+ if (xMatch && (plotItem->projectionRect().left() != xStart || plotItem->projectionRect().right() != xStop)) {
+ xMatch = false;
+ }
+ if (yMatch && (plotItem->projectionRect().top() != yStart || plotItem->projectionRect().bottom() != yStop)) {
+ yMatch = false;
+ }
+ if (xMin > plotItem->projectionRect().left()) {
+ xMin = plotItem->projectionRect().left();
+ }
+ if (xMax < plotItem->projectionRect().right()) {
+ xMax = plotItem->projectionRect().right();
+ }
+ if (yMin > plotItem->projectionRect().top()) {
+ yMin = plotItem->projectionRect().top();
+ }
+ if (yMax < plotItem->projectionRect().bottom()) {
+ yMax = plotItem->projectionRect().bottom();
+ }
+ }
+ }
+
+ if (!xMatch && !yMatch) {
+ xMatch = true;
+ yMatch = true;
+ }
+
+ QRectF projectionRect(QPointF(xMin, yMin), QPointF(xMax, yMax));
+
+ foreach (QGraphicsItem *graphicsItem, list) {
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(graphicsItem);
+ if (!viewItem || viewItem->hasStaticGeometry() || !viewItem->allowsLayout() || viewItem->parentItem() != item)
+ continue;
+
+ if (PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem)) {
+ if (xMatch && yMatch) {
+ plotItem->zoomFixedExpression(projectionRect);
+ } else if (xMatch) {
+ plotItem->zoomXRange(projectionRect);
+ } else if (yMatch) {
+ plotItem->zoomYRange(projectionRect);
+ }
+ }
+ }
+}
+
+
void ViewGridLayout::shareAxisWithPlotToLeft(LayoutItem item) {
PlotItem *plotItem = qobject_cast<PlotItem*>(item.viewItem);
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #906143:906144
@@ -56,6 +56,7 @@
void setEnabled(bool enabled);
void calculateSharing();
+ static void updateProjections(ViewItem *item);
static void resetSharedPlots(ViewItem *item);
static void standardizePlotMargins(ViewItem *item);
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #906143:906144
@@ -278,7 +278,7 @@
ViewItem *item() const { return _item; }
public Q_SLOTS:
- void creationComplete();
+ virtual void creationComplete();
protected:
QPointer<ViewItem> _item;
More information about the Kst
mailing list