A little refactoring

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-06-20 16:26:10 +02:00
parent 25df3c8afe
commit 9e36082ff0
2 changed files with 23 additions and 19 deletions

View file

@ -75,12 +75,8 @@ namespace GUIEditor
void CPropBrowserCtrl::clear() void CPropBrowserCtrl::clear()
{ {
disablePropertyWatchers();
browser->clear(); browser->clear();
disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
disconnect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
} }
void CPropBrowserCtrl::onSelectionChanged( std::string &id ) void CPropBrowserCtrl::onSelectionChanged( std::string &id )
@ -88,21 +84,13 @@ namespace GUIEditor
if( browser == NULL ) if( browser == NULL )
return; return;
disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), disablePropertyWatchers();
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
disconnect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
browser->clear(); browser->clear();
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
if( e == NULL ) if( e == NULL )
{ {
connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), enablePropertyWatchers();
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
connect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
return; return;
} }
@ -111,10 +99,7 @@ namespace GUIEditor
std::string n = e->getClassName(); std::string n = e->getClassName();
setupProperties( n, e ); setupProperties( n, e );
connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), enablePropertyWatchers();
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
connect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
} }
void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop, const QVariant &v ) void CPropBrowserCtrl::onPropertyChanged( QtProperty *prop, const QVariant &v )
@ -176,6 +161,22 @@ namespace GUIEditor
} }
} }
void CPropBrowserCtrl::enablePropertyWatchers()
{
connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
connect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
}
void CPropBrowserCtrl::disablePropertyWatchers()
{
disconnect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
this, SLOT( onPropertyChanged( QtProperty*, const QVariant& ) ) );
disconnect( enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ),
this, SLOT( onEnumPropertyChanged( QtProperty*, int ) ) );
}
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element ) void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
{ {
std::map< std::string, SWidgetInfo >::iterator itr = widgetInfo.find( type ); std::map< std::string, SWidgetInfo >::iterator itr = widgetInfo.find( type );

View file

@ -59,6 +59,9 @@ namespace GUIEditor
void onEnumPropertyChanged( QtProperty *prop, int value ); void onEnumPropertyChanged( QtProperty *prop, int value );
private: private:
void enablePropertyWatchers();
void disablePropertyWatchers();
void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element ); void setupProperties( const std::string &type, const NLGUI::CInterfaceElement *element );
void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element ); void setupProperty( const SPropEntry &prop, const NLGUI::CInterfaceElement *element );