Skip to content
Snippets Groups Projects
Commit 31c24484 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Clean code in BodyTreeWidget and BodyTreeItem

parent 35c4c642
No related branches found
No related tags found
No related merge requests found
......@@ -17,23 +17,6 @@
#ifndef GEPETTO_GUI_BODYTREEWIDGET_HH
#define GEPETTO_GUI_BODYTREEWIDGET_HH
// This does not work because of qt meta-object compiler
#define GEPETTO_GUI_BODYTREE_DECL_FEATURE(func, ArgType) \
public slots: \
void func (ArgType arg)
#define GEPETTO_GUI_BODYTREE_IMPL_FEATURE(func, ArgType, OutType, WindowsManagerFunc) \
void BodyTreeWidget::func (ArgType arg) { \
WindowsManagerPtr_t wsm = MainWindow::instance()->osg(); \
foreach (const QModelIndex& index, view_->selectionModel ()->selectedIndexes ()) { \
const BodyTreeItem *item = dynamic_cast <const BodyTreeItem*> \
(model_->itemFromIndex (index)); \
if (item) wsm->WindowsManagerFunc (item->node()->getID(), \
convertTo<OutType>::from(arg)); \
else \
qDebug() << model_->itemFromIndex(index)->text() << "is not a BodyTreeItem"; \
} \
}
#include <QWidget>
#include <QTreeView>
#include <QToolBox>
......@@ -63,10 +46,6 @@ namespace gepetto {
virtual ~BodyTreeWidget () {}
/// Display the value in the slider.
/// \param alpha alpha value to convert
void changeAlphaValue(const float& alpha);
/// Get the body tree view.
QTreeView* view ();
......@@ -95,26 +74,6 @@ namespace gepetto {
/// Get selected bodies
QList<BodyTreeItem*> selectedBodies() const;
/// Set the transparency of currently selected body.
/// \param value value of the slider to convert
void setTransparency(int value);
/// Set the visibility mode of currently selected body.
/// \param arg visibility mode
void setVisibilityMode (QString arg);
/// Set the wireframe mode of currently selected body.
/// \param arg wireframe mode
void setWireFrameMode (QString arg);
/// Set the color of currently selected body.
/// \param color new color of the body
void setColor (QColor color);
/// Set the scale of currently selected body.
/// \param scale new scale of the body
void setScale (int scale);
/// \}
protected slots:
......
......@@ -29,26 +29,7 @@
#include <QHBoxLayout>
#include <QApplication>
static void addSelector (QToolBox* tb, QString title, QStringList display, QStringList command,
QObject* receiver, const char* slot) {
QWidget* newW = new QWidget();
newW->setObjectName(title);
QSignalMapper* mapper = new QSignalMapper (tb);
QHBoxLayout* layout = new QHBoxLayout(newW);
layout->setSpacing(6);
layout->setContentsMargins(11, 11, 11, 11);
layout->setObjectName(title + "_layout");
for (int i = 0; i < display.size(); ++i) {
QPushButton* button = new QPushButton(display[i], newW);
button->setObjectName(title + "_button_" + display[i]);
layout->addWidget (button);
mapper->setMapping(button, command[i]);
QObject::connect (button, SIGNAL(clicked(bool)), mapper, SLOT(map()));
}
receiver->connect (mapper, SIGNAL(mapped(QString)), slot);
tb->addItem(newW, title);
}
/*
static void addColorSelector (QToolBox* tb, QString title, QObject* receiver, const char* slot) {
QWidget* newW = new QWidget();
newW->setObjectName(title);
......@@ -69,16 +50,7 @@ static void addColorSelector (QToolBox* tb, QString title, QObject* receiver, co
receiver->connect (colorDialog, SIGNAL(colorSelected(QColor)), slot);
tb->addItem(newW, title);
}
static void addSlider (QToolBox* tb, QString title, QObject* receiver, const char* slot) {
QSlider* slider = new QSlider (Qt::Horizontal);
slider->setMinimum(0);
slider->setMaximum(100);
slider->setObjectName(title);
receiver->connect (slider, SIGNAL(valueChanged(int)), slot);
tb->addItem(slider, title);
}
*/
namespace gepetto {
namespace gui {
......@@ -234,18 +206,5 @@ namespace gepetto {
contextMenu.exec(view_->mapToGlobal(pos));
}
}
void BodyTreeWidget::changeAlphaValue(const float& alpha)
{
QSlider *tr = qobject_cast<QSlider *>(toolBox_->widget(0));
tr->setValue((int)alpha * 100);
}
GEPETTO_GUI_BODYTREE_IMPL_FEATURE (setTransparency, int, int, setAlpha)
GEPETTO_GUI_BODYTREE_IMPL_FEATURE (setVisibilityMode, QString, std::string, setVisibility)
GEPETTO_GUI_BODYTREE_IMPL_FEATURE (setWireFrameMode, QString, std::string, setWireFrameMode)
GEPETTO_GUI_BODYTREE_IMPL_FEATURE (setColor, QColor, WindowsManager::Color_t, setColor)
GEPETTO_GUI_BODYTREE_IMPL_FEATURE (setScale, int, int, setScale)
}
}
......@@ -50,7 +50,6 @@ namespace gepetto {
int indexSelected = 0;
for (std::size_t i = 0; i < enumMeta->values.size(); ++i)
{
qDebug() << enumMeta->names[i].c_str() << ":" << enumMeta->values[i];
cb->addItem(enumMeta->names[i].c_str(), enumMeta->values[i]);
if (value == enumMeta->values[i]) indexSelected = i;
}
......@@ -149,7 +148,6 @@ namespace gepetto {
if (sender != NULL) {
QVariant nameVariant = sender->property("propertyName");
if (nameVariant.isValid()) {
qDebug() << "Set property" << nameVariant;
std::string name = nameVariant.toString().toStdString();
boost::mutex::scoped_lock lock (MainWindow::instance()->osg()->osgFrameMutex());
node_->setProperty<T>(name, value);
......@@ -174,7 +172,6 @@ namespace gepetto {
void BodyTreeItem::setFloatProperty (const double& value) const
{
qDebug() << "Set property" << float(value);
setProperty (QObject::sender(), float(value));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment