Commit 72d63b41 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added widget handler ( QtWidgets for Each Node)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9102 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b5c59b8e
...@@ -92,6 +92,29 @@ namespace QtWidgets { ...@@ -92,6 +92,29 @@ namespace QtWidgets {
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
SceneGraphWidgetGenerator::SceneGraphWidgetGenerator() {
std::cerr << "SceneGraphWidgetGenerator constructor " << std::endl;
}
QWidget* SceneGraphWidgetGenerator::getWidget(SceneGraph::BaseNode* _node ) {
std::cerr << "getWidget " << std::endl;
return 0;
}
bool SceneGraphWidgetGenerator::canHandle(std::string _className) {
std::cerr << "canHandle " << _className << std::endl;
return false;
}
std::string SceneGraphWidgetGenerator::handles() {
return std::string("Unset Type");
}
QString SceneGraphWidgetGenerator::contextMenuName() {
std::cerr << "contextMenuName " << std::endl;
return QString("Context Menu name unset");
}
QtSceneGraphWidget:: QtSceneGraphWidget::
QtSceneGraphWidget( QWidget * _parent, QtSceneGraphWidget( QWidget * _parent,
SceneGraph::BaseNode * _rootNode ) : SceneGraph::BaseNode * _rootNode ) :
...@@ -332,6 +355,14 @@ slotItemPressed( QTreeWidgetItem * _item, ...@@ -332,6 +355,14 @@ slotItemPressed( QTreeWidgetItem * _item,
this, SLOT( slotEditCoordinateFrame() ) ); this, SLOT( slotEditCoordinateFrame() ) );
} }
if ( generatorMap_.contains( node->className() ) ) {
std::cerr << "Found generator handles: " << generatorMap_[node->className()]->handles() << std::endl;
QWidget* widget = generatorMap_[node->className()]->getWidget( node );
modeMenu_->addAction( generatorMap_[node->className()]->contextMenuName() , widget, SLOT(show()) );
} else {
std::cerr << "No Generator found" << std::endl;
}
modeMenu_->popup( QCursor::pos() ); modeMenu_->popup( QCursor::pos() );
break; break;
...@@ -492,6 +523,21 @@ slotNodeChanged(ACG::SceneGraph::BaseNode* _node) ...@@ -492,6 +523,21 @@ slotNodeChanged(ACG::SceneGraph::BaseNode* _node)
emit signalNodeChanged(_node); emit signalNodeChanged(_node);
} }
//-----------------------------------------------------------------------------
bool QtSceneGraphWidget::addWidgetGenerator( SceneGraphWidgetGenerator* _generator ) {
// Check if we already have a generator for this type.
if ( generatorMap_.contains( _generator->handles() ) ) {
std::cerr << "Already handled" << std::endl;
return false;
}
// Store the generator
generatorMap_[_generator->handles() ] = _generator;
return true;
}
//============================================================================= //=============================================================================
......
...@@ -82,6 +82,40 @@ namespace QtWidgets { ...@@ -82,6 +82,40 @@ namespace QtWidgets {
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
class ACGDLLEXPORT SceneGraphWidgetGenerator {
public:
// constructor
SceneGraphWidgetGenerator();
/** \brief Get a widget for this Node
*
* 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()
* 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.
*/
virtual QWidget* getWidget(SceneGraph::BaseNode* _node );
/** \brief returns if the widgets can handle the given class
*/
virtual bool canHandle(std::string _className);
/** \brief return the type this generator handles
*
*/
virtual std::string handles();
/** \brief Return a name for your widget in the context menu
*/
virtual QString contextMenuName();
private:
std::map< SceneGraph::BaseNode* , QWidget* > widgetMap_;
};
/** \class QtSceneGraphWidget QtSceneGraphWidget.hh <ACG/QtWidgets/QtSceneGraphWidget.hh> /** \class QtSceneGraphWidget QtSceneGraphWidget.hh <ACG/QtWidgets/QtSceneGraphWidget.hh>
...@@ -105,7 +139,6 @@ public: ...@@ -105,7 +139,6 @@ public:
/// destructor /// destructor
~QtSceneGraphWidget() {} ~QtSceneGraphWidget() {}
enum Columns { Node, Type, Status, Mode }; enum Columns { Node, Type, Status, Mode };
...@@ -195,6 +228,21 @@ private: ...@@ -195,6 +228,21 @@ private:
QAction * actionHideChildren_; QAction * actionHideChildren_;
QAction * actionHideSubtree_; QAction * actionHideSubtree_;
} statusActions_; } statusActions_;
public:
/** \brief Add a node widget handler
*
* returns true, if the handler was sucessfully added.
*/
bool addWidgetGenerator( SceneGraphWidgetGenerator* _generator );
/** \brief Set a complete generator map (this will overwrite the existing one!
*/
void setGeneratorMap( QMap< std::string , SceneGraphWidgetGenerator* > _map) { generatorMap_ = _map; };
private:
QMap< std::string , SceneGraphWidgetGenerator* > generatorMap_;
}; };
...@@ -230,6 +278,11 @@ private slots: ...@@ -230,6 +278,11 @@ private slots:
void slotNodeChanged(ACG::SceneGraph::BaseNode* _node); void slotNodeChanged(ACG::SceneGraph::BaseNode* _node);
public:
/** \brief Set a complete generator map (this will overwrite the existing one!
*/
void setGeneratorMap( QMap< std::string , SceneGraphWidgetGenerator* > _map) { sgw_->setGeneratorMap(_map); };
private: private:
QtSceneGraphWidget * sgw_; QtSceneGraphWidget * sgw_;
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
#include "Light.hh" #include "Light.hh"
//== DEFINES ================================================================== //== DEFINES ==================================================================
...@@ -18,6 +20,34 @@ ...@@ -18,6 +20,34 @@
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
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();
}
virtual bool canHandle(std::string _className) {
return ( _className == std::string("LightNode") );
}
virtual std::string handles() {
return std::string("LightNode");
}
virtual QString contextMenuName() {
return QString("Light Node Context Menu");
}
};
static LightWidgetGenerator lightWidgetGenerator_;
/** Constructor for Light Objects. /** Constructor for Light Objects.
* You dont need to create an object of this type manually. * You dont need to create an object of this type manually.
*/ */
...@@ -29,6 +59,9 @@ LightObject::LightObject( ) : ...@@ -29,6 +59,9 @@ LightObject::LightObject( ) :
setDataType(DATA_LIGHT); setDataType(DATA_LIGHT);
setTypeIcon(DATA_LIGHT,"LightType.png"); setTypeIcon(DATA_LIGHT,"LightType.png");
init(); init();
// Make sure, the generator is added to the widget
PluginFunctions::addSceneGraphGenerator( &lightWidgetGenerator_ );
} }
//============================================================================= //=============================================================================
......
...@@ -135,6 +135,9 @@ static int targetCounter_ = 0; ...@@ -135,6 +135,9 @@ static int targetCounter_ = 0;
/// Map that holds the object handles /// Map that holds the object handles
static std::map<int, BaseObject*> objectMap_; static std::map<int, BaseObject*> objectMap_;
/// Map of scenegraph widget generators
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > sceneGraphGenerators_;
void setDataRoot( BaseObject* _root ) { void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root; objectRoot_ = _root;
} }
...@@ -1011,4 +1014,20 @@ void removeObjectFromMap(int _objectId) { ...@@ -1011,4 +1014,20 @@ 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;
}
// Store the generator
sceneGraphGenerators_[_generator->handles() ] = _generator;
}
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > getSceneGraphGeneratorList(){
std::cerr << "PluginFunctions::getmap" << std::endl;
return sceneGraphGenerators_;
}
} // End namespace PluginFunctions } // End namespace PluginFunctions
\ No newline at end of file
...@@ -64,6 +64,8 @@ ...@@ -64,6 +64,8 @@
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh> #include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <OpenFlipper/common/ViewerProperties.hh> #include <OpenFlipper/common/ViewerProperties.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
namespace PluginFunctions { namespace PluginFunctions {
//======================================= //=======================================
...@@ -142,6 +144,21 @@ void removeObjectFromMap(int _objectId); ...@@ -142,6 +144,21 @@ void removeObjectFromMap(int _objectId);
/** @} */ /** @} */
//=======================================
// SceneGraph Generator Map
/** @name Internal container for scenegraph widget generators
* @{ */
//=======================================
/// Add a scenegraph generator ( the handled type will be extracted from the generator)
DLLEXPORT
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator* _generator);
DLLEXPORT
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > getSceneGraphGeneratorList();
/** @} */
} }
#endif //PLUGINFUNCTIONSCORE_HH #endif //PLUGINFUNCTIONSCORE_HH
...@@ -976,6 +976,7 @@ CoreWidget::slotShowSceneGraphDialog() ...@@ -976,6 +976,7 @@ CoreWidget::slotShowSceneGraphDialog()
} }
sceneGraphDialog_->setGeneratorMap(PluginFunctions::getSceneGraphGeneratorList() );
sceneGraphDialog_->show(); sceneGraphDialog_->show();
} }
} }
......
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