cumbia-qtcontrols 1.x
Qt widgets on top of the cumbia C++ library
Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
QuLabel Class Reference

A label derived from Qt QLabel to display boolean values, strings, scalars and even vectors. More...

#include <qulabel.h>

Inheritance diagram for QuLabel:
Inheritance graph
[legend]

Public Slots

void setSource (const QString &s)
 Connect the reader to the specified source. More...
 
void unsetSource ()
 
void setDisplayUnitEnabled (bool en)
 enable or disable the display unit visualization. More...
 
void ctxSwitch (CumbiaPool *cumbia_pool, const CuControlsFactoryPool &fpool)
 
- Public Slots inherited from QuLabelBase
void setBorderWidth (double w)
 sets the width of the border(s) drawn with the chosen color More...
 
void setDrawInternalBorder (bool draw)
 
void setValue (const CuVariant &d, bool *background_modified=NULL)
 set the value to display on the label. Optionally check if the background color has been modified by the method More...
 
void setFormat (const QString &fmt)
 
void setMaximumLength (int len)
 if the data shown is a string, truncate it to the given length More...
 

Signals

void newData (const CuData &)
 
void propertyReady (const CuData &)
 
void linkStatsRequest (QWidget *myself, CuContextI *myself_as_cwi)
 

Public Member Functions

 QuLabel (QWidget *w, Cumbia *cumbia, const CuControlsReaderFactoryI &r_fac)
 Constructor with the parent widget, an engine specific Cumbia implementation and a CuControlsReaderFactoryI interface. More...
 
 QuLabel (QWidget *w, CumbiaPool *cumbia_pool, const CuControlsFactoryPool &fpool)
 Constructor with the parent widget, CumbiaPool and CuControlsFactoryPool More...
 
virtual ~QuLabel ()
 
QString source () const
 
CuContextgetContext () const
 returns the pointer to the CuContext More...
 
bool displayUnitEnabled () const
 returns true if the display unit is shown beside the value, false otherwise More...
 
QString displayUnit () const
 returns the display unit read by the configuration properties at initialization time. More...
 
QuPalette quPalette () const
 returns the QuPalette currently used More...
 
void setQuPalette (const QuPalette &colors)
 set a custom QuPalette to change the string/color association More...
 
void onUpdate (const CuData &d)
 
- Public Member Functions inherited from QuLabelBase
 QuLabelBase (QWidget *parent)
 
 QuLabelBase (const QString &text, QWidget *parent)
 
virtual ~QuLabelBase ()
 
void setBackground (const QColor &background)
 set the background color of the label More...
 
void setBorderColor (const QColor &border)
 changes the border color More...
 
void setDecoration (const QColor &background, const QColor &border)
 changes the colors for the decoration of the label More...
 
double borderWidth () const
 returns the width, in pixels, of the colored border that is drawn around the label More...
 
void setEnumDisplay (int val, const QString &text, const QColor &c)
 
int maximumLength () const
 returns the maximum length of the displayed string More...
 
QSize minimumSizeHint () const override
 reimplements QLabel::minimumSizeHint to ensure there is enough space to draw the decorations on the border More...
 
QSize sizeHint () const override
 
int heightForWidth (int w) const override
 
bool hasHeightForWidth () const override
 
bool drawInternalBorder () const
 if enabled, an external and an internal border are drawn More...
 
QString format () const
 returns the format used to represent a number, or an empty string if no format is specified More...
 
- Public Member Functions inherited from CuContextI
virtual ~CuContextI ()
 
virtual CuContextgetContext () const =0
 Return a reference to the CuContext in use. More...
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *e)
 
- Protected Member Functions inherited from QuLabelBase
void paintEvent (QPaintEvent *pe) override
 Reimplements QLabel::paintEvent. More...
 

Properties

QString source
 
bool displayUnitEnabled
 
- Properties inherited from QuLabelBase
double borderWidth
 
bool drawInternalBorder
 
QString format
 

Detailed Description

A label derived from Qt QLabel to display boolean values, strings, scalars and even vectors.

Connection is initiated with setSource. When new data arrives, it is displayed and the newData signal is emitted. A propertyReady signal is provided for convenience and emitted only once at configuration time.

Display enumeration values (if supported by the engine)
If the underlying engine supports a configuration property named values, the list of strings is used to associate a value to a label. Likewise, if the engine supports a colors property, the list of colors is used to associate a value to a color. The values and colors properties, if available, are extracted at configuration time into a std::vector of std::string. The value of the source is used as index to pick up the label and the color from the vectors. Indexes start from zero. Labels are displayed as they are, while color strings are mapped through QuPalette into QColor. The QuPalette used is accessible through quPalette and setQuPalette.

