[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Mon Jul 30 21:14:23 CEST 2007
SVN commit 694450 by treat:
* Redesign and refactor and add plumbing so we
can start drawing plots.
M +13 -24 plotitem.cpp
M +1 -8 plotitem.h
M +26 -26 plotrenderer2d.cpp
M +25 -31 plotrenderer2d.h
M +21 -1 render2dcartesian.cpp
M +7 -1 render2dcartesian.h
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #694449:694450
@@ -14,7 +14,6 @@
#include "plotitem.h"
-// FIXME temporary
#include "kstsvector.h"
#include "kstvcurve.h"
#include "kstdatacollection.h"
@@ -25,19 +24,19 @@
PlotItem::PlotItem(View *parent)
: ViewItem(parent) {
- _backgroundColor = Qt::transparent;
- // FIXME: temporary test code
- QColor temp = Qt::black;
- _colorStack.push(temp);
- // FIXME: fake data for testing rendering
+ // FIXME fake data for testing rendering
KstVectorPtr xTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("X vector"));
KstVectorPtr yTest = new KstSVector(-100.0, 100.0, 10000, KstObjectTag::fromString("Y vector"));
KstVCurvePtr renderTest = new KstVCurve(QString("rendertest"), xTest, yTest, NULL, NULL, NULL, NULL, QColor(Qt::red));
- Render2DCartesian carTest(QString("cartesiantest"));
- carTest.sources.append(kst_cast<KstRelation>(renderTest));
- renderers.append(carTest);
+ KstRelationList relationList;
+ relationList.append(kst_cast<KstRelation>(renderTest));
+
+ Render2DCartesian *test = new Render2DCartesian("cartesiantest");
+ test->setRelationList(relationList);
+
+ _renderers.append(test);
}
@@ -56,22 +55,12 @@
void PlotItem::paint(QPainter *painter) {
ViewItem::paint(painter);
- QPainterPath path;
- setBrush(Qt::transparent);
- //FIXME: temporary test code
- const qreal w = pen().widthF();
- path.addEllipse(rect().adjusted(w, w, -w, -w));
- painter->drawPath(path);
-
- //QFont testFont;
- //QColor fg = Qt::black;
- //QPen testPen(fg);
- //path.addText(100, 100, testFont, tr("This is a test"));
- /*
- for (KstRelationList::Iterator i = _sources.begin(); i != _sources.end(); ++i) {
- (*i)->paint(&path);
+ foreach (PlotRenderer2D *renderer, _renderers) {
+ QList<QPainterPath> paths = renderer->projectedPaths();
+ foreach (QPainterPath path, paths) {
+ painter->drawPath(path);
+ }
}
- */
}
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #694449:694450
@@ -31,15 +31,8 @@
virtual ~PlotItem();
void paint(QPainter *painter);
- // List of renderers to use
- QList<PlotRenderer2D> renderers;
-
private:
-
- // Options common to the plot and all rendered data
- QColor _backgroundColor;
- QStack<QColor> _colorStack;
-
+ QList<PlotRenderer2D*> _renderers;
};
class KST_EXPORT CreatePlotCommand : public CreateCommand
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderer2d.cpp #694449:694450
@@ -32,57 +32,57 @@
}
-void PlotRenderer2D::setRangeXY(const QRectF& range) {
- _xyRange = range;
- QPointF topLeft;
- QPointF bottomRight;
- projectPointInv(range.topLeft(), &topLeft);
- projectPointInv(range.bottomRight(), &bottomRight);
- _uvRange.setTopLeft(topLeft);
- _uvRange.setBottomRight(bottomRight);
+void PlotRenderer2D::setProjectedRange(const QRectF &range) {
+ _projectedRange = range;
+
+ _range = mapFromProjection(range);
+
refreshRange();
}
-void PlotRenderer2D::setRangeUV(const QRectF& range) {
- _uvRange = range;
- QPointF topLeft;
- QPointF bottomRight;
- projectPoint(range.topLeft(), &topLeft);
- projectPoint(range.bottomRight(), &bottomRight);
- _xyRange.setTopLeft(topLeft);
- _xyRange.setBottomRight(bottomRight);
+void PlotRenderer2D::setRange(const QRectF &range) {
+ _range = range;
+
+ _projectedRange = mapToProjection(range);
+
refreshRange();
}
-void PlotRenderer2D::rangeXY(QRectF *range) {
- (*range) = _xyRange;
+void PlotRenderer2D::setRelationList(const KstRelationList &relationList) {
+ _relationList = relationList;
}
-void PlotRenderer2D::rangeUV(QRectF *range) {
- (*range) = _uvRange;
+KstRelationList PlotRenderer2D::relationList() const {
+ return _relationList;
}
-void PlotRenderer2D::refreshRange() {
+QRectF PlotRenderer2D::projectedRange() {
+ return _projectedRange;
}
-void PlotRenderer2D::projectPath(QPainterPath *path) {
+QRectF PlotRenderer2D::range() {
+ return _range;
}
-void PlotRenderer2D::projectPoint(const QPointF& pold, QPointF *pnew) {
- (*pnew) = pold;
+QRectF PlotRenderer2D::mapToProjection(const QRectF &rect) {
+ return QRectF(mapToProjection(rect.topLeft()), mapToProjection(rect.bottomRight()));
}
-void PlotRenderer2D::projectPointInv(const QPointF& pold, QPointF *pnew) {
- (*pnew) = pold;
+QRectF PlotRenderer2D::mapFromProjection(const QRectF &rect) {
+ return QRectF(mapFromProjection(rect.topLeft()), mapFromProjection(rect.bottomRight()));
}
+
+void PlotRenderer2D::refreshRange() {
}
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderer2d.h #694449:694450
@@ -12,8 +12,9 @@
#ifndef PLOTRENDERER2D_H
#define PLOTRENDERER2D_H
+#include <QList>
#include <QPainterPath>
-#include "axis.h"
+
#include "kstrelation.h"
namespace Kst {
@@ -24,50 +25,43 @@
public:
PlotRenderer2D(const QString &name);
virtual ~PlotRenderer2D();
- // Set data range in terms of projected coordinates
- virtual void setRangeXY(const QRectF& range);
- // Set data range in terms of native coordinates
- virtual void setRangeUV(const QRectF& range);
- // Get data range in terms of projected coordinates
- virtual void rangeXY(QRectF *range);
- // Get data range in terms of native coordinates
- virtual void rangeUV(QRectF *range);
- // Take a PainterPath in native coordinates and project
- virtual void projectPath(QPainterPath *path);
- // Project a single point
- virtual void projectPoint(const QPointF& pold, QPointF *pnew);
- // Inverse projection of a single point
- virtual void projectPointInv(const QPointF& pold, QPointF *pnew);
- // Set and get the renderer type
void setType(RenderType2D type);
RenderType2D type();
- // The list of things to render
- KstRelationList sources;
+ // FIXME better name?
+ void setRange(const QRectF &range);
+ QRectF range();
+ // FIXME better name?
+ void setProjectedRange(const QRectF &range);
+ QRectF projectedRange();
+
+ void setRelationList(const KstRelationList &relationList);
+ KstRelationList relationList() const;
+
+ virtual QList<QPainterPath> projectedPaths() = 0;
+
protected:
+ virtual QPointF mapToProjection(const QPointF &point) = 0;
+ virtual QPointF mapFromProjection(const QPointF &point) = 0;
+
+ QRectF mapToProjection(const QRectF &rect);
+ QRectF mapFromProjection(const QRectF &rect);
+
+ // FIXME still not clear...
// Recompute auxilliary range information if the
// properties of the full plot have changed.
void refreshRange();
- // Range of plot in projected coordinates
- QRectF _xyRange;
- // Range of plot in native coordinates
- QRectF _uvRange;
-
- // Axes
- Axis _xAxis, _yAxis;
- // Axis styles
- AxisStyle _xAxisStyle, _yAxisStyle;
-
private:
- // Name of the plot
QString _name;
-
- // Type of the plot
RenderType2D _type;
+ QRectF _range;
+ QRectF _projectedRange;
+
+ KstRelationList _relationList;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/render2dcartesian.cpp #694449:694450
@@ -11,15 +11,35 @@
#include "render2dcartesian.h"
+#include <QDebug>
+
namespace Kst {
-Render2DCartesian::Render2DCartesian(const QString &name) : PlotRenderer2D(name) {
+Render2DCartesian::Render2DCartesian(const QString &name)
+ : PlotRenderer2D(name) {
setType(Cartesian);
}
Render2DCartesian::~Render2DCartesian() {
}
+QList<QPainterPath> Render2DCartesian::projectedPaths() {
+ qDebug() << "FIXME!! PUBLISH THE PLOT PATHS!" << endl;
+ return QList<QPainterPath>();
}
+
+QPointF Render2DCartesian::mapToProjection(const QPointF &point) {
+ qDebug() << "FIXME!! DO SOMETHING WITH" << point << endl;
+ return QPointF();
+}
+
+
+QPointF Render2DCartesian::mapFromProjection(const QPointF &point) {
+ qDebug() << "FIXME!! DO SOMETHING WITH" << point << endl;
+ return QPointF();
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/render2dcartesian.h #694449:694450
@@ -19,7 +19,13 @@
class Render2DCartesian : public PlotRenderer2D {
public:
Render2DCartesian(const QString &name);
- ~Render2DCartesian();
+ virtual ~Render2DCartesian();
+
+ virtual QList<QPainterPath> projectedPaths();
+
+ protected:
+ virtual QPointF mapToProjection(const QPointF &point);
+ virtual QPointF mapFromProjection(const QPointF &point);
};
}
More information about the Kst
mailing list