コード例 #1
0
QtProperty *CrossCommonPropertyGroup::extrackCategoryAxisProperty(QtVariantPropertyManager *manager,
                             QHash<QString, QtVariantProperty *> &propertyTable)
{
    QtProperty          *parameters;
    QtVariantProperty   *item;

    parameters = manager->addProperty(QtVariantPropertyManager::groupTypeId(),
                                      QString(QObject::tr("类型轴属性")));

    item = manager->addProperty(QVariant::String, QString(QObject::tr("名称")));
    item->setValue(QObject::tr("类型轴"));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/category_axis/name", item);

    item = manager->addProperty(QVariant::Color, QString(QObject::tr("颜色")));
    item->setValue(QColor(0, 0, 0, 255));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/category_axis/color", item);

    item = manager->addProperty(QVariant::Bool, QString(QObject::tr("标签可见")));
    item->setValue(true);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/category_axis/label_is_visible", item);

    return parameters;
}
コード例 #2
0
ファイル: objectcontroller.cpp プロジェクト: Elv13/Kimberlite
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));
                }
            }
        }
    }
}
コード例 #3
0
QtProperty *CrossCommonPropertyGroup::extrackViewProperty(QtVariantPropertyManager *manager,
                                                          QHash<QString, QtVariantProperty *> &propertyTable)
{
    QtProperty          *parameters;
    QtVariantProperty   *item;

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

    item = manager->addProperty(QVariant::Color, QString(QObject::tr("背景颜色")));
    item->setValue(QColor(0, 0, 0, 255));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/view/backgroud_color", item);

    item = manager->addProperty(QVariant::Color, QString(QObject::tr("边框颜色")));
    item->setValue(QColor(0, 0, 0, 255));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/view/border_color", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("边框宽度")));
    item->setValue(1);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/view/border_line_width", item);

    return parameters;
}
コード例 #4
0
void AbstractItemEditor::resetProperty(QtProperty *property)
{
    if (m_propertyManager->resetFontSubProperty(property))
        return;

    if (m_propertyManager->resetIconSubProperty(property))
        return;

    BoolBlocker block(m_updatingBrowser);

    QtVariantProperty *prop = m_propertyManager->variantProperty(property);
    int role = m_propertyToRole.value(prop);
    if (role == ItemFlagsShadowRole)
        prop->setValue(qVariantFromValue((int)QListWidgetItem().flags()));
    else
        prop->setValue(QVariant(prop->valueType(), (void *)0));
    prop->setModified(false);

    setItemData(role, QVariant());
    if (role == Qt::DecorationPropertyRole)
        setItemData(Qt::DecorationRole, qVariantFromValue(QIcon()));
    if (role == Qt::DisplayPropertyRole)
        setItemData(Qt::EditRole, qVariantFromValue(QString()));
    if (role == Qt::ToolTipPropertyRole)
        setItemData(Qt::ToolTipRole, qVariantFromValue(QString()));
    if (role == Qt::StatusTipPropertyRole)
        setItemData(Qt::StatusTipRole, qVariantFromValue(QString()));
    if (role == Qt::WhatsThisPropertyRole)
        setItemData(Qt::WhatsThisRole, qVariantFromValue(QString()));
}
コード例 #5
0
QtProperty *CrossCommonPropertyGroup::extrackValueAxisProperty(QtVariantPropertyManager *manager,
                             QHash<QString, QtVariantProperty *> &propertyTable)
{
    QtProperty          *parameters;
    QtVariantProperty   *item;

    parameters = manager->addProperty(QtVariantPropertyManager::groupTypeId(),
                                      QString(QObject::tr("数值轴属性")));

    item = manager->addProperty(QVariant::String, QString(QObject::tr("名称(单位)")));
    item->setValue(QObject::tr("数值轴"));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/name", item);

    item = manager->addProperty(QVariant::Color, QString(QObject::tr("颜色")));
    item->setValue(QColor(0, 0, 0, 255));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/color", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("起始值")));
    item->setValue(0);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/lower", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("结束值")));
    item->setValue(100);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/upper", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("主刻度间隔")));
    item->setValue(10);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/major_tick_size", item);

    item = manager->addProperty(QVariant::Int, QString(QObject::tr("副刻度数量")));
    item->setValue(5);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/minor_tick_count", item);

    item = manager->addProperty(QVariant::Bool, QString(QObject::tr("主刻度可见")));
    item->setValue(true);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/major_tick_is_visible", item);

    item = manager->addProperty(QVariant::Bool, QString(QObject::tr("副刻度可见")));
    item->setValue(true);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/minor_tick_is_visible", item);

    item = manager->addProperty(QVariant::Bool, QString(QObject::tr("标签可见")));
    item->setValue(true);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/value_axis/label_is_visible", item);

    return parameters;
}
コード例 #6
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;
    }
