Finis support for ENUM item types
This commit is contained in:
parent
e881472e7c
commit
3794e0031b
4 changed files with 96 additions and 1 deletions
|
|
@ -60,6 +60,13 @@ void ItemData::storeWithChanges(QJsonObject& json, const ItemFieldChanges& chang
|
||||||
json["Value"] = static_cast<double>(value_);
|
json["Value"] = static_cast<double>(value_);
|
||||||
if(changes.groupName)
|
if(changes.groupName)
|
||||||
json["GroupName"] = groupName_;
|
json["GroupName"] = groupName_;
|
||||||
|
if(changes.valueNames)
|
||||||
|
{
|
||||||
|
QJsonArray valueNamesArray;
|
||||||
|
for(const QString& name : valueNames_)
|
||||||
|
valueNamesArray.append(name);
|
||||||
|
json["ValueNames"] = valueNamesArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemData::load(const QJsonObject &json, const bool preserve)
|
void ItemData::load(const QJsonObject &json, const bool preserve)
|
||||||
|
|
@ -87,6 +94,19 @@ ItemFieldChanges ItemData::loadWithChanges(const QJsonObject& json, const bool p
|
||||||
groupName_ = json["GroupName"].toString();
|
groupName_ = json["GroupName"].toString();
|
||||||
changes.groupName = true;
|
changes.groupName = true;
|
||||||
}
|
}
|
||||||
|
if(json.contains("ValueType"))
|
||||||
|
{
|
||||||
|
type_ = static_cast<item_value_type_t>(json["ValueType"].toInt());
|
||||||
|
changes.type = true;
|
||||||
|
}
|
||||||
|
if(json.contains("ValueNames"))
|
||||||
|
{
|
||||||
|
valueNames_.clear();
|
||||||
|
QJsonArray valueNamesArray = json["ValueNames"].toArray();
|
||||||
|
for(int i = 0; i < valueNamesArray.size(); ++i)
|
||||||
|
valueNames_.push_back(valueNamesArray[i].toString());
|
||||||
|
changes.valueNames = true;
|
||||||
|
}
|
||||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||||
}
|
}
|
||||||
return changes;
|
return changes;
|
||||||
|
|
@ -120,6 +140,8 @@ bool ItemData::hasChanged(const ItemData& other, const ItemFieldChanges& changes
|
||||||
return true;
|
return true;
|
||||||
if(changes.actors)
|
if(changes.actors)
|
||||||
return true;
|
return true;
|
||||||
|
if(changes.valueNames && other.getValueNames() != getValueNames())
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,6 +170,33 @@ void ItemData::setGroupName(QString groupName)
|
||||||
groupName_ = groupName;
|
groupName_ = groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<QString> ItemData::getValueNames() const
|
||||||
|
{
|
||||||
|
return valueNames_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemData::setValueNames(std::vector<QString> valueNames)
|
||||||
|
{
|
||||||
|
valueNames_ = std::move(valueNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ItemData::valueNameToIndex(const QString& name) const
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < valueNames_.size(); ++i)
|
||||||
|
{
|
||||||
|
if(valueNames_[i] == name)
|
||||||
|
return static_cast<int>(i);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ItemData::indexToValueName(int index) const
|
||||||
|
{
|
||||||
|
if(index >= 0 && static_cast<size_t>(index) < valueNames_.size())
|
||||||
|
return valueNames_[index];
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
//item
|
//item
|
||||||
|
|
||||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||||
|
|
@ -205,6 +254,7 @@ Item& Item::operator=(const ItemData& other)
|
||||||
itemId_ = other.id();
|
itemId_ = other.id();
|
||||||
hidden_ = other.isHidden();
|
hidden_ = other.isHidden();
|
||||||
groupName_ = other.getGroupName();
|
groupName_ = other.getGroupName();
|
||||||
|
valueNames_ = other.getValueNames();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,6 +298,8 @@ void Item::requestUpdate(ItemUpdateRequest update)
|
||||||
for(std::shared_ptr<Actor>& actor : update.newActors)
|
for(std::shared_ptr<Actor>& actor : update.newActors)
|
||||||
addActor(actor);
|
addActor(actor);
|
||||||
}
|
}
|
||||||
|
if(update.changes.valueNames)
|
||||||
|
valueNames_ = update.payload.getValueNames();
|
||||||
update.payload = *this;
|
update.payload = *this;
|
||||||
updated(update);
|
updated(update);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,10 @@ public:
|
||||||
item_value_type_t getValueType();
|
item_value_type_t getValueType();
|
||||||
QString getGroupName() const;
|
QString getGroupName() const;
|
||||||
void setGroupName(QString groupName);
|
void setGroupName(QString groupName);
|
||||||
|
std::vector<QString> getValueNames() const;
|
||||||
|
void setValueNames(std::vector<QString> valueNames);
|
||||||
|
int valueNameToIndex(const QString& name) const;
|
||||||
|
QString indexToValueName(int index) const;
|
||||||
void storeWithChanges(QJsonObject& json, const ItemFieldChanges& changes);
|
void storeWithChanges(QJsonObject& json, const ItemFieldChanges& changes);
|
||||||
ItemFieldChanges loadWithChanges(const QJsonObject& json, const bool preserve = false);
|
ItemFieldChanges loadWithChanges(const QJsonObject& json, const bool preserve = false);
|
||||||
virtual QString getName() const;
|
virtual QString getName() const;
|
||||||
|
|
@ -130,6 +134,7 @@ struct ItemFieldChanges
|
||||||
bool type :1;
|
bool type :1;
|
||||||
bool groupName :1;
|
bool groupName :1;
|
||||||
bool actors :1;
|
bool actors :1;
|
||||||
|
bool valueNames :1;
|
||||||
ItemFieldChanges(bool defaultVal = false)
|
ItemFieldChanges(bool defaultVal = false)
|
||||||
{
|
{
|
||||||
name = defaultVal;
|
name = defaultVal;
|
||||||
|
|
@ -138,10 +143,11 @@ struct ItemFieldChanges
|
||||||
type = defaultVal;
|
type = defaultVal;
|
||||||
groupName = defaultVal;
|
groupName = defaultVal;
|
||||||
actors = false;
|
actors = false;
|
||||||
|
valueNames = defaultVal;
|
||||||
}
|
}
|
||||||
inline bool isNone() const
|
inline bool isNone() const
|
||||||
{
|
{
|
||||||
return !name && !value && !hidden && !type && !groupName && !actors;
|
return !name && !value && !hidden && !type && !groupName && !actors && !valueNames;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_itemwidget.h"
|
#include "ui_itemwidget.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include "itemsettingsdialog.h"
|
#include "itemsettingsdialog.h"
|
||||||
|
|
@ -26,6 +27,16 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool noGroupEdit, QWidget *pare
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
ui->slider->hide();
|
ui->slider->hide();
|
||||||
}
|
}
|
||||||
|
else if(workingItem->getValueType() == ITEM_VALUE_ENUM)
|
||||||
|
{
|
||||||
|
ui->slider->hide();
|
||||||
|
ui->checkBox->hide();
|
||||||
|
QStringList list;
|
||||||
|
for(const QString& name : workingItem->getValueNames())
|
||||||
|
list.append(name);
|
||||||
|
ui->comboBox->addItems(list);
|
||||||
|
ui->comboBox->setCurrentIndex(workingItem->getValue());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->slider->hide();
|
ui->slider->hide();
|
||||||
|
|
@ -37,6 +48,8 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool noGroupEdit, QWidget *pare
|
||||||
|
|
||||||
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
||||||
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
||||||
|
else if(workingItem->getValueType() == ITEM_VALUE_ENUM)
|
||||||
|
connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ItemWidget::moveToValue);
|
||||||
else
|
else
|
||||||
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
||||||
|
|
@ -84,6 +97,7 @@ void ItemWidget::disable()
|
||||||
ui->checkBox->setEnabled(false);
|
ui->checkBox->setEnabled(false);
|
||||||
ui->label->setEnabled(false);
|
ui->label->setEnabled(false);
|
||||||
ui->slider->setEnabled(false);
|
ui->slider->setEnabled(false);
|
||||||
|
ui->comboBox->setEnabled(false);
|
||||||
ui->pushButton_Remove->setEnabled(false);
|
ui->pushButton_Remove->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +129,16 @@ std::weak_ptr<Item> ItemWidget::getItem()
|
||||||
|
|
||||||
void ItemWidget::onItemUpdated(ItemUpdateRequest update)
|
void ItemWidget::onItemUpdated(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
|
if(update.changes.valueNames)
|
||||||
|
{
|
||||||
|
ui->comboBox->blockSignals(true);
|
||||||
|
ui->comboBox->clear();
|
||||||
|
QStringList list;
|
||||||
|
for(const QString& name : update.payload.getValueNames())
|
||||||
|
list.append(name);
|
||||||
|
ui->comboBox->addItems(list);
|
||||||
|
ui->comboBox->blockSignals(false);
|
||||||
|
}
|
||||||
stateChanged(update.payload.getValue());
|
stateChanged(update.payload.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,6 +150,9 @@ void ItemWidget::stateChanged(int state)
|
||||||
ui->checkBox->blockSignals(true);
|
ui->checkBox->blockSignals(true);
|
||||||
ui->checkBox->setChecked(state);
|
ui->checkBox->setChecked(state);
|
||||||
ui->checkBox->blockSignals(false);
|
ui->checkBox->blockSignals(false);
|
||||||
|
ui->comboBox->blockSignals(true);
|
||||||
|
ui->comboBox->setCurrentIndex(state);
|
||||||
|
ui->comboBox->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemWidget::~ItemWidget()
|
ItemWidget::~ItemWidget()
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QCheckBox" name="checkBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue