PDA

View Full Version : How to write station's name on the city map



Roman Novoselov
14th February 2011, 13:02
Hello,
I novice user qwt and problem is following
I represent the city map using qwt. And I want to represent bus stops (where coordinates of point is latitude and longitude).
I use QwtPlotCurve for display this (setStyle(QwtPlotCurve:: Dots)). I keep stations coordinates in xml and read its to two double-arrays in constructor.

The xml also keeps station's name. Could you tell me please, How can I display the name of station on the map? Should I use another class for represent this? Or mayde

Also I use QwtLegend (Qwtlegend:: CheckableItem) and when user press on the item "stations" in the legend. stations are disappeared. I want that this functionality will be remain.

Thanks a lot in advance!
PS: Sorry for my English :)

FelixB
14th February 2011, 13:13
To display names in your plot, take a look at QwtPlotMarker (http://qwt.sourceforge.net/class_qwt_plot_marker.html)

Roman Novoselov
14th February 2011, 13:32
To display names in your plot, take a look at QwtPlotMarker (http://qwt.sourceforge.net/class_qwt_plot_marker.html)

As I understand for each station I should create the instance of QwtPlotMaker. but in this case I can not add item "stations" to the legend and show/hide its on the map (see the original post)
or I am err ?

FelixB
14th February 2011, 13:44
As I understand for each station I should create the instance of QwtPlotMaker. but in this case I can not add item "stations" to the legend and show/hide its on the map (see the original post)
or I am err ?

you're right. that might be a little bit more complicated... since I never used QwtLegends, I can't help you further.

Just an idea: Maybe it is somehow possible to hide the station names from the legend and instead add an dummy-entry "station" which is not visible on the canvas. You catch the "clicked()"-signal for this element and set visibility for all station markers... do you understand my approach?

Roman Novoselov
15th February 2011, 06:22
do you understand my approach?
Yes, of course, thks
simple, I thought that some elegant solution exists :)

I put QwtPlotMarkers to QList <QwtPlotMarker *> and create slot to hide all items in the List

Uwe
15th February 2011, 07:33
I put QwtPlotMarkers to QList <QwtPlotMarker *>

a) You get a list of all attached markers with: "plot->itemList( QwtPlotItem::Rtti_PlotMarker );"

b) You don't need a dummy item. Simply add "marker->setItemAttribute( QwtPlotItem::Legend, true);" for the first of your markers.

Uwe

Roman Novoselov
15th February 2011, 08:13
I want draw on the map several types of stations ("bus stations", "tram stations" ant etc.) I am sorry that was not said before


You get a list of all attached markers with: "plot->itemList( QwtPlotItem::Rtti_PlotMarker );"
With help this method I can not recognize type of station, but this is good method I sure it will be useful for me, thks



You don't need a dummy item. Simply add "marker->setItemAttribute( QwtPlotItem::Legend, true);" for the first of your markers.

As I understand, using these method full list of stations are shown in the legend.

I use QwtLegend (Qwtlegend:: CheckableItem). Also I wants that legend does not shown the full list of stations and simply shown types of station ("Bus stations", "tram stations", "railway stations" and etc). And I want following functionality: when user checked item in the legend corresponding stations are appeared/disappeared on the plot.

Uwe
15th February 2011, 09:17
It might be a good idea to have different type of markers:


enum RttiValue
{
BusStation = QwtPlotItem::Rtti_PlotUserItem,
TramStation,
...
};

class StationMarker: public QwtPlotMarker
{
...
virtual int rtti() const { return TramStation; }
}

As I understand, using these method full list of stations are shown in the legend.
No, you can enable/disable the QwtPlotItem::Legend attribute for each plot item individually.

But I recommend not to use markers, when you have many stations. Instead use Qwt 6.x and implement your own type of plot item. Something like this:


class Station
{
public:
QString name;
QPointF pos;
};

class StationItem: public QwtPlotSeriesItem<Station>
{
public:
enum Type
{
Bus = QwtPlotItem::Rtti_PlotUserItem,
Tram,
...
};

StationItem( Type type, const QString &title = QString::null ):
StationItem<Station>( QwtText( title ) ),
m_type(type)
{
setItemAttribute( QwtPlotItem::Legend );
setItemAttribute( QwtPlotItem::AutoScale );

setZ( ... );
}

virtual int rtti() const
{
return m_type;
}

virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
int numStations = dataSize();

for ( int i = 0; i <= numStations; i++ )
{
const Station station = sample(i);
QPointF pos = QwtScaleMap::transform( xMap, yMap, station.pos );

if ( canvasRect.contains( pos ) )
{
painter->drawPixmap( ... );
painter->drawText( ..., station.name );
}
}
}

private:
const Type m_type;
}
Uwe