qwt_legend_data.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef QWT_LEGEND_DATA_H
  10. #define QWT_LEGEND_DATA_H
  11. #include "qwt_global.h"
  12. #include "qwt_text.h"
  13. #include "qwt_graphic.h"
  14. #include <qvariant.h>
  15. #include <qpixmap.h>
  16. #include <qmap.h>
  17. /*!
  18. \brief Attributes of an entry on a legend
  19. QwtLegendData is an abstract container ( like QAbstractModel )
  20. to exchange attributes, that are only known between to
  21. the plot item and the legend.
  22. By overloading QwtPlotItem::legendData() any other set of attributes
  23. could be used, that can be handled by a modified ( or completely
  24. different ) implementation of a legend.
  25. \sa QwtLegend, QwtPlotLegendItem
  26. \note The stockchart example implements a legend as a tree
  27. with checkable items
  28. */
  29. class QWT_EXPORT QwtLegendData
  30. {
  31. public:
  32. //! Mode defining how a legend entry interacts
  33. enum Mode
  34. {
  35. //! The legend item is not interactive, like a label
  36. ReadOnly,
  37. //! The legend item is clickable, like a push button
  38. Clickable,
  39. //! The legend item is checkable, like a checkable button
  40. Checkable
  41. };
  42. //! Identifier how to interprete a QVariant
  43. enum Role
  44. {
  45. // The value is a Mode
  46. ModeRole,
  47. // The value is a title
  48. TitleRole,
  49. // The value is an icon
  50. IconRole,
  51. // Values < UserRole are reserved for internal use
  52. UserRole = 32
  53. };
  54. QwtLegendData();
  55. ~QwtLegendData();
  56. void setValues( const QMap<int, QVariant> & );
  57. const QMap<int, QVariant> &values() const;
  58. void setValue( int role, const QVariant & );
  59. QVariant value( int role ) const;
  60. bool hasRole( int role ) const;
  61. bool isValid() const;
  62. QwtGraphic icon() const;
  63. QwtText title() const;
  64. Mode mode() const;
  65. private:
  66. QMap<int, QVariant> d_map;
  67. };
  68. #endif