[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Thu Oct 11 22:29:36 CEST 2007
SVN commit 724246 by treat:
* Move the RenderType enum to the PlotRenderItem class.
* PlotItem's can now have only one of each RenderType.
* The PlotRenderItem's are created from the PlotItem::renderItem()
factory.
* bugfix for PlotItem::projectionRect()
M +3 -8 curvedialog.cpp
M +3 -8 equationdialog.cpp
M +33 -24 plotitem.cpp
M +7 -12 plotitem.h
M +16 -4 plotrenderitem.cpp
M +4 -4 plotrenderitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/curvedialog.cpp #724245:724246
@@ -189,15 +189,10 @@
break;
}
- RelationList relationList;
- relationList.append(kst_cast<Relation>(curve));
+ PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+ renderItem->addRelation(kst_cast<Relation>(curve));
+ plotItem->update();
- //FIXME Should check for existing one...
- VectorCurveRenderItem *vectorCurve = new VectorCurveRenderItem(plotItem);
- vectorCurve->setRelationList(relationList);
-
- plotItem->addRenderItem(vectorCurve);
-
return ObjectPtr(curve.data());
}
--- branches/work/kst/portto4/kst/src/libkstapp/equationdialog.cpp #724245:724246
@@ -205,15 +205,10 @@
break;
}
- RelationList relationList;
- relationList.append(kst_cast<Relation>(curve));
+ PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+ renderItem->addRelation(kst_cast<Relation>(curve));
+ plotItem->update();
- //FIXME Should check for existing one...
- VectorCurveRenderItem *vectorCurve = new VectorCurveRenderItem(plotItem);
- vectorCurve->setRelationList(relationList);
-
- plotItem->addRenderItem(vectorCurve);
-
return ObjectPtr(equation.data());
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #724245:724246
@@ -21,7 +21,6 @@
#include "mainwindow.h"
#include "tabwidget.h"
-#include "curve.h"
#include "datacollection.h"
#include "dataobjectcollection.h"
#include "vectorcurverenderitem.h"
@@ -61,28 +60,29 @@
QList<PlotRenderItem*> PlotItem::renderItems() const {
- return _renderers;
+ return _renderers.values();
}
-void PlotItem::addRenderItem(PlotRenderItem *renderItem) {
- _renderers.append(renderItem);
- update();
-}
+PlotRenderItem *PlotItem::renderItem(PlotRenderItem::RenderType type) {
+ if (_renderers.contains(type))
+ return _renderers.value(type);
-
-void PlotItem::removeRenderItem(PlotRenderItem *renderItem) {
- _renderers.removeAll(renderItem);
- update();
+ switch (type) {
+ case PlotRenderItem::Cartesian:
+ {
+ VectorCurveRenderItem *renderItem = new VectorCurveRenderItem(this);
+ _renderers.insert(type, renderItem);
+ return renderItem;
+ }
+ case PlotRenderItem::Polar:
+ case PlotRenderItem::Sinusoidal:
+ default:
+ return 0;
+ }
}
-void PlotItem::clearRenderItems() {
- _renderers.clear();
- update();
-}
-
-
void PlotItem::paint(QPainter *painter) {
painter->save();
painter->setPen(Qt::NoPen);
@@ -132,11 +132,20 @@
QRectF PlotItem::projectionRect() const {
- QRectF rect(QPointF(-0.1, -0.1), QPointF(0.1, 0.1)); //default
- foreach (PlotRenderItem *renderer, _renderers) {
- if (!renderer->projectionRect().isEmpty())
- rect = rect.united(renderer->projectionRect());
+ QRectF rect;
+ foreach (PlotRenderItem *renderer, renderItems()) {
+ if (!renderer->projectionRect().isEmpty()) {
+ if (rect.isValid()) {
+ rect = rect.united(renderer->projectionRect());
+ } else {
+ rect = renderer->projectionRect();
+ }
+ }
}
+
+ if (!rect.isValid())
+ rect = QRectF(QPointF(-0.1, -0.1), QPointF(0.1, 0.1)); //default
+
return rect;
}
@@ -183,7 +192,7 @@
QString PlotItem::leftLabel() const {
- foreach (PlotRenderItem *renderer, _renderers) {
+ foreach (PlotRenderItem *renderer, renderItems()) {
if (!renderer->leftLabel().isEmpty())
return renderer->leftLabel();
}
@@ -192,7 +201,7 @@
QString PlotItem::bottomLabel() const {
- foreach (PlotRenderItem *renderer, _renderers) {
+ foreach (PlotRenderItem *renderer, renderItems()) {
if (!renderer->bottomLabel().isEmpty())
return renderer->bottomLabel();
}
@@ -201,7 +210,7 @@
QString PlotItem::rightLabel() const {
- foreach (PlotRenderItem *renderer, _renderers) {
+ foreach (PlotRenderItem *renderer, renderItems()) {
if (!renderer->rightLabel().isEmpty())
return renderer->rightLabel();
}
@@ -210,7 +219,7 @@
QString PlotItem::topLabel() const {
- foreach (PlotRenderItem *renderer, _renderers) {
+ foreach (PlotRenderItem *renderer, renderItems()) {
if (!renderer->topLabel().isEmpty())
return renderer->topLabel();
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #724245:724246
@@ -12,19 +12,16 @@
#ifndef PLOTITEM_H
#define PLOTITEM_H
-#include <QObject>
-#include <QColor>
-#include <QStack>
-#include <QGraphicsItem>
-
-#include "plotiteminterface.h"
#include "viewitem.h"
+
+#include <QHash>
+
#include "relation.h"
+#include "plotrenderitem.h"
+#include "plotiteminterface.h"
namespace Kst {
-class PlotRenderItem;
-
class PlotItem : public ViewItem, public PlotItemInterface
{
Q_OBJECT
@@ -35,9 +32,7 @@
virtual QString plotName() const; //from PlotItemInterface
QList<PlotRenderItem*> renderItems() const;
- void addRenderItem(PlotRenderItem *renderItem);
- void removeRenderItem(PlotRenderItem *renderItem);
- void clearRenderItems();
+ PlotRenderItem *renderItem(PlotRenderItem::RenderType type);
virtual void paint(QPainter *painter);
@@ -92,7 +87,7 @@
QSizeF calculateTopLabelBound(QPainter *painter);
private:
- QList<PlotRenderItem*> _renderers;
+ QHash<PlotRenderItem::RenderType, PlotRenderItem*> _renderers;
bool _isTiedZoom;
bool _isLeftLabelVisible;
bool _isBottomLabelVisible;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #724245:724246
@@ -64,12 +64,12 @@
}
-RenderType PlotRenderItem::type() {
+PlotRenderItem::RenderType PlotRenderItem::type() {
return _type;
}
-void PlotRenderItem::setType(RenderType type) {
+void PlotRenderItem::setType(PlotRenderItem::RenderType type) {
_type = type;
}
@@ -174,12 +174,24 @@
}
-void PlotRenderItem::setRelationList(const RelationList &relationList) {
- _relationList = relationList;
+void PlotRenderItem::addRelation(RelationPtr relation) {
+ _relationList.append(relation);
zoomMaximum();
}
+void PlotRenderItem::removeRelation(RelationPtr relation) {
+ _relationList.removeAll(relation);
+ zoomMaximum();
+}
+
+
+void PlotRenderItem::clearRelations() {
+ _relationList.clear();
+ zoomMaximum();
+}
+
+
void PlotRenderItem::paint(QPainter *painter) {
painter->setRenderHint(QPainter::Antialiasing, false);
painter->drawRect(rect());
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #724245:724246
@@ -23,9 +23,6 @@
namespace Kst {
class PlotItem;
-
-enum RenderType { Cartesian, Polar, Sinusoidal };
-
class PlotRenderItem;
struct ZoomState {
@@ -43,6 +40,7 @@
{
Q_OBJECT
public:
+ enum RenderType { Cartesian, Polar, Sinusoidal };
enum ZoomMode { Auto, AutoBorder, FixedExpression, SpikeInsensitive, MeanCentered };
PlotRenderItem(PlotItem *parentItem);
@@ -80,7 +78,9 @@
void setProjectionRect(const QRectF &rect);
RelationList relationList() const;
- void setRelationList(const RelationList &relationList);
+ void addRelation(RelationPtr relation);
+ void removeRelation(RelationPtr relation);
+ void clearRelations();
virtual void paint(QPainter *painter);
virtual void paintRelations(QPainter *painter) = 0;
More information about the Kst
mailing list