See if is a sub property (wxPropertyGrid 1.4.6)

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
majc
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Aug 11, 2009 5:17 pm

See if is a sub property (wxPropertyGrid 1.4.6)

Post by majc »

I'm having problems discovering how can i find if a property has a sub property for example:

Image

How can i see if Max. Skill Value is a child of swordsmanship?
I tried IsSubProperty() function but it didn't work.
I want to save the information of the property grid in a xml like this:

Code: Select all

<skill name=swordsmanship>
   <MaxSkillValue>100.0</MaxSkillValue>
  ...
</skill>
Thanks in advance!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Well first of all this XML document is not correctly formatted, it should be

Code: Select all

<skill name="swordsmanship">
   <MaxSkillValue>100.0</MaxSkillValue>
  ...
</skill>
Furthermore, you didn't say which XML library you use, nor posted any code snippet... I'll assume wxXmlDocument. In this case, it seems to me that the example at the top of the docs of this class show the solution : doc.GetRoot()->GetChildren(). When you get a "skill", get its children and iterate through them
"Keyboard not detected. Press F1 to continue"
-- Windows
majc
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Aug 11, 2009 5:17 pm

Post by majc »

I'm using tinyxml but i'm trying to create a xml from the grid not the other way, my problem is to see if max skill value is a child of swordsmanship. By the way you are right i forgot the "" but that wasn't the problem.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

majc wrote:I'm using tinyxml but i'm trying to create a xml from the grid not the other way, my problem is to see if max skill value is a child of swordsmanship. By the way you are right i forgot the "" but that wasn't the problem.
Sorry, I guess either you were not clear, either I was asleep ;) (or maybe both)

Well, without telling which control you are using to store the values it's a bit hard to tell.
"Keyboard not detected. Press F1 to continue"
-- Windows
majc
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Aug 11, 2009 5:17 pm

Post by majc »

Here is the code:

Code: Select all

void cSkillsPanel::OnSaveButtonClicked(wxCommandEvent &event)
{
	wxString s_value;
	wxPropertyGridIterator it;

	TiXmlDocument doc;  
	TiXmlElement *msg;
	TiXmlElement *skill;

	bool isSub;


	wxPGProperty *parent = m_pSkillsPropertyPanel->getSkillsPropertiesGrid()->GetRoot();

	TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );  
	doc.LinkEndChild( decl );  
 
	TiXmlElement * root = new TiXmlElement( "Skills" );  
	doc.LinkEndChild( root );  

	TiXmlComment * comment = new TiXmlComment();
	comment->SetValue(" NPC's skills list " );  
	root->LinkEndChild( comment );  

	for ( it = m_pSkillsPropertyPanel->getSkillsPropertiesGrid()->GetIterator() ; !it.AtEnd(); it++ )
	{
		wxPGProperty* p = *it;

		s_value = p->GetLabel();
		char buf[100];
		strcpy( buf, (const char*)s_value.mb_str(wxConvUTF8) );
		//isSub = p->;

		if (p->IsExpanded() == false)
		{
			skill = new TiXmlElement( "Skill" );  
			root->LinkEndChild( skill );  
			skill->SetAttribute("name", buf );
		}

		TiXmlElement * sub_property;
		sub_property = new TiXmlElement( buf );  
		skill->LinkEndChild( sub_property );  
		
		
	}

	doc.SaveFile( "c:\\skills.xml" );  
}
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Auria wrote: Well, without telling which control you are using to store the values it's a bit hard to tell.
Sorry, forgot to check for information in the topic title :oops:

I can't help with wxPropGrid but hopefully someone will be able to help you.
"Keyboard not detected. Press F1 to continue"
-- Windows
majc
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Aug 11, 2009 5:17 pm

Post by majc »

Thanks anyway mate.
Post Reply