Skip to content

Commit

Permalink
Merge pull request #4045 from bjorn/new-properties-framework
Browse files Browse the repository at this point in the history
New properties framework.
  • Loading branch information
bjorn authored Jan 12, 2025
2 parents dc71c70 + 544ae78 commit e51770c
Show file tree
Hide file tree
Showing 179 changed files with 7,668 additions and 23,418 deletions.
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ Icons from the Elementary icon theme (GPLv3)
* src/tiled/images/32/dialog-error.png
* src/tiled/images/32/dialog-warning.png

Icons from the GNOME project (CC0 1.0 Universal)
* src/tiled/resources/images/scalable/text-bold-symbolic.svg
* src/tiled/resources/images/scalable/text-italic-symbolic.svg
* src/tiled/resources/images/scalable/text-underline-symbolic.svg
* src/tiled/resources/images/scalable/text-strikethrough-symbolic.svg


Tilesets:

Expand Down
3 changes: 1 addition & 2 deletions src/libtiled/imagelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ ImageLayer *ImageLayer::initializeClone(ImageLayer *clone) const
clone->mImageSource = mImageSource;
clone->mTransparentColor = mTransparentColor;
clone->mImage = mImage;
clone->mRepeatX = mRepeatX;
clone->mRepeatY = mRepeatY;
clone->mRepetition = mRepetition;

return clone;
}
43 changes: 23 additions & 20 deletions src/libtiled/imagelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ namespace Tiled {
class TILEDSHARED_EXPORT ImageLayer : public Layer
{
public:
enum Repetition {
/**
* Makes the image repeat along the X axis.
*/
RepeatX = 0x1,

/**
* Makes the image repeat along the Y axis.
*/
RepeatY = 0x2,
};
Q_DECLARE_FLAGS(RepetitionFlags, Repetition)

ImageLayer(const QString &name, int x, int y);
~ImageLayer() override;

Expand Down Expand Up @@ -114,25 +127,13 @@ class TILEDSHARED_EXPORT ImageLayer : public Layer
*/
bool isEmpty() const override;

/**
* Returns true if the image of this layer repeats along the X axis.
*/
bool repeatX() const { return mRepeatX; }

/**
* Returns true if the image of this layer repeats along the Y axis.
*/
bool repeatY() const { return mRepeatY; }

/**
* Sets whether the image of this layer repeats along the X axis.
*/
void setRepeatX(bool repeatX) { mRepeatX = repeatX; }
bool repeatX() const { return mRepetition & RepeatX; }
bool repeatY() const { return mRepetition & RepeatY; }
RepetitionFlags repetition() const { return mRepetition; }

/**
* Sets whether the image of this layer repeats along the Y axis.
*/
void setRepeatY(bool repeatY) { mRepeatY = repeatY; }
void setRepeatX(bool repeatX) { mRepetition.setFlag(RepeatX, repeatX); }
void setRepeatY(bool repeatY) { mRepetition.setFlag(RepeatY, repeatY); }
void setRepetition(RepetitionFlags repetition) { mRepetition = repetition; }

ImageLayer *clone() const override;

Expand All @@ -143,8 +144,10 @@ class TILEDSHARED_EXPORT ImageLayer : public Layer
QUrl mImageSource;
QColor mTransparentColor;
QPixmap mImage;
bool mRepeatX = false;
bool mRepeatY = false;
RepetitionFlags mRepetition;
};

} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::ImageLayer::RepetitionFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::ImageLayer::RepetitionFlags)
12 changes: 10 additions & 2 deletions src/libtiled/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class TILEDSHARED_EXPORT Map : public Object
QString exportFormat;

enum Property {
TileWidthProperty,
TileHeightProperty,
TileSizeProperty,
InfiniteProperty,
HexSideLengthProperty,
StaggerAxisProperty,
Expand Down Expand Up @@ -212,6 +211,7 @@ class TILEDSHARED_EXPORT Map : public Object
void setTileHeight(int height);

QSize tileSize() const;
void setTileSize(QSize size);

bool infinite() const;
void setInfinite(bool infinite);
Expand Down Expand Up @@ -455,6 +455,12 @@ inline QSize Map::tileSize() const
return QSize(mParameters.tileWidth, mParameters.tileHeight);
}

inline void Map::setTileSize(QSize size)
{
mParameters.tileWidth = size.width();
mParameters.tileHeight = size.height();
}

inline bool Map::infinite() const
{
return mParameters.infinite;
Expand Down Expand Up @@ -791,3 +797,5 @@ Q_DECLARE_METATYPE(Tiled::Map*)
Q_DECLARE_METATYPE(Tiled::Map::Orientation)
Q_DECLARE_METATYPE(Tiled::Map::LayerDataFormat)
Q_DECLARE_METATYPE(Tiled::Map::RenderOrder)
Q_DECLARE_METATYPE(Tiled::Map::StaggerAxis)
Q_DECLARE_METATYPE(Tiled::Map::StaggerIndex)
41 changes: 28 additions & 13 deletions src/libtiled/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ Object::~Object()
delete mEditable;
}

