Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ set(MOC_HEADER_FILES
${SRC_ROOT}/SofaVideoRecorderManager.h
${SRC_ROOT}/SofaPluginManager.h
${SRC_ROOT}/SofaSceneGraphWidget.h
${SRC_ROOT}/WDoubleLineEdit.h
${SRC_ROOT}/WDoubleLineEdit.h
${SRC_ROOT}/datawidgets/OptionsGroupWidget.h
${SRC_ROOT}/datawidgets/SelectableItemWidget.h
)
set(HEADER_FILES
${SRC_ROOT}/config.h.in
Expand Down Expand Up @@ -243,6 +245,8 @@ set(SOURCE_FILES
${SRC_ROOT}/SofaSceneGraphWidget.cpp
${SRC_ROOT}/viewer/VisualModelPolicy.cpp
${SRC_ROOT}/QtDataRepository.cpp
${SRC_ROOT}/datawidgets/OptionsGroupWidget.cpp
${SRC_ROOT}/datawidgets/SelectableItemWidget.cpp
)
set(UI_FILES
${SRC_ROOT}/AboutDialog.ui
Expand Down
210 changes: 0 additions & 210 deletions src/sofa/qt/SimpleDataWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,214 +139,4 @@ Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowS
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<3,double>> > > DWClass_CRSCVec3d("default",true);
Creator<DataWidgetFactory, SimpleDataWidget< sofa::linearalgebra::CompressedRowSparseMatrixConstraint<Vec<6,double>> > > DWClass_CRSCVec6d("default",true);

////////////////////////////////////////////////////////////////
/// OptionsGroup support
////////////////////////////////////////////////////////////////

//these functions must be written here for effect of writeToData
Creator<DataWidgetFactory,RadioDataWidget> DWClass_OptionsGroup("default",true);

bool RadioDataWidget::createWidgets()
{
QVBoxLayout* layout = new QVBoxLayout(this);
const sofa::helper::OptionsGroup m_radiotrick = getData()->getValue();
const unsigned int LIMIT_NUM_BUTTON=4;
buttonMode=m_radiotrick.size() < LIMIT_NUM_BUTTON;
if (buttonMode)
{
buttonList=new QButtonGroup(this);

for(unsigned int i=0; i<m_radiotrick.size(); i++)
{
std::string m_itemstring=m_radiotrick[i];

QRadioButton * m_radiobutton=new QRadioButton(QString(m_itemstring.c_str()), this);
if (i==m_radiotrick.getSelectedId()) m_radiobutton->setChecked(true);
layout->addWidget(m_radiobutton);
buttonList->addButton(m_radiobutton,i);
}
connect(buttonList, SIGNAL(buttonClicked(int)), this, SLOT(setWidgetDirty())) ;
}
else
{
comboList=new QComboBox(this);
comboList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

const sofa::helper::OptionsGroup m_radiotrick = getData()->getValue();
QStringList list;
for(unsigned int i=0; i<m_radiotrick.size(); i++) list << m_radiotrick[i].c_str();

comboList->insertItems(0, list);

comboList->setCurrentIndex(m_radiotrick.getSelectedId());

connect(comboList, SIGNAL(activated(int)), this, SLOT(setWidgetDirty()));
layout->addWidget(comboList);

}

return true;
}
void RadioDataWidget::setDataReadOnly(bool readOnly)
{
if (buttonMode)
{
const QList<QAbstractButton *> buttons = buttonList->buttons();
for (int i = 0; i < buttons.size(); ++i)
{
buttons.at(i)->setEnabled(!readOnly);
}
}
else
{
comboList->setEnabled(!readOnly);
}
}

void RadioDataWidget::readFromData()
{
const sofa::helper::OptionsGroup m_radiotrick = getData()->getValue();

if (buttonMode)
{
buttonList->button(m_radiotrick.getSelectedId())->setChecked(true);
}
else
{
comboList->setCurrentIndex(m_radiotrick.getSelectedId());
}
}
void RadioDataWidget::writeToData()
{
sofa::helper::OptionsGroup m_radiotrick = getData()->getValue();
if (buttonMode)
{
m_radiotrick.setSelectedItem((unsigned int)buttonList->checkedId ());
}
else
{
m_radiotrick.setSelectedItem((unsigned int)comboList->currentIndex());
}

this->getData()->setValue(m_radiotrick);
}

Creator<DataWidgetFactory, SelectableItemWidget> DWClass_SelectableItem("default",true);

SelectableItemWidget::SelectableItemWidget(QWidget* parent, const char* name,
core::BaseData* m_data, const helper::BaseSelectableItem* item)
: TDataWidget(parent, name, m_data, item)
, m_selectableItem(item)
{}

bool SelectableItemWidget::createWidgets()
{
if ((Tdata && Tdata->getValueTypeString() != "SelectableItem") ||
(baseData && baseData->getValueTypeString() != "SelectableItem"))
{
return false;
}

QVBoxLayout* layout = new QVBoxLayout(this);
static constexpr unsigned int LIMIT_NUM_BUTTON = 4;

assert(m_selectableItem);
const std::size_t nbItems = m_selectableItem->getNumberOfItems();
m_buttonMode = nbItems < LIMIT_NUM_BUTTON;
const auto* items = m_selectableItem->getItemsData();

const auto getItem = [](const sofa::helper::Item* item)
{
std::stringstream ss;
ss << item->key;
if (!item->description.empty())
{
ss << " (" << item->description << ")";
}
return ss.str();
};

if (m_buttonMode)
{
m_buttonList = new QButtonGroup(this);

for (std::size_t i = 0; i < nbItems; i++)
{
const helper::Item* item_i = items + i;

QRadioButton * m_radiobutton = new QRadioButton(QString(getItem(item_i).c_str()), this);
if (i == m_selectableItem->getSelectedId())
{
m_radiobutton->setChecked(true);
}
layout->addWidget(m_radiobutton);
m_buttonList->addButton(m_radiobutton, i);
}
connect(m_buttonList, SIGNAL(buttonClicked(int)), this, SLOT(setWidgetDirty())) ;
}
else
{
m_comboList=new QComboBox(this);
m_comboList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

QStringList list;
for (std::size_t i = 0; i < nbItems; i++)
{
const helper::Item* item_i = items + i;
list << getItem(item_i).c_str();
}

m_comboList->insertItems(0, list);

m_comboList->setCurrentIndex(m_selectableItem->getSelectedId());

connect(m_comboList, SIGNAL(activated(int)), this, SLOT(setWidgetDirty()));
layout->addWidget(m_comboList);

}

return true;
}

void SelectableItemWidget::setDataReadOnly(const bool readOnly)
{
if (m_buttonMode)
{
const QList<QAbstractButton *> buttons = m_buttonList->buttons();
for (auto& button : buttons)
{
button->setEnabled(!readOnly);
}
}
else
{
m_comboList->setEnabled(!readOnly);
}
}

void SelectableItemWidget::readFromData()
{
if (m_buttonMode)
{
m_buttonList->button(m_selectableItem->getSelectedId())->setChecked(true);
}
else
{
m_comboList->setCurrentIndex(m_selectableItem->getSelectedId());
}
}

void SelectableItemWidget::writeToData()
{
if (m_buttonMode)
{
const_cast<helper::BaseSelectableItem*>(m_selectableItem)->setSelectedId(static_cast<std::size_t>(m_buttonList->checkedId()));
}
else
{
const_cast<helper::BaseSelectableItem*>(m_selectableItem)->setSelectedId(static_cast<std::size_t>(m_comboList->currentIndex()));
}
}


} //namespace sofa::qt
57 changes: 0 additions & 57 deletions src/sofa/qt/SimpleDataWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "ModifyObject.h"
#include <sofa/type/Vec.h>
#include <sofa/defaulttype/VecTypes.h>
//#include <sofa/defaulttype/RigidTypes.h>
#include <sofa/type/fixed_array.h>
#include <sofa/core/topology/Topology.h>
#include <sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h>
Expand Down Expand Up @@ -971,60 +970,4 @@ class data_widget_trait <sofa::linearalgebra::CompressedRowSparseMatrixConstrain

};

