Skip to content
Snippets Groups Projects
Commit b337e8cc authored by Yann Boucher's avatar Yann Boucher
Browse files

Improved the Property class by separating the visual name and the identifier name

parent fbda5448
No related branches found
No related tags found
No related merge requests found
......@@ -73,12 +73,17 @@ public:
//! \brief Accepte un visiteur. Cette fonction est automatiquement redéfinie correctement en héritant de PropertyImpl<Classe>?
virtual void accept(PropertyVisitor& v) = 0;
//! \brief Retourne le nom de la propriété.
std::string name() const
{ return prop_name; }
//! \brief Retourne le nom identifiant propriété.
std::string identifier() const
{ return m_identifier; }
//! \brief Retourne le nom d'affichage de la propriété, qui est purement cosmétique.
std::string display_name() const
{ return m_display_name; }
private:
std::string prop_name;
std::string m_identifier;
std::string m_display_name;
};
/**
......@@ -118,10 +123,11 @@ public:
protected:
//! \brief Appelée internalement par les macros DEFINE_CONFIGURABLE_*.
template <typename PropertyType, typename... Args>
PropertyType& register_property(const std::string& name, Args&&... args)
PropertyType& register_property(const std::string& prop_name, const std::string& display_name, Args&&... args)
{
m_properties.emplace_back(std::make_unique<PropertyType>(std::forward<Args>(args)...));
m_properties.back()->prop_name = name;
m_properties.back()->m_identifier = prop_name;
m_properties.back()->m_display_name = display_name;
return static_cast<PropertyType&>(*m_properties.back());
}
......@@ -266,8 +272,8 @@ private:
\param name Nom affichable de la propriété.
\param ... Arguments supplémentaires à passer au constructeur de 'prop_type'
**/
#define DEFINE_CONFIGURABLE_PROPERTY(prop_type, identifier, name, ...) \
prop_type& identifier = register_property<prop_type>(name, ##__VA_ARGS__)
#define DEFINE_CONFIGURABLE_PROPERTY(prop_type, identifier, display_name, ...) \
prop_type& identifier = register_property<prop_type>(#identifier, display_name, ##__VA_ARGS__)
/** Permet de déclarer une liste fixée de propriétés 'identifier' de type 'prop_type', avec comme nom affichable 'name'.
\param prop_type Type des propriétés.
......@@ -275,8 +281,8 @@ prop_type& identifier = register_property<prop_type>(name, ##__VA_ARGS__)
\param name Nom affichable de la liste de propriétés.
\param ... Arguments supplémentaires à passer au constructeur de 'prop_type' lors de la créatin d'une propriété dans la liste
**/
#define DEFINE_CONFIGURABLE_LIST(prop_type, identifier, name, ...) \
PropertyList& identifier = register_property<PropertyList>(name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type>(__VA_ARGS__); false, ##__VA_ARGS__ })
#define DEFINE_CONFIGURABLE_LIST(prop_type, identifier, display_name, ...) \
PropertyList& identifier = register_property<PropertyList>(#identifier, display_name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type>(__VA_ARGS__); false, ##__VA_ARGS__ })
/** Permet de déclarer une liste dynamique de propriétés 'identifier' de type 'prop_type', avec comme nom affichable 'name'.
\param prop_type Type des propriétés.
\param identifier Nom de la variable dans le code.
......@@ -284,7 +290,7 @@ PropertyList& identifier = register_property<PropertyList>(name, []()->std::uniq
\param inner_args Arguments supplémentaires à passer au constructeur de 'prop_type' lors de la créatin d'une propriété dans la liste
\param ... Arguments supplémentaires à passer au constructeur de PropertyList.
**/
#define DEFINE_CONFIGURABLE_DYNLIST(prop_type, identifier, name, inner_args, ...) \
PropertyList& identifier = register_property<PropertyList>(name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type> inner_args; }, true, ##__VA_ARGS__ )
#define DEFINE_CONFIGURABLE_DYNLIST(prop_type, identifier, display_name, inner_args, ...) \
PropertyList& identifier = register_property<PropertyList>(#identifier, display_name, []()->std::unique_ptr<Property>{ return std::make_unique<prop_type> inner_args; }, true, ##__VA_ARGS__ )
#endif // PROPERTY_HPP
......@@ -15,7 +15,7 @@ public:
private:
DEFINE_CONFIGURABLE_PROPERTY(IntegerProperty, states, "State count", 1);
DEFINE_CONFIGURABLE_PROPERTY(IntegerProperty, thresold, "Threshold");
DEFINE_CONFIGURABLE_PROPERTY(IntegerProperty, threshold, "Threshold");
};
REGISTER_FACTORY_ENTRY(TransitionRule, CircularTransition, "Circular");
......
......@@ -5,13 +5,13 @@
"date": "lun. mai 24 2021",
"desc": "aaa",
"neighborhood_data": {
"Radius": 4
"radius": 4
},
"neighborhood_name": "Von Neumann",
"title": "test3",
"transition_data": {
"State count": 4,
"Threshold": 3
"states": 4,
"threshold": 3
},
"transition_name": "Circular"
}
{
"alphabet": [
],
"author": "JM",
"date": "ven. mai 28 2021",
"desc": "",
"neighborhood_data": {
"radius": 5
},
"neighborhood_name": "Von Neumann",
"title": "test_modele3",
"transition_data": {
"states": 3,
"threshold": 6
},
"transition_name": "Circular"
}
......@@ -65,7 +65,7 @@ QWidget *UIBuilderVisitor::current_widget()
void UIBuilderVisitor::push_array_widget(const Property &prop)
{
QGroupBox* box = new QGroupBox(QString::fromStdString(prop.name()), current_widget());
QGroupBox* box = new QGroupBox(QString::fromStdString(prop.identifier()), current_widget());
box->setLayout(new QVBoxLayout);
add_widget("", box);
m_widget_hierarchy.push(box);
......@@ -82,7 +82,7 @@ QWidget* UIBuilderVisitor::pop_widget()
void UIBuilderVisitor::visit(StringProperty &str)
{
QLineEdit* line = new QLineEdit(QString::fromStdString(str.str), current_widget());
add_widget(str.name(), line);
add_widget(str.identifier(), line);
QObject::connect(line, &QLineEdit::textEdited,
[&str](const QString& qstr) { str.str = qstr.toStdString(); });
......@@ -91,7 +91,7 @@ void UIBuilderVisitor::visit(StringProperty &str)
void UIBuilderVisitor::visit(IntegerProperty &prop)
{
QSpinBox* spin = new QSpinBox(current_widget());
add_widget(prop.name(), spin);
add_widget(prop.identifier(), spin);
spin->setValue(prop.val);
spin->setMinimum(prop.prop_min);
......@@ -112,7 +112,7 @@ void UIBuilderVisitor::visit(CoordinateProperty &prop)
frame->layout()->addWidget(new QLabel("y :", frame));
frame->layout()->addWidget(spin_y);
frame->layout()->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
add_widget(prop.name(), frame);
add_widget(prop.identifier(), frame);
spin_x->setValue(prop.c.x); spin_y->setValue(prop.c.y);
QObject::connect(spin_x, QOverload<int>::of(&QSpinBox::valueChanged),
......@@ -205,7 +205,7 @@ void PropertySaverVisitor::save_value(Property &prop, const QJsonValue &val)
else
{
QJsonObject obj = current().toJsonObject();
obj[QString::fromStdString(prop.name())] = val;
obj[QString::fromStdString(prop.identifier())] = val;
current() = obj;
}
}
......@@ -295,7 +295,7 @@ QJsonValue PropertyLoaderVisitor::fetch_value(Property &prop)
return val;
}
else
return current()[prop.name().c_str()];
return current()[prop.identifier().c_str()];
}
void PropertyLoaderVisitor::visit(StringProperty &prop)
......
......@@ -4,7 +4,7 @@ unsigned CircularTransition::getState(unsigned cell, const Neighborhood &neighbo
{
unsigned next_state = (cell+1) % states.val;
unsigned next_state_neighbors = neighborhood.getNb(next_state);
if ((int)next_state_neighbors >= thresold.val)
if ((int)next_state_neighbors >= threshold.val)
return next_state;
else
return cell;
......
......@@ -22,7 +22,7 @@ void CellulutTests::test_arbitrary_neighborhood_rule()
entry.push_back(coord.y);
json_array.push_back(entry);
}
obj["Neighbors"] = json_array;
obj["neighbors"] = json_array;
ArbitraryNeighborhoodRule rule;
{
......
......@@ -6,8 +6,8 @@
void CellulutTests::test_circulartransition()
{
QJsonObject obj;
obj["Nombre d'états"] = 4;
obj["Seuil"] = 3;
obj["states"] = 4;
obj["threshold"] = 3;
CircularTransition rule; // load
{
......
......@@ -15,7 +15,8 @@ void CellulutTests::test_property()
PropertyClass test;
QVERIFY(test.test_str.str == "hello world");
QVERIFY(test.test_str.name() == "Test String");
QVERIFY(test.test_str.identifier() == "test_str");
QVERIFY(test.test_str.display_name() == "Test String");
QVERIFY(test.get_properties().size() == 1);
QVERIFY(test.get_properties()[0].get() == &test.test_str);
}
......
......@@ -90,7 +90,7 @@ void CellulutTests::test_totalistictransition()
TotalisticTransition rule;
QJsonObject obj;
obj["Rule String"] = "1->2\n"
obj["rule_string"] = "1->2\n"
"2->3\n"
"3,1:[1..2]->1\n";
PropertyLoaderVisitor visit(obj);
......@@ -134,7 +134,7 @@ void CellulutTests::test_totalistictransition()
TotalisticTransition rule;
QJsonObject obj;
obj["Rule String"] = "0,1:[3]->1\n"
obj["rule_string"] = "0,1:[3]->1\n"
"1,1:[0..1]->0\n"
"1,1:[4..*]->0\n";
PropertyLoaderVisitor visit(obj);
......
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