Skip to content

Commit

Permalink
Focus the change on enums and improved UI
Browse files Browse the repository at this point in the history
* Removed unused "color" and "valueType" members of PropertyType
* Renamed 'Object Types Editor' to 'Enums Editor'
* Added a line edit for the enum name (can still be renamed in list as
  well)
* Show text on 'Add Enum' and 'Add Value' buttons
* Use QTreeViews instead of QTableViews
* Removed unnecessary splitter
* Apply a default name to new enums
  • Loading branch information
bjorn committed Jun 29, 2021
1 parent a04ad53 commit 795461a
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 280 deletions.
3 changes: 0 additions & 3 deletions examples/examples.tiled-project
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"objectTypesFile": "objecttypes.xml",
"propertyTypes": [
{
"color": "#a0a0a4",
"id": 1,
"name": "BodyType",
"values": [
Expand All @@ -19,7 +18,6 @@
]
},
{
"color": "#a0a0a4",
"id": 2,
"name": "EnemyType",
"values": [
Expand All @@ -29,7 +27,6 @@
]
},
{
"color": "#a0a0a4",
"id": 3,
"name": "State",
"values": [
Expand Down
8 changes: 8 additions & 0 deletions src/libtiled/containerhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ inline bool contains(const Container &container, Value value)
container.end(),
value) != container.end();
}

template<typename Container, typename Pred>
inline bool contains_where(const Container &container, Pred pred)
{
return std::find_if(container.begin(),
container.end(),
pred) != container.end();
}
2 changes: 0 additions & 2 deletions src/libtiled/propertytype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ QVariantHash PropertyType::toVariant() const
{ QStringLiteral("id"), id },
{ QStringLiteral("name"), name },
{ QStringLiteral("values"), values },
{ QStringLiteral("color"), color },
};
}

Expand All @@ -80,7 +79,6 @@ PropertyType PropertyType::fromVariant(const QVariant &variant)
propertyType.id = hash.value(QStringLiteral("id")).toInt();
propertyType.name = hash.value(QStringLiteral("name")).toString();
propertyType.values = hash.value(QStringLiteral("values")).toStringList();
propertyType.color = hash.value(QStringLiteral("color")).toString();

nextId = std::max(nextId, propertyType.id);

Expand Down
5 changes: 1 addition & 4 deletions src/libtiled/propertytype.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@
namespace Tiled {

/**
* Defines a custom property type.
* Defines a custom property type. Currently this includes only enums.
*/
class TILEDSHARED_EXPORT PropertyType
{
public:
int id = 0;
QString name;
QColor color = Qt::gray;
QStringList values;

int valueType = QMetaType::Int;

static int nextId;

QVariant wrap(const QVariant &value) const;
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
mShowObjectTypesEditor = new QAction(tr("Object Types Editor"), this);
mShowObjectTypesEditor->setCheckable(true);

mShowPropertyTypesEditor = new QAction(tr("Property Types Editor"), this);
mShowPropertyTypesEditor = new QAction(tr("Enums Editor"), this);
mShowPropertyTypesEditor->setCheckable(true);

mUi->menuView->insertAction(mUi->actionShowGrid, mViewsAndToolbarsAction);
Expand Down Expand Up @@ -2345,7 +2345,7 @@ void MainWindow::retranslateUi()
mResetToDefaultLayout->setText(tr("Reset to Default Layout"));
mLockLayout->setText(tr("Lock Layout"));
mShowObjectTypesEditor->setText(tr("Object Types Editor"));
mShowPropertyTypesEditor->setText(tr("Property Types Editor"));
mShowPropertyTypesEditor->setText(tr("Enums Editor"));
mActionHandler->retranslateUi();
CommandManager::instance()->retranslateUi();
}
Expand Down
13 changes: 13 additions & 0 deletions src/tiled/objecttypeseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@

namespace Tiled {

class ColorDelegate : public QStyledItemDelegate
{
public:
explicit ColorDelegate(QObject *parent = nullptr)
: QStyledItemDelegate(parent)
{ }

void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;

QSize sizeHint(const QStyleOptionViewItem &,
const QModelIndex &) const override;
};

void ColorDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
Expand Down
15 changes: 0 additions & 15 deletions src/tiled/objecttypeseditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ class QtVariantPropertyManager;

namespace Tiled {

class ColorDelegate : public QStyledItemDelegate
{
public:
explicit ColorDelegate(QObject *parent = nullptr)
: QStyledItemDelegate(parent)
{ }

void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;

QSize sizeHint(const QStyleOptionViewItem &,
const QModelIndex &) const override;
};


class ObjectTypesModel;

class ObjectTypesEditor : public QDialog
Expand Down
Loading

0 comments on commit 795461a

Please sign in to comment.