コード例 #1
0
ファイル: itemlisteditor.cpp プロジェクト: Suneal/qt
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);
    }
}
コード例 #2
0
ファイル: StkCubic.cpp プロジェクト: Archie3d/qmusic
void StkCubic::createProperties()
{
    QtVariantProperty *pRoot = rootProperty();

    QtVariantProperty *pCoefs = propertyManager()->addProperty(propertyManager()->groupTypeId(), "Coefficients");

    m_pPropA1 = propertyManager()->addProperty(QVariant::Double, "A1");
    m_pPropA1->setAttribute("singleStep", 0.0);
    m_pPropA1->setValue(1.0);
    pCoefs->addSubProperty(m_pPropA1);

    m_pPropA2 = propertyManager()->addProperty(QVariant::Double, "A2");
    m_pPropA2->setAttribute("singleStep", 0.0);
    m_pPropA2->setValue(0.0);
    pCoefs->addSubProperty(m_pPropA2);

    m_pPropA3 = propertyManager()->addProperty(QVariant::Double, "A3");
    m_pPropA3->setAttribute("singleStep", 0.0);
    m_pPropA3->setValue(-1.0 / 3.0);
    pCoefs->addSubProperty(m_pPropA3);


    m_pPropThreshold = propertyManager()->addProperty(QVariant::Double, "Threshold");
    m_pPropThreshold->setAttribute("minimum", 0.0);
    m_pPropThreshold->setAttribute("maximum", 1.0);
    m_pPropThreshold->setAttribute("singleStep", 0.1);
    m_pPropThreshold->setValue(0.66);

    pRoot->addSubProperty(pCoefs);
    pRoot->addSubProperty(m_pPropThreshold);

    // Properties change handler
    QObject::connect (propertyManager(), &QtVariantPropertyManager::propertyChanged, [this](QtProperty *pProperty){
        Q_UNUSED(pProperty);
        setValues();
    });
}
コード例 #3
0
ファイル: propertyeditor.cpp プロジェクト: Fale/qtmoko
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)));
            }
        }
コード例 #4
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());
 }
コード例 #5
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);
 }
コード例 #6
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);
}
コード例 #7
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;
}
コード例 #8
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);
}
コード例 #9
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);
}
コード例 #10
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();
    }
コード例 #11
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);
    }
}
コード例 #12
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;
}
コード例 #13
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
}
コード例 #14
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;
}
コード例 #15
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;
}
コード例 #16
0
ファイル: mainwindow.cpp プロジェクト: darkfall/exlibs
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"));
    }
}