const ClassPropertyType *Object::classType() const
{
QString objectClassName = className();
if (objectClassName.isEmpty() && typeId() == Object::MapObjectType) {
auto mapObject = static_cast<const MapObject*>(this);
objectClassName = mapObject->effectiveClassName();
}

return propertyTypes().findClassFor(objectClassName, *this);
}

/**
* Returns the value of the property \a name, taking into account that it may
* be inherited from another object or from the class.
Expand Down Expand Up @@ -78,32 +89,36 @@ QVariant Object::resolvedProperty(const QString &name) const
QVariantMap Object::resolvedProperties() const
{
QVariantMap allProperties;
Tiled::mergeProperties(allProperties, inheritedProperties());
return allProperties;
}

/**
* Computes the inherited properties for this object. This excludes the
* properties that are directly set on the object.
*/
QVariantMap Object::inheritedProperties() const
{
QVariantMap inheritedProperties;

// Insert properties into allProperties in the reverse order that
// Object::resolvedProperty searches them, to make sure that the
// same precedence is maintained.

QString objectClassName = className();
if (objectClassName.isEmpty() && typeId() == Object::MapObjectType) {
auto mapObject = static_cast<const MapObject*>(this);
objectClassName = mapObject->effectiveClassName();
}

if (auto type = propertyTypes().findClassFor(objectClassName, *this))
Tiled::mergeProperties(allProperties, type->members);
if (auto type = classType())
Tiled::mergeProperties(inheritedProperties, type->members);

if (typeId() == Object::MapObjectType) {
auto mapObject = static_cast<const MapObject*>(this);

if (const Tile *tile = mapObject->cell().tile())
Tiled::mergeProperties(allProperties, tile->properties());
Tiled::mergeProperties(inheritedProperties, tile->properties());

if (const MapObject *templateObject = mapObject->templateObject())
Tiled::mergeProperties(allProperties, templateObject->properties());
Tiled::mergeProperties(inheritedProperties, templateObject->properties());
}

Tiled::mergeProperties(allProperties, properties());

return allProperties;
return inheritedProperties;
}

bool Object::setProperty(const QStringList &path, const QVariant &value)
Expand Down
3 changes: 3 additions & 0 deletions src/libtiled/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class TILEDSHARED_EXPORT Object
const QString &className() const;
void setClassName(const QString &className);

const ClassPropertyType *classType() const;

/**
* Returns the properties of this object.
*/
Expand Down Expand Up @@ -111,6 +113,7 @@ class TILEDSHARED_EXPORT Object

QVariant resolvedProperty(const QString &name) const;
QVariantMap resolvedProperties() const;
QVariantMap inheritedProperties() const;

/**
* Returns the value of the object's \a name property, as a string.
Expand Down
1 change: 1 addition & 0 deletions src/libtiled/objectgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,4 @@ TILEDSHARED_EXPORT ObjectGroup::DrawOrder drawOrderFromString(const QString &);
} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::ObjectGroup*)
Q_DECLARE_METATYPE(Tiled::ObjectGroup::DrawOrder)
6 changes: 3 additions & 3 deletions src/libtiled/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ bool setPropertyMemberValue(Properties &properties,
Q_ASSERT(!path.isEmpty());

auto &topLevelName = path.first();
auto topLevelValue = properties.value(topLevelName);

if (path.size() > 1) {
auto topLevelValue = properties.value(topLevelName);
if (!setClassPropertyMemberValue(topLevelValue, 1, path, value))
return false;
properties.insert(topLevelName, topLevelValue);
} else {
topLevelValue = value;
properties.insert(topLevelName, value);
}

properties.insert(topLevelName, topLevelValue);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/libtiled/propertytype.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class TILEDSHARED_EXPORT ClassPropertyType final : public PropertyType
int usageFlags = AnyUsage;
bool memberValuesResolved = true;
bool drawFill = true;

ClassPropertyType(const QString &name) : PropertyType(PT_Class, name) {}

ExportValue toExportValue(const QVariant &value, const ExportContext &) const override;
Expand Down
4 changes: 4 additions & 0 deletions src/libtiled/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,5 +739,9 @@ inline void Tileset::setTransformationFlags(TransformationFlags flags)

Q_DECLARE_METATYPE(Tiled::Tileset*)
Q_DECLARE_METATYPE(Tiled::SharedTileset)
Q_DECLARE_METATYPE(Tiled::Tileset::Orientation)
Q_DECLARE_METATYPE(Tiled::Tileset::TileRenderSize)
Q_DECLARE_METATYPE(Tiled::Tileset::FillMode)
Q_DECLARE_METATYPE(Tiled::Tileset::TransformationFlags)

Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::Tileset::TransformationFlags)
3 changes: 2 additions & 1 deletion src/libtiled/wangset.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,6 @@ TILEDSHARED_EXPORT WangSet::Type wangSetTypeFromString(const QString &);

} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::WangSet*)
Q_DECLARE_METATYPE(Tiled::WangId)
Q_DECLARE_METATYPE(Tiled::WangSet*)
Q_DECLARE_METATYPE(Tiled::WangSet::Type)
93 changes: 0 additions & 93 deletions src/qtpropertybrowser/README.TXT

This file was deleted.

5 changes: 0 additions & 5 deletions src/qtpropertybrowser/common.pri

This file was deleted.

Loading

0 comments on commit e51770c

Please sign in to comment.