forked from OpenModelica/OpenModelica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qwt_legend_data.cpp
131 lines (108 loc) · 2.74 KB
/
qwt_legend_data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_legend_data.h"
#include "qwt_text.h"
#include "qwt_graphic.h"
//! Constructor
QwtLegendData::QwtLegendData()
{
}
//! Destructor
QwtLegendData::~QwtLegendData()
{
}
/*!
Set the legend attributes
QwtLegendData actually is a QMap<int, QVariant> with some
convenience interfaces
\param map Values
\sa values()
*/
void QwtLegendData::setValues( const QMap< int, QVariant >& map )
{
m_map = map;
}
/*!
\return Legend attributes
\sa setValues()
*/
const QMap< int, QVariant >& QwtLegendData::values() const
{
return m_map;
}
/*!
\param role Attribute role
\return True, when the internal map has an entry for role
*/
bool QwtLegendData::hasRole( int role ) const
{
return m_map.contains( role );
}
/*!
Set an attribute value
\param role Attribute role
\param data Attribute value
\sa value()
*/
void QwtLegendData::setValue( int role, const QVariant& data )
{
m_map[role] = data;
}
/*!
\param role Attribute role
\return Attribute value for a specific role
*/
QVariant QwtLegendData::value( int role ) const
{
if ( !m_map.contains( role ) )
return QVariant();
return m_map[role];
}
//! \return True, when the internal map is empty
bool QwtLegendData::isValid() const
{
return !m_map.isEmpty();
}
//! \return Value of the TitleRole attribute
QwtText QwtLegendData::title() const
{
QwtText text;
const QVariant titleValue = value( QwtLegendData::TitleRole );
if ( titleValue.canConvert< QwtText >() )
{
text = qvariant_cast< QwtText >( titleValue );
}
else if ( titleValue.canConvert< QString >() )
{
text.setText( qvariant_cast< QString >( titleValue ) );
}
return text;
}
//! \return Value of the IconRole attribute
QwtGraphic QwtLegendData::icon() const
{
const QVariant iconValue = value( QwtLegendData::IconRole );
QwtGraphic graphic;
if ( iconValue.canConvert< QwtGraphic >() )
{
graphic = qvariant_cast< QwtGraphic >( iconValue );
}
return graphic;
}
//! \return Value of the ModeRole attribute
QwtLegendData::Mode QwtLegendData::mode() const
{
const QVariant modeValue = value( QwtLegendData::ModeRole );
if ( modeValue.canConvert< int >() )
{
const int mode = qvariant_cast< int >( modeValue );
return static_cast< QwtLegendData::Mode >( mode );
}
return QwtLegendData::ReadOnly;
}