Last active
October 22, 2025 06:06
-
-
Save Rolias/48d453a0490d36090193 to your computer and use it in GitHub Desktop.
Revisions
-
Rolias revised this gist
Dec 4, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ } \ Q_SIGNAL void NAME ## Changed(TYPE value);\ private: \ TYPE a_ ## NAME; #define READONLY_PROPERTY(TYPE, NAME) \ Q_PROPERTY(TYPE NAME READ NAME CONSTANT ) \ -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #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: \ -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ #include <QObject> //See Gist Comment for description, usage, and warnings #define AUTO_PROPERTY(TYPE, NAME) \ Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \ public: \ TYPE NAME() const { return a_ ## NAME ; } \ -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ #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; -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 11 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,22 @@ #pragma once #include <QObject> //See Gist Comment for description, usage, and warnings #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 PROP_NAME() const { return a_ ## PROP_NAME ; } \ private: \ -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #pragma once #include <QObject> //See Gist Comment for description, usage, and warnings #define AUTO_PROPERTY(TYPE, PROP_NAME) \ \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME WRITE PROP_NAME NOTIFY PROP_NAME ## Changed ) \ -
Rolias revised this gist
Nov 5, 2014 . 1 changed file with 11 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,22 +5,20 @@ \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME WRITE PROP_NAME NOTIFY PROP_NAME ## Changed ) \ public: \ TYPE PROP_NAME() const { return a_ ## PROP_NAME ; } \ void PROP_NAME(TYPE value) { \ if (a_ ## PROP_NAME == value) return; \ a_ ## PROP_NAME = value; \ emit PROP_NAME ## Changed(value); \ } \ Q_SIGNAL void PROP_NAME ## Changed(TYPE value);\ private: \ TYPE a_ ## PROP_NAME{}; #define READONLY_PROPERTY(TYPE, PROP_NAME) \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME CONSTANT ) \ public: \ TYPE PROP_NAME() const { return a_ ## PROP_NAME ; } \ private: \ void PROP_NAME(TYPE value) {a_ ## PROP_NAME = value; } \ TYPE a_ ## PROP_NAME; -
Rolias revised this gist
Nov 4, 2014 . 1 changed file with 1 addition and 52 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,57 +1,6 @@ #pragma once #include <QObject> //See Comment for description, usage, and warnings #define AUTO_PROPERTY(TYPE, PROP_NAME) \ \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME WRITE PROP_NAME NOTIFY PROP_NAME ## Changed ) \ -
Rolias revised this gist
Nov 4, 2014 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,11 +10,11 @@ //passed type and name. In addition, it will create a standard getter named NAME, //setter named Name and signal named NAMEChanged(TYPE value) //It will also create the member data variable. //Note that the macro doesn't use the standard set prefix followed by a capitalized //first letter for the setter. I wasn't sure how to do this in a Macro and I prefer //having the same syntax for the getter and setter. //The member var is named with an a_ prefix (for auto) because it is intended //to remind the user to *NOT* use the member variable name directly. The user //should use the property name instead. If you don't like the a_ prefix simply change //the macro. // -
Rolias created this gist
Nov 4, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ #pragma once #include <QObject> //DESCRIPTION: //These macros are intended to reduce the amount of boilerplate code the //user has to write when using the Qt Q_PROPERTY feature. The idea was to //provide something similar to C#'s auto property feature. // //AUTO_PROPERTY(TYPE, NAME) will create a standard //Q_PROPERTY (TYPE, NAME READ NAME WRITE Name NOTIFY NAMEChanged) of the //passed type and name. In addition, it will create a standard getter named NAME, //setter named Name and signal named NAMEChanged(TYPE value) //It will also create the member data variable. //The macro could easily be changed to use setName for the setter but I prefer //this syntax. If you want a set prefix add set_ ## NAME in both the Q_PROPERTY //and function signature. //The member var is named with an a_ prefix (for auto) because it is intened //to remind the user to NOT use the member variable name directly. The user //should use the property name instead. If you don't like the a_ prefix simply change //the macro. // //READONLY_PROPERTY(TYPE, NAME) will create a standard //Q_PROPERTY( TYPE NAME READ NAME CONST) //It will create the getter and the member variable name. In this macro //the member variable again uses a_ but the user is expected to initialize this //variable directly. The variable shouldn't be upated. // All reads of the variable should be done through the property // //NOTE: Use these macros in the "private" section of your header only. //They use both public and private keywords and leave the header in the //private section. Putting these macros direcly under the Q_OBJECT macro //at the top of the class is acceptable. // //EXAMPLE USAGES: // AUTO_PROPERTY(QString, myProperty) // READONLY_PROPERTY(double, myValueProp) // //WARNING: Note that these macros are only intended to be used as shown. //The parameters are NOT intended to be expressions but simply the type and //name. The parameters aren't parenthesized in the body of the macro and the entire //macro is not parenthesized. Use responsibly. // // NOTE ON INITIALIZERS //If you uses these macros at the top of your class then the member variables //they create will be the first ones in your class and therefore to make tools //like lint happy you should add these variables to your initializer list in the //order they are declared and before any variables that come after these macros. //If you want to fully initialize variables in the order they are declared then //even AUTO variables will need to be accessed directly. There is no harm in doing //this. In general I was trying to adhere to the philosophy of the member variables //being hidden and only the property being used. If you have an initialization //order dependency on auto properties it might be a code smell and that variable //might be better off not being an auto property. #define AUTO_PROPERTY(TYPE, PROP_NAME) \ \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME WRITE PROP_NAME NOTIFY PROP_NAME ## Changed ) \ public: \ TYPE PROP_NAME() const { return a_ ## PROP_NAME ; } \ void PROP_NAME(TYPE value) \ { \ if (a_ ## PROP_NAME == value) \ return; \ a_ ## PROP_NAME = value; \ emit PROP_NAME ## Changed(value); \ } \ Q_SIGNAL void PROP_NAME ## Changed(TYPE value);\ private: \ TYPE a_ ## PROP_NAME{}; #define READONLY_PROPERTY(TYPE, PROP_NAME) \ Q_PROPERTY(TYPE PROP_NAME READ PROP_NAME CONSTANT ) \ public: \ TYPE PROP_NAME() const { return a_ ## PROP_NAME ; } \ private: \ void PROP_NAME(TYPE value) {a_ ## PROP_NAME = value; } \ TYPE a_ ## PROP_NAME;