Results 1 to 8 of 8

Thread: How to write station's name on the city map

  1. #1
    Join Date
    Feb 2011
    Location
    Nizhny Novgorod, Russian Federation
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question How to write station's name on the city map

    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

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write station's name on the city map

    To display names in your plot, take a look at QwtPlotMarker

  3. #3
    Join Date
    Feb 2011
    Location
    Nizhny Novgorod, Russian Federation
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write station's name on the city map

    Quote Originally Posted by FelixB View Post
    To display names in your plot, take a look at QwtPlotMarker
    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 ?

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write station's name on the city map

    Quote Originally Posted by Roman Novoselov View Post
    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?

  5. #5
    Join Date
    Feb 2011
    Location
    Nizhny Novgorod, Russian Federation
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write station's name on the city map

    Quote Originally Posted by FelixB View Post
    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

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to write station's name on the city map

    Quote Originally Posted by Roman Novoselov View Post
    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

  7. #7
    Join Date
    Feb 2011
    Location
    Nizhny Novgorod, Russian Federation
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write station's name on the city map

    I want draw on the map several types of stations ("bus stations", "tram stations" ant etc.) I am sorry that was not said before

    Quote Originally Posted by Uwe View Post
    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


    Quote Originally Posted by Uwe View Post
    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.

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to write station's name on the city map

    It might be a good idea to have different type of markers:

    Qt Code:
    1. enum RttiValue
    2. {
    3. BusStation = QwtPlotItem::Rtti_PlotUserItem,
    4. TramStation,
    5. ...
    6. };
    7.  
    8. class StationMarker: public QwtPlotMarker
    9. {
    10. ...
    11. virtual int rtti() const { return TramStation; }
    12. }
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. class Station
    2. {
    3. public:
    4. QString name;
    5. QPointF pos;
    6. };
    7.  
    8. class StationItem: public QwtPlotSeriesItem<Station>
    9. {
    10. public:
    11. enum Type
    12. {
    13. Bus = QwtPlotItem::Rtti_PlotUserItem,
    14. Tram,
    15. ...
    16. };
    17.  
    18. StationItem( Type type, const QString &title = QString::null ):
    19. StationItem<Station>( QwtText( title ) ),
    20. m_type(type)
    21. {
    22. setItemAttribute( QwtPlotItem::Legend );
    23. setItemAttribute( QwtPlotItem::AutoScale );
    24.  
    25. setZ( ... );
    26. }
    27.  
    28. virtual int rtti() const
    29. {
    30. return m_type;
    31. }
    32.  
    33. virtual void draw( QPainter *painter,
    34. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    35. const QRectF &canvasRect ) const
    36. {
    37. int numStations = dataSize();
    38.  
    39. for ( int i = 0; i <= numStations; i++ )
    40. {
    41. const Station station = sample(i);
    42. QPointF pos = QwtScaleMap::transform( xMap, yMap, station.pos );
    43.  
    44. if ( canvasRect.contains( pos ) )
    45. {
    46. painter->drawPixmap( ... );
    47. painter->drawText( ..., station.name );
    48. }
    49. }
    50. }
    51.  
    52. private:
    53. const Type m_type;
    54. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

  9. The following user says thank you to Uwe for this useful post:

    Roman Novoselov (16th February 2011)

Similar Threads

  1. City state and zip code dialog
    By newbie43 in forum Qt Programming
    Replies: 1
    Last Post: 24th December 2010, 13:48
  2. Replies: 2
    Last Post: 2nd November 2010, 05:15
  3. confusion city
    By Petr_Kropotkin in forum Newbie
    Replies: 1
    Last Post: 3rd February 2010, 15:30
  4. Replies: 5
    Last Post: 13th November 2008, 13:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.