QwtPlot - showing two values on x-Axis
Hi! I am pretty new to Qwt programming and I'm stuck at the Moment.
I have a QwtPlot which shows drained Liquid over time. (Time is shown on x Axis) Now I would like to not just show the Time Value (in Seconds), but also the Simulation Steps of my Program. These two Values are going hand in hand and I have them together in a QVector<QPointF>.
Now my problem is, how to get additional Information to the x Axis.
So I want it to look somehow like this:
0s (Step 0) - 10s(Step 15) - 20s(Step 25)...
and so on, I hope you get what I want.
I know i can derive from QwtScaleDraw, and I did it like this:
Code:
{
public:
virtual ~MyScaleDraw() { }
virtual QwtText label
(double val
) const {
}
};
So now I get the (s) shown next to the values. But I guess I will not get what I want with this class and I couldn't quite figure out when exactly it is called. Also, it seems to first add the first Value of the Axis, then the last, then the inbetween. Therefore providing the Step Values or smth like that wouldn't work in my Opinion.
I guess I may have to reimplement QwtPlot, but I wanted to know if there is a better solution, maybe a super easy one. I can't imagine that this is such a big Issue. Also I am a little bit rusty with deriving classes, so if I have to derrive from QwtPlot and reimplement some functions, I also would appreciate some help.
I appreciate any help! Thanks in advance!
Re: QwtPlot - showing two values on x-Axis
Quote:
Originally Posted by
Earinor
These two Values are going hand in hand and I have them together ...
Then all you need is make your scale draw object being aware of this mapping and build the corresponding string.
What exactly is the problem you are struggling with ?
Uwe
Re: QwtPlot - showing two values on x-Axis [solved]
Yeah sorry, I thought about a way to do this yesterday after posting the question. I feel a bit stupid now.
But the only way I can think of is giving the CTor the mapping(the Vector) and then searching it through every time the label function is called. Because the axis is not built from left to right. I'm not that happy with it, but it works. I just think about the many steps the program has to do just for this, it isn't that slow, you can't see it, but when I write Code all over the place like this... well just my concerns about this solution.
And in this example it is a List not a Vector, because I have some errors with QVector, but that's a question for antoher day... for this implementation it should definetly be a Vector.. ^^" If someone else is having the same issue and finding this code, please make a Vector or another mapping ;)
Code:
{
public:
MyScaleDraw
(QList<QPointF> Vec
) : QwtScaleDraw() {this
->mVec
=Vec;
} virtual ~MyScaleDraw() { }
virtual QwtText label
(double val
) const {
for(int i=0; i< this->mVec.size();i++)
{
if(this->mVec[i].x()==val)
{
}
}
}
private:
QList<QPointF> mVec;
};
Code:
this
->mWidget.
Graph->setAxisScaleDraw
(QwtPlot::xBottom,
new MyScaleDraw
(this
->mVec
));
Re: QwtPlot - showing two values on x-Axis [solved]
Quote:
Originally Posted by
Earinor
I just think about the many steps the program has to do just for this, it isn't that slow, you can't see it, but
Writing a linear search is of course the worst way to do it. As your array is sorted you can use something like qBinaryFind/qUpperBound/qLowerBound that brings it down to logarithmic order. Even better is introducing a hash tab where you would have a constant order.
Simply doing what we all learned in school.
Uwe