Page MenuHomePhorge

PROPERTY macro for applicationdomain types
Closed, ResolvedPublic

Description

To provide a little more type-safety and documentation than setPropert(QByteArray, QVariant) we should define properties in the applicationdomaintype instance with macros like this:
PROPERTY(QString, "subject")
EXTRACTED_PROPERTY(QString, "subject")
BLOB_PROPERTY("mimeMessage")

All properties generate:

static QByteArray $NameProperty();

A regular property will generate:

$type get$Name() const;
void set$Name(const $type &);

An extracted property will generate (to make clear that these properties should not be set by clients)

$type get$Name() const;
void setExtracted$Name(const $type &);

A blob property will generate:

QByteArray get$Name() const;
QString get$NamePath() const;
void set$NamePath(const QString &path);
void set$Name(const QByteArray &path);

Details

Ticket Type
Task

Event Timeline

mollekopf updated the task description. (Show Details)
mollekopf updated the task description. (Show Details)

Alternatively we could define properties with classes and use template wrappers like this:

struct SubjectProperty {
  static constexpr char name[] = "summary";
  typedef QString Type;
}
QString subject;
set<SubjectProperty>(subject);
subject = get<SubjectProperty>();

That ends up being more verbose (without additional macro magic), but the property definitions can be reused in other places, such as the property mapping.

Another alternative would be

Propert<QString> summary {"summary", this};

Mail mail;
mail.summary.set("foobar");
auto result = mail.summary.get();
mollekopf claimed this task.

Most likely candidate is: