From 0a22de2cb23a1636f076d1dd8a05b7f873b9b653 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 21 Feb 2012 21:22:26 +0000 Subject: Save all changes made to the properties in the Sidebar. --- src/entityproperties.cc | 13 ++++++- src/entityproperties.h | 9 ++++- src/properties.cc | 5 --- src/properties.h | 12 +++++- src/sidebar.cc | 99 +++++++++++++++++++++++++++++++++++++++++-------- src/sidebar.h | 15 +++++++- 6 files changed, 127 insertions(+), 26 deletions(-) diff --git a/src/entityproperties.cc b/src/entityproperties.cc index 84a6bc4..bbef6c9 100644 --- a/src/entityproperties.cc +++ b/src/entityproperties.cc @@ -12,20 +12,21 @@ namespace editor EntityProperties::EntityProperties() { + properties_radius = 0; } EntityProperties::~EntityProperties() { } -void EntityProperties::add_subsection(const QString &name) +void EntityProperties::add_subsection_header(const QString &header) { if (properties_subsections.size()) { properties_subsections += '\n'; } properties_subsections += '['; - properties_subsections += name; + properties_subsections += header; properties_subsections += ']'; properties_subsections += '\n'; @@ -47,6 +48,14 @@ void EntityProperties::save(QTextStream &textstream) if (name().size()) textstream << "name=" << name() << '\n'; + // location + textstream << "location=" << location().x() << " " << location().y() << " " << location().z() << '\n'; + + // radius + if (radius()) { + textstream << "radius=" << radius() << '\n'; + } + // other values if (values().size()) { textstream << values(); diff --git a/src/entityproperties.h b/src/entityproperties.h index f91be1a..a47fc53 100644 --- a/src/entityproperties.h +++ b/src/entityproperties.h @@ -54,10 +54,17 @@ public: /* ---- mutators ---- */ + /** + * @brief set the subsection string of this object + * */ + void set_subsections(const QString &text) { + properties_subsections = text; + } + /** * @brief add a header to the subsection string of this object * */ - void add_subsection(const QString &name); + void add_subsection_header(const QString &header); /** * @brief add a value key pair to the subsection string of this object diff --git a/src/properties.cc b/src/properties.cc index f533c15..f5e2159 100644 --- a/src/properties.cc +++ b/src/properties.cc @@ -26,11 +26,6 @@ void Properties::add_value(const QString &key, const QString &value) properties_values += '\n'; } -void Properties::set_info(const QString &text) -{ - properties_info = text; -} - void Properties::add_info(const QString &text) { properties_info += text; diff --git a/src/properties.h b/src/properties.h index 472d4b4..6faf885 100644 --- a/src/properties.h +++ b/src/properties.h @@ -76,19 +76,27 @@ public: /** * @brief set the info string of this object * */ - void set_info(const QString &text); + inline void set_info(const QString &text) { + properties_info = text; + } /** * @brief add a line of text to the info string of this object * */ void add_info(const QString &text); + /** + * @brief set the subsection string of this object + * */ + inline void set_values(const QString &text) { + properties_values = text; + } + /** * @brief add a value key pair to the values string * */ void add_value(const QString &key, const QString &value); - /** * @brief set the object label * */ diff --git a/src/sidebar.cc b/src/sidebar.cc index 0a75b1b..77d87ae 100644 --- a/src/sidebar.cc +++ b/src/sidebar.cc @@ -29,19 +29,18 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) // entity label QHBoxLayout *box_entitylabel = new QHBoxLayout(); QLabel *label_entitylabel = new QLabel(tr("label")); - - edit_entitylabel = new QLineEdit(tr("entity_label")); - + edit_entitylabel = new QLineEdit(tr("entity_label")); box_entitylabel->addWidget(label_entitylabel); box_entitylabel->addWidget(edit_entitylabel); + connect(edit_entitylabel, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLabel(const QString &))); // entity name QHBoxLayout *box_entityname = new QHBoxLayout(); - QLabel *label_entityname = new QLabel(tr("name")); - + QLabel *label_entityname = new QLabel(tr("name")); edit_entityname = new QLineEdit(tr("Entity Name")); box_entityname->addWidget(label_entityname); box_entityname->addWidget(edit_entityname); + connect(edit_entityname, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityName(const QString &))); // entity location QHBoxLayout *box_entitylocation = new QHBoxLayout(); @@ -53,22 +52,35 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) box_entitylocation->addWidget(edit_entitylocation_x); box_entitylocation->addWidget(edit_entitylocation_y); box_entitylocation->addWidget(edit_entitylocation_z); - connect(edit_entitylocation_x, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationX(const QString &))); connect(edit_entitylocation_y, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationY(const QString &))); connect(edit_entitylocation_z, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityLocationZ(const QString &))); - // entity properties + // entity radius + QHBoxLayout *box_entityradius = new QHBoxLayout(); + QLabel *label_entityradius = new QLabel(tr("radius")); + edit_entityradius = new QLineEdit(tr("radius")); + box_entityradius->addWidget(label_entityradius); + box_entityradius->addWidget(edit_entityradius); + connect(edit_entityradius, SIGNAL(textChanged(const QString &)), this, SLOT(updateEntityRadius(const QString &))); + + // entity values QLabel *label_entityproperties = new QLabel(tr("properties")); - text_entityproperties = new QTextEdit(); + text_entityvalues = new QTextEdit(); + text_entityvalues ->setTabChangesFocus(true); + connect(text_entityvalues, SIGNAL(textChanged()), this, SLOT(updateEntityValues())); // entity info QLabel *label_info = new QLabel(tr("info")); text_info = new QTextEdit(); + text_info ->setTabChangesFocus(true); + connect(text_info, SIGNAL(textChanged()), this, SLOT(updateEntityInfo())); // entity subsections QLabel *label_entitysubsections = new QLabel(tr("subsections")); text_subsections = new QTextEdit(); + text_subsections ->setTabChangesFocus(true); + connect(text_subsections, SIGNAL(textChanged()), this, SLOT(updateEntitySubSections())); // global vertical layout QVBoxLayout *box_global = new QVBoxLayout(); @@ -81,9 +93,10 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) box_global->addLayout(box_entitylabel); box_global->addLayout(box_entityname); box_global->addLayout(box_entitylocation); + box_global->addLayout(box_entityradius); box_global->addWidget(label_entityproperties); - box_global->addWidget(text_entityproperties,1); + box_global->addWidget(text_entityvalues,1); box_global->addWidget(label_info); box_global->addWidget(text_info,1); @@ -96,6 +109,20 @@ SideBar::SideBar(QWidget *parent) : QWidget(parent) setProperties(0); } +void SideBar::updateEntityLabel(const QString &value) +{ + if (last_selected) { + last_selected->set_label(value); + } +} + +void SideBar::updateEntityName(const QString &value) +{ + if (last_selected) { + last_selected->set_name(value); + } +} + void SideBar::updateEntityLocationX(const QString &value) { if (last_selected) { @@ -132,6 +159,41 @@ void SideBar::updateEntityLocationZ(const QString &value) } } +void SideBar::updateEntityRadius(const QString &value) +{ + if (last_selected) { + bool ok; + float r = value.toFloat(&ok); + if (ok) { + last_selected->set_radius(r); + } else { + last_selected->set_radius(0.0f); + } + emit entityChanged(); + } +} + +void SideBar::updateEntityValues() +{ + if (last_selected) { + last_selected->set_values(text_entityvalues->toPlainText()); + } +} + +void SideBar::updateEntitySubSections() +{ + if (last_selected) { + last_selected->set_subsections(text_subsections->toPlainText()); + } +} + +void SideBar::updateEntityInfo() +{ + if (last_selected) { + last_selected->set_info(text_info->toPlainText()); + } +} + void SideBar::setProperties(EntityProperties *properties) { last_selected = properties; @@ -154,8 +216,11 @@ void SideBar::setProperties(EntityProperties *properties) edit_entitylocation_z->setEnabled(false); edit_entitylocation_z->clear(); - text_entityproperties->setEnabled(false); - text_entityproperties->clear(); + edit_entityradius->setEnabled(false); + edit_entityradius->clear(); + + text_entityvalues->setEnabled(false); + text_entityvalues->clear(); text_subsections->setEnabled(false); text_subsections->clear(); @@ -189,14 +254,18 @@ void SideBar::setProperties(EntityProperties *properties) value.setNum(properties->location()[2]); edit_entitylocation_z->setText(value); - text_entityproperties->setEnabled(true); - text_entityproperties->setText(properties->values()); + edit_entityradius->setEnabled(true); + value.setNum(properties->radius()); + edit_entityradius->setText(value); + + text_entityvalues->setEnabled(true); + text_entityvalues->setPlainText(properties->values()); text_subsections->setEnabled(true); - text_subsections->setText(properties->subsections()); + text_subsections->setPlainText(properties->subsections()); text_info->setEnabled(true); - text_info->setText(properties->info()); + text_info->setPlainText(properties->info()); } } diff --git a/src/sidebar.h b/src/sidebar.h index cfa87c7..e731327 100644 --- a/src/sidebar.h +++ b/src/sidebar.h @@ -47,11 +47,23 @@ public slots: private slots: + void updateEntityLabel(const QString &value); + + void updateEntityName(const QString &value); + void updateEntityLocationX(const QString &value); void updateEntityLocationY(const QString &value); void updateEntityLocationZ(const QString &value); + + void updateEntityRadius(const QString &value); + + void updateEntityValues(); + + void updateEntitySubSections(); + + void updateEntityInfo(); signals: void entityChanged(); @@ -65,7 +77,8 @@ private: QLineEdit *edit_entitylocation_x; QLineEdit *edit_entitylocation_y; QLineEdit *edit_entitylocation_z; - QTextEdit *text_entityproperties; + QLineEdit *edit_entityradius; + QTextEdit *text_entityvalues; QTextEdit *text_subsections; QTextEdit *text_info; -- cgit v1.2.3