[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Mar 4 19:27:53 CET 2008
SVN commit 782272 by fenton:
Add Fix for Shared Axis.
Update handling of PlotAxis margin calculations.
M +136 -53 plotitem.cpp
M +22 -1 plotitem.h
M +9 -9 viewgridlayout.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #782271:782272
@@ -50,6 +50,8 @@
_isBottomLabelVisible(true),
_isRightLabelVisible(true),
_isTopLabelVisible(true),
+ _isBottomAxisVisible(true),
+ _isLeftAxisVisible(true),
_calculatedLabelMarginWidth(0.0),
_calculatedLabelMarginHeight(0.0),
_calculatedAxisMarginWidth(0.0),
@@ -119,6 +121,8 @@
void PlotItem::save(QXmlStreamWriter &xml) {
xml.writeStartElement("plot");
xml.writeAttribute("tiedzoom", QVariant(_isTiedZoom).toString());
+ xml.writeAttribute("bottomaxisvisible", QVariant(_isBottomAxisVisible).toString());
+ xml.writeAttribute("leftaxisvisible", QVariant(_isLeftAxisVisible).toString());
xml.writeAttribute("leftlabelvisible", QVariant(_isLeftLabelVisible).toString());
xml.writeAttribute("bottomlabelvisible", QVariant(_isBottomLabelVisible).toString());
xml.writeAttribute("rightlabelvisible", QVariant(_isRightLabelVisible).toString());
@@ -239,7 +243,7 @@
paintTopLabel(painter);
paintPlot(painter, xMajorTicks, xMinorTicks, yMajorTicks, yMinorTicks);
- paintMajorTickLabels(painter, xMajorTicks, yMajorTicks, xLabels, yLabels);
+ paintTickLabels(painter, xMajorTicks, yMajorTicks, xLabels, yLabels);
paintPlotMarkers(painter);
painter->restore();
@@ -410,17 +414,15 @@
}
-void PlotItem::paintMajorTickLabels(QPainter *painter,
+void PlotItem::paintBottomTickLabels(QPainter *painter,
const QList<qreal> &xMajorTicks,
- const QList<qreal> &yMajorTicks,
- const QMap<qreal, QString> &xLabelsIn,
- const QMap<qreal, QString> &yLabelsIn) {
+ const QMap<qreal, QString> &xLabelsIn) {
- QRectF yLabelRect, xLabelRect;
+ QRectF xLabelRect;
int flags = Qt::TextSingleLine | Qt::AlignVCenter;
+ QMap<qreal, QString> xLabels;
+ QString xBaseLabel;
- QMap<qreal, QString> xLabels;
- QString xBaseLabel, yBaseLabel;
if (_xAxisBaseOffset || _xAxisInterpret) {
qreal base;
int shortest = 1000;
@@ -480,6 +482,31 @@
painter->drawText(bound, flags, xLabelIt.value());
}
+ if (!xBaseLabel.isEmpty()) {
+ QRectF bound = painter->boundingRect(QRectF(), flags, xBaseLabel);
+ QPointF p = QPointF(plotRect().left(), plotRect().bottom() + bound.height() * 2.0);
+ bound.moveBottomLeft(p);
+
+ if (xLabelRect.isValid()) {
+ xLabelRect = xLabelRect.united(bound);
+ } else {
+ xLabelRect = bound;
+ }
+
+ painter->drawText(bound, flags, xBaseLabel);
+ }
+ _xLabelRect = xLabelRect;
+}
+
+
+void PlotItem::paintLeftTickLabels(QPainter *painter,
+ const QList<qreal> &yMajorTicks,
+ const QMap<qreal, QString> &yLabelsIn) {
+
+ QRectF yLabelRect;
+ int flags = Qt::TextSingleLine | Qt::AlignVCenter;
+ QString yBaseLabel;
+
QMap<qreal, QString> yLabels;
if (_yAxisBaseOffset || _yAxisInterpret) {
qreal base;
@@ -560,32 +587,23 @@
painter->drawText(t.mapRect(bound), flags, yBaseLabel);
painter->restore();
}
+ _yLabelRect = yLabelRect;
+}
- if (!xBaseLabel.isEmpty()) {
- QRectF bound = painter->boundingRect(QRectF(), flags, xBaseLabel);
- QPointF p = QPointF(plotRect().left(), plotRect().bottom() + bound.height() * 2.0);
- bound.moveBottomLeft(p);
- if (xLabelRect.isValid()) {
- xLabelRect = xLabelRect.united(bound);
- } else {
- xLabelRect = bound;
- }
+void PlotItem::paintTickLabels(QPainter *painter,
+ const QList<qreal> &xMajorTicks,
+ const QList<qreal> &yMajorTicks,
+ const QMap<qreal, QString> &xLabelsIn,
+ const QMap<qreal, QString> &yLabelsIn) {
- painter->drawText(bound, flags, xBaseLabel);
+ if (isBottomAxisVisible()) {
+ paintBottomTickLabels(painter, xMajorTicks, xLabelsIn);
}
- _xLabelRect = xLabelRect;
- _yLabelRect = yLabelRect;
-
-/* painter->save();
- painter->setOpacity(0.3);
-// qDebug() << "xLabelRect:" << xLabelRect << endl;
- painter->fillRect(xLabelRect, Qt::blue);
-
-// qDebug() << "yLabelRect:" << yLabelRect << endl;
- painter->fillRect(yLabelRect, Qt::green);
- painter->restore();*/
+ if (isLeftAxisVisible()) {
+ paintLeftTickLabels(painter, yMajorTicks, yLabelsIn);
+ }
}
@@ -930,8 +948,11 @@
QRectF PlotItem::plotRect() const {
//the PlotRenderItems use this to set their rects
QRectF plot = plotAxisRect();
- plot.setLeft(plot.left() + axisMarginWidth());
- plot.setBottom(plot.bottom() - axisMarginHeight());
+ qreal xOffset = isBottomAxisVisible() ? axisMarginHeight() : 0.0;
+ qreal yOffset = isLeftAxisVisible() ? axisMarginHeight() : 0.0;
+
+ plot.setLeft(plot.left() + yOffset);
+ plot.setBottom(plot.bottom() - xOffset);
return plot;
}
@@ -1561,6 +1582,56 @@
}
+void PlotItem::setTopSuppressed(bool visible) {
+ setTopLabelVisible(visible);
+}
+
+
+void PlotItem::setRightSuppressed(bool visible) {
+ setRightLabelVisible(visible);
+}
+
+
+void PlotItem::setLeftSuppressed(bool visible) {
+ setLeftLabelVisible(visible);
+ setLeftAxisVisible(visible);
+}
+
+
+void PlotItem::setBottomSuppressed(bool visible) {
+ setBottomLabelVisible(visible);
+ setBottomAxisVisible(visible);
+}
+
+
+bool PlotItem::isBottomAxisVisible() const {
+ return _isBottomAxisVisible;
+}
+
+
+void PlotItem::setBottomAxisVisible(bool visible) {
+ if (_isBottomAxisVisible == visible)
+ return;
+
+ _isBottomAxisVisible = visible;
+ emit marginsChanged();
+}
+
+
+bool PlotItem::isLeftAxisVisible() const {
+ return _isLeftAxisVisible;
+}
+
+
+void PlotItem::setLeftAxisVisible(bool visible) {
+ if (_isLeftAxisVisible == visible)
+ return;
+
+ _isLeftAxisVisible = visible;
+ emit marginsChanged();
+}
+
+
bool PlotItem::isLeftLabelVisible() const {
return _isLeftLabelVisible;
}
@@ -1622,6 +1693,8 @@
setRightLabelVisible(visible);
setBottomLabelVisible(visible);
setTopLabelVisible(visible);
+ setBottomAxisVisible(visible);
+ setLeftAxisVisible(visible);
}
@@ -2154,21 +2227,22 @@
QSizeF PlotItem::calculateXTickLabelBound(QPainter *painter,
const QList<qreal> &xMajorTicks) {
QRectF xLabelRect;
- foreach (qreal x, xMajorTicks) {
- int flags = Qt::TextSingleLine | Qt::AlignVCenter;
- QString label = QString::number(x);
+ if (isBottomAxisVisible()) {
+ foreach (qreal x, xMajorTicks) {
+ int flags = Qt::TextSingleLine | Qt::AlignVCenter;
+ QString label = QString::number(x);
- QRectF bound = painter->boundingRect(QRectF(), flags, label);
- QPointF p(mapXToPlot(x), plotRect().bottom() + bound.height() / 2.0);
- bound.moveCenter(p);
+ QRectF bound = painter->boundingRect(QRectF(), flags, label);
+ QPointF p(mapXToPlot(x), plotRect().bottom() + bound.height() / 2.0);
+ bound.moveCenter(p);
- if (xLabelRect.isValid()) {
- xLabelRect = xLabelRect.united(bound);
- } else {
- xLabelRect = bound;
+ if (xLabelRect.isValid()) {
+ xLabelRect = xLabelRect.united(bound);
+ } else {
+ xLabelRect = bound;
+ }
}
}
-
return xLabelRect.size();
}
@@ -2176,21 +2250,22 @@
QSizeF PlotItem::calculateYTickLabelBound(QPainter *painter,
const QList<qreal> &yMajorTicks) {
QRectF yLabelRect;
- foreach (qreal y, yMajorTicks) {
- int flags = Qt::TextSingleLine | Qt::AlignVCenter;
- QString label = QString::number(y);
+ if (isLeftAxisVisible()) {
+ foreach (qreal y, yMajorTicks) {
+ int flags = Qt::TextSingleLine | Qt::AlignVCenter;
+ QString label = QString::number(y);
- QRectF bound = painter->boundingRect(QRectF(), flags, label);
- QPointF p(plotRect().left() - bound.width() / 2.0, mapYToPlot(y));
- bound.moveCenter(p);
+ QRectF bound = painter->boundingRect(QRectF(), flags, label);
+ QPointF p(plotRect().left() - bound.width() / 2.0, mapYToPlot(y));
+ bound.moveCenter(p);
- if (yLabelRect.isValid()) {
- yLabelRect = yLabelRect.united(bound);
- } else {
- yLabelRect = bound;
+ if (yLabelRect.isValid()) {
+ yLabelRect = yLabelRect.united(bound);
+ } else {
+ yLabelRect = bound;
+ }
}
}
-
return yLabelRect.size();
}
@@ -2290,6 +2365,14 @@
if (!av.isNull()) {
rc->setTopLabelVisible(QVariant(av.toString()).toBool());
}
+ av = attrs.value("bottomaxisvisible");
+ if (!av.isNull()) {
+ rc->setBottomAxisVisible(QVariant(av.toString()).toBool());
+ }
+ av = attrs.value("leftaxisvisible");
+ if (!av.isNull()) {
+ rc->setLeftAxisVisible(QVariant(av.toString()).toBool());
+ }
av = attrs.value("xaxislog");
if (!av.isNull()) {
rc->setXAxisLog(QVariant(av.toString()).toBool());
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #782271:782272
@@ -71,6 +71,17 @@
QString rightLabel() const;
QString topLabel() const;
+ void setTopSuppressed(bool visible);
+ void setBottomSuppressed(bool visible);
+ void setLeftSuppressed(bool visible);
+ void setRightSuppressed(bool visible);
+
+ bool isBottomAxisVisible() const;
+ void setBottomAxisVisible(bool visible);
+
+ bool isLeftAxisVisible() const;
+ void setLeftAxisVisible(bool visible);
+
bool isLeftLabelVisible() const;
void setLeftLabelVisible(bool visible);
@@ -270,12 +281,20 @@
const QList<qreal> &xMinorTicks,
const QList<qreal> &yMinorTicks);
- virtual void paintMajorTickLabels(QPainter *painter,
+ virtual void paintTickLabels(QPainter *painter,
const QList<qreal> &xMajorTicks,
const QList<qreal> &yMajorTicks,
const QMap<qreal, QString> &xLabels,
const QMap<qreal, QString> &yLabels);
+ virtual void paintBottomTickLabels(QPainter *painter,
+ const QList<qreal> &xMajorTicks,
+ const QMap<qreal, QString> &xLabels);
+
+ virtual void paintLeftTickLabels(QPainter *painter,
+ const QList<qreal> &yMajorTicks,
+ const QMap<qreal, QString> &yLabels);
+
virtual void paintPlotMarkers(QPainter *painter);
qreal calculatedLabelMarginWidth() const;
@@ -329,6 +348,8 @@
bool _isBottomLabelVisible;
bool _isRightLabelVisible;
bool _isTopLabelVisible;
+ bool _isBottomAxisVisible;
+ bool _isLeftAxisVisible;
qreal _calculatedLabelMarginWidth;
qreal _calculatedLabelMarginHeight;
qreal _calculatedAxisMarginWidth;
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #782271:782272
@@ -16,7 +16,7 @@
#include <QDebug>
-// #define DEBUG_LAYOUT
+//#define DEBUG_LAYOUT
static qreal DEFAULT_STRUT = 20.0;
@@ -300,8 +300,8 @@
return;
if (item.rowSpan == left.rowSpan && item.columnSpan == left.columnSpan) {
- plotItem->setLeftLabelVisible(false);
- leftItem->setRightLabelVisible(false);
+ plotItem->setLeftSuppressed(false);
+ leftItem->setRightSuppressed(false);
setSpacing(QSizeF(0.0, spacing().height()));
}
}
@@ -325,8 +325,8 @@
return;
if (item.rowSpan == right.rowSpan && item.columnSpan == right.columnSpan) {
- plotItem->setRightLabelVisible(false);
- rightItem->setLeftLabelVisible(false);
+ plotItem->setRightSuppressed(false);
+ rightItem->setLeftSuppressed(false);
setSpacing(QSizeF(0.0, spacing().height()));
}
}
@@ -350,8 +350,8 @@
return;
if (item.rowSpan == top.rowSpan && item.columnSpan == top.columnSpan) {
- plotItem->setTopLabelVisible(false);
- topItem->setBottomLabelVisible(false);
+ plotItem->setTopSuppressed(false);
+ topItem->setBottomSuppressed(false);
setSpacing(QSizeF(spacing().width(), 0.0));
}
}
@@ -375,8 +375,8 @@
return;
if (item.rowSpan == bottom.rowSpan && item.columnSpan == bottom.columnSpan) {
- plotItem->setBottomLabelVisible(false);
- bottomItem->setTopLabelVisible(false);
+ plotItem->setBottomSuppressed(false);
+ bottomItem->setTopSuppressed(false);
setSpacing(QSizeF(spacing().width(), 0.0));
}
}
More information about the Kst
mailing list