[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Sep 16 16:37:13 CEST 2008
SVN commit 861586 by fenton:
Add PlotStandarization to ensure uniform margin sizes.
M +39 -2 plotitem.cpp
M +9 -0 plotitem.h
M +56 -3 viewgridlayout.cpp
M +2 -0 viewgridlayout.h
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #861585:861586
@@ -64,6 +64,8 @@
_calculatedLabelMarginHeight(0.0),
_calculatedAxisMarginWidth(0.0),
_calculatedAxisMarginHeight(0.0),
+ _leftPadding(0.0),
+ _bottomPadding(0.0),
_leftLabelFontScale(0.0),
_bottomLabelFontScale(0.0),
_topLabelFontScale(0.0),
@@ -94,6 +96,8 @@
// Set the initial projection.
setProjectionRect(QRectF(QPointF(-0.1, -0.1), QPointF(0.1, 0.1)));
renderItem(PlotRenderItem::Cartesian);
+
+ connect(this, SIGNAL(marginsChanged()), this, SLOT(marginsUpdated()));
}
@@ -334,6 +338,11 @@
}
+void PlotItem::marginsUpdated() {
+ ViewGridLayout::standardizePlotMargins(this);
+}
+
+
QList<PlotRenderItem*> PlotItem::renderItems() const {
return _renderers.values();
}
@@ -730,13 +739,41 @@
QRectF plot = plotAxisRect();
qreal xOffset = _xAxis->isAxisVisible() ? axisMarginHeight() : 0.0;
qreal yOffset = _yAxis->isAxisVisible() ? axisMarginWidth() : 0.0;
+ qreal xPadding = _xAxis->isAxisVisible() ? _bottomPadding : 0.0;
+ qreal yPadding = _yAxis->isAxisVisible() ? _leftPadding : 0.0;
- plot.setLeft(plot.left() + yOffset);
- plot.setBottom(plot.bottom() - xOffset);
+ plot.setLeft(plot.left() + yOffset + yPadding);
+ plot.setBottom(plot.bottom() - xOffset - xPadding);
return plot;
}
+qreal PlotItem::leftMarginSize() const {
+ qreal margin = isLeftLabelVisible() ? leftLabelMargin() : 0.0;
+ margin += _yAxis->isAxisVisible() ? axisMarginWidth() : 0.0;
+
+ return margin;
+}
+
+
+qreal PlotItem::bottomMarginSize() const {
+ qreal margin = isBottomLabelVisible() ? bottomLabelMargin() : 0.0;
+ margin += _xAxis->isAxisVisible() ? axisMarginHeight() : 0.0;
+
+ return margin;
+}
+
+
+void PlotItem::setLeftPadding(const qreal padding) {
+ _leftPadding = padding;
+}
+
+
+void PlotItem::setBottomPadding(const qreal padding) {
+ _bottomPadding = padding;
+}
+
+
QRectF PlotItem::projectionRect() const {
return _projectionRect;
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #861585:861586
@@ -79,6 +79,11 @@
bool isTiedZoom() const;
void setTiedZoom(bool tiedZoom);
+ qreal leftMarginSize() const;
+ void setLeftPadding(const qreal);
+ qreal bottomMarginSize() const;
+ void setBottomPadding(const qreal);
+
qreal leftLabelMargin() const;
qreal rightLabelMargin() const;
qreal topLabelMargin() const;
@@ -204,6 +209,7 @@
void zoomNormalizeYtoX();
void zoomLogY();
virtual void edit();
+ void marginsUpdated();
private:
void createActions();
@@ -287,6 +293,9 @@
qreal _calculatedAxisMarginWidth;
qreal _calculatedAxisMarginHeight;
+ qreal _leftPadding;
+ qreal _bottomPadding;
+
PlotAxis *_xAxis;
PlotAxis *_yAxis;
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #861585:861586
@@ -16,7 +16,9 @@
#include <QDebug>
-// #define DEBUG_LAYOUT
+// 0 off, 1 On
+#define DEBUG_LAYOUT 0
+#define DEBUG_PLOT_STANDARDIZATION 0
static qreal DEFAULT_STRUT = 20.0;
@@ -178,6 +180,57 @@
}
+void ViewGridLayout::standardizePlotMargins(ViewItem *item) {
+
+ QList<QGraphicsItem*> list;
+ QList<PlotItem*> plotItems;
+ if (item->parentView()) {
+ QList<QGraphicsItem*> list = item->parentView()->items();
+ foreach (QGraphicsItem *item, list) {
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
+ if (!viewItem || viewItem->parentItem() || !viewItem->isVisible())
+ continue;
+ if (PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem)) {
+ plotItems.append(plotItem);
+ }
+ }
+ }
+
+#if DEBUG_PLOT_STANDARDIZATION
+ qDebug() << "Ready to standarize" << plotItems.count() << "plots";
+#endif
+
+ QMap<qreal, qreal> marginWidths;
+ QMap<qreal, qreal> marginHeights;
+ foreach (PlotItem* plotItem, plotItems) {
+ if (marginWidths[plotItem->width()] < plotItem->leftMarginSize()) {
+ marginWidths[plotItem->width()] = plotItem->leftMarginSize();
+ }
+ if (marginHeights[plotItem->height()] < plotItem->bottomMarginSize()) {
+ marginHeights[plotItem->height()] = plotItem->bottomMarginSize();
+ }
+ }
+
+#if DEBUG_PLOT_STANDARDIZATION
+ qDebug() << "Maximum margin widths" << marginWidths;
+ qDebug() << "Maximum margin heights" << marginHeights;
+#endif
+
+
+ foreach (PlotItem* plotItem, plotItems) {
+
+#if DEBUG_PLOT_STANDARDIZATION
+ qDebug() << "Margin width is " << plotItem->leftMarginSize() << "setting to" << marginWidths[plotItem->width()] - plotItem->leftMarginSize();
+ qDebug() << "Margin height is " << plotItem->bottomMarginSize() << "setting to" << marginHeights[plotItem->height()] - plotItem->bottomMarginSize();
+#endif
+
+ plotItem->setLeftPadding(marginWidths[plotItem->width()] - plotItem->leftMarginSize());
+ plotItem->setBottomPadding(marginHeights[plotItem->height()] - plotItem->bottomMarginSize());
+ emit plotItem->updatePlotRect();
+ }
+}
+
+
void ViewGridLayout::resetSharedAxis() {
foreach (LayoutItem item, _items) {
if (PlotItem *plotItem = qobject_cast<PlotItem*>(item.viewItem)) {
@@ -205,7 +258,7 @@
qreal itemWidth = layoutSize.width() / columnCount();
qreal itemHeight = layoutSize.height() / rowCount();
-#ifdef DEBUG_LAYOUT
+#if DEBUG_LAYOUT
qDebug() << "layouting" << _items.count()
<< "itemWidth:" << itemWidth
<< "itemHeight:" << itemHeight
@@ -254,7 +307,7 @@
if (PlotItem *plotItem = qobject_cast<PlotItem*>(item.viewItem))
emit plotItem->updatePlotRect();
-#ifdef DEBUG_LAYOUT
+#if DEBUG_LAYOUT
qDebug() << "layout"
<< "row:" << item.row
<< "column:" << item.column
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #861585:861586
@@ -53,7 +53,9 @@
bool isEnabled() const;
void setEnabled(bool enabled);
+
static void resetSharedPlots(ViewItem *item);
+ static void standardizePlotMargins(ViewItem *item);
public Q_SLOTS:
void reset();
More information about the Kst
mailing list