示例#1
0
/*
    Update the label text
    This is the slot used to recieve data updates from a QCaObject based class.
 */
void QELabel::setLabelText( const QString& textIn, QCaAlarmInfo& alarmInfo, QCaDateTime&, const unsigned int& ) {

    // Extract any formatting info from the text
    // For example "<background-color: red>Engineering Mode" or "<color: red>not selected"
    currentText = textIn;
    QString textStyle;
    int textStyleStart = currentText.indexOf( '<' );
    if( textStyleStart >= 0 )
    {
        int textStyleEnd = currentText.indexOf( '>', textStyleStart );
        if( textStyleEnd >= 1 )
        {
            textStyle = currentText.mid( textStyleStart+1, textStyleEnd-textStyleStart-1 );
            currentText = currentText.left( textStyleStart ).append( currentText.right( currentText.length()-textStyleEnd-1 ));
        }
    }

    // Update the color
    if( textStyle.compare( lastTextStyle ) )
    {
        if( !textStyle.isEmpty() )
        {
            updateDataStyle( QString( "QWidget { " ).append( textStyle ).append( "; }") );
        }
        else
        {
            updateDataStyle( "" );
        }
        lastTextStyle = textStyle;
    }

    // Signal a database value change to any Link (or other) widgets using one
    // of the dbValueChanged.
    emitDbValueChanged( currentText, 0 );

    switch( updateOption )
    {
        // Update the text if required
        case UPDATE_TEXT:
            setText( currentText );
            break;

        // Update the pixmap if required
        case UPDATE_PIXMAP:
            setPixmap( getDataPixmap( currentText ).scaled( size() ) );
            break;
    }

    // Invoke common alarm handling processing.
    processAlarmInfo( alarmInfo );
}
/*
  Implement a slot to set the current text of the push button
  This is the slot used to recieve data updates from a QCaObject based class.
*/
void QEGenericButton::setGenericButtonText( const QString& text, QCaAlarmInfo& alarmInfo, QCaDateTime&, const unsigned int& variableIndex )
{
    // If not subscribing, or subscribing but update is not for the readback variable, then do nothing.
    //
    // Note, This will still be called even if not subscribing as there may be an initial sing shot read
    // to ensure we have valid information about the variable when it is time to do a write.
    //
    // Note, variableIndex = 0 = Primary readback variable, variableIndex = 1 = Alternate readback variable,
    // so an update for variable 1 is always OK, an update from variable 0 is OK as long as there is no variable 1
    if( !subscribe || ( variableIndex == 0 && !getSubstitutedVariableName( 1 ).isEmpty() ))
    {
        return;
    }

    // Signal a database value change to any Link widgets
    emitDbValueChanged( text );

    // Update the button state if required
    // Display checked if text matches what is written when checked
    if( updateOption == UPDATE_STATE )
    {
        setButtonState( !text.compare( clickCheckedText ) );
    }

    // Update the text if required
    if( updateOption == UPDATE_TEXT || updateOption == UPDATE_TEXT_AND_ICON )
    {
        setButtonText( text );
    }

    // Update the icon if required
    if( updateOption == UPDATE_ICON || updateOption == UPDATE_TEXT_AND_ICON )
    {
        QIcon icon;
        icon.addPixmap( getDataPixmap( text ) );
        setButtonIcon( icon );
    }

    // Invoke common alarm handling processing.
    processAlarmInfo( alarmInfo, variableIndex );
}