////////////////////////////////////////////////////////////////
/// OptionsGroup support
////////////////////////////////////////////////////////////////


class RadioDataWidget : public TDataWidget<sofa::helper::OptionsGroup >
{
Q_OBJECT
public :

///The class constructor takes a TData<RadioTrick> since it creates
///a widget for a that particular data type.
RadioDataWidget(QWidget* parent, const char* name,
core::objectmodel::Data<sofa::helper::OptionsGroup >* m_data)
: TDataWidget<sofa::helper::OptionsGroup >(parent,name,m_data) {}

///In this method we create the widgets and perform the signal / slots connections.
virtual bool createWidgets();
virtual void setDataReadOnly(bool readOnly);

protected:
///Implements how update the widgets knowing the data value.
virtual void readFromData();

///Implements how to update the data, knowing the widget value.
virtual void writeToData();

QButtonGroup *buttonList;
QComboBox *comboList;
bool buttonMode;
};

class SelectableItemWidget final : public TDataWidget<helper::BaseSelectableItem>
{
Q_OBJECT
public :

SelectableItemWidget(QWidget* parent, const char* name,
core::BaseData* m_data, const helper::BaseSelectableItem* item);

bool createWidgets() override;
void setDataReadOnly(bool readOnly) override;

protected:
void readFromData() override;

void writeToData() override;

QButtonGroup *m_buttonList { nullptr };
QComboBox *m_comboList { nullptr };
bool m_buttonMode { false };

const helper::BaseSelectableItem* m_selectableItem { nullptr };
};


} //namespace sofa::qt
68 changes: 68 additions & 0 deletions src/sofa/qt/datawidgets/OptionsGroupWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: [email protected] *
******************************************************************************/

#include <sofa/helper/Factory.inl>
#include <sofa/qt/datawidgets/OptionsGroupWidget.h>

namespace sofa::qt
{
//these functions must be written here for effect of writeToData
Creator<DataWidgetFactory,OptionsGroupWidget> DWClass_OptionsGroup("default",true);

bool OptionsGroupWidget::createWidgets()
{
QVBoxLayout* layout = new QVBoxLayout(this);

comboList=new QComboBox(this);
comboList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

auto optiongroup = getData()->getValue();
QStringList list;
for(unsigned int i=0; i<optiongroup.size(); i++) list << optiongroup[i].c_str();

comboList->insertItems(0, list);
comboList->setCurrentIndex(optiongroup.getSelectedId());

connect(comboList, SIGNAL(activated(int)), this, SLOT(setWidgetDirty()));
layout->addWidget(comboList);

return true;
}
void OptionsGroupWidget::setDataReadOnly(bool readOnly)
{
comboList->setEnabled(!readOnly);
}

void OptionsGroupWidget::readFromData()
{
auto optiongroup = getData()->getValue();
comboList->setCurrentIndex(optiongroup.getSelectedId());
}

void OptionsGroupWidget::writeToData()
{
auto optiongroup = getData()->getValue();
optiongroup.setSelectedItem(static_cast<std::size_t>(comboList->currentIndex()));
getData()->setValue(optiongroup);
}

} //namespace sofa::qt
Loading
Loading