[Kst] extragear/graphics/kst/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Fri Nov 4 18:20:29 CET 2005
SVN commit 477670 by netterfield:
The basecurves hold the parsed legendlabels.
M +14 -0 kstbasecurve.cpp
M +6 -3 kstbasecurve.h
M +6 -6 kstlegend.cpp
M +24 -15 kstviewlegend.cpp
M +1 -1 kstviewlegend.h
--- trunk/extragear/graphics/kst/kst/kstbasecurve.cpp #477669:477670
@@ -31,10 +31,15 @@
void KstBaseCurve::commonConstructor() {
_ignoreAutoScale = false;
+ _parsedLegendTag = 0L;
}
KstBaseCurve::~KstBaseCurve() {
+ if (_parsedLegendTag) {
+ delete _parsedLegendTag;
+ _parsedLegendTag = 0L;
+ }
}
@@ -50,5 +55,14 @@
_ignoreAutoScale = ignoreAutoScale;
}
+Label::Parsed *KstBaseCurve::parsedLegendTag(){
+ //FIXME: massive optimization needed, but this will get us going for now.
+ if (_parsedLegendTag) {
+ delete _parsedLegendTag;
+ }
+ _parsedLegendTag = Label::parse(tagName(), true);
+
+ return (_parsedLegendTag);
+}
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstbasecurve.h #477669:477670
@@ -23,6 +23,7 @@
#include "kstdataobject.h"
#include "kst_export.h"
+#include "labelparser.h"
/**A class for handling curves for kst
*@author C. Barth Netterfield
@@ -99,8 +100,8 @@
virtual void paintLegendSymbol(QPainter *p, const QRect& bound) = 0;
// Return a name suitible for a legend
- virtual QString legendTag() const { return tagName(); }
-
+ virtual Label::Parsed *parsedLegendTag();
+
protected:
double _ns_maxx;
@@ -116,9 +117,11 @@
double MinPosY;
int NS;
-
+
bool _ignoreAutoScale;
+ Label::Parsed *_parsedLegendTag;
+
private:
void commonConstructor();
};
--- trunk/extragear/graphics/kst/kst/kstlegend.cpp #477669:477670
@@ -151,7 +151,7 @@
iCharWidth = p.fontMetrics().width("M");
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
- iItemWidth = p.fontMetrics().width((*it)->legendTag()) + 4*iCharWidth;
+ iItemWidth = p.fontMetrics().width((*it)->tagName()) + 4*iCharWidth;
iLineWidth += iItemWidth;
if(iNumInLine > 0 && px + iLineWidth > rect.width()) {
iNumInLine = 1;
@@ -198,7 +198,7 @@
iY = iLineHeight;
iX = 0;
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
- iTextWidth = p.fontMetrics().width((*it)->legendTag());
+ iTextWidth = p.fontMetrics().width((*it)->tagName());
int iTextHeight = iLineHeight - p.fontMetrics().descent();
iItemWidth = iTextWidth + 4*iCharWidth;
if(iNumInLine > 0 && px + iX + iItemWidth > rect.width()) {
@@ -211,7 +211,7 @@
}
p.setPen(_colorForeground);
- p.drawText(px + iX + (iCharWidth/2), py + iY, (*it)->legendTag());
+ p.drawText(px + iX + (iCharWidth/2), py + iY, (*it)->tagName());
// draw the symbol for this curve
QRect symbolBound(QPoint(px+iX+(iCharWidth/2)+iTextWidth+(1*iCharWidth), py+iY-iTextHeight + 1),
@@ -239,7 +239,7 @@
iCharWidth = p.fontMetrics().width("M");
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
- iLineWidth = p.fontMetrics().width((*it)->legendTag());
+ iLineWidth = p.fontMetrics().width((*it)->tagName());
if( iLineWidth > iLineWidthMax ) {
iLineWidthMax = iLineWidth;
}
@@ -273,7 +273,7 @@
}
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
- iLineWidth = p.fontMetrics().width((*it)->legendTag());
+ iLineWidth = p.fontMetrics().width((*it)->tagName());
int iTextHeight = iLineHeight - p.fontMetrics().descent();
if(it == pCurves->begin()) {
px += iCharWidth / 2;
@@ -293,7 +293,7 @@
break;
}
- p.drawText( iX, py, (*it)->legendTag());
+ p.drawText( iX, py, (*it)->tagName());
// draw the legend symbol
QRect symbolBound(QPoint(iX + iLineWidth + iCharWidth, py-iTextHeight + 1),
--- trunk/extragear/graphics/kst/kst/kstviewlegend.cpp #477669:477670
@@ -64,7 +64,7 @@
_standardActions |= Delete | Edit;
_parsed = 0L;
reparse();
- computeTextSize(_parsed);
+ computeTextSize();
setDirty(false);
_autoResize = true;
}
@@ -112,14 +112,18 @@
KstViewLegend::~KstViewLegend() {
- delete _parsed;
+ //delete _parsed;
_parsed = 0L;
}
void KstViewLegend::reparse() {
- delete _parsed;
- _parsed = Label::parse(_txt, _interpret);
+ //delete _parsed;
+ if (Curves.count()>0) {
+ _parsed = Curves[0]->parsedLegendTag();
+ } else {
+ _parsed = Label::parse(_txt, _interpret);
+ }
setDirty();
}
@@ -211,7 +215,7 @@
computeTextSize(lp); // hmm this is inefficient
}
#endif
-
+ reparse();
setDirty(false);
_backBuffer.buffer().resize(size());
@@ -288,13 +292,18 @@
}
-void KstViewLegend::computeTextSize(Label::Parsed *lp) {
- RenderContext rc(_fontName, _symbolFontName, _absFontSize, 0L);
- rc.precision = _dataPrecision;
- renderLabel(rc, lp->chunk);
- _textWidth = rc.xMax;
- _ascent = rc.ascent;
- _textHeight = 1 + rc.ascent + rc.descent;
+void KstViewLegend::computeTextSize() {
+ _textWidth = 0;
+ _ascent = 0;
+ _textHeight = 0;
+ for (unsigned i = 0; i < Curves.count(); i++) {
+ RenderContext rc(_fontName, _symbolFontName, _absFontSize, 0L);
+ rc.precision = _dataPrecision;
+ renderLabel(rc, Curves[i]->parsedLegendTag()->chunk);
+ if (rc.xMax>_textWidth) _textWidth = rc.xMax;
+ _ascent = rc.ascent;
+ _textHeight += 1 + rc.ascent + rc.descent;
+ }
}
@@ -304,7 +313,7 @@
if (_autoResize) {
adjustSizeForText(p.window());
} else {
- computeTextSize(_parsed);
+ computeTextSize();
}
p.setViewport(geometry());
p.setWindow(0,0,geometry().width(), geometry().height());
@@ -320,7 +329,7 @@
if (_autoResize) {
adjustSizeForText(p.window()); // calls computeTextSize and drawToBuffer
} else {
- computeTextSize(_parsed);
+ computeTextSize();
drawToBuffer(_parsed);
}
}
@@ -403,7 +412,7 @@
}
if (_parsed) {
- computeTextSize(_parsed);
+ computeTextSize();
}
if (_rotation != 0 && _rotation != 180) {
--- trunk/extragear/graphics/kst/kst/kstviewlegend.h #477669:477670
@@ -115,7 +115,7 @@
private:
void drawToBuffer(Label::Parsed *lp);
void drawToPainter(Label::Parsed *lp, QPainter& p);
- void computeTextSize(Label::Parsed*);
+ void computeTextSize();
double _rotation;
QString _txt;
More information about the Kst
mailing list