ADDED: #1471 The widget hierarchy tree view is now filled with real data, when loading a project.

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2012-07-20 06:53:30 +02:00
parent b711965b15
commit 16af5289ee
5 changed files with 88 additions and 66 deletions

View file

@ -69,16 +69,16 @@ namespace GUIEditor
QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this ); QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this );
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
WidgetHierarchy *ha = new WidgetHierarchy; hierarchyView = new WidgetHierarchy;
dock->setWidget( ha ); dock->setWidget( hierarchyView );
addDockWidget( Qt::LeftDockWidgetArea, dock ); addDockWidget( Qt::LeftDockWidgetArea, dock );
dock = new QDockWidget( "Widget Properties", this ); dock = new QDockWidget( "Widget Properties", this );
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
QtTreePropertyBrowser *tb = new QtTreePropertyBrowser; QtTreePropertyBrowser *propBrowser = new QtTreePropertyBrowser;
browserCtrl.setBrowser( tb ); browserCtrl.setBrowser( propBrowser );
browserCtrl.setup(); browserCtrl.setup();
dock->setWidget( tb ); dock->setWidget( propBrowser );
addDockWidget( Qt::RightDockWidgetArea, dock ); addDockWidget( Qt::RightDockWidgetArea, dock );
viewPort->init(); viewPort->init();
@ -102,6 +102,10 @@ namespace GUIEditor
delete viewPort; delete viewPort;
viewPort = NULL; viewPort = NULL;
// no deletion needed for these, since dockwidget owns them
hierarchyView = NULL;
propBrowser = NULL;
} }
QUndoStack *GUIEditorWindow::undoStack() const QUndoStack *GUIEditorWindow::undoStack() const
@ -145,7 +149,10 @@ namespace GUIEditor
currentProject = projectFiles.projectName.c_str(); currentProject = projectFiles.projectName.c_str();
projectWindow->setupFiles( projectFiles ); projectWindow->setupFiles( projectFiles );
if( viewPort->parse( projectFiles ) ) if( viewPort->parse( projectFiles ) )
viewPort->draw(); {
hierarchyView->buildHierarchy( projectFiles.masterGroup );
viewPort->draw();
}
else else
{ {
QMessageBox::critical( this, QMessageBox::critical( this,
@ -168,7 +175,10 @@ namespace GUIEditor
tr( "There was an error while parsing the GUI XML files. See the log file for details." ) ); tr( "There was an error while parsing the GUI XML files. See the log file for details." ) );
} }
else else
{
hierarchyView->buildHierarchy( projectFiles.masterGroup );
viewPort->draw(); viewPort->draw();
}
setCursor( Qt::ArrowCursor ); setCursor( Qt::ArrowCursor );
} }

View file

@ -24,10 +24,13 @@
#include "widget_info.h" #include "widget_info.h"
#include "property_browser_ctrl.h" #include "property_browser_ctrl.h"
class QtTreePropertyBrowser;
namespace GUIEditor namespace GUIEditor
{ {
class CWidgetProperties; class CWidgetProperties;
class WidgetHierarchy;
class LinkEditor; class LinkEditor;
class ProcEditor; class ProcEditor;
class ProjectWindow; class ProjectWindow;
@ -62,6 +65,8 @@ private:
Ui::GUIEditorWindow m_ui; Ui::GUIEditorWindow m_ui;
CWidgetProperties *widgetProps; CWidgetProperties *widgetProps;
WidgetHierarchy *hierarchyView;
QtTreePropertyBrowser *propBrowser;
LinkEditor *linkEditor; LinkEditor *linkEditor;
ProcEditor *procEditor; ProcEditor *procEditor;
ProjectWindow *projectWindow; ProjectWindow *projectWindow;

View file

@ -16,6 +16,8 @@
#include "widget_hierarchy.h" #include "widget_hierarchy.h"
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
namespace GUIEditor namespace GUIEditor
{ {
@ -28,4 +30,57 @@ namespace GUIEditor
WidgetHierarchy::~WidgetHierarchy() WidgetHierarchy::~WidgetHierarchy()
{ {
} }
void WidgetHierarchy::clearHierarchy()
{
widgetHT->clear();
}
void WidgetHierarchy::buildHierarchy( std::string &masterGroup )
{
clearHierarchy();
CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
if( mg != NULL )
{
QTreeWidgetItem *item = new QTreeWidgetItem( NULL );
item->setText( 0, "root" );
widgetHT->addTopLevelItem( item );
buildHierarchy( item, mg );
}
}
void WidgetHierarchy::buildHierarchy( QTreeWidgetItem *parent, CInterfaceGroup *group )
{
// First add ourselves
QTreeWidgetItem *item = new QTreeWidgetItem( parent );
item->setText( 0, group->getId().c_str() );
// Then add recursively our subgroups
const std::vector< CInterfaceGroup* > &groups = group->getGroups();
std::vector< CInterfaceGroup* >::const_iterator gitr;
for( gitr = groups.begin(); gitr != groups.end(); ++gitr )
{
buildHierarchy( item, *gitr );
}
// Add our controls
const std::vector< CCtrlBase* > &controls = group->getControls();
std::vector< CCtrlBase* >::const_iterator citr;
for( citr = controls.begin(); citr != controls.end(); ++citr )
{
QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, (*citr)->getId().c_str() );
}
// Add our views
const std::vector< CViewBase* > &views = group->getViews();
std::vector< CViewBase* >::const_iterator vitr;
for( vitr = views.begin(); vitr != views.end(); ++vitr )
{
QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, (*vitr)->getId().c_str() );
}
}
} }

View file

@ -19,6 +19,13 @@
#include "ui_widget_hierarchy.h" #include "ui_widget_hierarchy.h"
namespace NLGUI
{
class CInterfaceGroup;
}
class QTreeWidgetItem;
namespace GUIEditor namespace GUIEditor
{ {
class WidgetHierarchy : public QWidget, public Ui::WidgetHierarchyTree class WidgetHierarchy : public QWidget, public Ui::WidgetHierarchyTree
@ -28,6 +35,11 @@ namespace GUIEditor
WidgetHierarchy( QWidget *parent = NULL ); WidgetHierarchy( QWidget *parent = NULL );
~WidgetHierarchy(); ~WidgetHierarchy();
void clearHierarchy();
void buildHierarchy( std::string &masterGroup );
private:
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
}; };
} }

View file

@ -21,66 +21,6 @@
<string>Widgets</string> <string>Widgets</string>
</property> </property>
</column> </column>
<item>
<property name="text">
<string>root</string>
</property>
<item>
<property name="text">
<string>container1</string>
</property>
<item>
<property name="text">
<string>group1</string>
</property>
<item>
<property name="text">
<string>group3</string>
</property>
</item>
<item>
<property name="text">
<string>group4</string>
</property>
<item>
<property name="text">
<string>button1</string>
</property>
</item>
<item>
<property name="text">
<string>button2</string>
</property>
</item>
<item>
<property name="text">
<string>text1</string>
</property>
</item>
<item>
<property name="text">
<string>bitmap1</string>
</property>
</item>
</item>
</item>
<item>
<property name="text">
<string>group2</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>container2</string>
</property>
</item>
<item>
<property name="text">
<string>container3</string>
</property>
</item>
</item>
</widget> </widget>
</item> </item>
</layout> </layout>