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 {
//== 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( QWidget * _parent,
SceneGraph::BaseNode * _rootNode ) :
......@@ -332,6 +355,14 @@ slotItemPressed( QTreeWidgetItem * _item,
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() );
break;
......@@ -492,6 +523,21 @@ slotNodeChanged(ACG::SceneGraph::BaseNode* _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 {
//== 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>
......@@ -105,7 +139,6 @@ public:
/// destructor
~QtSceneGraphWidget() {}
enum Columns { Node, Type, Status, Mode };
......@@ -195,6 +228,21 @@ private:
QAction * actionHideChildren_;
QAction * actionHideSubtree_;
} 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:
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:
QtSceneGraphWidget * sgw_;
......
......@@ -10,6 +10,8 @@
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
#include "Light.hh"
//== DEFINES ==================================================================
......@@ -18,6 +20,34 @@
//== 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.
* You dont need to create an object of this type manually.
*/
......@@ -29,6 +59,9 @@ LightObject::LightObject( ) :
setDataType(DATA_LIGHT);
setTypeIcon(DATA_LIGHT,"LightType.png");
init();
// Make sure, the generator is added to the widget
PluginFunctions::addSceneGraphGenerator( &lightWidgetGenerator_ );
}
//=============================================================================
......
......@@ -135,6 +135,9 @@ static int targetCounter_ = 0;
/// Map that holds the object handles
static std::map<int, BaseObject*> objectMap_;
/// Map of scenegraph widget generators
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > sceneGraphGenerators_;
void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root;
}
......@@ -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
\ No newline at end of file
......@@ -64,6 +64,8 @@
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <OpenFlipper/common/ViewerProperties.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
namespace PluginFunctions {
//=======================================
......@@ -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
......@@ -976,6 +976,7 @@ CoreWidget::slotShowSceneGraphDialog()
}
sceneGraphDialog_->setGeneratorMap(PluginFunctions::getSceneGraphGeneratorList() );
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