Beispiel #1
0
void ObjectControllerPrivate::updateClassProperties(const QMetaObject *metaObject, bool recursive)
{
    if (!metaObject)
        return;

    if (recursive)
        updateClassProperties(metaObject->superClass(), recursive);

    QtProperty *classProperty = m_classToProperty.value(metaObject);
    if (!classProperty)
        return;

    for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
        QMetaProperty metaProperty = metaObject->property(idx);
        if (metaProperty.isReadable()) {
            if (m_classToIndexToProperty.contains(metaObject) && m_classToIndexToProperty[metaObject].contains(idx)) {
                QtVariantProperty *subProperty = m_classToIndexToProperty[metaObject][idx];
                if (metaProperty.isEnumType()) {
                    if (metaProperty.isFlagType())
                        subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
                    else
                        subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
                } else {
                    subProperty->setValue(metaProperty.read(m_object));
                }
            }
        }
    }
}
void MainWindow::setupClassViewer()
{
    tbtnAdd_class->setAction(actionAdd_class, true);
    tbtnAdd_class->setText(tr("Add"));
    tbtnAdd_class->setIconSize(QSize(16, 16));
    tbtnDelete_class->setAction(actionDelete_class, true);
    tbtnDelete_class->setText(tr("Delete"));
    tbtnDelete_class->setIconSize(QSize(16, 16));
    tbtnAdd_student->setAction(actionAdd_student, true);
    tbtnAdd_student->setText(tr("Add"));
    tbtnAdd_student->setIconSize(QSize(16, 16));
    tbtnDelete_student->setAction(actionDelete_student, true);
    tbtnDelete_student->setText(tr("Delete"));
    tbtnDelete_student->setIconSize(QSize(16, 16));
    tbtnAdd_session->setAction(actionAdd_session, true);
    tbtnAdd_session->setText(tr("Add"));
    tbtnAdd_session->setIconSize(QSize(16, 16));
    tbtnDelete_session->setAction(actionDelete_session, true);
    tbtnDelete_session->setText(tr("Delete"));
    tbtnDelete_session->setIconSize(QSize(16, 16));
    QObject::connect(actionAdd_class, SIGNAL(triggered()), this, SLOT(addClass()));
    QObject::connect(actionDelete_class, SIGNAL(triggered()), this, SLOT(deleteClass()));
    QObject::connect(actionPrint_class_summary, SIGNAL(triggered()), this, SLOT(printClassSummary()));
    QObject::connect(actionAdd_student, SIGNAL(triggered()), this, SLOT(addStudent()));
    QObject::connect(actionDelete_student, SIGNAL(triggered()), this, SLOT(deleteStudent()));
    QObject::connect(actionAdd_session, SIGNAL(triggered()), this, SLOT(addSession()));
    QObject::connect(actionDelete_session, SIGNAL(triggered()), this, SLOT(deleteSession()));
    QObject::connect(CLSCFirstYearSpinBox, SIGNAL(valueChanged(int)), CLSCLastYearSpinBox, SLOT(setMinimum(int)));
    QObject::connect(CLLCListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(setCurrentClass(QListWidgetItem *)));
    QObject::connect(CLLSListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(setCurrentClassMember(QListWidgetItem *)));
    QObject::connect(CLLSSListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(viewSession(QListWidgetItem *)));
    QObject::connect(CLLSSListWidget, SIGNAL(currentIndexAvailabilityChanged(bool)), actionDelete_session, SLOT(setEnabled(bool)));
    QObject::connect(CLLSSListWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(toggleAddSessionToMemberEnabled()));
    QObject::connect(CLSSResultsTableWidget, SIGNAL(currentIndexAvailabilityChanged(bool)), tbtnRemoveSession, SLOT(setEnabled(bool)));
    QObject::connect(CLSSResultsTableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem *)), this, SLOT(viewSessionAndStudent(QTableWidgetItem *)));
    QObject::connect(CLLCSearchLineEdit, SIGNAL(textChanged(QLineEdit *, const QString &)), CLLCListWidget, SLOT(filterItems(QLineEdit *, const QString &)));
    QObject::connect(CLLSSearchLineEdit, SIGNAL(textChanged(QLineEdit *, const QString &)), CLLSListWidget, SLOT(filterItems(QLineEdit *, const QString &)));
    QObject::connect(CLLSSSearchLineEdit, SIGNAL(textChanged(QLineEdit *, const QString &)), CLLSSListWidget, SLOT(filterItems(QLineEdit *, const QString &)));
    QObject::connect(tbtnApplyClassChanges, SIGNAL(released()), this, SLOT(updateClassProperties()));
    QObject::connect(tbtnSaveMemberName, SIGNAL(released()), this, SLOT(updateClassMemberName()));
    QObject::connect(tbtnAddSession, SIGNAL(released()), this, SLOT(addSessionToMember()));
    QObject::connect(tbtnRemoveSession, SIGNAL(released()), this, SLOT(removeSessionFromMember()));
    CLLCListWidget->setSortingEnabled(true);
    CLLSSListWidget->setSortingEnabled(true);
    CLSSResultsTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    CLSSResultsTableWidget->verticalHeader()->hide();
    CLSSResultsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    setCLSCEnabled(false);
}
Beispiel #3
0
void ObjectControllerPrivate::slotValueChanged(QtProperty *property, const QVariant &value)
{
    if (!m_propertyToIndex.contains(property))
        return;

    int idx = m_propertyToIndex.value(property);

    const QMetaObject *metaObject = m_object->metaObject();
    QMetaProperty metaProperty = metaObject->property(idx);
    if (metaProperty.isEnumType()) {
        if (metaProperty.isFlagType())
            metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt()));
        else
            metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt()));
    } else {
        metaProperty.write(m_object, value);
    }

    updateClassProperties(metaObject, true);
}
Beispiel #4
0
void ObjectControllerPrivate::addClassProperties(const QMetaObject *metaObject)
{
    if (!metaObject)
        return;

    addClassProperties(metaObject->superClass());

    QtProperty *classProperty = m_classToProperty.value(metaObject);
    if (!classProperty) {
        QString className = QLatin1String(metaObject->className());
        classProperty = m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), className);
        m_classToProperty[metaObject] = classProperty;
        m_propertyToClass[classProperty] = metaObject;

        for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
            QMetaProperty metaProperty = metaObject->property(idx);
            int type = metaProperty.userType();
            QtVariantProperty *subProperty = 0;
            if (!metaProperty.isReadable()) {
                subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
                subProperty->setValue(QLatin1String("< Non Readable >"));
            } else if (metaProperty.isEnumType()) {
                if (metaProperty.isFlagType()) {
                    subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name()));
                    QMetaEnum metaEnum = metaProperty.enumerator();
                    QMap<int, bool> valueMap;
                    QStringList flagNames;
                    for (int i = 0; i < metaEnum.keyCount(); i++) {
                        int value = metaEnum.value(i);
                        if (!valueMap.contains(value) && isPowerOf2(value)) {
                            valueMap[value] = true;
                            flagNames.append(QLatin1String(metaEnum.key(i)));
                        }
                    subProperty->setAttribute(QLatin1String("flagNames"), flagNames);
                    subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt()));
                    }
                } else {
                    subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name()));
                    QMetaEnum metaEnum = metaProperty.enumerator();
                    QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
                    QStringList enumNames;
                    for (int i = 0; i < metaEnum.keyCount(); i++) {
                        int value = metaEnum.value(i);
                        if (!valueMap.contains(value)) {
                            valueMap[value] = true;
                            enumNames.append(QLatin1String(metaEnum.key(i)));
                        }
                    }
                    subProperty->setAttribute(QLatin1String("enumNames"), enumNames);
                    subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt()));
                }
            } else if (m_manager->isPropertyTypeSupported(type)) {
                if (!metaProperty.isWritable())
                    subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Writable)"));
                if (!metaProperty.isDesignable())
                    subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Designable)"));
                else
                    subProperty = m_manager->addProperty(type, QLatin1String(metaProperty.name()));
                subProperty->setValue(metaProperty.read(m_object));
            } else {
                subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
                subProperty->setValue(QLatin1String("< Unknown Type >"));
                subProperty->setEnabled(false);
            }
            classProperty->addSubProperty(subProperty);
            m_propertyToIndex[subProperty] = idx;
            m_classToIndexToProperty[metaObject][idx] = subProperty;
        }
    } else {
        updateClassProperties(metaObject, false);
    }

    m_topLevelProperties.append(classProperty);
    m_browser->addProperty(classProperty);
}
void ObjectControllerPrivate::addClassProperties(const QMetaObject *inmetaObject, bool subGroup)
{
    if (!inmetaObject)
        return;
    
    // Collect a list of all sub classes in the object
    QList< const QMetaObject *> metaObjectsList;
    metaObjectsList.clear();

    metaObjectsList << inmetaObject;

    const QMetaObject *tmpObj = inmetaObject->superClass();
    metaObjectsList << tmpObj;
    while (tmpObj)
    {
        tmpObj = tmpObj->superClass();
        if (tmpObj)
            metaObjectsList << tmpObj;
    }
    
    const QMetaObject *metaObject;

    for (int i = 0; i < metaObjectsList.count(); i++)
    {
        metaObject = metaObjectsList[i];
        
        QtProperty *classProperty = m_classToProperty.value(metaObject);
        if (!classProperty) {
            QString className = QLatin1String(metaObject->className());

            // Note: Skip class QObject from the property views
            if (className == QLatin1String("QObject")) return;

            // Process Class name into a user friendly view
            // Strip prefix C_ and process all _ to spaces
            
            QString prefix("C_"); // String to replace.
            QString replaceprefix(""); // Replacement string.
            className.replace(className.indexOf(prefix), prefix.size(), replaceprefix);
            className.replace(QString("_"), QString(" "));
            classProperty = m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), className);
            m_classToProperty[metaObject] = classProperty;
            m_propertyToClass[classProperty] = metaObject;

            for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {

                QMetaProperty metaProperty = metaObject->property(idx);
                int type = metaProperty.userType();
                QtVariantProperty *subProperty = 0;

                // Note:  Get the var member name and check if we want it to be writable (Enabled)
                QString memberVarName = QLatin1String(metaProperty.name());
                bool b_SetEnabled = true;

                // Special case for enabling or disabling editing
                QString ememberVarName = "e" + QLatin1String(metaProperty.name());
                QByteArray array = ememberVarName.toLocal8Bit();
                char* buffer = array.data();
                QVariant set = m_object->property(buffer);
                if (set.type() == QVariant::Bool)
                {
                    b_SetEnabled = (bool &)set;
                }

                // qDebug() << "Member Name :" << memberVarName;

                // Note: process the first char if it contains _ then the var is read only and remove the _ char
                if (memberVarName.at(0) == "_") {
                    b_SetEnabled = false;
                    memberVarName.remove(0, 1);
                }

                // after that replace all occurance of _ with space char for display 
                memberVarName.replace(QString("_"), QString(" "));

                if (!metaProperty.isReadable()) {
                    subProperty = m_readOnlyManager->addProperty(QVariant::String, memberVarName);
                    subProperty->setValue(QLatin1String("< Non Readable >"));
                }
                else if (metaProperty.isEnumType()) {
                    if (metaProperty.isFlagType()) {
                        subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), memberVarName);
                        QMetaEnum metaEnum = metaProperty.enumerator();
                        QMap<int, bool> valueMap;
                        QStringList flagNames;
                        for (int i = 0; i < metaEnum.keyCount(); i++) {
                            int value = metaEnum.value(i);
                            if (!valueMap.contains(value) && isPowerOf2(value)) {
                                valueMap[value] = true;
                                flagNames.append(QLatin1String(metaEnum.key(i)));
                            }
                            subProperty->setAttribute(QLatin1String("flagNames"), flagNames);
                            subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt()));
                        }
                    }
                    else {
                        subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), memberVarName);
                        QMetaEnum metaEnum = metaProperty.enumerator();
                        QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
                        QStringList enumNames;
                        for (int i = 0; i < metaEnum.keyCount(); i++) {
                            int value = metaEnum.value(i);
                            if (!valueMap.contains(value)) {
                                valueMap[value] = true;
                                enumNames.append(QLatin1String(metaEnum.key(i)));
                            }
                        }
                        subProperty->setAttribute(QLatin1String("enumNames"), enumNames);
                        subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt()));
                    }
                }
                else if (m_manager->isPropertyTypeSupported(type)) {
                    if (!metaProperty.isWritable())
                        subProperty = m_readOnlyManager->addProperty(type, memberVarName + QLatin1String(" (Non Writable)"));
                    if (!metaProperty.isDesignable())
                        subProperty = m_readOnlyManager->addProperty(type, memberVarName + QLatin1String(" (Non Designable)"));
                    else
                        subProperty = m_manager->addProperty(type, memberVarName);
                    subProperty->setValue(metaProperty.read(m_object));
                }
                else {
                    subProperty = m_readOnlyManager->addProperty(QVariant::String, memberVarName);
                    subProperty->setValue(QLatin1String("< Unknown Type >"));
                    b_SetEnabled = false;
                }


                // Notes: QtVariantProperty *priority = variantManager->addProperty(QVariant::Int, "Priority");	

                if (subProperty)
                    subProperty->setEnabled(b_SetEnabled);

                m_propertyToIndex[subProperty] = idx;
                m_classToIndexToProperty[metaObject][idx] = subProperty;
                if (subGroup)
                    classProperty->addSubProperty(subProperty);
                else
                    m_browser->addProperty(subProperty);
            }
        }
        else {
            updateClassProperties(metaObject, false);
        }

        m_topLevelProperties.append(classProperty);
        if (subGroup)
            m_browser->addProperty(classProperty);
    } // Loop i
}