コード例 #7
0
	void CPropBrowserCtrl::setupProperty( const SPropEntry &prop, const CInterfaceElement *element )
	{
		QtVariantProperty *p = NULL;
		QVariant v;
		
		if( prop.propType == "string" )
		{
			p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() );
			v = element->getProperty( prop.propName ).c_str();
		}
		else
		if( prop.propType == "bool" )
		{
			p = propertyMgr->addProperty( QVariant::Bool, prop.propName.c_str() );
			bool value = false;
			NLMISC::fromString( element->getProperty( prop.propName ), value );
			v = value;
		}
		else
		if( prop.propType == "int" )
		{
			p = propertyMgr->addProperty( QVariant::Int, prop.propName.c_str() );
			sint32 value = 0;
			NLMISC::fromString( element->getProperty( prop.propName ), value );
			v = value;
		}

		if( p == NULL )
			return;

		p->setValue( v );
		browser->addProperty( p );
	}
コード例 #8
0
ファイル: main.cpp プロジェクト: nhatson1987/QtPropBuildTest
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();
}
コード例 #9
0
QtProperty *CrossCommonPropertyGroup::extrackGridProperty(QtVariantPropertyManager *manager,
                                QHash<QString, QtVariantProperty *> &propertyTable)
{
    QtProperty          *parameters;
    QtVariantProperty   *item;

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

    item = manager->addProperty(QVariant::Color, QString(QObject::tr("颜色")));
    item->setValue(QColor(0, 0, 0, 255));
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/grid/color", item);

    item = manager->addProperty(QVariant::Double, QString(QObject::tr("粗细")));
    item->setValue(1);
    parameters->addSubProperty(item);
    propertyTable.insert("/map_key/grid/line_width", item);

    return parameters;
}
コード例 #10
0
    void FontPropertyManager::setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value)
    {
        updateModifiedState(property, value);

        if (QtProperty *antialiasingProperty = m_propertyToAntialiasing.value(property, 0)) {
            QtVariantProperty *antialiasing = vm->variantProperty(antialiasingProperty);
            if (antialiasing) {
                QFont font = qVariantValue<QFont>(value);
                antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
            }
        }
    }
コード例 #11
0
static QtVariantProperty* createQtProperty(
        const Property* prop, QtVariantPropertyManager* varPropMgr)
{
    typedef typename PropTraits<T>::PropertyType PropertyType;
    auto castedProp = static_cast<const PropertyType*>(prop);
    QtVariantProperty* qtProp =
            varPropMgr->addProperty(
                PropTraits<T>::qVariantTypeId(), prop->label());
    QtPropertyInit<T>::func(qtProp, castedProp);
    qtProp->setValue(PropertyQVariantCast<T>::toQVariantValue(castedProp));
    return qtProp;
}
コード例 #12
0
ファイル: Mapper.cpp プロジェクト: flv0/mapmap
void Mapper::_updateShapeProperty(QtProperty* shapeItem, MShape* shape)
{
  QList<QtProperty*> pointItems = shapeItem->subProperties();
  for (int i=0; i<shape->nVertices(); i++)
  {
    // XXX mesh control points are not added to properties
    if (i < pointItems.size())
    {
      QtVariantProperty* pointItem = (QtVariantProperty*)pointItems[i];
      const QPointF& p = shape->getVertex(i);
      pointItem->setValue(p);
    }
  }
}
コード例 #13
0
ファイル: pgeitems.cpp プロジェクト: llibuda/impresario
 //-----------------------------------------------------------------------
 // Class MacroLinkItem
 //-----------------------------------------------------------------------
 void MacroLinkItem::setupProperties(WndProperties& propWnd) const
 {
   QtVariantPropertyManager& propManager = propWnd.infoPropertyManager();
   QtVariantProperty* item;
   QtVariantProperty* group;
   group = propManager.addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("General"));
   item = propManager.addProperty(QVariant::String, QObject::tr("Link type"));
   item->setValue(edge().srcPin().data()->dataRef().staticCast<app::MacroPin>()->getType());
   group->addSubProperty(item);
   group = propManager.addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("Source"));
   item = propManager.addProperty(QVariant::String, QObject::tr("Macro"));
   item->setValue(edge().srcPin().data()->vertex().dataRef().staticCast<app::Macro>()->getName());
   group->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Output pin"));
   item->setValue(edge().srcPin().data()->dataRef().staticCast<app::MacroPin>()->getName());
   group->addSubProperty(item);
   group = propManager.addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("Destination"));
   item = propManager.addProperty(QVariant::String, QObject::tr("Macro"));
   item->setValue(edge().destPin().data()->vertex().dataRef().staticCast<app::Macro>()->getName());
   group->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Input pin"));
   item->setValue(edge().destPin().data()->dataRef().staticCast<app::MacroPin>()->getName());
   group->addSubProperty(item);
 }
