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
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ void ColorEdit::paintEvent(QPaintEvent *ev) {
painter.setPen(Qt::NoPen);
painter.setBrush(m_brush);
painter.drawRect(r);
painter.setBrush(m_color);
painter.drawRect(r);
r.setWidth(r.width() / 2);
painter.setBrush(QColor(m_color.rgb()));
painter.drawRect(r);
r.translate(r.width(), 0);
painter.setBrush(m_color);
painter.drawRect(r);
painter.end();
}

Expand Down
61 changes: 51 additions & 10 deletions worldeditor/src/screens/propertyedit/editors/EnumEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@ QVariant EnumEdit::data() const {
void EnumEdit::setData(const QVariant &data) {
const QMetaObject *meta = m_qObject->metaObject();
int index = meta->indexOfProperty(qPrintable(m_propertyName));
QMetaProperty prop = meta->property(index);
if(index > -1) {
QMetaProperty prop = meta->property(index);

QString key = prop.enumerator().valueToKey(data.toInt());
index = ui->comboBox->findText(key);
} else {
QVariant variant = m_qObject->property(qPrintable(m_propertyName));
if(variant.isValid()) {
QMetaType type(variant.userType());

QByteArray typeName = type.name();
for(auto i = 0; i < meta->enumeratorCount(); i++) {
QMetaEnum qenum = meta->enumerator(i);
if(typeName.contains(qenum.enumName())) {
QString key = qenum.valueToKey(data.toInt());
index = ui->comboBox->findText(key);
break;
}
}
}
}

QString key = prop.enumerator().valueToKey(data.toInt());
index = ui->comboBox->findText(key);
if(index > -1) {
ui->comboBox->blockSignals(true);
ui->comboBox->setCurrentIndex(index);
Expand All @@ -40,14 +58,37 @@ void EnumEdit::setObject(QObject *object, const QString &name) {
ui->comboBox->clear();

const QMetaObject *meta = m_qObject->metaObject();
QMetaProperty prop = meta->property(meta->indexOfProperty(qPrintable(name)));

if(prop.isEnumType()) {
QStringList enums;
QMetaEnum qenum = prop.enumerator();
for(int i = 0; i < qenum.keyCount(); i++) {
enums << qenum.key(i);
int index = meta->indexOfProperty(qPrintable(name));
if(index > -1) {
QMetaProperty prop = meta->property(index);

if(prop.isEnumType()) {
QStringList enums;
QMetaEnum qenum = prop.enumerator();
for(int i = 0; i < qenum.keyCount(); i++) {
enums << qenum.key(i);
}
ui->comboBox->addItems(enums);
}
} else {
QVariant variant = m_qObject->property(qPrintable(name));
if(variant.isValid()) {
QMetaType type(variant.userType());

QByteArray typeName = type.name();
for(auto i = 0; i < meta->enumeratorCount(); i++) {
QMetaEnum qenum = meta->enumerator(i);
if(typeName.contains(qenum.enumName())) {
QStringList enums;
for(int i = 0; i < qenum.keyCount(); i++) {
enums << qenum.key(i);
}
ui->comboBox->addItems(enums);

break;
}
}
}
ui->comboBox->addItems(enums);
}
}
3 changes: 3 additions & 0 deletions worldeditor/src/screens/propertyedit/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ QWidget *Property::createEditor(QWidget *parent) const {
if(index > -1) {
QVariant data = m_propertyObject->property(qPrintable(objectName()));
type = data.userType();
if(QMetaType(type).flags() & QMetaType::IsEnumeration) {
type = -1;
}
}
}
}
Expand Down
20 changes: 7 additions & 13 deletions worldeditor/src/screens/propertyedit/propertymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,11 @@ void PropertyModel::addItem(QObject *propertyObject) {
propertyItem = new Property(name, static_cast<Property *>(m_rootItem), true);
propertyItem->setPropertyObject(propertyObject);

bool empty = true;
for(int i = 0; i < count; i++) {
QMetaProperty property = metaObject->property(i);

if(property.isUser(propertyObject)) { // Hide Qt specific properties
if(!QString(property.name()).toLower().contains("enable")) {
empty = false;

Property *p = new Property(property.name(), (propertyItem) ? propertyItem : static_cast<Property *>(m_rootItem), false);
p->setPropertyObject(propertyObject);

Expand All @@ -173,17 +170,17 @@ void PropertyModel::addItem(QObject *propertyObject) {
}
}
}

if(empty) {
delete propertyItem;
propertyItem = static_cast<Property *>(m_rootItem);
}
}

if(propertyItem) {
updateDynamicProperties(propertyItem, propertyObject);
}

if(propertyItem != m_rootItem && propertyItem->children().isEmpty()) {
delete propertyItem;
propertyItem = static_cast<Property *>(m_rootItem);
}

emit layoutAboutToBeChanged();
emit layoutChanged();
}
Expand All @@ -209,12 +206,9 @@ void PropertyModel::updateDynamicProperties(Property *parent, QObject *propertyO

Property *it = parent;

// Add properties left in the list
for(QByteArray &dynProp : dynamicProperties) {
QByteArrayList list = dynProp.split('/');

Property *s = it;
it = (list.size() > 1) ? static_cast<Property *>(m_rootItem) : it;
for(int i = 0; i < list.size(); i++) {
Property *p = nullptr;

Expand All @@ -224,7 +218,7 @@ void PropertyModel::updateDynamicProperties(Property *parent, QObject *propertyO
if(child) {
it = child;
} else {
p = new Property(path, it, true);
p = new Property(path, it, false);
p->setPropertyObject(propertyObject);
it = p;
}
Expand All @@ -234,7 +228,7 @@ void PropertyModel::updateDynamicProperties(Property *parent, QObject *propertyO
p->setProperty("__Dynamic", true);
}
}
it = s;
it = parent;
}
}

Expand Down
Loading