Skip to content

Commit

Permalink
Applied trivial review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Jun 7, 2021
1 parent 5fe79da commit bc72b0c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 66 deletions.
61 changes: 25 additions & 36 deletions src/libtiled/customproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ namespace Tiled {
*/
struct CustomProp
{
CustomProp() : color(Qt::gray) {}
CustomProp()
: color(Qt::gray)
{}

CustomProp(QString name,
const QColor &color)
CustomProp(QString name, const QColor &color)
: name(std::move(name))
, color(color)
{}

CustomProp(const CustomProp &prop)
CustomProp(const CustomProp &prop)
{
name = prop.name;
color = prop.color;
Expand All @@ -64,43 +65,46 @@ struct CustomProp
~CustomProp()
{}


QString name;

QColor color;

QStringList values;

int currentIndex;

void addValue(const QString &name){
void addValue(const QString &name)
{
values << name;
validateValues();
}
void validateValues(){

void validateValues()
{
values.removeAll(QString());
values.removeDuplicates();
}

QString currentValue(){
QString currentValue()
{
if (currentIndex !=-1)
{return values.at(currentIndex);}
else {
return QString::fromUtf8("No value");
}
return values.at(currentIndex);

return QString::fromUtf8("No value");
}

void setValue(const QString&value){
void setValue(const QString &value)
{
currentIndex = values.indexOf(value);
}

void setIndex(int index){
void setIndex(int index)
{
if (index < values.size() && index >= -1)
currentIndex = index;
}

QVariantHash toVariant() const {
return QVariantHash {
QVariantHash toVariant() const
{
return {
{ QStringLiteral("name"), name },
{ QStringLiteral("values"), values },
{ QStringLiteral("color"), color },
Expand All @@ -111,32 +115,17 @@ struct CustomProp
{
const auto hash = variant.toHash();

auto read = [&] (const QString &prop) {
if (hash.contains(prop))
return hash.value(prop);

QString oldProp = prop.at(0).toUpper() + prop.mid(1);
return hash.value(oldProp);
};

const QVariant name = read(QStringLiteral("name"));
const QVariant values = read(QStringLiteral("values"));
const QVariant color= read(QStringLiteral("color"));

CustomProp cProp;

cProp.color = color.toString();
cProp.name = name.toString();
cProp.values = values.toStringList();
cProp.name = hash.value(QStringLiteral("name")).toString();
cProp.values = hash.value(QStringLiteral("values")).toStringList();
cProp.color = hash.value(QStringLiteral("color")).toString();

return cProp;
}
};

typedef QVector<CustomProp> CustomProps;


} // namespace Tiled


Q_DECLARE_METATYPE(Tiled::CustomProp);
2 changes: 0 additions & 2 deletions src/libtiled/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ void aggregateProperties(AggregatedProperties &aggregated, const Properties &pro
}
}


int customTypeId()
{
return qMetaTypeId<CustomProp>();
}


int filePathTypeId()
{
return qMetaTypeId<FilePath>();
Expand Down
10 changes: 3 additions & 7 deletions src/tiled/addpropertydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ AddPropertyDialog::AddPropertyDialog(QWidget *parent)
mUi->typeBox->addItem(typeToName(objectRefTypeId()), QVariant::fromValue(ObjectRef()));
mUi->typeBox->addItem(typeToName(QMetaType::QString), QString());


CustomProps customProps = Object::customProps();


for (const CustomProp cProp: customProps) {
for (const CustomProp &cProp: Object::customProps()) {
QVariant var;
var.setValue(cProp);
mUi->typeBox->addItem(cProp.name, var);
Expand All @@ -74,9 +70,9 @@ AddPropertyDialog::AddPropertyDialog(QWidget *parent)
mUi->typeBox->setCurrentText(session::propertyType);

connect(mUi->name, &QLineEdit::textChanged,
this, &AddPropertyDialog::nameChanged);
this, &AddPropertyDialog::nameChanged);
connect(mUi->typeBox, &QComboBox::currentTextChanged,
this, &AddPropertyDialog::typeChanged);
this, &AddPropertyDialog::typeChanged);
}

AddPropertyDialog::~AddPropertyDialog()
Expand Down
1 change: 0 additions & 1 deletion src/tiled/objecttypeseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ QtVariantProperty *ObjectTypesEditor::createProperty(int type,
QtVariantProperty *property = mVariantManager->addProperty(type, name);
if (!property) {
// fall back to string property for unsupported property types
qDebug() << "test";
property = mVariantManager->addProperty(QMetaType::QString, name);
}

Expand Down
7 changes: 1 addition & 6 deletions src/tiled/objecttypeseditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@
#include "properties.h"

#include <QDialog>
#include <QColorDialog>
#include <QCloseEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QPainter>
#include <QStyledItemDelegate>

namespace Ui {
class ObjectTypesEditor;
}
Expand Down
21 changes: 7 additions & 14 deletions src/tiled/variantpropertymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ int VariantPropertyManager::alignmentTypeId()
return qMetaTypeId<Qt::Alignment>();
}

int VariantPropertyManager::unstyledGroupTypeId()
int VariantPropertyManager::displayObjectRefTypeId()
{
return qMetaTypeId<UnstyledGroup>();
return qMetaTypeId<DisplayObjectRef>();
}

int VariantPropertyManager::displayObjectRefTypeId()
int VariantPropertyManager::unstyledGroupTypeId()
{
return qMetaTypeId<DisplayObjectRef>();
return qMetaTypeId<UnstyledGroup>();
}

QString VariantPropertyManager::objectRefLabel(const MapObject *object) const
Expand Down Expand Up @@ -202,17 +202,10 @@ QString VariantPropertyManager::valueText(const QtProperty *property) const
return tr("%1: Object not found").arg(QString::number(ref.id()));
}

if (typeId == filePathTypeId()) {
FilePath filePath = value.value<FilePath>();
QString fileName = filePath.url.fileName();
if (fileName.isEmpty()) {
QString path = filePath.url.toLocalFile();
if (path.endsWith(QLatin1Char('/')))
path.chop(1);
fileName = QFileInfo(path).fileName();
}
return fileName;
if (typeId == customTypeId()) {
// todo?
}

if (typeId == filePathTypeId()) {
FilePath filePath = value.value<FilePath>();
QString fileName = filePath.url.fileName();
Expand Down

0 comments on commit bc72b0c

Please sign in to comment.