예제 #1
0
    void FontPropertyManager::postInitializeProperty(QtVariantPropertyManager *vm,
                                                     QtProperty *property,
                                                     int type,
                                                     int enumTypeId)
    {
        if (type != QVariant::Font)
            return;

        // This will cause a recursion
        QtVariantProperty *antialiasing = vm->addProperty(enumTypeId, QCoreApplication::translate("FontPropertyManager", "Antialiasing"));
        const QFont font = qVariantValue<QFont>(vm->variantProperty(property)->value());

        antialiasing->setAttribute(QLatin1String("enumNames"), m_aliasingEnumNames);
        antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
        property->addSubProperty(antialiasing);

        m_propertyToAntialiasing[property] = antialiasing;
        m_antialiasingToProperty[antialiasing] = property;
        // Fiddle family names
        if (!m_familyMappings.empty()) {
            const PropertyToSubPropertiesMap::iterator it = m_propertyToFontSubProperties.find(m_createdFontProperty);
            QtVariantProperty *familyProperty = vm->variantProperty(it.value().front());
            const QString enumNamesAttribute = QLatin1String("enumNames");
            QStringList plainFamilyNames = familyProperty->attributeValue(enumNamesAttribute).toStringList();
            // Did someone load fonts or something?
            if (m_designerFamilyNames.size() != plainFamilyNames.size())
                m_designerFamilyNames = designerFamilyNames(plainFamilyNames, m_familyMappings);
            familyProperty->setAttribute(enumNamesAttribute, m_designerFamilyNames);
        }
        // Next
        m_createdFontProperty = 0;
    }
