Skip to content
Snippets Groups Projects
  • Bryant's avatar
    c96458cf
    Update Qwt to 6.1. · c96458cf
    Bryant authored
    We also document how we got the source code and keep our modifications out of the Qwt directory.
    c96458cf
    History
    Update Qwt to 6.1.
    Bryant authored
    We also document how we got the source code and keep our modifications out of the Qwt directory.
qwt_legend_data.cpp 2.67 KiB
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * 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"

//! 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 )
{
    d_map = map;
}

/*!
  \return Legend attributes
  \sa setValues()
 */
const QMap<int, QVariant> &QwtLegendData::values() const
{
    return d_map;
}

/*!
  \param role Attribute role
  \return True, when the internal map has an entry for role
 */
bool QwtLegendData::hasRole( int role ) const
{
    return d_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 )
{
    d_map[role] = data;
}

/*!
  \param role Attribute role
  \return Attribute value for a specific role
 */
QVariant QwtLegendData::value( int role ) const
{
    if ( !d_map.contains( role ) )
        return QVariant();

    return d_map[role];
}

//! \return True, when the internal map is empty
bool QwtLegendData::isValid() const
{
    return !d_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;
}