예제 #1
0
bool BaseGenericObject::addProperty(const char* name, const Variant& value, MetaData metadata, bool enableNotification)
{
	const IClassDefinition& definition = *this->getDefinition();
	ObjectHandle provider = this->getDerivedType();

	auto definitionModifier = definition.getDetails().getDefinitionModifier();
	if (definitionModifier == nullptr)
	{
		return false;
	}

	Collection testCollection;
	bool isCollection = value.tryCast<Collection>(testCollection);

	if (!definitionModifier->addProperty(name, value.type()->typeId(), std::move(metadata), isCollection))
	{
		return false;
	}

	PropertyAccessor accessor = definition.bindProperty(name, provider);
	if (enableNotification)
	{
		return accessor.setValue(value);
	}
	else
	{
		return accessor.setValueWithoutNotification(value);
	}
}
예제 #2
0
	void setValue( const PropertyAccessor & pa, const Variant & data )
	{
		Key key;
		if (!createKey( pa, key ))
		{
			pa.setValue( data );
			return;
		}

		std::unique_ptr< ReflectedPropertyCommandArgument > args( new ReflectedPropertyCommandArgument );
		args->setContextId( key.first );
		args->setPath( key.second.c_str() );
		args->setValue( data );
		
		// Access is only on the main thread
		assert( std::this_thread::get_id() == commandManager_.ownerThreadId() );

		const auto commandId = getClassIdentifier< SetReflectedPropertyCommand >();
		const auto pArgsDefinition =
			pa.getDefinitionManager()->getDefinition< ReflectedPropertyCommandArgument >();
		ObjectHandle commandArgs( std::move( args ), pArgsDefinition );
		auto command = commandManager_.queueCommand( commandId, commandArgs );

		// Queuing may cause it to execute straight away
		// Based on the thread affinity of SetReflectedPropertyCommand
		if (!command->isComplete())
		{
			commands_.emplace( std::pair< Key, CommandInstancePtr >( key, command ) );
		}
	}
//==============================================================================
ObjectHandle SetReflectedPropertyCommand::execute(
	const ObjectHandle & arguments ) const
{
	ReflectedPropertyCommandArgument * commandArgs =
		arguments.getBase< ReflectedPropertyCommandArgument >();
	auto objManager = definitionManager_.getObjectManager();
	assert( objManager != nullptr );
	ObjectHandle object = objManager->getObject( commandArgs->getContextId() );
	if (!object.isValid())
	{
		return CommandErrorCode::INVALID_ARGUMENTS;
	}
	PropertyAccessor property = object.getDefinition( definitionManager_ )->bindProperty( 
		commandArgs->getPropertyPath(), object );
	if (property.isValid() == false)
	{
		//Can't set
		return CommandErrorCode::INVALID_ARGUMENTS;
	}
	const Variant & data = commandArgs->getPropertyValue();
	bool br = property.setValue( data );
	if (!br)
	{
		return CommandErrorCode::INVALID_VALUE;
	}

	// Do not return the object
	// CommandInstance will hold a reference to the return value
	// and the CommandInstance is stored in the undo/redo history forever
	// This is due to a circular reference in CommandManagerImpl::pushFrame
	return nullptr;
}
예제 #4
0
void DialogTestModel::callBasicDialog(bool modal)
{
	assert(context_ != nullptr);
	auto uiFramework = context_->queryInterface<IUIFramework>();
	assert(uiFramework != nullptr);

	IDialog::ClosedCallback callback = [this](IDialog& dialog) {
		assert(definition_ != nullptr);
		PropertyAccessor accessor = definition_->bindProperty("basicDialogResult", this);
		accessor.setValue(dialog.result());
	};

	const IDialog::Mode mode = modal ? IDialog::Mode::MODAL : IDialog::Mode::MODELESS;
	uiFramework->showDialog("plg_dialog_test/basic_dialog.qml", mode, callback);
}
예제 #5
0
bool BaseGenericObject::setProperty(const char* name, const Variant& value, bool enableNotification)
{
	// Get existing property
	const IClassDefinition& definition = *this->getDefinition();
	ObjectHandle provider = this->getDerivedType();
	PropertyAccessor accessor = definition.bindProperty(name, provider);

	// do nothing if property does not exist and the value is void
	if (!accessor.isValid() && value.isVoid())
	{
		return false;
	}

	// set value to the property if property exists and the value is not void
	if (accessor.isValid() && !value.isVoid())
	{
		if (enableNotification)
		{
			return accessor.setValue(value);
		}
		else
		{
			return accessor.setValueWithoutNotification(value);
		}
	}

	// Property does not exist
	// Add new property and set it
	auto definitionModifier = definition.getDetails().getDefinitionModifier();
	if (definitionModifier == nullptr)
	{
		return false;
	}

	if (accessor.isValid() && value.isVoid())
	{
		definitionModifier->removeProperty(name);
		return false;
	}

	return addProperty(name, value, nullptr, enableNotification);
}