-
-
Save yossioo/669ba6f8e9b0b69a9cd1776659712461 to your computer and use it in GitHub Desktop.
Qt Auto Property Macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <QObject> | |
//See Gist Comment for description, usage, warnings and license information | |
#define AUTO_PROPERTY(TYPE, NAME) \ | |
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \ | |
public: \ | |
TYPE NAME() const { return a_ ## NAME ; } \ | |
void NAME(TYPE value) { \ | |
if (a_ ## NAME == value) return; \ | |
a_ ## NAME = value; \ | |
emit NAME ## Changed(value); \ | |
} \ | |
Q_SIGNAL void NAME ## Changed(TYPE value);\ | |
private: \ | |
TYPE a_ ## NAME; | |
#define READONLY_PROPERTY(TYPE, NAME) \ | |
Q_PROPERTY(TYPE NAME READ NAME CONSTANT ) \ | |
public: \ | |
TYPE NAME() const { return a_ ## NAME ; } \ | |
private: \ | |
void NAME(TYPE value) {a_ ## NAME = value; } \ | |
TYPE a_ ## NAME; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment