qwt_legend_data.cpp
Go to the documentation of this file.
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 
10 #include "qwt_legend_data.h"
11 
14 {
15 }
16 
19 {
20 }
21 
31 void QwtLegendData::setValues( const QMap<int, QVariant> &map )
32 {
33  d_map = map;
34 }
35 
40 const QMap<int, QVariant> &QwtLegendData::values() const
41 {
42  return d_map;
43 }
44 
49 bool QwtLegendData::hasRole( int role ) const
50 {
51  return d_map.contains( role );
52 }
53 
62 void QwtLegendData::setValue( int role, const QVariant &data )
63 {
64  d_map[role] = data;
65 }
66 
71 QVariant QwtLegendData::value( int role ) const
72 {
73  if ( !d_map.contains( role ) )
74  return QVariant();
75 
76  return d_map[role];
77 }
78 
81 {
82  return !d_map.isEmpty();
83 }
84 
87 {
88  QwtText text;
89 
90  const QVariant titleValue = value( QwtLegendData::TitleRole );
91  if ( titleValue.canConvert<QwtText>() )
92  {
93  text = qvariant_cast<QwtText>( titleValue );
94  }
95  else if ( titleValue.canConvert<QString>() )
96  {
97  text.setText( qvariant_cast<QString>( titleValue ) );
98  }
99 
100  return text;
101 }
102 
105 {
106  const QVariant iconValue = value( QwtLegendData::IconRole );
107 
108  QwtGraphic graphic;
109  if ( iconValue.canConvert<QwtGraphic>() )
110  {
111  graphic = qvariant_cast<QwtGraphic>( iconValue );
112  }
113 
114  return graphic;
115 }
116 
119 {
120  const QVariant modeValue = value( QwtLegendData::ModeRole );
121  if ( modeValue.canConvert<int>() )
122  {
123  const int mode = qvariant_cast<int>( modeValue );
124  return static_cast<QwtLegendData::Mode>( mode );
125  }
126 
128 }
129 
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
Definition: qwt_text.cpp:244
void setValues(const QMap< int, QVariant > &)
The legend item is not interactive, like a label.
QMap< int, QVariant > d_map
bool hasRole(int role) const
~QwtLegendData()
Destructor.
QwtLegendData()
Constructor.
A class representing a text.
Definition: qwt_text.h:51
QVariant value(int role) const
QwtGraphic icon() const
A paint device for scalable graphics.
Definition: qwt_graphic.h:74
Mode mode() const
QwtText title() const
const QMap< int, QVariant > & values() const
void setValue(int role, const QVariant &)
bool isValid() const
Mode
Mode defining how a legend entry interacts.


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17