I think I will just use a factory class, and recreate the shape at the desired size (outside of draw()) instead of QTransforming the the current shape().
I think I will just use a factory class, and recreate the shape at the desired size (outside of draw()) instead of QTransforming the the current shape().
What exactly do you want to do with the coordinates of the painter path of your shape items ?
Uwe
Horizontal scaling of the shape.
For instance, a 15 minute chart has a rectangle drawn at 10:15 to 10:45 (spanning 2 bars), when the time frame is changed to a 1 hour chart the rectangle is drawn only on one bar. I have already implemented axis/index<->date conversion calculations, and they are working good with a subclass of QwtPlotMarker, just had to add a invalidateCache() that re-index the markers, and a custom setValue() was enough.
Shapes (and QwtPlotShapeItem) don't have setters for left/right/x. I looked into QTransform and got the m11 scaling right, but couldn't get the translation to accurately place the item, I stopped looking at QTransform as it requires a QPainter (probably?) and re-applying the QTransform in a custom draw() is probably a bit heavy.
I may have to iterate over all elements in the shape and scale their x manually. The most elegant solution is probably to subclass QwtScaleMap.
Basically I would like to set the equivalent of boundingRect().left() and boundingRect().right() on the shape.
--
For those interested the m11 calculation that was working for me (I think) was
Qt Code:
double m11 = m_rightIndex - m_leftIndex / shape().controlPointRect().right() - shape().controlPointRect().left()To copy to clipboard, switch view to plain text mode
The points of the painter path of a shape item are always in plot coordinates. If you don't want this QwtPlotShapeItem is probably the wrong type of item. Maybe a marker/curve with QwtSymbol::Path symbols ( or QwtSymbol::Graphic when you need symbols with different colors ) is what you are looking for ?
Uwe
I got QwtPlotShapeItem to do what I required after looking at the QwtSymbol::setPath() example. I only had to add this:
This is called only when the charts/samples time frame changes, I chose to use QwtPlotShapeItem as it didn't require modification to my plot item editor. It also automatically shifts the shape as new candles come in from the server.Qt Code:
void PlotShapeItem::invalidateCache() { if(! m_xScaleDraw) return; m_leftIndex = m_xScaleDraw->indexOf(m_leftDate, true); m_rightIndex = m_xScaleDraw->indexOf(m_rightDate, true); // Scale transform double w = m_rightIndex - m_leftIndex; double m11; if (w > 0) m11 = w / (int)(m_path.controlPointRect().width() + 0.5); else m11 = 0; QTransform t(m11, 0, 0, 1.0, 0, 0); pp = t.map(pp); // Translate transform double dx = m_leftIndex - (int)(pp.controlPointRect().left() + 0.5); QTransform ts(1, 0, 0, 1, dx, 0); pp = ts.map(pp); setShape(pp); }To copy to clipboard, switch view to plain text mode
Results look like this (note - these are shapes not rectangles):
5m.jpg1m.jpg
I will take a closer look at QwtGraphic and QwtPlotSvgItem, as I would like the user to be able to load custom analysis/shapes.
Last edited by Seamus; 24th January 2013 at 04:28.
Issue with QwtSymbol::setPinPoint()?
I create a QPainterPath and add it to a QwtSymbol, then to a QwtPlotMarker. The path draws Fibonacci retracement and extension levels, the extension levels also go beyond the area selected by a user with a QwtPicker, so I have used QwtSymbol::setPinPoint(). Here are the results:
fib-pin-point.jpg
The fib control lines are the angled black lines, they were drawn from the upper blue line to the lower blue line. When setPinPoint() is used a portion of the left side is cut off, the extent of the cut off area gets larger as you get closer to y-axis (yRight), the text also gets cut. It also looks like if you draw a line connecting the black lines tops that the cut-off area increases smoothly.
When I don't use setPinPoint(), the path is drawn properly (except its position).
Has anybody out-there experienced this?
Please upload a small demo showing the effects.
Uwe
markerPinPointDemo.jpg
Effect most evident in the rightmost numbers 50.00 and 90.00, but the most important part for me is the missing line start.
Qt Code:
{ QPainterPath path; path.moveTo(topLeft0); path.lineTo(bottomRight0); const QVector<double> levels = QVector<double>() << 0.1 << 0.5 << 0.9 << 1.2 << 1.4; const double left = topLeft0.x(); const double right = bottomRight0.x(); const double top = topLeft0.y(); const double height = bottomRight0.y() - topLeft0.y(); QFont font; font.setPointSize(24); foreach(const double f, levels) { const double level = top + (height * f); path.moveTo(left, level); path.lineTo(right, level); } symbol->setPath(path); symbol->setPinPoint(pinPoint0); // Center of picked area marker->setAxes(xBottom, yRight); marker->setValue(center); marker->setSymbol(symbol); marker->attach(this); autoRefresh(); }To copy to clipboard, switch view to plain text mode
Last edited by Seamus; 28th January 2013 at 08:09.
Please attach a compilable project - not only a code snippet.
Uwe
PS: what happens when you set QwtSymbol::NoCache ?
QwtSymbol::NoCache rectified the issue.PS: what happens when you set QwtSymbol::NoCache ?
I suppose you don't need this anymore.
Spotted this though:
Qt Code:
{ if ( shape != d_data->shape ) { d_data->shape = shape; if ( shape.isEmpty() ) { // ^ Comparison not assignment } else { d_data->boundingRect = shape.boundingRect(); } itemChanged(); } }To copy to clipboard, switch view to plain text mode
What probably means, that the result of QwtSymbol::boundingRect() is wrong. To be honest I never tried painter paths with texts inside, so there might be something wrong in general with them.
That's why I'm still interested in understanding the effect - even if you have a workaround for your situation.
Uwe
The snippet "Comparison not assignment" was for QwtPlotShapeItem, not QwtSymbol.
Attachments: Modified stockchart demo showing the problem, image of the demo too.That's why I'm still interested in understanding the effect - even if you have a workaround for your situation.
stockchart-marker.tar.gzstockchart-marker.jpg
In the code left may be right and right may be left, as the demo does most things opposite to how I've done them
I also don't use text in painter paths (with markers) as the pen width makes it unreadable at most desired font sizes.To be honest I never tried painter paths with texts inside, so there might be something wrong in general with them.
Hi,
I have just started to use qwt for a trading software and I'm stuck doing the (probably) simplest things. Now I stumbled upon this very informative thread and wanted to ask, if the application you, Seamus, are working on is open source or if not, would you share just the drawing/gui part?
There seem to be quite a lot of programmers that are interested in creating a decent open source trading platform (like qttrader.com or some posts in this forum suggest) and QT/qwt seems to be the way to do it. Maybe we should join forces?
Hi,
Is there any open source project that plot the stock chart kind of discussed above?
If not can we have interested people for a project like this.
Bookmarks