getContext returns a pointer to the CuContext used as a delegate for the connection.

Constructor & Destructor Documentation

◆ QuLabel() [1/2]

QuLabel::QuLabel ( QWidget *  w,
Cumbia *  cumbia,
const CuControlsReaderFactoryI r_factory 
)

Constructor with the parent widget, an engine specific Cumbia implementation and a CuControlsReaderFactoryI interface.

Please refer to md_src_cumbia_qtcontrols_widget_constructors documentation.

◆ QuLabel() [2/2]

QuLabel::QuLabel ( QWidget *  w,
CumbiaPool *  cumbia_pool,
const CuControlsFactoryPool fpool 
)

Constructor with the parent widget, CumbiaPool and CuControlsFactoryPool

Please refer to md_src_cumbia_qtcontrols_widget_constructors documentation.

◆ ~QuLabel()

QuLabel::~QuLabel ( )
virtual

Member Function Documentation

◆ contextMenuEvent()

void QuLabel::contextMenuEvent ( QContextMenuEvent *  e)
protected

◆ ctxSwitch

void QuLabel::ctxSwitch ( CumbiaPool *  cumbia_pool,
const CuControlsFactoryPool fpool 
)
slot

◆ displayUnit()

QString QuLabel::displayUnit ( ) const

returns the display unit read by the configuration properties at initialization time.

Returns
a string containing the display unit read from the initial configuration, if available from the source.
See also
displayUnitEnabled

◆ displayUnitEnabled()

bool QuLabel::displayUnitEnabled ( ) const

returns true if the display unit is shown beside the value, false otherwise

Returns
true the display unit is shown
false only the value is shown
note The source must provide a non empty "display_unit" property
See also
setDisplayUnitEnabled

◆ getContext()

CuContext * QuLabel::getContext ( ) const
virtual

returns the pointer to the CuContext

CuContext sets up the connection and is used as a mediator to send and get data to and from the reader.

See also
CuContext

Implements CuContextI.

Referenced by QuInputOutput::getOutputContext().

◆ linkStatsRequest

void QuLabel::linkStatsRequest ( QWidget *  myself,
CuContextI myself_as_cwi 
)
signal

◆ newData

void QuLabel::newData ( const CuData &  )
signal

Referenced by onUpdate().

◆ onUpdate()

void QuLabel::onUpdate ( const CuData &  d)

◆ propertyReady

void QuLabel::propertyReady ( const CuData &  )
signal

Referenced by onUpdate().

◆ quPalette()

QuPalette QuLabel::quPalette ( ) const

returns the QuPalette currently used

Returns
QuPalette in use
See also
setQuPalette

◆ setDisplayUnitEnabled

void QuLabel::setDisplayUnitEnabled ( bool  en)
slot

enable or disable the display unit visualization.

See displayUnitEnabled documantation for further details.

◆ setQuPalette()

void QuLabel::setQuPalette ( const QuPalette colors)

set a custom QuPalette to change the string/color association

Parameters
colorsa new QuPalette that replaces the current one

QuPalette maps color names to QColor colors. You can use this method as a trick to change the color for a state represented by the label. For example, if normally an OK state is associated to "green", you can set a custom palette so that the "green" color string is mapped into white color. In the following example, white color is used with the green key:

QuPalette myPalette = stateWidget->quPalette();
myPalette["green"] = QColor(Qt::white);
stateWidget->setQuPalette(myPalette);
a map associating a color name to a QColor
Definition: qupalette.h:35

Altering the QuPalette of a QuLabel (or a QuLed) is useful when a given state is associated to a predefined color (e.g. ON:green, OFF:white, ALARM:yellow, FAULT:red) and you want different combinations. Cumbia engines must store a state_color key/value pair in the CuVariant data delivered by the onUpdate method when the engine itself handles a *"s"* data type.

See also
quPalette

◆ setSource

void QuLabel::setSource ( const QString &  s)
slot

Connect the reader to the specified source.

If a reader with a different source is configured, it is deleted. If options have been set with QuContext::setOptions, they are used to set up the reader as desired.

See also
QuContext::setOptions
source

References CuControlsReaderA::setSource().

◆ source()

QString QuLabel::source ( ) const

◆ unsetSource

void QuLabel::unsetSource ( )
slot

Property Documentation

◆ displayUnitEnabled

bool QuLabel::displayUnitEnabled
readwrite

◆ source

QString QuLabel::source
readwrite

The documentation for this class was generated from the following files: