Commit 6efa4664 authored by Jan Möbius's avatar Jan Möbius
Browse files

Removed debug output, use qmap instead of std::map, return same widget in...

Removed debug output, use qmap instead of std::map, return same widget in generator if already existing.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9103 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 72d63b41
......@@ -93,25 +93,29 @@ namespace QtWidgets {
//== IMPLEMENTATION ==========================================================
SceneGraphWidgetGenerator::SceneGraphWidgetGenerator() {
std::cerr << "SceneGraphWidgetGenerator constructor " << std::endl;
}
QWidget* SceneGraphWidgetGenerator::getWidget(SceneGraph::BaseNode* _node ) {
std::cerr << "getWidget " << std::endl;
// Warn as this you have to derive from this class before it can be used!
std::cerr << "SceneGraphWidgetGenerator::getWidget not implemented!" << std::endl;
return 0;
}
bool SceneGraphWidgetGenerator::canHandle(std::string _className) {
std::cerr << "canHandle " << _className << std::endl;
// Warn as this you have to derive from this class before it can be used!
std::cerr << "SceneGraphWidgetGenerator::canHandle not implemented!" << _className << std::endl;
return false;
}
std::string SceneGraphWidgetGenerator::handles() {
// Warn as this you have to derive from this class before it can be used!
std::cerr << "SceneGraphWidgetGenerator::canHandle not implemented!" << std::endl;
return std::string("Unset Type");
}
QString SceneGraphWidgetGenerator::contextMenuName() {
std::cerr << "contextMenuName " << std::endl;
// Warn as this you have to derive from this class before it can be used!
std::cerr << "SceneGraphWidgetGenerator::contextMenuName not implemented!" << std::endl;
return QString("Context Menu name unset");
}
......
......@@ -92,29 +92,34 @@ public:
*
* Derive from this class to get a widget for the given node
* you have to overload this function. First check, if your
* widget can handle nodes of the given type (check for _node->className()
* widget can handle nodes of the given type (check for _node->className() )
* Then generate your widget and handle the _node inside it.
* Return 0 if you can not handle it and check if the map already contains
* a widget for this node.
* a widget for this node so that you generate one widget per node.
*/
virtual QWidget* getWidget(SceneGraph::BaseNode* _node );
/** \brief returns if the widgets can handle the given class
/** \brief returns if the widgets can handle the given class
*
* This function has to check if the given classname is supported
*/
virtual bool canHandle(std::string _className);
/** \brief return the type this generator handles
*
* return the classname of the node this generator can handle
*/
virtual std::string handles();
/** \brief Return a name for your widget in the context menu
*
* This name will be the same for all passed in nodes
*/
virtual QString contextMenuName();
private:
protected:
std::map< SceneGraph::BaseNode* , QWidget* > widgetMap_;
QMap< SceneGraph::BaseNode* , QWidget* > widgetMap_;
};
/** \class QtSceneGraphWidget QtSceneGraphWidget.hh <ACG/QtWidgets/QtSceneGraphWidget.hh>
......
......@@ -24,13 +24,24 @@ class LightWidgetGenerator : public ACG::QtWidgets::SceneGraphWidgetGenerator {
public:
// constructor
LightWidgetGenerator() {
std::cerr << "LightWidget Generator constructor" << std::endl;
}
virtual QWidget* getWidget(ACG::SceneGraph::BaseNode* _node ) {
std::cerr << "Generating widget" << std::endl;
return new QWidget();
// Check if we can handle this type
if ( ! canHandle( _node->className() ) )
return 0;
// Check if we already have a widget, otherwise generate a new one.
if ( widgetMap_.contains(_node) ) {
return widgetMap_[_node];
} else {
QWidget* widget = new QWidget();
widgetMap_[_node] = widget;
return widget;
}
}
virtual bool canHandle(std::string _className) {
......@@ -42,7 +53,7 @@ class LightWidgetGenerator : public ACG::QtWidgets::SceneGraphWidgetGenerator {
}
virtual QString contextMenuName() {
return QString("Light Node Context Menu");
return QString("Edit Light");
}
};
......
......@@ -1015,10 +1015,10 @@ void removeObjectFromMap(int _objectId) {
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator* _generator) {
// Check if we already have a generator for this type.
if ( sceneGraphGenerators_.contains( _generator->handles() ) ) {
std::cerr << "PluginFunctions Already handled" << std::endl;
}
if ( sceneGraphGenerators_.contains( _generator->handles() ) )
return;
// Store the generator
sceneGraphGenerators_[_generator->handles() ] = _generator;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment