Logo Search packages:      
Sourcecode: qtemu version File versions  Download package

void MachineConfigObject::setObjectValue ( QObject *  object,
const QString &  nodeType,
const QString &  nodeName,
const QString &  optionName,
const QVariant &  defaultValue = QVariant() 
) [private]

set an object to the value of its associated config option, or default

set an object's property to the value of its associated config option, or default

Definition at line 156 of file machineconfigobject.cpp.

References getObjectValue(), and getOption().

Referenced by configChanged(), and registerObject().

{
    //get the value from the config
    QVariant value = getOption(nodeType, nodeName, optionName, defaultValue);
#ifdef DEVELOPER
    //qDebug("setting object for " + optionName.toAscii() + " to " + value.toByteArray());
#endif
    //disconnect so that we don't go in a loop forever

    //set the object's value, analyzing its type / properties to determine how to do so.

    //multiple property object
    if(object->property("optionName").isNull())
    {
        object->removeEventFilter(this);
        if(object->property(optionName.toAscii()) != value)
            object->setProperty(optionName.toAscii(), value);
        object->installEventFilter(this);
    }
    //QButtonGroup handling is tricky...
    else if(object->inherits("QButtonGroup"))
    {
        object->disconnect(this);
        QButtonGroup *group = static_cast<QButtonGroup *>(object);
        QList<QAbstractButton *> buttons = group->buttons();
        for(int i=0;i<buttons.size();i++)
        {
            if(((buttons.at(i)->property("value").toString().isEmpty()) && buttons.at(i)->text() == value.toString()) || buttons.at(i)->property("value") == value)
            {
                if(object->property("checked").toBool() != true)
                    buttons.at(i)->setProperty("checked", true);
            }
            else
            {
                if(object->property("checked").toBool() != false)
                    buttons.at(i)->setProperty("checked", false);
            }
        }
        connect(object, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(getObjectValue()));
    }
    else if(object->inherits("QComboBox"))
    {
        object->disconnect(this);
        QComboBox *thisBox = static_cast<QComboBox *>(object);
        int index;
        if(thisBox->findData(value) == -1)
            index = thisBox->findText(value.toString());
        else
            index = thisBox->findData(value);

        if(index!=-1 && object->property("currentIndex").toInt() != index)
            object->setProperty("currentIndex", index);
        else if(thisBox->currentText() != value.toString() && thisBox->itemData(thisBox->currentIndex()) != value)
            thisBox->setEditText(value.toString());

        connect(object, SIGNAL(currentIndexChanged(int)), this, SLOT(getObjectValue()));
        connect(object, SIGNAL(editTextChanged(QString)), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QRadioButton"))
    {
        object->disconnect(this);
        if(object->property("value") == value && object->property("checked").toBool() != true)
            object->setProperty("checked", true);
        else if (object->property("value").isNull() && object->property("checked") != value)
            object->setProperty("checked", value);
        connect(object, SIGNAL(toggled(bool)), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QAbstractButton")||object->inherits("QAction"))
    {
        object->disconnect(this);
        object->setProperty("checkable", true);
        if(object->property("valueIfTrue").isNull())
        {
            if(object->property("checked") != value)
                object->setProperty("checked", value);
        }
        else
        {
            if(object->property("valueIfTrue") != value)
                object->setProperty("checked", false);
            else
                object->setProperty("checked", true);
        }
        connect(object, SIGNAL(toggled(bool)), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QSpinBox")||object->inherits("QAbstractSlider"))
    {
        object->disconnect(this);
        if(object->property("value") != value)
            object->setProperty("value", value);
        connect(object, SIGNAL(valueChanged(int)), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QLineEdit"))
    {
        object->disconnect(this);
        if(object->property("text") != value)
            object->setProperty("text", value);
        connect(object, SIGNAL(textChanged(QString)), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QTextEdit"))
    {
        object->disconnect(this);
        if(object->property("plainText") != value)
            object->setProperty("plainText", value);
        connect(object, SIGNAL(textChanged()), this, SLOT(getObjectValue()));
    }
    else if (object->inherits("QWidget") && object->property("enableDisable").toBool() == true)
    {
        //if the "enableDisable" property is set to true, we want to enable or disable the widget.
        QWidget *thisWidget = static_cast<QWidget *>(object);
        thisWidget->setEnabled(value.toBool());
    }
    else
    {
        //if it's none of those... we don't know what it is yet.
        //qDebug("unknown object type" + QByteArray(object->metaObject()->className()));
        //we set a single property (the option name) to the value.
        object->removeEventFilter(this);
        object->setProperty(optionName.toAscii(), value);
        object->installEventFilter(this);
    }
    //qDebug("set!");
}


Generated by  Doxygen 1.6.0   Back to index