Is it possible to get a legend ID using QwtLegend?
Hello,
I'm using QwtLegend to insert legends in my plot area, I setted my legend as CheckableItem and I added a connection:
Code:
connect(plot.
at(iPlotCounter
),
SIGNAL(legendChecked
(QwtPlotItem *,
bool)),
this,
Normally my plot has 8 curves and there is a possibility that two curves have the same legend name (the same title). I know it's possible to get the name when I click on one legend:
Code:
{
if (ta==true)
{
qDebug() << te->title().text() << "\n";
qDebug() << te-> << "\n";
}
}
But because of the problem that I can have two legends with the same name, get the name doesn't help me so much. So, I was wondering if there is a possibility to get an ID, for example, when I add each legend, maybe there is a value for each, in my case 8, maybe an ID that comes from 0 to 7, I don't know.
Anyone knows if is there an ID, a specific number for each legend or the only possibility is using the name?
Thanks in advance
Best Regards
Re: Is it possible to get a legend ID using QwtLegend?
Try using z-order (QwtPlotItem::z()).
If it won't work out-of-a-box try setting z-order when creating the curve and then retreiving it later.
It's not foolproof as anything can change it but always something.
Re: Is it possible to get a legend ID using QwtLegend?
Hi,
I didn't work for what I want. I was trying to do this:
Code:
{
if (ta==true)
{
QList<QWidget*> t = plot.at(iPlotCounter)->legend()->legendItems();
for (int i=0; i<t.size(); i++)
{
qDebug
() <<
"Name: " <<
((QwtLegendItem *)t
[i
])->text
().
text() <<
"\n";
qDebug
() <<
"Checked: " <<
((QwtLegendItem *)t
[i
])->isChecked
() <<
"\n";
}
}
}
The problem is: when I use QList, I don't know why (maybe you can explain me), my list gets unsorted, for example, my legend's names are:
Current
Voltage
Voltage
Charge
Discharge
Total
I was expecting that my list order would be the same and then I could use the index as my index, but when I get the list, it's always in a different order.
After this problem I was trying to find any information that I could use, inside of this legendItems that I got, I found a variable that calls "ser_no", I don't know how to take the value of this variable, but it seems to be what I need, because the values are increasing according by the plotted order, then I could use them as my index.
Ok, I have three other questions:
First: Is it possible to create a QList using (QList<QWidget*> t = plot.at(iPlotCounter)->legend()->legendItems();) and make sure that the list has the same order that's been showed?
Second: Why does QList change the order?
Third: Anyone knows how to get this "ser_no" or what this "ser_no" means?
Thanks in advance
Best Regards
Re: Is it possible to get a legend ID using QwtLegend?
Hey,
The legend item list is sorted, but the key is not the text but the pointer to the widget:
So answer to question 2 is: list doesn't change the order, it's just ordered by something else that you'd expect.
I don't know where you got the 'ser_no', but I couldn't find it anywhere in qwt 6.0.1 source I have.
To answer your original question:
Create additional map of your curves in format: QMap< QwtPlotItem*, int >, where pointer is your curve, and int is its ID (may be index in other list you have or anything else that you find useful);
this way in your setConfig() you can get ID of each curve from the pointer you're getting there.
Now I have a question:
Why do you need it for?
There may be something wrong with your thinking here.
Re: Is it possible to get a legend ID using QwtLegend?
Hello,
I found a way to get the ser_no.
It's working know, I have the ID I need and I can find which legend even if they have the same name.
Thanks for your help.
Bye
Re: Is it possible to get a legend ID using QwtLegend?
I'm sorry to reopen this topic.
I have the same problem but QwtLegendItem doesn't exist now with Qwt 6.1.2! Now we only have QwtPlotLegendItem.
This line is not possible :
I just can do this but it's not ok :
Code:
QwtPlotItem *plotItem
= plot_spectre
->infoToItem
( itemInfo
);
nom_courbe = plotItem->title().text();
What can i do?
Maybe put the legend with QwtPlotLegendItem but i don't arrive to put on right the legend as :
Code:
insertLegend
(legend,
QwtPlot::RightLegend);
The legend is inside the plot.