コード例 #1
0
void PropertyEditorView::dataChanged(const QModelIndex &, const QModelIndex &)
{
	for (int i = 0, rows = mModel->rowCount(QModelIndex()); i < rows; ++i) {
		QModelIndex const &valueIndex = mModel->index(i, 1);
		QtVariantProperty *property = dynamic_cast<QtVariantProperty*>(mPropertyEditor->properties().at(i));
		QVariant value = valueIndex.data();
		if (property) {
			if (property->propertyType() == QtVariantPropertyManager::enumTypeId()) {
				value = enumPropertyIndexOf(valueIndex, value.toString());
			}

			setPropertyValue(property, value);
			property->setToolTip(value.toString());
		}
	}
}
コード例 #2
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();
}
コード例 #3
0
void PropertyEditorView::dataChanged(const QModelIndex &, const QModelIndex &)
{
	for (int i = 0, rows = mModel->rowCount(QModelIndex()); i < rows; ++i) {
		const QModelIndex &valueIndex = mModel->index(i, 1);
		QtVariantProperty *property = dynamic_cast<QtVariantProperty*>(mPropertyEditor->properties().at(i));
		QVariant value = valueIndex.data();
		if (property) {
			if (property->propertyType() == QtVariantPropertyManager::enumTypeId()) {
				const int index = enumPropertyIndexOf(valueIndex, value.toString());
				if (!mModel->enumEditable(valueIndex) || index >= 0) {
					value = index;
				}
			}

			setPropertyValue(property, value);

			const QString description = propertyDescription(i);
			const QString tooltip = description.isEmpty() ? value.toString() : description;

			property->setToolTip(tooltip);
		}
	}
}
コード例 #4
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);
}
コード例 #5
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);
}
コード例 #6
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;
}