コード例 #14
0
ファイル: Mapper.cpp プロジェクト: flv0/mapmap
void Mapper::_buildShapeProperty(QtProperty* shapeItem, MShape* shape)
{
  for (int i=0; i<shape->nVertices(); i++)
  {
    // Add point.
    QtVariantProperty* pointItem = _variantManager->addProperty(QVariant::PointF,
                                                                QObject::tr("Point %1").arg(i));

    const QPointF& p = shape->getVertex(i);
    pointItem->setValue(p);

    shapeItem->addSubProperty(pointItem);
    _propertyToVertex[pointItem] = std::make_pair(shape, i);
  }

}
コード例 #15
0
void AbstractItemEditor::propertyChanged(QtProperty *property)
{
    if (m_updatingBrowser)
        return;


    BoolBlocker block(m_updatingBrowser);
    QtVariantProperty *prop = m_propertyManager->variantProperty(property);
    int role;
    if ((role = m_propertyToRole.value(prop, -1)) == -1)
        // Subproperty
        return;

    if ((role == ItemFlagsShadowRole && prop->value().toInt() == (int)QListWidgetItem().flags())
            || (role == Qt::DecorationPropertyRole && !qVariantValue<PropertySheetIconValue>(prop->value()).mask())
            || (role == Qt::FontRole && !qVariantValue<QFont>(prop->value()).resolve())) {
        prop->setModified(false);
        setItemData(role, QVariant());
    } else {
        prop->setModified(true);
        setItemData(role, prop->value());
    }

    switch (role) {
    case Qt::DecorationPropertyRole:
        setItemData(Qt::DecorationRole, qVariantFromValue(iconCache()->icon(qVariantValue<PropertySheetIconValue>(prop->value()))));
        break;
    case Qt::DisplayPropertyRole:
        setItemData(Qt::EditRole, qVariantFromValue(qVariantValue<PropertySheetStringValue>(prop->value()).value()));
        break;
    case Qt::ToolTipPropertyRole:
        setItemData(Qt::ToolTipRole, qVariantFromValue(qVariantValue<PropertySheetStringValue>(prop->value()).value()));
        break;
    case Qt::StatusTipPropertyRole:
        setItemData(Qt::StatusTipRole, qVariantFromValue(qVariantValue<PropertySheetStringValue>(prop->value()).value()));
        break;
    case Qt::WhatsThisPropertyRole:
        setItemData(Qt::WhatsThisRole, qVariantFromValue(qVariantValue<PropertySheetStringValue>(prop->value()).value()));
        break;
    default:
        break;
    }

    prop->setValue(getItemData(role));
}
コード例 #16
0
ファイル: propertybrowser.cpp プロジェクト: josephbleau/tiled
void PropertyBrowser::updateCustomProperties()
{
    mUpdating = true;

    qDeleteAll(mNameToProperty);
    mNameToProperty.clear();

    QMapIterator<QString,QString> it(mObject->properties());
    while (it.hasNext()) {
        it.next();
        QtVariantProperty *property = createProperty(CustomProperty,
                                                     QVariant::String,
                                                     it.key(),
                                                     mCustomPropertiesGroup);
        property->setValue(it.value());
    }

    mUpdating = false;
}
コード例 #17
0
    bool FontPropertyManager::resetFontSubProperty(QtVariantPropertyManager *vm, QtProperty *property)
    {
        const PropertyToPropertyMap::iterator it = m_fontSubPropertyToProperty.find(property);
        if (it == m_fontSubPropertyToProperty.end())
            return false;

        QtVariantProperty *fontProperty = vm->variantProperty(it.value());

        QVariant v = fontProperty->value();
        QFont font = qvariant_cast<QFont>(v);
        unsigned mask = font.resolve();
        const unsigned flag = fontFlag(m_fontSubPropertyToFlag.value(property));

        mask &= ~flag;
        font.resolve(mask);
        qVariantSetValue(v, font);
        fontProperty->setValue(v);
        return true;
    }