예제 #2
0
void PropertyBrowser::addLayerProperties(QtProperty *parent)
{
    createProperty(NameProperty, QVariant::String, tr("Name"), parent);
    createProperty(VisibleProperty, QVariant::Bool, tr("Visible"), parent);

    QtVariantProperty *opacityProperty =
            createProperty(OpacityProperty, QVariant::Double, tr("Opacity"), parent);
    opacityProperty->setAttribute(QLatin1String("minimum"), 0.0);
    opacityProperty->setAttribute(QLatin1String("maximum"), 1.0);
    opacityProperty->setAttribute(QLatin1String("singleStep"), 0.1);
}
QtProperty *CrossCommonPropertyGroup::extrackBaseProperty(QtVariantPropertyManager *manager,
                                                          QHash<QString, QtVariantProperty *> &propertyTable)
{
    QtProperty          *parameters;
    QtVariantProperty   *item;

    parameters = manager->addProperty(QtVariantPropertyManager::groupTypeId(),
                                      QString(QObject::tr("基本属性")));


    #ifdef QT_DEBUG
        item = manager->addProperty(QVariant::Int, QString(QObject::tr("id(发布版本无此项)")));
        item->setValue("0");
        item->setEnabled(false);
        parameters->addSubProperty(item);
        propertyTable.insert("/map_key/base/id", item);
    #endif

    item = manager->addProperty(QVariant::String, QString(QObject::tr("图名")));
    item->setValue(QObject::tr("交会图"));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/base/title", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("宽度")));
    item->setValue(400);
    item->setAttribute(QLatin1String("minimum"), 0);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/base/width", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("高度")));
    item->setValue(300);
    item->setAttribute(QLatin1String("minimum"), 0);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/base/height", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("x")));
    item->setValue(0);
    item->setAttribute(QLatin1String("minimum"), 0);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/base/x", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("y")));
    item->setValue(0);
    item->setAttribute(QLatin1String("minimum"), 0);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/base/y", item);

    return parameters;
}
예제 #4
0
int main(int argc, char **argv)
{
	QApplication app(argc, argv);
	
	Test t;

	QtVariantPropertyManager *variantManager = new VariantManager();
	QtVariantProperty *priority = variantManager->addProperty(QVariant::Int, "Priority");

	priority->setToolTip("Task Priority");

	priority->setAttribute("minimum", 1);
	priority->setAttribute("maximum", 5);
	priority->setValue(3);

	QtVariantProperty *reportType = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), "Report Type");
	QStringList types;
	types << "Bug" << "Suggestion" << "To Do";
	reportType->setAttribute("enumNames", types);
	reportType->setValue(1); // current value will be "Suggestion"

	QtVariantProperty *task1 = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), "Task 1");

	task1->addSubProperty(priority);
	task1->addSubProperty(reportType);

	QtTreePropertyBrowser *browser = new QtTreePropertyBrowser();

	QtVariantEditorFactory *variantFactory = new VariantFactory();
	browser->setFactoryForManager(variantManager, variantFactory);

	browser->addProperty(task1);
	browser->show();

	QtVariantProperty *example = variantManager->addProperty(VariantManager::filePathTypeId(), "Example");
	example->setValue("main.cpp");
	example->setAttribute("filter", "Source files (*.cpp *.c)");

	
	QObject::connect(variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
					&t, SLOT(onValueChanged(QtProperty * , const QVariant &)));

	task1->addSubProperty(example);

	return app.exec();
}
예제 #5
0
void BrushPropertyManager::initializeProperty(QtVariantPropertyManager *vm, QtProperty *property, int enumTypeId)
{
    m_brushValues.insert(property, QBrush());
    // style
    QtVariantProperty *styleSubProperty = vm->addProperty(enumTypeId, QCoreApplication::translate("BrushPropertyManager", "Style"));
    property->addSubProperty(styleSubProperty);
    QStringList styles;
    const int brushStyleCount = sizeof(brushStyles)/sizeof(const char *);
    for (int i = 0; i < brushStyleCount; i++)
        styles.push_back(QCoreApplication::translate("BrushPropertyManager", brushStyles[i]));
    styleSubProperty->setAttribute(QLatin1String("enumNames"), styles);
    styleSubProperty->setAttribute(QLatin1String("enumIcons"), qVariantFromValue(brushStyleIcons()));
    m_brushPropertyToStyleSubProperty.insert(property, styleSubProperty);
    m_brushStyleSubPropertyToProperty.insert(styleSubProperty, property);
    // color
    QtVariantProperty *colorSubProperty = vm->addProperty(QVariant::Color, QCoreApplication::translate("BrushPropertyManager", "Color"));
    property->addSubProperty(colorSubProperty);
    m_brushPropertyToColorSubProperty.insert(property, colorSubProperty);
    m_brushColorSubPropertyToProperty.insert(colorSubProperty, property);
}
예제 #6
0
void QwtPlotPropertySetDialog::addCurveSet(QwtPlotCurve* curve)
{
    m_enableSet = false;
    int curveID = makeCurveBaseID(curve);
    QString name = QStringLiteral("%1-图表参数").arg(curve->title().text());
    QtProperty *groupItem = m_propertyGroup->addProperty(name);
    QtVariantProperty *pro = nullptr;

    m_property_id.rememberTheProperty(curveID,groupItem);
    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
                                                  ,groupItem,QStringLiteral("标题")
                                                  ,makeCurvePropertyID(curveID,ID_CurveTitle)
                                                  ,curve->title().text());

    const QPen pen = curve->pen();
    pro=  m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Color
                                                  ,groupItem,QStringLiteral("颜色")
                                                  ,makeCurvePropertyID(curveID,ID_CurveColore)
                                                  ,pen.color());

    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Int
                                                  ,groupItem,QStringLiteral("线宽")
                                                  ,makeCurvePropertyID(curveID,ID_CurveWidth)
                                                  ,pen.width());
    pro->setAttribute(QStringLiteral("singleStep"), 1);

    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
                                                  ,groupItem,QStringLiteral("线形")
                                                  ,makeCurvePropertyID(curveID,ID_CurvePenStyle)
                                                  ,penStyle2Order(pen.style()));
    pro->setAttribute(QLatin1String("enumNames"),QStringList()
                      <<QStringLiteral("实线")
                      <<QStringLiteral("虚线")
                      <<QStringLiteral("点线")
                      <<QStringLiteral("点划线")
                      <<QStringLiteral("双点划线")
                      );
    m_property->addProperty(groupItem);
    m_enableSet = true;
}
예제 #7
0
void PropertyBrowser::addImageLayerProperties()
{
    QtProperty *groupProperty = mGroupManager->addProperty(tr("Image Layer"));
    addLayerProperties(groupProperty);

    QtVariantProperty *imageSourceProperty = createProperty(ImageSourceProperty,
                                                            VariantPropertyManager::filePathTypeId(),
                                                            tr("Image"), groupProperty);

    imageSourceProperty->setAttribute(QLatin1String("filter"),
                                      Utils::readableImageFormatsFilter());

    createProperty(ColorProperty, QVariant::Color, tr("Transparent Color"), groupProperty);
    addProperty(groupProperty);
}
예제 #8
0
void PropertyBrowser::addMapObjectProperties()
{
    QtProperty *groupProperty = mGroupManager->addProperty(tr("Object"));
    createProperty(NameProperty, QVariant::String, tr("Name"), groupProperty);

    QtVariantProperty *typeProperty =
            createProperty(TypeProperty, QVariant::String, tr("Type"), groupProperty);
    typeProperty->setAttribute(QLatin1String("suggestions"), objectTypeNames());

    createProperty(VisibleProperty, QVariant::Bool, tr("Visible"), groupProperty);
    createProperty(PositionProperty, QVariant::PointF, tr("Position"), groupProperty);
    createProperty(SizeProperty, QVariant::SizeF, tr("Size"), groupProperty);
    createProperty(RotationProperty, QVariant::Double, tr("Rotation"), groupProperty);

    if (!static_cast<const MapObject*>(mObject)->cell().isEmpty()) {
        QtVariantProperty *flippingProperty =
                createProperty(FlippingProperty, VariantPropertyManager::flagTypeId(),
                               tr("Flipping"), groupProperty);

        flippingProperty->setAttribute(QLatin1String("flagNames"), mFlippingFlagNames);
    }

    addProperty(groupProperty);
}
예제 #9
0
void PropertyBrowser::addObjectGroupProperties()
{
    QtProperty *groupProperty = mGroupManager->addProperty(tr("Object Layer"));
    addLayerProperties(groupProperty);

    createProperty(ColorProperty, QVariant::Color, tr("Color"), groupProperty);

    QtVariantProperty *drawOrderProperty =
            createProperty(DrawOrderProperty,
                           QtVariantPropertyManager::enumTypeId(),
                           tr("Drawing Order"),
                           groupProperty);

    drawOrderProperty->setAttribute(QLatin1String("enumNames"), mDrawOrderNames);

    addProperty(groupProperty);
}
예제 #10
0
QtVariantProperty *ObjectTypesEditor::createProperty(int type,
                                                     const QString &name)
{
    QtVariantProperty *property = mVariantManager->addProperty(type, name);
    if (!property) {
        // fall back to string property for unsupported property types
        property = mVariantManager->addProperty(QVariant::String, name);
    }

    if (type == QVariant::Bool)
        property->setAttribute(QLatin1String("textVisible"), false);

    mUi->propertiesView->addProperty(property);
    mNameToProperty.insert(name, property);

    return property;
}
예제 #11
0
QtVariantProperty *PropertyBrowser::createProperty(PropertyId id, int type,
                                                   const QString &name,
                                                   QtProperty *parent)
{
    QtVariantProperty *property = mVariantManager->addProperty(type, name);
    if (type == QVariant::Bool)
        property->setAttribute(QLatin1String("textVisible"), false);

    parent->addSubProperty(property);
    mPropertyToId.insert(property, id);

    if (id != CustomProperty)
        mIdToProperty.insert(id, property);
    else
        mNameToProperty.insert(name, property);

    return property;
}
예제 #12
0
void QwtPlotPropertySetDialog::addPlotSet(ChartWave_qwt* plot)
{
    m_enableSet = false;
    //图表参数
    QtVariantProperty *pro = nullptr;
    QtProperty *groupItem = m_propertyGroup->addProperty(QStringLiteral("图表参数"));
    m_property_id.rememberTheProperty(ID_GroupPlot,groupItem);
    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
                                            ,groupItem,QStringLiteral("图表标题"),ID_PlotTitle,m_plot->title().text());
    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
                                            ,groupItem,QStringLiteral("脚标"),ID_PlotFooter,m_plot->footer().text());
    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Color
                                            ,groupItem,QStringLiteral("画布背景"),ID_PlotCanvasBackground,m_plot->canvasBackground().color());
    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Bool
                                            ,groupItem,QStringLiteral("缩放滚动条"),ID_PlotEnableZoomerScroll,m_plot->isEnableZoomerScroll());

    //坐标轴设置

    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::flagTypeId()
                                                  ,groupItem,QStringLiteral("坐标轴设置"),ID_PlotAxisSet,getAxisEnable(plot));
    pro->setAttribute(QLatin1String("flagNames"), QStringList()
                      <<QStringLiteral("x底")
                      <<QStringLiteral("x顶")
                      <<QStringLiteral("y左")
                      <<QStringLiteral("y右")
                      );//在setAttribute过程中会触发onPropertyValueChanged,而onPropertyValueChanged的值是0,需要使用m_enableAxisEnableSet来抑制
    pro->setValue(getAxisEnable(plot));

    //轴详细设置
    addAxisSet(groupItem,plot,QwtPlot::xBottom);
    addAxisSet(groupItem,plot,QwtPlot::yLeft);
    addAxisSet(groupItem,plot,QwtPlot::xTop);
    addAxisSet(groupItem,plot,QwtPlot::yRight);
    m_property->addProperty(groupItem);
    m_enableSet = true;
}
예제 #13
0
void AbstractItemEditor::setupProperties(PropertyDefinition *propList)
{
    for (int i = 0; propList[i].name; i++) {
        int type = propList[i].typeFunc ? propList[i].typeFunc() : propList[i].type;
        int role = propList[i].role;
        QtVariantProperty *prop = m_propertyManager->addProperty(type, QLatin1String(propList[i].name));
        Q_ASSERT(prop);
        if (role == Qt::ToolTipPropertyRole || role == Qt::WhatsThisPropertyRole)
            prop->setAttribute(QLatin1String("validationMode"), ValidationRichText);
        else if (role == Qt::DisplayPropertyRole)
            prop->setAttribute(QLatin1String("validationMode"), ValidationMultiLine);
        else if (role == Qt::StatusTipPropertyRole)
            prop->setAttribute(QLatin1String("validationMode"), ValidationSingleLine);
        else if (role == ItemFlagsShadowRole)
            prop->setAttribute(QLatin1String("flagNames"), c2qStringList(itemFlagNames));
        else if (role == Qt::CheckStateRole)
            prop->setAttribute(QLatin1String("enumNames"), c2qStringList(checkStateNames));
        prop->setAttribute(QLatin1String("resettable"), true);
        m_properties.append(prop);
        m_rootProperties.append(prop);
        m_propertyToRole.insert(prop, role);
    }
}
예제 #14
0
void MainWindow::itemClicked(QtCanvasItem *item)
{
    updateExpandState();

    QMap<QtProperty *, QString>::ConstIterator itProp = propertyToId.constBegin();
    while (itProp != propertyToId.constEnd()) {
        delete itProp.key();
        itProp++;
    }
    propertyToId.clear();
    idToProperty.clear();

    currentItem = item;
    if (!currentItem) {
        deleteAction->setEnabled(false);
        return;
    }

    deleteAction->setEnabled(true);

    QtVariantProperty *property;

    property = variantManager->addProperty(QVariant::Double, tr("Position X"));
    property->setAttribute(QLatin1String("minimum"), 0);
    property->setAttribute(QLatin1String("maximum"), canvas->width());
    property->setValue(item->x());
    addProperty(property, QLatin1String("xpos"));

    property = variantManager->addProperty(QVariant::Double, tr("Position Y"));
    property->setAttribute(QLatin1String("minimum"), 0);
    property->setAttribute(QLatin1String("maximum"), canvas->height());
    property->setValue(item->y());
    addProperty(property, QLatin1String("ypos"));

    property = variantManager->addProperty(QVariant::Double, tr("Position Z"));
    property->setAttribute(QLatin1String("minimum"), 0);
    property->setAttribute(QLatin1String("maximum"), 256);
    property->setValue(item->z());
    addProperty(property, QLatin1String("zpos"));

    if (item->rtti() == QtCanvasItem::Rtti_Rectangle) {
        QtCanvasRectangle *i = (QtCanvasRectangle *)item;

        property = variantManager->addProperty(QVariant::Color, tr("Brush Color"));
        property->setValue(i->brush().color());
        addProperty(property, QLatin1String("brush"));

        property = variantManager->addProperty(QVariant::Color, tr("Pen Color"));
        property->setValue(i->pen().color());
        addProperty(property, QLatin1String("pen"));

        property = variantManager->addProperty(QVariant::Size, tr("Size"));
        property->setValue(i->size());
        addProperty(property, QLatin1String("size"));
    } else if (item->rtti() == QtCanvasItem::Rtti_Line) {
        QtCanvasLine *i = (QtCanvasLine *)item;

        property = variantManager->addProperty(QVariant::Color, tr("Pen Color"));
        property->setValue(i->pen().color());
        addProperty(property, QLatin1String("pen"));

        property = variantManager->addProperty(QVariant::Point, tr("Vector"));
        property->setValue(i->endPoint());
        addProperty(property, QLatin1String("endpoint"));
    } else if (item->rtti() == QtCanvasItem::Rtti_Ellipse) {
        QtCanvasEllipse *i = (QtCanvasEllipse *)item;

        property = variantManager->addProperty(QVariant::Color, tr("Brush Color"));
        property->setValue(i->brush().color());
        addProperty(property, QLatin1String("brush"));

        property = variantManager->addProperty(QVariant::Size, tr("Size"));
        property->setValue(QSize(i->width(), i->height()));
        addProperty(property, QLatin1String("size"));
    } else if (item->rtti() == QtCanvasItem::Rtti_Text) {
        QtCanvasText *i = (QtCanvasText *)item;

        property = variantManager->addProperty(QVariant::Color, tr("Color"));
        property->setValue(i->color());
        addProperty(property, QLatin1String("color"));

        property = variantManager->addProperty(QVariant::String, tr("Text"));
        property->setValue(i->text());
        addProperty(property, QLatin1String("text"));

        property = variantManager->addProperty(QVariant::Font, tr("Font"));
        property->setValue(i->font());
        addProperty(property, QLatin1String("font"));
    }
}
예제 #15
0
void PropertyEditor::setObject(QObject *object)
{
    QDesignerFormWindowInterface *oldFormWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
    // In the first setObject() call following the addition of a dynamic property, focus and edit it.
    const bool editNewDynamicProperty = object != 0 && m_object == object && !m_recentlyAddedDynamicProperty.isEmpty();
    m_object = object;
    m_propertyManager->setObject(object);
    QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object);
    FormWindowBase *fwb = qobject_cast<FormWindowBase *>(formWindow);
    m_treeFactory->setFormWindowBase(fwb);
    m_groupFactory->setFormWindowBase(fwb);

    storeExpansionState();

    UpdateBlocker ub(this);

    updateToolBarLabel();

    QMap<QString, QtVariantProperty *> toRemove = m_nameToProperty;

    const QDesignerDynamicPropertySheetExtension *dynamicSheet =
            qt_extension<QDesignerDynamicPropertySheetExtension*>(m_core->extensionManager(), m_object);
    const QDesignerPropertySheet *sheet = qobject_cast<QDesignerPropertySheet*>(m_core->extensionManager()->extension(m_object, Q_TYPEID(QDesignerPropertySheetExtension)));

    // Optimizization: Instead of rebuilding the complete list every time, compile a list of properties to remove,
    // remove them, traverse the sheet, in case property exists just set a value, otherwise - create it.
    QExtensionManager *m = m_core->extensionManager();

    m_propertySheet = qobject_cast<QDesignerPropertySheetExtension*>(m->extension(object, Q_TYPEID(QDesignerPropertySheetExtension)));
    if (m_propertySheet) {
        const int propertyCount = m_propertySheet->count();
        for (int i = 0; i < propertyCount; ++i) {
            if (!m_propertySheet->isVisible(i))
                continue;

            const QString propertyName = m_propertySheet->propertyName(i);
            if (m_propertySheet->indexOf(propertyName) != i)
                continue;
            const QString groupName = m_propertySheet->propertyGroup(i);
            const QMap<QString, QtVariantProperty *>::const_iterator rit = toRemove.constFind(propertyName);
            if (rit != toRemove.constEnd()) {
                QtVariantProperty *property = rit.value();
                if (m_propertyToGroup.value(property) == groupName && toBrowserType(m_propertySheet->property(i), propertyName) == property->propertyType())
                    toRemove.remove(propertyName);
            }
        }
    }

    QMapIterator<QString, QtVariantProperty *> itRemove(toRemove);
    while (itRemove.hasNext()) {
        itRemove.next();

        QtVariantProperty *property = itRemove.value();
        m_nameToProperty.remove(itRemove.key());
        m_propertyToGroup.remove(property);
        delete property;
    }

    if (oldFormWindow != formWindow)
        reloadResourceProperties();

    bool isMainContainer = false;
    if (QWidget *widget = qobject_cast<QWidget*>(object)) {
        if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(widget)) {
            isMainContainer = (fw->mainContainer() == widget);
        }
    }
    m_groups.clear();

    if (m_propertySheet) {
        QtProperty *lastProperty = 0;
        QtProperty *lastGroup = 0;
        const int propertyCount = m_propertySheet->count();
        for (int i = 0; i < propertyCount; ++i) {
            if (!m_propertySheet->isVisible(i))
                continue;

            const QString propertyName = m_propertySheet->propertyName(i);
            if (m_propertySheet->indexOf(propertyName) != i)
                continue;
            const QVariant value = m_propertySheet->property(i);

            const int type = toBrowserType(value, propertyName);

            QtVariantProperty *property = m_nameToProperty.value(propertyName, 0);
            bool newProperty = property == 0;
            if (newProperty) {
                property = m_propertyManager->addProperty(type, propertyName);
                if (property) {
                    newProperty = true;
                    if (type == DesignerPropertyManager::enumTypeId()) {
                        const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(value);
                        QStringList names;
                        QStringListIterator it(e.metaEnum.keys());
                        while (it.hasNext())
                            names.append(it.next());
                        m_updatingBrowser = true;
                        property->setAttribute(m_strings.m_enumNamesAttribute, names);
                        m_updatingBrowser = false;
                    } else if (type == DesignerPropertyManager::designerFlagTypeId()) {
                        const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(value);
                        QList<QPair<QString, uint> > flags;
                        QStringListIterator it(f.metaFlags.keys());
                        while (it.hasNext()) {
                            const QString name = it.next();
                            const uint val = f.metaFlags.keyToValue(name);
                            flags.append(qMakePair(name, val));
                        }
                        m_updatingBrowser = true;
                        QVariant v;
                        qVariantSetValue(v, flags);
                        property->setAttribute(m_strings.m_flagsAttribute, v);
                        m_updatingBrowser = false;
                    }
                }
            }

            if (property != 0) {
                const bool dynamicProperty = (dynamicSheet && dynamicSheet->isDynamicProperty(i))
                            || (sheet && sheet->isDefaultDynamicProperty(i));
                switch (type) {
                case QVariant::Palette:
                    setupPaletteProperty(property);
                    break;
                case QVariant::KeySequence:
                    //addCommentProperty(property, propertyName);
                    break;
                default:
                    break;
                }
                if (type == QVariant::String || type == qMetaTypeId<PropertySheetStringValue>())
                    setupStringProperty(property, isMainContainer);
                property->setAttribute(m_strings.m_resettableAttribute, m_propertySheet->hasReset(i));

                const QString groupName = m_propertySheet->propertyGroup(i);
                QtVariantProperty *groupProperty = 0;

                if (newProperty) {
                    QMap<QString, QtVariantProperty*>::const_iterator itPrev = m_nameToProperty.insert(propertyName, property);
                    m_propertyToGroup[property] = groupName;
                    if (m_sorting) {
                        QtProperty *previous = 0;
                        if (itPrev != m_nameToProperty.constBegin())
                            previous = (--itPrev).value();
                        m_currentBrowser->insertProperty(property, previous);
                    }
                }
                const QMap<QString, QtVariantProperty*>::const_iterator gnit = m_nameToGroup.constFind(groupName);
                if (gnit != m_nameToGroup.constEnd()) {
                    groupProperty = gnit.value();
                } else {
                    groupProperty = m_propertyManager->addProperty(QtVariantPropertyManager::groupTypeId(), groupName);
                    QtBrowserItem *item = 0;
                    if (!m_sorting)
                         item = m_currentBrowser->insertProperty(groupProperty, lastGroup);
                    m_nameToGroup[groupName] = groupProperty;
                    m_groups.append(groupProperty);
                    if (dynamicProperty)
                        m_dynamicGroup = groupProperty;
                    if (m_currentBrowser == m_treeBrowser && item) {
                        m_treeBrowser->setBackgroundColor(item, propertyColor(groupProperty));
                        groupProperty->setModified(true);
                    }
                }
                /*  Group changed or new group. Append to last subproperty of
                 * that group. Note that there are cases in which a derived
                 * property sheet appends fake properties for the class
                 * which will appear after the layout group properties
                 * (QWizardPage). To make them appear at the end of the
                 * actual class group, goto last element. */
                if (lastGroup != groupProperty) {
                    lastGroup = groupProperty;
                    lastProperty = 0;  // Append at end
                    const QList<QtProperty*> subProperties = lastGroup->subProperties();
                    if (!subProperties.empty())
                        lastProperty = subProperties.back();
                    lastGroup = groupProperty;
                }
                if (!m_groups.contains(groupProperty))
                    m_groups.append(groupProperty);
                if (newProperty)
                    groupProperty->insertSubProperty(property, lastProperty);

                lastProperty = property;

                updateBrowserValue(property, value);

                property->setModified(m_propertySheet->isChanged(i));
                if (propertyName == QLatin1String("geometry") && type == QVariant::Rect) {
                    QList<QtProperty *> subProperties = property->subProperties();
                    foreach (QtProperty *subProperty, subProperties) {
                        const QString subPropertyName = subProperty->propertyName();
                        if (subPropertyName == QLatin1String("X") || subPropertyName == QLatin1String("Y"))
                            subProperty->setEnabled(!isMainContainer);
                    }
                }
            } else {
                qWarning("%s", qPrintable(msgUnsupportedType(propertyName, type)));
            }
        }
예제 #16
0
void QwtPlotPropertySetDialog::addAxisSet(QtProperty* parentGroup, ChartWave_qwt* plot,QwtPlot::Axis axis)
{
    m_enableSet = false;
    QtVariantProperty *pro = nullptr;
    //QwtScaleWidget* scaleWidget = plot->axisWidget(axis);
    QwtScaleDraw *scaleDraw = plot->axisScaleDraw(axis);
    QwtDateScaleDraw* dateScale = dynamic_cast<QwtDateScaleDraw*>(scaleDraw);
    //轴详细设置
    QtProperty *childGroup = m_property_id.addGroupInGroup(m_variantManager,parentGroup
                                                           ,QStringLiteral("%1轴设置").arg(axisString(axis))
                                                           ,axisPropertyID(axis,0));
    childGroup->setEnabled(plot->axisEnabled(axis));//在轴允许时才让设置

    QwtInterval inv= plot->axisInterval(axis);

    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::PointF
                                            ,childGroup
                                            ,QStringLiteral("坐标范围")
                                            ,axisPropertyID(axis,4)
                                            ,QPointF(inv.minValue(),inv.maxValue()));

    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
                                            ,childGroup,QStringLiteral("标题")
                                            ,axisPropertyID(axis,1)
                                            ,m_plot->axisTitle(axis).text());
    //
    m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Double
                                            ,childGroup,QStringLiteral("刻度文字角度")
                                            ,axisPropertyID(axis,5)
                                            ,scaleDraw->labelRotation());
    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
                                                  ,childGroup
                                                  ,QStringLiteral("%1轴样式").arg(axisString(axis))
                                                  ,axisPropertyID(axis,2)
                                                  ,0);
    pro->setAttribute(QLatin1String("enumNames"),QStringList()
                      <<QStringLiteral("正常坐标轴")
                      <<QStringLiteral("时间坐标轴")
                      );
    ScaleDraw sd = NormalScale;
    sd = ((dateScale == nullptr) ? NormalScale : DateScale);
    pro->setValue(int(sd));

    pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
                                                  ,childGroup
                                                  ,QStringLiteral("时间格式")
                                                  ,axisPropertyID(axis,3)
                                                  ,int(ChartWave_qwt::hh_mm_ss));
    pro->setAttribute(QLatin1String("enumNames"), QStringList()
                      <<QStringLiteral("h_m")
                      <<QStringLiteral("hh_mm")
                      <<QStringLiteral("h_m_s")
                      <<QStringLiteral("hh_mm_ss")
                      <<QStringLiteral("yyyy_M_d")
                      <<QStringLiteral("yyyy_M_d_h_m")
                      <<QStringLiteral("yyyy_M_d_h_m_s")
                      <<QStringLiteral("yyyy_MM_dd")
                      <<QStringLiteral("yyyy_MM_dd_hh_mm")
                      <<QStringLiteral("yyyy_MM_dd_hh_mm_ss")
                      );//在setAttribute过程中会触发onPropertyValueChanged,而onPropertyValueChanged的值是0,需要使用m_enableAxisEnableSet来抑制
    pro->setValue(int(ChartWave_qwt::hh_mm_ss));
    pro->setEnabled(sd == DateScale);

    m_enableSet = true;
}
/** Utility function for creating a property from a key/value pair
@param key The key
@param value The value
@return the created QtProperty
*/
QtVariantProperty* QtSpacescapeMainWindow::createProperty(const Ogre::String& key, const Ogre::String& value)
{
    QStringList noiseTypes, layerTypes, blendTypes, textureSizes;
    noiseTypes << "fbm" << "ridged";
    layerTypes << "points" << "billboards" << "noise";
    blendTypes << "one" << "zero" << "dest_colour" << "src_colour" 
        << "one_minus_dest_colour" << "one_minus_src_colour" 
        << "dest_alpha" << "src_alpha" << "one_minus_dest_alpha" 
        << "one_minus_src_alpha";
    textureSizes << "64" << "128" << "256" << "512" << "1024" << "2048" << "4096" << "8192";

    int propertyType = getPropertyType(key);
    QtVariantProperty* property;

    property = mPropertyManager->addProperty(propertyType, getPropertyTitle(key));
    property->setStatusTip(getPropertyStatusTip(key));
    property->setToolTip(getPropertyStatusTip(key));

    if(propertyType == QVariant::Int) {
        property->setValue(Ogre::StringConverter::parseInt(value));
        property->setAttribute(QLatin1String("minimum"), 0);
        property->setAttribute(QLatin1String("singleStep"), 1);
    }
    else if(propertyType == QVariant::Bool) {
        property->setValue(Ogre::StringConverter::parseBool(value));
    }
    else if(propertyType == QtVariantPropertyManager::enumTypeId()) {
        QStringList *enumList = NULL;
        if(key == "destBlendFactor" || key == "sourceBlendFactor") {
            enumList = &blendTypes;
        }
        else if(key == "type") {
            enumList = &layerTypes;
        }
        else if(key == "noiseType" || key == "maskNoiseType") {
            enumList = &noiseTypes;
        }
        else if(key == "previewTextureSize") {
            enumList = &textureSizes;    
        }

        property->setAttribute(QLatin1String("enumNames"), *enumList);

        int valueIndex = 0;

        // find the selected value
        for(int i = 0; i < enumList->size(); i++) {
            if((*enumList)[i] == QString(value.c_str())) {
                valueIndex = i;
                break;
            }
        }
        
        property->setValue(valueIndex);
    }
    else if(propertyType == QVariant::Double) {
        property->setValue(Ogre::StringConverter::parseReal(value));
        property->setAttribute(QLatin1String("singleStep"), 0.01);
        property->setAttribute(QLatin1String("decimals"), 3);
    }
    else if(propertyType == QVariant::Color) {
       property->setValue(getColor(value));
    }
    else {
        // assume string
        property->setValue(value.c_str());
    }

    return property;
}
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
}
예제 #19
0
void PropertyEditorView::setRootIndex(const QModelIndex &index)
{
	mPropertyEditor->clear();

	mPropertyEditor->unsetFactoryForManager(mButtonManager);
	mPropertyEditor->unsetFactoryForManager(mVariantManager);

	delete mVariantManager;
	delete mVariantFactory;
	delete mButtonManager;
	delete mButtonFactory;

	mVariantManager = new QtVariantPropertyManager();
	mVariantFactory = new QtVariantEditorFactory();
	mButtonManager = new PushButtonPropertyManager();
	mButtonFactory = new PushButtonFactory();

	mPropertyEditor->setFactoryForManager(mButtonManager, mButtonFactory);
	mPropertyEditor->setFactoryForManager(mVariantManager, mVariantFactory);

	for (int i = 0, rows = mModel->rowCount(index); i < rows; ++i) {
		const QModelIndex &valueCell = mModel->index(i, 1);
		QString name = mModel->data(mModel->index(i, 0)).toString();
		const QVariant &value = mModel->data(valueCell);

		int type = QVariant::String;
		QString typeName = mModel->typeName(valueCell).toLower();
		QList<QPair<QString, QString>> const values = mModel->enumValues(valueCell);
		bool isButton = false;
		if (typeName == "int") {
			type = QVariant::Int;
		} else if (typeName == "bool") {
			type = QVariant::Bool;
		} else if (typeName == "string") {
			type = QVariant::String;
		} else if (typeName == "code" || typeName == "directorypath" || typeName == "filepath") {
			isButton = true;
		} else if (!values.isEmpty()) {
			type = QtVariantPropertyManager::enumTypeId();
		}

		/// @todo: Not property name should be hard-coded, new type must be introduced (like 'sdf' or 'qml')!
		if ((name == "shape" && typeName == "string") || mModel->isReference(valueCell, name)) { // hack
			isButton = true;
		}

		QtProperty *item = nullptr;
		if (isButton) {
			item = mButtonManager->addProperty(name);
		} else {
			QtVariantProperty *vItem = mVariantManager->addProperty(type, name);

			vItem->setValue(value);
			vItem->setToolTip(value.toString());

			if (!values.isEmpty()) {
				QStringList friendlyNames;
				for (QPair<QString, QString> const &pair : values) {
					friendlyNames << pair.second;
				}

				vItem->setAttribute("enumNames", friendlyNames);
				vItem->setAttribute("enumEditable", mModel->enumEditable(valueCell));
				const int idx = enumPropertyIndexOf(valueCell, value.toString());
				if (mModel->enumEditable(valueCell)) {
					vItem->setValue(idx < 0 ? value.toString() : values[idx].second);
				} else {
					vItem->setValue(idx);
				}
			}

			item = vItem;
		}

		const QString description = propertyDescription(i);

		if (!description.isEmpty()) {
			item->setToolTip(description);
		}

		mPropertyEditor->addProperty(item);
	}

	connect(mButtonManager, SIGNAL(buttonClicked(QtProperty*))
			, this, SLOT(buttonClicked(QtProperty*)), Qt::UniqueConnection);
	connect(mVariantManager, SIGNAL(valueChanged(QtProperty*, QVariant))
			, this, SLOT(editorValueChanged(QtProperty *, QVariant)), Qt::UniqueConnection);
	mPropertyEditor->setPropertiesWithoutValueMarked(true);
	mPropertyEditor->setRootIsDecorated(false);
}
예제 #20
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QtVariantPropertyManager *variantManager = new QtVariantPropertyManager();

    int i = 0;
    QtProperty *topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
                QString::number(i++) + QLatin1String(" Group Property"));

    QtVariantProperty *item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property"));
    item->setValue(true);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property"));
    item->setValue(20);
    item->setAttribute(QLatin1String("minimum"), 0);
    item->setAttribute(QLatin1String("maximum"), 100);
    item->setAttribute(QLatin1String("singleStep"), 10);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property"));
    item->setValue(1.2345);
    item->setAttribute(QLatin1String("singleStep"), 0.1);
    item->setAttribute(QLatin1String("decimals"), 3);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property"));
    item->setValue("Value");
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property"));
    item->setValue(QDate::currentDate().addDays(2));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property"));
    item->setValue(QTime::currentTime());
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property"));
    item->setValue(QDateTime::currentDateTime());
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property"));
    item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property"));
    item->setValue(QChar(386));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property"));
    item->setValue(QLocale(QLocale::Polish, QLocale::Poland));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property"));
    item->setValue(QPoint(10, 10));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property"));
    item->setValue(QPointF(1.2345, -1.23451));
    item->setAttribute(QLatin1String("decimals"), 3);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property"));
    item->setValue(QSize(20, 20));
    item->setAttribute(QLatin1String("minimum"), QSize(10, 10));
    item->setAttribute(QLatin1String("maximum"), QSize(30, 30));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property"));
    item->setValue(QSizeF(1.2345, 1.2345));
    item->setAttribute(QLatin1String("decimals"), 3);
    item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34));
    item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property"));
    item->setValue(QRect(10, 10, 20, 20));
    topItem->addSubProperty(item);
    item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50));

    item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property"));
    item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345));
    topItem->addSubProperty(item);
    item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50));
    item->setAttribute(QLatin1String("decimals"), 3);

    item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(),
                    QString::number(i++) + QLatin1String(" Enum Property"));
    QStringList enumNames;
    enumNames << "Enum0" << "Enum1" << "Enum2";
    item->setAttribute(QLatin1String("enumNames"), enumNames);
    item->setValue(1);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(),
                    QString::number(i++) + QLatin1String(" Flag Property"));
    QStringList flagNames;
    flagNames << "Flag0" << "Flag1" << "Flag2";
    item->setAttribute(QLatin1String("flagNames"), flagNames);
    item->setValue(5);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property"));
    topItem->addSubProperty(item);

    QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();

    QtTreePropertyBrowser *variantEditor = new QtTreePropertyBrowser();
    variantEditor->setFactoryForManager(variantManager, variantFactory);
    variantEditor->addProperty(topItem);
    variantEditor->setPropertiesWithoutValueMarked(true);
    variantEditor->setRootIsDecorated(false);

    variantEditor->show();

    int ret = app.exec();

    delete variantManager;
    delete variantFactory;
    delete variantEditor;

    return ret;
}
예제 #21
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);
}
예제 #22
0
void PropertyEditorView::setRootIndex(const QModelIndex &index)
{
	mPropertyEditor->clear();

	mPropertyEditor->unsetFactoryForManager(mButtonManager);
	mPropertyEditor->unsetFactoryForManager(mVariantManager);

	delete mVariantManager;
	delete mVariantFactory;
	delete mButtonManager;
	delete mButtonFactory;

	mVariantManager = new QtVariantPropertyManager();
	mVariantFactory = new QtVariantEditorFactory();
	mButtonManager = new PushButtonPropertyManager();
	mButtonFactory = new PushButtonFactory();

	mPropertyEditor->setFactoryForManager(mButtonManager, mButtonFactory);
	mPropertyEditor->setFactoryForManager(mVariantManager, mVariantFactory);

	for (int i = 0, rows = mModel->rowCount(index); i < rows; ++i) {
		QModelIndex const &valueCell = mModel->index(i, 1);
		QString name = mModel->data(mModel->index(i, 0)).toString();
		QVariant const &value = mModel->data(valueCell);

		int type = QVariant::String;
		QString typeName = mModel->typeName(valueCell).toLower();
		QStringList values = mModel->enumValues(valueCell);
		bool isButton = false;
		if (typeName == "int") {
			type = QVariant::Int;
		} else if (typeName == "bool") {
			type = QVariant::Bool;
		} else if (typeName == "string") {
			type = QVariant::String;
		} else if (typeName == "code" || typeName == "directorypath") {
			isButton = true;
		} else if (!values.isEmpty()) {
			type = QtVariantPropertyManager::enumTypeId();
		} else {
			if (name == "shape" || mModel->isReference(valueCell, name)) { // hack
				isButton = true;
			}
		}

		QtProperty *item = NULL;
		if (isButton) {
			item = mButtonManager->addProperty(name);
		} else {
			QtVariantProperty *vItem = mVariantManager->addProperty(type, name);

			vItem->setValue(value);
			vItem->setToolTip(value.toString());
			if (!values.isEmpty()) {
				vItem->setAttribute("enumNames", values);
				QVariant idx(enumPropertyIndexOf(valueCell, value.toString()));
				vItem->setValue(idx);
			}
			item = vItem;
		}
		mPropertyEditor->addProperty(item);
	}

	connect(mButtonManager, SIGNAL(buttonClicked(QtProperty*))
			, this, SLOT(buttonClicked(QtProperty*)));
	connect(mVariantManager, SIGNAL(valueChanged(QtProperty*, QVariant))
			, this, SLOT(editorValueChanged(QtProperty *, QVariant)));
	mPropertyEditor->setPropertiesWithoutValueMarked(true);
	mPropertyEditor->setRootIsDecorated(false);
}
예제 #23
0
void PropertiesEditorDialog::canvasSelectionChanged()
{
    // Clear the existing properties.
    QMap<QtProperty *, QString>::ConstIterator itProp =
            m_property_to_id.constBegin();
    while (itProp != m_property_to_id.constEnd())
    {
        delete itProp.key();
        itProp++;
    }
    m_property_to_id.clear();
    m_id_to_property.clear();

    if (!m_canvas)
    {
        return;
    }
    QList<QGraphicsSvgItem *> list = m_canvas->selectedGeneralItems();

    QObject *item = m_canvas;
    int firstProperty = Canvas::staticMetaObject.propertyOffset();
    bool canvasItemProperties = false;
    if (list.count() > 0)
    {
        item = list.front();
        canvasItemProperties = true;
        firstProperty = QGraphicsSvgItem::staticMetaObject.propertyOffset();
    }

    QtVariantProperty *property = NULL;

    const QMetaObject* metaObject = item->metaObject();
    QStringList properties;
    for(int i = firstProperty; i < metaObject->propertyCount(); ++i)
    {
        //qDebug("== %s", metaObject->property(i).name());

        // Justin: Get rid of the first 2 special properties for QGraphicsSvgItems; it's meaningless to display them.
        if (QString(metaObject->property(i).name()).compare(QString("elementId")) == 0 || QString(metaObject->property(i).name()).compare(QString("maximumCacheSize")) == 0) continue;

        const QMetaProperty& prop = metaObject->property(i);

        int type = prop.userType();
        if (type == QVariant::UInt)
        {
            type = QVariant::Int;
        }

        //qDebug("## %s,  %d,  %s", prop.name(), prop.userType(), item->property(prop.name()).typeName());

        if (prop.isEnumType())
        {
            property = m_variant_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(prop.name()));
            QMetaEnum metaEnum = prop.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)));
                }
            }
            property->setAttribute(QLatin1String("enumNames"), enumNames);
            //qDebug() << prop.name() << "= " << item->property(prop.name()).value<dunnart::Connector::RoutingType>();
            int enumValueIndex = *reinterpret_cast<const int *>
                    (item->property(prop.name()).constData());
            property->setValue(metaEnum.value(enumValueIndex));
        }
        else if (m_variant_manager->isPropertyTypeSupported(type))
        {
            if (!prop.isWritable())
            {
                property = m_read_only_manager->addProperty(type,  QLatin1String(prop.name()) + QLatin1String(" (read-only)"));
            }
            else
            {
                property = m_variant_manager->addProperty(type,  QLatin1String(prop.name()));
            }
            property->setValue(item->property(prop.name()));
        }
        else
        {
            property = m_read_only_manager->addProperty(QVariant::String,  QLatin1String(prop.name()));
            property->setValue(QLatin1String("< Unknown Type >"));
            property->setEnabled(false);
        }
        Q_ASSERT(property);

        //property->setAttribute(QLatin1String("minimum"), 0);
        //property->setAttribute(QLatin1String("maximum"), 100);
        addProperty(property, prop.name());
    }
    QList<QByteArray> propertyList = item->dynamicPropertyNames();
    for (int i = 0; i < propertyList.size(); ++i)
    {
        //qDebug("-- %s", propertyList.at(i).constData());

        const char *propName = propertyList.at(i).constData();
        const QVariant& propVariant = item->property(propName);
        property = m_variant_manager->addProperty(propVariant.userType(), QString(propName));
        //property->setAttribute(QLatin1String("minimum"), 0);
        //property->setAttribute(QLatin1String("maximum"), 100);
        property->setValue(propVariant);
        Q_ASSERT(property);
        addProperty(property, propName);
    }
}