void TreeExtensionOld::Implementation::saveStates( const char * id )
{
	if (id == nullptr || id == std::string( "" ))
	{
		NGT_WARNING_MSG( 
			"Tree preference won't save: %s\n", "Please provide unique objectName for WGTreeModel in qml" );
		return;
	}
	auto preferences = self_.qtFramework_->getPreferences();
	if (preferences == nullptr)
	{
		return;
	}
	auto & preference = preferences->getPreference( id );
	auto count = expandedList_.size();
	preference->set( "treeNodeCount", count );
	if (count == 0)
	{
        if (!memoryExpandedList_.empty())
        {
            NGT_WARNING_MSG( 
                "Tree preference won't save for WGTreeModel: %s, %s\n",  id,
                "please provide an unique path string for IndexPathRole of IItem." );
        }
		return;
	}
	int i = 0;
	for (auto item : expandedList_)
	{
		preference->set( std::to_string( i++ ).c_str(), item );
	}
}
Exemple #2
0
bool Project::init( const char * projectName, const char * dataFile )
{
    projectName_ = projectName;
    auto defManager = contextManager_.queryInterface<IDefinitionManager>();
    auto controller = contextManager_.queryInterface<IReflectionController>();
    auto fileSystem = contextManager_.queryInterface<IFileSystem>();
    assert( defManager != nullptr && controller != nullptr && fileSystem != nullptr );
    if( dataFile == nullptr || !fileSystem->exists(dataFile))
    {
        projectData_ =  defManager->create< ProjectData >();
    }
    else
    {
        IFileSystem::IStreamPtr fileStream = 
            fileSystem->readFile( dataFile, std::ios::in | std::ios::binary );
        XMLSerializer serializer( *fileStream, *defManager );
        defManager->deserializeDefinitions( serializer );
        Variant variant;
        bool br = serializer.deserialize( variant );
        assert( br );
        if(!br)
        {
            NGT_WARNING_MSG( "Error loading project data\n" );
            return false;
        }
        br = variant.tryCast( projectData_ );
        assert( br );
        if(!br)
        {
            NGT_WARNING_MSG( "Error loading project data\n" );
            return false;
        }
    }
    
    auto model = std::unique_ptr< ITreeModel >(
        new ReflectedTreeModel( projectData_, *defManager, controller ) );

    auto em = contextManager_.queryInterface<IEnvManager>();
    envId_ = em->addEnv( projectName_.c_str() );
    em->loadEnvState( envId_ );
    em->selectEnv( envId_ );

    auto uiFramework = contextManager_.queryInterface<IUIFramework>();
    auto uiApplication = contextManager_.queryInterface<IUIApplication>();
    assert( uiFramework != nullptr && uiApplication != nullptr );
    view_ = uiFramework->createView( projectName_.c_str(), "TestingProjectControl/ProjectDataPanel.qml", 
        IUIFramework::ResourceType::Url, std::move( model ) );
    if(view_ == nullptr)
    {
        return false;
    }
    uiApplication->addView( *view_ );
    return true;
}
bool CustomConnection::UnBind()
{
	bool result = true;

	while (true)
	{
		if (!isConnected)
		{
			NGT_WARNING_MSG("Connection is not connected\n");
			break;
		}

		if (!m_inputSlot->Disconnect(m_id, m_outputSlot))
		{
			result = false;
			NGT_ERROR_MSG("Failed to disconnect input slot with output slot\n");
			break;
		}

		if (!m_outputSlot->Disconnect(m_id, m_inputSlot))
		{
			result = false;
			NGT_ERROR_MSG("Failed to disconnect output slot with input slot\n");
			break;
		}

		m_inputSlot = nullptr;
		m_outputSlot = nullptr;
		isConnected = false;
		break;
	}

	return result;
}
Exemple #4
0
	virtual bool warning( const QXmlParseException & exception ) override
	{
		NGT_WARNING_MSG( "%d, %d: %s\n",
			exception.lineNumber(),
			exception.columnNumber(),
			exception.message().toUtf8().constData() );
		return true;
	}
Exemple #5
0
QAction* QtMenu::createQAction(IAction& action)
{
	auto qAction = getQAction(action);
	if (qAction != nullptr)
	{
		NGT_WARNING_MSG("Action %s already existing.\n", action.text());
		return nullptr;
	}

	actions_[&action] = createSharedQAction(action);
	qAction = getQAction(action);
	TF_ASSERT(qAction != nullptr);

	return qAction;
}
void FileSystemAssetBrowserModel::addFolderItems(const AssetPaths& paths)
{
	IFileSystem& fs = impl_->fileSystem_;

	std::list<std::string> directories;

	for (auto& path : paths)
	{
		if (!fs.exists(path.c_str()))
		{
			NGT_WARNING_MSG("FileSystemAssetBrowserModel::addFolderItems: "
			                "asset folder path does not exist: %s\n",
			                path.c_str());
			continue;
		}

		directories.push_back(path);
	}

	while (!directories.empty())
	{
		const std::string& dir = directories.front();

		fs.enumerate(dir.c_str(), [&](IFileInfoPtr&& info) {
			if (!info->isDirectory())
			{
				impl_->addFolderItem(info);
			}
			// TODO: For search/filtering we should add all resources on a separate thread
			// We don't want to block the main UI thread
			// For now do not add sub-folders to avoid performance issues
			// else if (!info.isDots())
			//{
			//	directories.push_back( info.fullPath );
			//}
			return true;
		});

		directories.pop_front();
	}
}
IResourceSystem::BinaryBlockPtr QtResourceSystem::readBinaryContent(const char* resource) const
{
	std::unique_ptr<QIODevice> device;
	if (!QFile::exists(resource))
	{
		return nullptr;
	}
	device.reset(new QFile(resource));
	device->open(QFile::ReadOnly);

	assert(device != nullptr);
	auto size = device->size();
	auto data = device->readAll();
	device->close();
	if (data.isEmpty())
	{
		NGT_WARNING_MSG("Read action data error from %s.\n", resource);
		return nullptr;
	}
	auto buffer = data.constData();

	return std::unique_ptr<BinaryBlock>(new BinaryBlock(buffer, size, false));
}