コード例 #18
0
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;
}
コード例 #19
0
ファイル: objecttypeseditor.cpp プロジェクト: ihuangx/tiled
void ObjectTypesEditor::updateProperties()
{
    const auto selectionModel = mUi->objectTypesTable->selectionModel();
    const auto selectedRows = selectionModel->selectedRows();

    AggregatedProperties aggregatedProperties;

    for (const QModelIndex &index : selectedRows) {
        ObjectType objectType = mObjectTypesModel->objectTypeAt(index);
        aggregatedProperties.aggregate(objectType.defaultProperties);
    }

    mAddPropertyAction->setEnabled(!selectedRows.isEmpty());

    mProperties = aggregatedProperties;

    mUpdating = true;
    mVariantManager->clear();
    mNameToProperty.clear();

    QMapIterator<QString, AggregatedPropertyData> it(aggregatedProperties);
    while (it.hasNext()) {
        it.next();

        const QString &name = it.key();
        const AggregatedPropertyData &data = it.value();

        QtVariantProperty *property = createProperty(data.value().userType(), name);
        property->setValue(data.value());

        bool everywhere = data.presenceCount() == selectedRows.size();
        bool consistent = everywhere && data.valueConsistent();
        if (!everywhere)
            property->setNameColor(Qt::gray);
        if (!consistent)
            property->setValueColor(Qt::gray);
    }

    mUpdating = false;
}
コード例 #20
0
    FontPropertyManager::ValueChangedResult FontPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value)
    {
        QtProperty *antialiasingProperty = m_antialiasingToProperty.value(property, 0);
        if (!antialiasingProperty) {
            if (m_propertyToFontSubProperties.contains(property)) {
                updateModifiedState(property, value);
            }
            return NoMatch;
        }

        QtVariantProperty *fontProperty = vm->variantProperty(antialiasingProperty);
        const QFont::StyleStrategy newValue = indexToAntialiasing(value.toInt());

        QFont font = qVariantValue<QFont>(fontProperty->value());
        const QFont::StyleStrategy oldValue = font.styleStrategy();
        if (newValue == oldValue)
            return Unchanged;

        font.setStyleStrategy(newValue);
        fontProperty->setValue(qVariantFromValue(font));
        return Changed;
    }
