Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_legend_data.cpp
1/******************************************************************************
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#include "qwt_text.h"
12#include "qwt_graphic.h"
13
18
23
34{
35 m_map = map;
36}
37
43{
44 return m_map;
45}
46
51bool QwtLegendData::hasRole( int role ) const
52{
53 return m_map.contains( role );
54}
55
64void QwtLegendData::setValue( int role, const QVariant& data )
65{
66 m_map[role] = data;
67}
68
73QVariant QwtLegendData::value( int role ) const
74{
75 if ( !m_map.contains( role ) )
76 return QVariant();
77
78 return m_map[role];
79}
80
83{
84 return !m_map.isEmpty();
85}
86
89{
90 QwtText text;
91
92 const QVariant titleValue = value( QwtLegendData::TitleRole );
93 if ( titleValue.canConvert< QwtText >() )
94 {
95 text = qvariant_cast< QwtText >( titleValue );
96 }
97 else if ( titleValue.canConvert< QString >() )
98 {
99 text.setText( qvariant_cast< QString >( titleValue ) );
100 }
101
102 return text;
103}
104
107{
108 const QVariant iconValue = value( QwtLegendData::IconRole );
109
110 QwtGraphic graphic;
111 if ( iconValue.canConvert< QwtGraphic >() )
112 {
113 graphic = qvariant_cast< QwtGraphic >( iconValue );
114 }
115
116 return graphic;
117}
118
121{
122 const QVariant modeValue = value( QwtLegendData::ModeRole );
123 if ( modeValue.canConvert< int >() )
124 {
125 const int mode = qvariant_cast< int >( modeValue );
126 return static_cast< QwtLegendData::Mode >( mode );
127 }
128
130}
131
A paint device for scalable graphics.
Definition qwt_graphic.h:76
Mode mode() const
void setValue(int role, const QVariant &)
QwtLegendData()
Constructor.
~QwtLegendData()
Destructor.
void setValues(const QMap< int, QVariant > &)
QVariant value(int role) const
bool isValid() const
Mode
Mode defining how a legend entry interacts.
@ ReadOnly
The legend item is not interactive, like a label.
bool hasRole(int role) const
const QMap< int, QVariant > & values() const
QwtGraphic icon() const
QwtText title() const
A class representing a text.
Definition qwt_text.h:52
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
Definition qwt_text.cpp:277