Some refactoring.

This commit is contained in:
dfighter1985 2014-06-21 22:55:10 +02:00
parent c004b02091
commit b108dd7d34

View file

@ -101,10 +101,11 @@ namespace
}
};
}
namespace GUIEditor
class NelButtonType
{
public:
enum NELButtonTypes
{
BUTTON_TYPE_PUSH = 0,
@ -112,6 +113,42 @@ namespace GUIEditor
BUTTON_TYPE_RADIO = 2
};
static int fromString( const std::string &s )
{
int r = -1;
if( s == "push_button" )
r = BUTTON_TYPE_PUSH;
else
if( s == "toggle_button" )
r = BUTTON_TYPE_TOGGLE;
else
if( s == "radio_button" )
r = BUTTON_TYPE_RADIO;
return r;
}
static std::string toString( int value )
{
std::string v;
switch( value )
{
case BUTTON_TYPE_PUSH: v = "push_button"; break;
case BUTTON_TYPE_TOGGLE: v = "toggle_button"; break;
case BUTTON_TYPE_RADIO: v = "radio_button"; break;
}
return v;
}
};
class NelTxtJustification
{
public:
enum NELTxtJustification
{
TEXT_CLIPWORD,
@ -119,6 +156,43 @@ namespace GUIEditor
TEXT_JUSTIFIED
};
static int fromString( const std::string &s )
{
int r = -1;
if( s == "clip_word" )
r = TEXT_CLIPWORD;
else
if( s == "dont_clip_word" )
r = TEXT_DONTCLIPWORD;
else
if( s == "justified" )
r = TEXT_JUSTIFIED;
return r;
}
static std::string toString( int value )
{
std::string v;
switch( value )
{
case TEXT_CLIPWORD: v = "clip_word"; break;
case TEXT_DONTCLIPWORD: v = "dont_clip_word"; break;
case TEXT_JUSTIFIED: v = "justified"; break;
}
return v;
}
};
}
namespace GUIEditor
{
CPropBrowserCtrl::CPropBrowserCtrl()
{
browser = NULL;
@ -229,17 +303,10 @@ namespace GUIEditor
if( e == NULL )
return;
if( ( value < BUTTON_TYPE_PUSH ) || ( value > BUTTON_TYPE_RADIO ) )
return;
std::string v;
switch( value )
{
case BUTTON_TYPE_PUSH: v = "push_button"; break;
case BUTTON_TYPE_TOGGLE: v = "toggle_button"; break;
case BUTTON_TYPE_RADIO: v = "radio_button"; break;
}
v = NelButtonType::toString( value );
if( v.empty() )
return;
e->setProperty( propName.toUtf8().constData(), v );
}
@ -250,16 +317,10 @@ namespace GUIEditor
if( e == NULL )
return;
if( ( value < TEXT_CLIPWORD ) || ( value > TEXT_JUSTIFIED ) )
return;
std::string v;
switch( value )
{
case TEXT_CLIPWORD: v = "clip_word"; break;
case TEXT_DONTCLIPWORD: v = "dont_clip_word"; break;
case TEXT_JUSTIFIED: v = "justified"; break;
}
v = NelTxtJustification::toString( value );
if( v.empty() )
return;
e->setProperty( propName.toUtf8().constData(), v );
}
@ -327,15 +388,7 @@ namespace GUIEditor
return;
int e = -1;
if( btype == "push_button" )
e = BUTTON_TYPE_PUSH;
else
if( btype == "toggle_button" )
e = BUTTON_TYPE_TOGGLE;
else
if( btype == "radio_button" )
e = BUTTON_TYPE_RADIO;
e = NelButtonType::fromString( btype );
if( e == -1 )
return;
@ -361,15 +414,7 @@ namespace GUIEditor
return;
int e = -1;
if( j == "clip_word" )
e = TEXT_CLIPWORD;
else
if( j == "dont_clip_word" )
e = TEXT_DONTCLIPWORD;
else
if( j == "justified" )
e = TEXT_JUSTIFIED;
e = NelTxtJustification::fromString( j );
if( e == -1 )
return;