コード例 #21
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;
}
コード例 #22
0
ファイル: DataWidget.cpp プロジェクト: bergatt/mars
    void DataWidget::timerEvent(QTimerEvent* event) {
      (void)event;

      string path;

      // go throud the add list
      addMutex.lock();
      ignore_change = true;
      map<unsigned long, paramWrapper>::iterator it;
      map<unsigned long, paramWrapper> tmpList;
      DataItem *item;
      //DataItem *item2;

      for(it=addList.begin(); it!=addList.end(); ++it) {
        it->second.dataPackage = dataBroker->getDataPackage(it->second.info.dataId);
        for(unsigned int i = 0; i < it->second.dataPackage.size(); ++i) {
          std::map<QString, QVariant> attr;
          attr["singleStep"] = 0.01;
          attr["decimals"] = 7;
          path = "";
          path.append(it->second.info.groupName);
          path.append("/");
          path.append(it->second.info.dataName);
          if(it->second.dataPackage.size() > 1) {
            path.append("/");
            path.append(it->second.dataPackage[i].getName());
          }
          item = &it->second.dataPackage[i];
          QtVariantProperty *guiElem;
          switch(item->type) {
          case data_broker::FLOAT_TYPE:
            guiElem = pDialog->addGenericProperty(path,
                                                  QVariant::Double,
                                                  item->f, &attr);
            break;
          case data_broker::DOUBLE_TYPE:
            guiElem = pDialog->addGenericProperty(path,
                                                  QVariant::Double,
                                                  item->d, &attr);
            break;
          case data_broker::INT_TYPE:
            guiElem = pDialog->addGenericProperty(path, QVariant::Int,
                                                  item->i);
            break;
          case data_broker::LONG_TYPE:
            guiElem = pDialog->addGenericProperty(path, QVariant::Int,
                                                  (int)item->l);
            break;
          case data_broker::BOOL_TYPE:
            guiElem = pDialog->addGenericProperty(path, QVariant::Bool,
                                                  item->b);
            break;
          case data_broker::STRING_TYPE:
            guiElem = pDialog->addGenericProperty(path, QVariant::String,
                                                  QString::fromStdString(item->s));
            break;
          default:
            guiElem = 0;
          }
          if(guiElem && 
             !(it->second.info.flags & data_broker::DATA_PACKAGE_WRITE_FLAG)) {
            guiElem->setEnabled(false);
          }
          it->second.guiElements.push_back(guiElem);
          if(!it->second.guiElements.empty()) {
            listMutex.lock();
            paramList[it->first] = it->second;
            guiToWrapper[guiElem] = &paramList[it->first];//it->second;
            //guiToWrapper[&it->second.guiElements] = it->second;
            listMutex.unlock();
          }
        }
      
        if(it->second.guiElements.empty()) {
          tmpList[it->first] = it->second;
        }
      }
      addList.clear();
      addList = tmpList;
    
      ignore_change = false;
      addMutex.unlock();
      // and check for updates
      changeMutex.lock();
      ignore_change = true;
      while(changeList.size() > 0) {
        it = paramList.find(*changeList.begin());
        if(it != paramList.end() && !it->second.guiElements.empty()) {
          for(unsigned int i = 0; i < it->second.guiElements.size(); ++i) {
            QtVariantProperty *guiElem = it->second.guiElements[i];
            item = &it->second.dataPackage[i];
            //item2 = &guiToWrapper[it->second.guiElements.front()]->dataPackage[i];
            switch(item->type) {
            case data_broker::DOUBLE_TYPE:
              guiElem->setValue(QVariant(item->d));
              //item2->d = item->d;
              break;
            case data_broker::FLOAT_TYPE:
              guiElem->setValue(QVariant(item->f));
              //item2->f = item->f;
              break;
            case data_broker::INT_TYPE:
              guiElem->setValue(QVariant(item->i));
              //item2->i = item->i;
              break;
            case data_broker::LONG_TYPE:
              guiElem->setValue(QVariant((int)item->l));
              //item2->l = item->l;
              break;
            case data_broker::BOOL_TYPE:
              guiElem->setValue(QVariant(item->b));
              //item2->b = item->b;
              break;
            case data_broker::STRING_TYPE:
              guiElem->setValue(QVariant(QString::fromStdString(item->s)));
              //item2->s = item->s;
              break;
            case data_broker::UNDEFINED_TYPE:
              break;
            // don't supply a default case so that the compiler might warn
            // us if we forget to handle a new enum value.
            }
          }
        }
        changeList.erase(changeList.begin());
      }
      ignore_change = false;
      changeMutex.unlock();
    }
コード例 #23
0
ファイル: pgeitems.cpp プロジェクト: llibuda/impresario
 void MacroItem::setupProperties(WndProperties& propWnd) const
 {
   QtVariantPropertyManager& propManager = propWnd.infoPropertyManager();
   QtVariantProperty* item;
   QtVariantProperty* group;
   app::Macro::Ptr macro = vertex().dataRef().staticCast<app::Macro>();
   group = propManager.addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("General"));
   item = propManager.addProperty(QVariant::String, QObject::tr("Macro"));
   item->setValue(macro->getName());
   group->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Instance UUID"));
   item->setValue(vertex().id().toString());
   group->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Creator"));
   item->setValue(macro->getCreator());
   group->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Group"));
   item->setValue(macro->getGroup());
   group->addSubProperty(item);
   QtVariantProperty* libItem = propManager.addProperty(QVariant::String, QObject::tr("Library"));
   libItem->setValue(macro->getLibrary().getName());
   group->addSubProperty(libItem);
   item = propManager.addProperty(QVariant::String, QObject::tr("Libray file"));
   item->setValue(macro->getLibrary().getPath());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Version"));
   item->setValue(macro->getLibrary().getVersionString());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Build"));
   item->setValue(macro->getLibrary().getBuildType());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Build date"));
   item->setValue(macro->getLibrary().getBuildDate());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Qt version"));
   item->setValue(macro->getLibrary().getQtVersionString());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("Creator"));
   item->setValue(macro->getLibrary().getCreator());
   libItem->addSubProperty(item);
   item = propManager.addProperty(QVariant::String, QObject::tr("API Version"));
   item->setValue(macro->getLibrary().getAPIVersionString());
   libItem->addSubProperty(item);
   // setup QML
   propWnd.setQMLProperties(macro.toWeakRef());
 }
コード例 #24
0
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
}
コード例 #25
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);
}
コード例 #26
0
ファイル: main.cpp プロジェクト: Felipeasg/QtPropertyBrowser
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;
}
コード例 #27
0
ファイル: objectcontroller.cpp プロジェクト: Elv13/Kimberlite
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);
}
コード例 #28
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);
}
コード例 #29
0
/** 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;
}
コード例 #30
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);
    }
}